@layer components {
  /* The phone simulator: an iPhone. Before a call, the Phone keypad; during one, the USSD alert over the phone pad keyboard. */
  .phone { max-width: 32rem; }
  .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .device { position: relative; margin: 0 auto; max-width: 30rem; padding: 9px; border-radius: 44px; background: #1b2320; box-shadow: inset 0 0 0 1.5px #3a4641, inset 0 0 0 4px #141a18, 0 1px 2px rgb(var(--shade) / .1), 0 18px 40px rgb(var(--shade) / .16); }
  .device::before, .device::after { content: ""; position: absolute; width: 3px; border-radius: 2px; background: #2c3632; }
  .device::before { left: -3px; top: 96px; height: 52px; box-shadow: 0 64px 0 #2c3632; }
  .device::after { right: -3px; top: 132px; height: 72px; }
  .device-screen { position: relative; display: flex; flex-direction: column; height: clamp(50rem, 62vh, 60rem); overflow: hidden; border-radius: 36px; background: var(--phone-app-bg); color: var(--phone-ink); font-family: var(--phone-font); -webkit-font-smoothing: antialiased; }
  .device-status { position: relative; z-index: 3; display: flex; align-items: center; justify-content: space-between; height: 34px; padding: 0 20px 0 26px; font-size: 13px; font-weight: 600; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
  .device-island { position: absolute; left: 50%; top: 9px; width: 74px; height: 21px; margin-left: -37px; border-radius: 999px; background: #000; }
  .device-signal { display: flex; align-items: center; gap: 5px; }
  .device-signal .status-cellular { width: 17px; height: 17px; }
  .device-signal .status-battery { width: 25px; height: 25px; margin-right: -2px; }
  .device-body { position: relative; isolation: isolate; flex: 1; display: flex; flex-direction: column; min-height: 0; }
  .device-home { position: absolute; left: 50%; bottom: 7px; z-index: 4; width: 108px; height: 4px; margin-left: -54px; border-radius: 999px; background: var(--phone-ink); }

  /* The Phone app keypad: round keys, letters under the digits, a green call key. */
  .dialer { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; min-height: 0; padding: 0 0 34px; }
  .dialer.is-behind { pointer-events: none; }
  .dialer.is-behind .phone-note { visibility: hidden; }
  .dialer-display { flex: 1; display: grid; align-content: center; justify-items: center; gap: 6px; min-height: 0; padding: 0 20px; text-align: center; }
  .dialer-number { min-height: 38px; max-width: 100%; overflow: hidden; font-size: 32px; font-weight: 400; letter-spacing: .02em; white-space: nowrap; text-overflow: ellipsis; }
  .phone-note { max-width: 24ch; margin: 0; font-size: 13px; line-height: 1.35; color: var(--phone-muted); }
  .phone-note.is-error { color: #ff3b30; }
  .dialer > .phone-note { margin: auto; }
  .dial-pad { display: grid; grid-template-columns: repeat(3, 62px); grid-auto-rows: 62px; justify-content: center; gap: 12px 20px; }
  .dial-key { display: grid; place-content: center; justify-items: center; border: 0; border-radius: 50%; background: var(--phone-dial-key); color: var(--phone-ink); font: inherit; line-height: 1; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background-color .15s ease; }
  .dial-key:active { background: var(--phone-dial-key-press); transition: none; }
  .dial-key:disabled { cursor: default; }
  .dial-digit { font-size: 28px; font-weight: 400; font-variant-numeric: tabular-nums; }
  .dial-letters { margin-top: 1px; font-size: 8px; font-weight: 700; letter-spacing: .2em; padding-left: .2em; }
  .dial-key.is-symbol .dial-digit { font-size: 32px; font-weight: 300; }
  .dial-key[aria-label="*"] .dial-digit { transform: translateY(9px); font-size: 52px; font-weight: 300; }
  .call-key { display: grid; place-items: center; border: 0; border-radius: 50%; background: #34c759; color: #fff; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .call-key .icon { width: 28px; height: 28px; }
  .call-key:active { filter: brightness(.9); }
  .call-key:disabled { cursor: default; }
  .dial-delete { display: grid; place-items: center; border: 0; background: transparent; color: var(--phone-dial-key-press); cursor: pointer; }
  .dial-delete .icon { width: 26px; height: 26px; color: var(--phone-muted); }
  .dial-delete[hidden] { display: grid !important; visibility: hidden; }

  /* During a session: iOS dims the app and shows the USSD message as an alert. */
  .ussd-stage { position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center; padding: 12px 12px 0; background: var(--phone-dim); }
  .device-screen:has(.keypad) .ussd-stage { bottom: var(--keyboard-height); }
  .ussd-dialog { position: relative; width: min(100%, 222px); overflow: hidden; border-radius: 13px; background: var(--phone-alert); backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6); }
  .ussd-message { padding: 16px 14px 14px; text-align: center; }
  .phone-text { max-height: 15rem; margin: 0; overflow: auto; font-size: 13px; line-height: 1.33; color: var(--phone-ink); white-space: pre-wrap; overflow-wrap: anywhere; }
  .ussd-detail { max-height: 8rem; margin: 8px 0 0; padding: 6px 8px; overflow: auto; border-radius: 6px; background: var(--error-soft); color: var(--error-ink); font-family: var(--mono); font-size: 10px; line-height: 1.4; text-align: left; white-space: pre-wrap; }
  .ussd-reply { margin-top: 12px; }
  .ussd-input { box-sizing: border-box; width: 100%; height: 26px; padding: 0 6px; border: .5px solid var(--phone-field-line); border-radius: 6px; background: var(--phone-field); color: var(--phone-ink); font: inherit; font-size: 13px; caret-color: var(--phone-link); }
  .ussd-input:focus { outline: none; }
  .ussd-input::placeholder { color: var(--phone-muted); }
  .ussd-buttons { display: grid; grid-template-columns: 1fr 1fr; border-top: .5px solid var(--phone-alert-line); }
  .ussd-buttons.is-single { grid-template-columns: 1fr; }
  .ussd-buttons > * + * { border-left: .5px solid var(--phone-alert-line); }
  .ussd-buttons .button_to { display: block; }
  .ussd-button { width: 100%; height: 42px; border: 0; background: transparent; color: var(--phone-link); font: inherit; font-size: 16px; font-weight: 400; cursor: pointer; }
  .ussd-button.is-primary { font-weight: 600; }
  .ussd-button:active { background: var(--phone-alert-press); }
  .ussd-progress { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; gap: 8px; margin: 0; background: var(--phone-veil); font-size: 13px; color: var(--phone-muted); }
  turbo-frame#simulator[busy] .ussd-progress { display: flex; }
  .ussd-spinner { width: 16px; height: 16px; border: 2px solid var(--phone-spinner-track); border-top-color: var(--phone-muted); border-radius: 50%; animation: ussd-spin .8s linear infinite; }
  @keyframes ussd-spin { to { transform: rotate(360deg); } }

  /* The phone pad keyboard: white keys on grey, +*# and delete without key caps. */
  .device-screen { --keyboard-height: 222px; }
  .keypad { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; height: var(--keyboard-height); padding: 6px 6px 30px; background: var(--phone-keypad); }
  .keypad-layer { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(4, 1fr); gap: 6px; height: 100%; }
  .phone-key { display: grid; place-content: center; justify-items: center; border: 0; border-radius: 5px; background: var(--phone-key); color: var(--phone-key-ink); font: inherit; line-height: 1; cursor: pointer; box-shadow: 0 1px 0 var(--phone-key-shadow); -webkit-tap-highlight-color: transparent; }
  .key-digit { font-size: 22px; font-weight: 400; font-variant-numeric: tabular-nums; }
  .key-digit.is-small { font-size: 16px; letter-spacing: .04em; }
  .key-letters { min-height: 9px; font-size: 8px; font-weight: 600; letter-spacing: .18em; padding-left: .18em; }
  .phone-key.is-symbol .key-digit { font-size: 26px; }
  .phone-key:active { background: var(--phone-key-press); }
  .phone-key.is-function { background: transparent; box-shadow: none; }
  .phone-key.is-function:active { background: var(--phone-key); }
  .phone-key .icon { width: 24px; height: 24px; }
  .phone-key:focus-visible, .dial-key:focus-visible, .call-key:focus-visible, .ussd-button:focus-visible { outline: 2px solid var(--phone-link); outline-offset: 1px; }
  .keypad-gap { display: block; }

  .phone-status { display: flex; align-items: center; justify-content: center; gap: .8rem; margin: 1.2rem 0 0; font-size: 1.25rem; color: var(--ink-2); }
  .phone-state { display: inline-flex; align-items: center; gap: .5rem; }
  .phone-state::before { content: ""; width: .7rem; height: .7rem; border-radius: 50%; background: #2fb567; box-shadow: 0 0 0 3px rgba(47, 181, 103, .18); }
  .phone-state.is-ended::before { background: var(--ink-3); box-shadow: none; }
  .phone-status code { font-size: 1.15rem; }
  @media (prefers-reduced-motion: reduce) { .ussd-spinner { animation: none; } }

  .receipt { margin-top: 1.6rem; padding: 1.2rem 1.4rem 1.4rem; border: 1px solid var(--line); border-radius: var(--r-card); background: var(--surface); }
  .receipt-title { margin: 0 0 .6rem; font-size: 1.35rem; font-weight: 650; }
  .trace { position: relative; list-style: none; margin: 0; padding: 0; font-size: 1.3rem; }
  .trace li { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .8rem; padding: .5rem 0 .5rem 2rem; }
  .trace li::before { content: ""; position: absolute; left: .4rem; top: 1.25rem; width: .7rem; height: .7rem; border-radius: 50%; background: var(--surface); box-shadow: 0 0 0 1.5px var(--ink-3); }
  .trace li:not(:last-child)::after { content: ""; position: absolute; left: .75rem; top: 2rem; bottom: -.5rem; width: 1px; background: var(--line-strong); }
  .trace li:last-child::before { background: #2fb567; box-shadow: 0 0 0 1.5px #2fb567; }
  .trace-input { min-width: 3.2rem; padding: 0 .6rem; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: var(--r-control); background: var(--surface); font-family: var(--mono); font-size: 1.2rem; font-weight: 600; text-align: center; }
  .trace-screen { font-family: var(--mono); font-size: 1.2rem; }
  .trace-call { flex-basis: 100%; font-family: var(--mono); font-size: 1.1rem; color: var(--ink-3); overflow-wrap: anywhere; }

  /* A WhatsApp flow's phone: a chat, drawn from the messages the Cloud API would be sent. */
  .device-screen.is-chat { background: var(--chat-bg); color: var(--chat-ink); font-size: 13.2px; line-height: 17.6px; }
  .is-chat .device-status { background: var(--chat-head); }
  .chat-head { display: flex; align-items: center; gap: 7px; padding: 7px 8px; background: var(--chat-head); }
  .chat-head .icon { width: 20px; height: 20px; color: var(--chat-ink); }
  .chat-leave { display: grid; place-items: center; padding: 0; border: 0; background: transparent; color: var(--chat-ink); cursor: pointer; }
  .chat-leave .icon { width: 22px; height: 22px; }
  .chat-avatar { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--input); color: #fff; font-size: 14px; font-weight: 600; letter-spacing: .02em; }
  .chat-who { flex: 1; display: grid; min-width: 0; line-height: 1.25; }
  .chat-name { overflow: hidden; font-size: 15px; font-weight: 500; letter-spacing: .1px; white-space: nowrap; text-overflow: ellipsis; }
  .chat-sub { font-size: 11.5px; color: var(--chat-muted); }
  /* The tools a real chat carries; none of them can act on a simulated one, so they are dimmed. */
  .chat-tools { display: flex; gap: 13px; margin-left: 2px; color: var(--chat-ink); opacity: .45; }
  .chat-tools .icon { width: 19px; height: 19px; }
  .chat-log { flex: 1; display: flex; flex-direction: column; gap: 2px; min-height: 0; padding: 12px 6% 8px; overflow-y: auto; overscroll-behavior: contain; }
  /* The wallpaper: line doodles tiled behind the messages, drawn on the body so it neither scrolls nor anchors a sheet. */
  .is-chat .device-body::before { content: ""; position: absolute; inset: 0; z-index: -1; background-image: url("/assets/chat-doodles-39697f05.svg"); background-size: 420px; opacity: var(--chat-doodle); pointer-events: none; }
  :root:not([data-theme="dark"]) .is-chat .device-body::before { filter: invert(1); }
  @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .is-chat .device-body::before { filter: none; } }
  :root[data-theme="dark"] .is-chat .device-body::before { filter: none; }
  .chat-day { align-self: center; margin: 4px 0 10px; padding: 4px 11px; border-radius: 8px; background: var(--chat-note); color: var(--chat-muted); font-size: 11.5px; box-shadow: 0 1px .5px rgb(var(--phone-shade) / .13); }
  .chat-note { align-self: center; max-width: 76%; margin: 0 0 10px; padding: 5px 11px; border-radius: 8px; background: var(--chat-note); color: var(--chat-muted); font-size: 11.5px; line-height: 1.4; text-align: center; box-shadow: 0 1px .5px rgb(var(--phone-shade) / .13); }
  .chat-error { align-self: stretch; margin: 0; padding: 8px; border-radius: 7px; background: var(--chat-in); font-family: var(--mono); font-size: 11px; white-space: pre-wrap; overflow-wrap: anywhere; }

  .bubble { position: relative; max-width: 80%; margin: 0; padding: 6px 7px 8px 9px; border-radius: 7.5px; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 1px .5px rgb(var(--phone-shade) / .13); }
  .bubble.is-in { align-self: flex-start; background: var(--chat-in); }
  .bubble.is-out { align-self: flex-end; background: var(--chat-out); }
  .bubble.is-first { margin-top: 8px; }
  .bubble.is-first.is-in { border-top-left-radius: 0; }
  .bubble.is-first.is-out { border-top-right-radius: 0; }
  /* The tail the first message of a run carries, curved as WhatsApp curves it. */
  .bubble.is-first::before { content: ""; position: absolute; top: 0; width: 8px; height: 13px; }
  .bubble.is-first.is-in::before { left: -8px; background: var(--chat-in); clip-path: path("M8 0L0 0C4 0 8 4 8 13Z"); }
  .bubble.is-first.is-out::before { right: -8px; background: var(--chat-out); clip-path: path("M0 0L8 0C4 0 0 4 0 13Z"); }
  .bubble.is-refused { box-shadow: inset 3px 0 0 var(--chat-refused), 0 1px .5px rgb(var(--phone-shade) / .13); }
  .bubble-meta { float: right; display: inline-flex; align-items: center; gap: 3px; margin: 5px 0 -3px 8px; font-size: 10.5px; color: var(--chat-muted); white-space: nowrap; }
  .bubble-ticks { display: inline-grid; color: var(--chat-tick); }
  .bubble-ticks .icon { width: 14px; height: 14px; }
  .bubble.has-actions { padding-bottom: 6px; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
  .bubble-actions { display: grid; align-self: flex-start; width: 80%; }
  .bubble-action { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 8px; border: 0; border-top: 1px solid var(--chat-line); background: var(--chat-in); color: var(--chat-action); font: inherit; font-size: 13.2px; text-align: center; box-shadow: 0 1px .5px rgb(var(--phone-shade) / .13); cursor: pointer; }
  .bubble-action:last-child { border-radius: 0 0 7.5px 7.5px; }
  .bubble-action:disabled { color: var(--chat-muted); cursor: default; }
  .bubble-action .icon { width: 14px; height: 14px; margin-right: 5px; vertical-align: -2px; }

  .chat-list, .chat-form { align-self: flex-start; width: 80%; }
  .chat-list > summary, .chat-form > summary { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 8px; border-top: 1px solid var(--chat-line); border-radius: 0 0 7.5px 7.5px; background: var(--chat-in); color: var(--chat-action); font-weight: 400; white-space: normal; list-style: none; cursor: pointer; box-shadow: 0 1px .5px rgb(var(--phone-shade) / .13); }
  .chat-list > summary::-webkit-details-marker, .chat-form > summary::-webkit-details-marker { display: none; }
  .chat-list > summary .icon, .chat-form > summary .icon { width: 16px; height: 16px; }
  .chat-list:not(.is-live) > summary, .chat-form:not(.is-live) > summary { color: var(--chat-muted); cursor: default; pointer-events: none; }
  /* Open, the summary is the dim behind the sheet, which covers the screen rather than the bubble it came from. */
  .chat-list[open] > summary, .chat-form[open] > summary { position: absolute; inset: 0; z-index: 4; margin: 0; padding: 0; border: 0; border-radius: 0; background: rgb(0 0 0 / .35); color: transparent; box-shadow: none; }
  .chat-sheet { position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; max-height: 80%; overflow-y: auto; padding: 6px 0 26px; border-radius: 12px 12px 0 0; background: var(--chat-sheet); color: var(--chat-ink); white-space: normal; }
  .chat-sheet-head { margin: 0; padding: 8px 14px 10px; border-bottom: .5px solid var(--chat-line); font-size: 15px; font-weight: 600; text-align: center; }
  .chat-sheet-rows { margin: 0; padding: 0 0 0 16px; list-style: none; }
  .chat-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 16px 9px 0; border: 0; border-bottom: .5px solid var(--chat-line); background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
  .chat-row-text { flex: 1; display: grid; gap: 1px; }
  .chat-row-title { font-size: 13.4px; }
  .chat-row-description { font-size: 12.5px; line-height: 1.3; color: var(--chat-muted); }
  .chat-row::after { content: ""; flex: none; width: 19px; height: 19px; border: 1.5px solid var(--chat-muted); border-radius: 50%; box-sizing: border-box; }
  .chat-row:hover::after, .chat-row:focus-visible::after { border: 5.5px solid var(--chat-accent); }
  .chat-row.is-page .chat-row-title { color: var(--chat-action); font-weight: 500; }

  /* A form WhatsApp opens on its own screen, drawn here so a draft can be filled in before Meta holds one. */
  .bubble-answers { display: block; margin-top: 6px; padding-top: 6px; border-top: .5px solid rgb(var(--phone-shade) / .18); font-size: 12.5px; line-height: 1.5; opacity: .85; }
  .bubble-answer { display: block; }
  .form-sheet { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; overflow-y: auto; border-radius: 12px 12px 0 0; background: var(--chat-sheet); color: var(--chat-ink); white-space: normal; }
  .form-head { margin: 0; padding: 12px 14px; border-bottom: .5px solid var(--chat-line); font-size: 15px; font-weight: 600; text-align: center; }
  .form-lock { display: block; font-size: 11px; font-weight: 400; color: var(--chat-muted); }
  .form-body { flex: 1; display: grid; align-content: start; gap: 14px; padding: 14px 16px; }
  .form-field { display: grid; gap: 5px; }
  .form-label { font-size: 12.5px; color: var(--chat-muted); }
  .form-required { color: var(--chat-refused); }
  .form-input { min-height: 34px; padding: 7px 10px; border: .5px solid var(--chat-line); border-radius: 6px; background: var(--chat-field); color: var(--chat-ink); font: inherit; font-size: 14.5px; }
  .form-choices { display: grid; gap: 8px; }
  .form-choice { display: flex; align-items: center; gap: 9px; font-size: 14.5px; }
  .form-choice input { accent-color: var(--chat-accent); width: 17px; height: 17px; }
  .form-submit { margin: 0 16px; padding: 11px; border: 0; border-radius: 22px; background: var(--chat-accent); color: #fff; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; }
  .form-note { margin: 8px 16px 26px; font-size: 11px; color: var(--chat-muted); text-align: center; }

  .chat-composer { display: flex; align-items: center; gap: 8px; padding: 6px 8px 26px; background: var(--chat-bar); }
  .chat-write { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; padding: 0 12px; border-radius: 21px; background: var(--chat-field); }
  .chat-write .icon { flex: none; width: 20px; height: 20px; color: var(--chat-muted); opacity: .8; }
  .chat-field { flex: 1; min-width: 0; height: 40px; padding: 0; border: 0; background: transparent; color: var(--chat-ink); font: inherit; font-size: 13.2px; }
  .chat-field:focus { outline: none; }
  .chat-field::placeholder { color: var(--chat-muted); }
  .chat-send { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--chat-accent); color: #fff; cursor: pointer; }
  .chat-send .icon { width: 21px; height: 21px; }
  .bubble-action:focus-visible, .chat-send:focus-visible, .chat-row:focus-visible, .chat-list > summary:focus-visible, .chat-form > summary:focus-visible, .form-submit:focus-visible { outline: 2px solid var(--chat-action); outline-offset: -2px; }
}
