:root {
      --viewport-height: 100vh;
      --brand: #35bfb6;
      --brand-dark: #1fa39f;
      --text: #20252d;
      --muted: #8a929e;
      --line: #e8edf2;
      --surface: #ffffff;
      --soft: #f5f7f9;
      --bubble: #f1f2f4;
      --self: #dff7f4;
      --danger: #d54a4a;
      --shadow: 0 20px 60px rgba(28, 40, 55, 0.14);
    }

    * {
      box-sizing: border-box;
    }

    html,
    body {
      width: 100%;
      height: 100%;
      overflow: hidden;
      margin: 0;
      color: var(--text);
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
      background: #fff;
    }

    body {
      display: grid;
      place-items: center;
      height: var(--viewport-height);
      min-height: 0;
      padding: 24px 20px;
    }

    body.wechat-browser-open,
    body.image-viewer-open {
      overflow: hidden;
    }

    .wechat-browser-overlay {
      position: fixed;
      z-index: 1100;
      inset: 0;
      padding: 112px 20px 32px;
      overflow-y: auto;
      color: #fff;
      background: rgba(22, 25, 34, 0.94);
      text-align: center;
      overscroll-behavior: contain;
    }

    .wechat-browser-overlay[hidden] {
      display: none;
    }

    .wechat-browser-arrow {
      position: absolute;
      top: calc(28px + env(safe-area-inset-top, 0px));
      right: 28px;
    }

    .wechat-browser-content {
      max-width: 560px;
      margin: 0 auto;
    }

    .wechat-browser-content h2 {
      margin: 0 0 22px;
      font-size: clamp(22px, 5.5vw, 32px);
      line-height: 1.5;
    }

    .wechat-browser-content p {
      margin: 0;
      color: rgba(255, 255, 255, 0.78);
      font-size: clamp(16px, 4vw, 22px);
      line-height: 2;
    }

    .wechat-browser-content strong {
      color: #fff;
    }

    .wechat-browser-menu {
      padding: 0 4px;
      letter-spacing: 5px;
    }

    .connection-loading-overlay,
    .language-loading-overlay {
      position: fixed;
      z-index: 900;
      inset: 0;
      display: grid;
      place-items: center;
      padding: 24px;
      background: rgba(255, 255, 255, 0.92);
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
      transition: opacity 220ms ease, visibility 220ms ease;
    }

    .connection-loading-overlay[hidden],
    .language-loading-overlay[hidden] {
      display: none;
    }

    .connection-loading-overlay.is-visible,
    .language-loading-overlay.is-visible {
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
    }

    .connection-loading-content,
    .language-loading-content {
      display: flex;
      flex-direction: column;
      align-items: center;
      min-width: 220px;
      color: var(--muted);
      text-align: center;
    }

    .connection-loading-spinner,
    .language-loading-spinner {
      width: 72px;
      height: 72px;
      margin-bottom: 24px;
      border: 4px solid rgba(53, 191, 182, 0.14);
      border-top-color: var(--brand);
      border-right-color: var(--brand-dark);
      border-bottom-color: transparent;
      border-radius: 50%;
      animation: languageSwitchSpin 900ms linear infinite;
    }

    .connection-loading-content strong,
    .language-loading-content strong {
      color: var(--brand-dark);
      font-size: 18px;
      line-height: 1.45;
    }

    .connection-loading-content span,
    .language-loading-content span {
      margin-top: 8px;
      color: var(--muted);
      font-size: 13px;
    }

    .connection-loading-overlay {
      z-index: 880;
      background: #fff;
    }

    .connection-loading-overlay.has-error .connection-loading-content strong {
      color: var(--text);
    }

    .connection-retry-button {
      min-width: 112px;
      height: 40px;
      margin-top: 24px;
      padding: 0 22px;
      border-radius: 6px;
      color: #fff;
      background: var(--brand);
      font-size: 14px;
      font-weight: 700;
      transition: background 160ms ease, transform 160ms ease;
    }

    .connection-retry-button:hover {
      background: var(--brand-dark);
      transform: translateY(-1px);
    }

    button,
    textarea,
    input {
      font: inherit;
    }

    button {
      border: 0;
      background: none;
      cursor: pointer;
    }

    .complaint-dialog {
      --complaint-padding: 24px;
      width: min(440px, calc(100vw - 40px));
      max-height: calc(var(--viewport-height) - 40px);
      max-height: min(calc(var(--viewport-height) - 40px), calc(100dvh - 40px));
      margin: auto;
      padding: 0;
      overflow: hidden;
      overscroll-behavior: contain;
      border: 0;
      border-radius: 16px;
      color: #222;
      background: #fff;
      box-shadow: 0 16px 56px rgba(0, 0, 0, 0.12);
    }

    .complaint-dialog form {
      display: flex;
      flex-direction: column;
      max-height: inherit;
      min-height: 0;
      margin: 0;
    }

    #complaintDialog {
      position: fixed;
      inset-block-start: var(--viewport-top, 0px);
      inset-block-end: calc(100% - var(--viewport-top, 0px) - var(--viewport-height));
      overflow: clip;
    }

    .complaint-header {
      flex: 0 0 auto;
      padding: var(--complaint-padding) var(--complaint-padding) 12px;
    }

    .complaint-body {
      flex: 1 1 auto;
      min-height: 0;
      padding: 4px var(--complaint-padding);
      overflow-y: auto;
      overscroll-behavior: contain;
      -webkit-overflow-scrolling: touch;
      overflow-wrap: anywhere;
    }

    .complaint-footer {
      flex: 0 0 auto;
      padding: 16px var(--complaint-padding) var(--complaint-padding);
    }

    .complaint-dialog[open] {
      animation: complaint-appear 160ms ease-out;
    }

    .complaint-dialog::backdrop {
      background: rgba(0, 0, 0, 0.52);
      animation: complaint-backdrop 160ms ease-out;
    }

    .complaint-dialog h2 {
      margin: 0 0 8px;
      color: #111;
      font-size: 22px;
      font-weight: 700;
      line-height: 1.4;
    }

    .complaint-hint {
      margin: 0;
      color: #999;
      font-size: 16px;
      line-height: 1.5;
    }

    .complaint-options {
      display: grid;
      gap: 10px;
      min-width: 0;
      margin: 0 0 16px;
      padding: 0;
      border: 0;
    }

    .complaint-options[hidden] {
      display: none;
    }

    .complaint-option {
      position: relative;
      display: block;
      cursor: pointer;
    }

    .complaint-option input {
      position: absolute;
      width: 1px;
      height: 1px;
      opacity: 0;
    }

    .complaint-option span {
      display: flex;
      align-items: center;
      min-height: 52px;
      padding: 12px 16px;
      border: 1px solid #e3e3e3;
      border-radius: 10px;
      font-size: 16px;
      line-height: 1.5;
      transition:
        border-color 140ms ease,
        background 140ms ease,
        color 140ms ease;
    }

    .complaint-option:hover span {
      border-color: var(--brand);
    }

    .complaint-option input:checked + span {
      border-color: var(--brand);
      color: var(--brand-dark);
      background: var(--soft);
      background: color-mix(in srgb, var(--brand) 8%, #fff);
      box-shadow: inset 0 0 0 1px var(--brand);
    }

    .complaint-option input:focus-visible + span,
    .complaint-dialog button:focus-visible,
    .complaint-description:focus-visible {
      outline: 2px solid var(--brand);
      outline-offset: 3px;
    }

    .complaint-description {
      display: block;
      width: 100%;
      min-height: 104px;
      padding: 12px;
      resize: vertical;
      border: 1px solid #e3e3e3;
      border-radius: 10px;
      color: #222;
      background: #fff;
      font-size: 16px;
      line-height: 1.5;
    }

    .complaint-description::placeholder {
      color: #aaa;
    }

    .complaint-feedback {
      margin: 0 0 10px;
      color: #c34836;
      font-size: 13px;
      line-height: 1.5;
    }

    .complaint-actions {
      display: flex;
      justify-content: flex-end;
      gap: 12px;
      margin-top: 0;
    }

    .complaint-actions button {
      min-height: 48px;
      padding: 10px 20px;
      border: 1px solid transparent;
      border-radius: 10px;
      font-size: 16px;
      line-height: 1.5;
      transition: background 140ms ease;
    }

    .complaint-actions .complaint-cancel {
      border-color: #ddd;
      color: #687284;
      background: #f7f7f7;
    }

    .complaint-cancel:hover {
      background: #eee;
    }

    .complaint-submit {
      color: #fff;
      background: var(--brand);
    }

    .complaint-submit:hover {
      background: var(--brand-dark);
    }

    @keyframes complaint-appear {
      from {
        opacity: 0;
        transform: translateY(6px) scale(0.98);
      }
      to {
        opacity: 1;
        transform: translateY(0) scale(1);
      }
    }

    @keyframes complaint-backdrop {
      from {
        opacity: 0;
      }
      to {
        opacity: 1;
      }
    }

    @media (max-width: 600px), (max-height: 500px) and (pointer: coarse) {
      .complaint-dialog {
        --complaint-padding: 16px;
        width: min(380px, calc(100% - 32px));
        max-height: calc(var(--viewport-height) - 48px);
        max-height: min(calc(var(--viewport-height) - 48px), 84dvh);
        border-radius: 12px;
      }

      .complaint-header {
        padding-bottom: 8px;
      }

      #complaintDialog {
        /* Reclaim vertical space when the keyboard shortens the viewport. */
        --complaint-vertical-padding: clamp(4px, calc((var(--viewport-height) - 200px) / 4), 16px);
        max-height: min(calc(var(--viewport-height) - 16px), max(240px, calc(var(--viewport-height) - 48px)));
        max-height: min(calc(var(--viewport-height) - 16px), max(240px, min(calc(var(--viewport-height) - 48px), 84dvh)));
      }

      #complaintDialog .complaint-header {
        padding-top: var(--complaint-vertical-padding);
        padding-bottom: min(8px, var(--complaint-vertical-padding));
      }

      .complaint-dialog h2 {
        margin-bottom: 4px;
        font-size: 18px;
      }

      .complaint-hint {
        font-size: 13px;
      }

      .complaint-options {
        gap: 8px;
        margin-bottom: 10px;
      }

      .complaint-option span {
        min-height: 44px;
        padding: 6px 9px;
        font-size: 14px;
      }

      .complaint-description {
        min-height: 76px;
        padding: 8px;
        line-height: 1.25;
      }

      .complaint-footer {
        padding-top: 8px;
        padding-bottom: 12px;
      }

      #complaintDialog .complaint-footer {
        padding-top: min(8px, var(--complaint-vertical-padding));
        padding-bottom: min(12px, var(--complaint-vertical-padding));
      }

      .complaint-actions {
        gap: 8px;
      }

      .complaint-actions button {
        min-height: 44px;
        padding: 6px 14px;
        font-size: 14px;
      }
    }

    @media (prefers-reduced-motion: reduce) {
      .complaint-dialog[open],
      .complaint-dialog::backdrop {
        animation: none;
      }
      .complaint-option span,
      .complaint-actions button {
        transition: none;
      }
    }

    .image-picker {
      margin-top: 12px;
    }
    .image-picker-heading {
      display: flex;
      align-items: baseline;
      margin-bottom: 8px;
      font-size: 14px;
      font-weight: 600;
    }
    .image-picker-heading span {
      color: #646b76;
      font-size: 12px;
      font-weight: 400;
    }
    .image-picker-count {
      margin-left: auto;
    }
    .image-picker-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(68px, 80px));
      gap: 10px;
    }
    .image-picker-preview,
    .image-picker-add {
      aspect-ratio: 1;
      border-radius: 10px;
    }
    .image-picker-preview {
      position: relative;
      overflow: hidden;
      background: #f3f5f7;
    }
    .image-picker-preview img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
    .image-picker-add {
      display: grid;
      place-content: center;
      gap: 3px;
      border: 1px dashed #b5bec9;
      background: #f8fafc;
      color: #465468;
      font: inherit;
      font-size: 12px;
      cursor: pointer;
    }
    .image-picker-add span {
      font-size: 23px;
      line-height: 1;
    }
    .image-picker-add:hover:not(:disabled) {
      border-color: var(--brand);
    }
    .image-picker-remove {
      position: absolute;
      top: 4px;
      right: 4px;
      display: grid;
      place-items: center;
      width: 28px;
      height: 28px;
      padding: 0;
      border: 0;
      border-radius: 50%;
      background: #1c2535d9;
      color: #fff;
      font-size: 20px;
      cursor: pointer;
    }
    .image-picker button:disabled {
      opacity: 0.55;
      cursor: default;
    }
    .image-picker-warning {
      margin: 6px 0 0;
      color: #a12b24;
      font-size: 12px;
    }

    .complaint-success {
      width: min(320px, calc(100% - 32px));
    }

    .complaint-success-content {
      align-items: center;
      gap: 14px;
      padding: var(--complaint-padding);
      overflow-y: auto;
      text-align: center;
    }

    .complaint-success-icon {
      display: grid;
      flex: none;
      width: 44px;
      height: 44px;
      place-items: center;
      border-radius: 50%;
      background: var(--soft);
      color: var(--brand-dark);
      font-size: 24px;
    }

    .chat-shell {
      width: min(1280px, calc(100vw - 32px));
      height: calc(var(--viewport-height) - 48px);
      max-height: 840px;
      min-height: 0;
      min-width: 0;
      overflow: hidden;
      display: grid;
      grid-template-rows: 64px minmax(0, 1fr) auto;
      background: var(--surface);
      border-radius: 14px;
      box-shadow: var(--shadow);
      animation: rise 360ms ease-out both;
    }

    .chat-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 22px 0 24px;
      color: #fff;
      /* background: linear-gradient(135deg, #55d6bd 0%, #24a6b3 100%); */
    }

    .brand-lockup,
    .header-actions {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .brand-mark {
      position: relative;
      width: 16px;
      height: 16px;
      flex: 0 0 auto;
    }

    .brand-mark::before,
    .brand-mark::after {
      position: absolute;
      content: "";
      border-radius: 999px 999px 999px 3px;
      transform: rotate(8deg);
    }

    .brand-mark::before {
      width: 13px;
      height: 8px;
      left: 1px;
      top: 2px;
      background: #fff;
    }

    .brand-mark::after {
      width: 8px;
      height: 6px;
      right: 0;
      bottom: 1px;
      background: #ffc13b;
    }

    .brand-mark.has-image {
      width: 28px;
      height: 28px;
      border-radius: 50%;
      background-position: center;
      background-size: cover;
    }

    .brand-mark.has-image::before,
    .brand-mark.has-image::after {
      display: none;
    }

    .brand-name {
      font-size: 17px;
      font-weight: 700;
      letter-spacing: 0;
    }

    .brand-lockup {
      min-width: 0;
    }

    .brand-name {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .service-presence {
      display: inline-flex;
      align-items: center;
      gap: 5px;
      flex-shrink: 0;
      font-size: 12px;
      white-space: nowrap;
    }

    .service-presence[hidden] {
      display: none;
    }

    .service-presence::before {
      content: "";
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: #d1d5db;
    }

    .service-presence.is-online::before {
      background: #86efac;
    }

    .header-actions {
      flex-shrink: 0;
    }

    .status-pill {
      display: inline-flex;
      align-items: center;
      gap: 7px;
      min-width: 92px;
      padding: 6px 10px;
      border-radius: 999px;
      color: rgba(255, 255, 255, 0.92);
      background: rgba(255, 255, 255, 0.16);
      font-size: 12px;
      white-space: nowrap;
    }

    .status-dot {
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: #f6c756;
      box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.12);
    }

    .status-dot.online {
      background: #d9fff4;
    }

    .status-dot.error {
      background: #ffb1a8;
    }

    .icon-button {
      width: 34px;
      height: 34px;
      display: inline-grid;
      place-items: center;
      border-radius: 50%;
      color: #fff;
      transition: background 160ms ease, transform 160ms ease;
    }

    .icon-button[hidden] {
      display: none;
    }

    .icon-button:hover {
      background: rgba(255, 255, 255, 0.16);
      transform: translateY(-1px);
    }

    .language-picker {
      position: relative;
      display: flex;
    }

    .language-menu {
      position: absolute;
      z-index: 60;
      top: calc(100% + 8px);
      right: 0;
      width: 190px;
      /* Keep a scrollable height in WebViews without svh/min() support. */
      max-height: 360px;
      max-height: calc(var(--viewport-height, 100vh) - 110px);
      max-height: min(360px, calc(var(--viewport-height, 100vh) - 110px));
      -webkit-overflow-scrolling: touch;
      touch-action: pan-y;
      overflow-x: hidden;
      overflow-y: auto;
      padding: 7px;
      border: 1px solid var(--line);
      border-radius: 12px;
      color: var(--text);
      background: #fff;
      box-shadow: 0 14px 36px rgba(28, 40, 55, 0.18);
      overscroll-behavior: contain;
      scrollbar-width: thin;
      animation: menuIn 140ms ease-out both;
    }

    .language-menu[hidden] {
      display: none;
    }

    .language-menu button {
      width: 100%;
      min-height: 38px;
      display: flex;
      align-items: center;
      padding: 0 10px;
      border-radius: 8px;
      color: var(--text);
      text-align: left;
      font-size: 13px;
      white-space: nowrap;
    }

    .language-menu button:hover,
    .language-menu button.active {
      color: var(--brand-dark);
      background: #eefaf8;
    }

    .chat-main {
      min-height: 0;
      min-width: 0;
      overflow-x: hidden;
      overflow-y: auto;
      overscroll-behavior-y: contain;
      -webkit-overflow-scrolling: touch;
      padding: 20px 24px 28px;
      scroll-behavior: smooth;
    }

    .message-row {
      display: flex;
      gap: 10px;
      align-items: flex-start;
      margin: 0 0 14px;
      animation: messageIn 180ms ease-out both;
    }

    .message-row.self {
      justify-content: flex-end;
    }

    .message-row.self .message-stack {
      display: flex;
      flex-direction: column;
      align-items: flex-end;
    }

    .avatar {
      width: 24px;
      height: 24px;
      margin-top: 4px;
      display: grid;
      place-items: center;
      flex: 0 0 auto;
      border-radius: 50%;
      color: #fff;
      background: linear-gradient(135deg, #52cfbf, #239fb0);
      font-size: 12px;
      font-weight: 700;
    }

    .message-stack {
      min-width: 0;
      max-width: min(78%, 460px);
    }

    .message-meta {
      margin: 0 0 5px 2px;
      color: var(--muted);
      font-size: 12px;
    }

    .message-row.self .message-meta {
      text-align: right;
      margin-right: 2px;
    }

    .read-status-text {
      margin: 5px 3px 0;
      color: var(--muted);
      font-size: 11px;
      line-height: 1;
      text-align: right;
    }

    .read-status-text.read {
      color: var(--brand-dark);
    }

    .bubble {
      width: fit-content;
      max-width: 100%;
      padding: 13px 16px;
      border-radius: 4px 18px 18px 18px;
      background: var(--bubble);
      color: #20252d;
      font-size: 14px;
      line-height: 1.7;
      white-space: pre-wrap;
      overflow-wrap: anywhere;
    }

    .message-row.self .bubble {
      margin-left: auto;
      border-radius: 18px 4px 18px 18px;
      background: var(--self);
    }

    .bubble img {
      max-width: 100%;
    }
    .bubble p {
      margin: 0;
    }

    .rich-message a:focus-visible {
      outline: 2px solid currentColor;
      outline-offset: 2px;
    }

    .rich-message img:not(.emojis-item) {
      display: block;
      max-width: 100%;
      height: auto;
      margin: 12px 0;
      border-radius: 6px;
      object-fit: contain;
    }

    /* Keep greeting typography in sync with the PC account settings editor. */
    .rich-message {
      line-height: 1.75;
    }

    .rich-message :is(p, h1, h2, h3, h4, h5, h6, blockquote, pre, ul, ol) {
      margin: 0 0 0.8em;
    }

    .rich-message h2 {
      font-size: 1.5em;
      line-height: 1.35;
    }

    .rich-message h3 {
      font-size: 1.22em;
      line-height: 1.4;
    }

    .rich-message blockquote {
      border-left: 3px solid var(--brand);
      background: #f6f8fa;
      color: #606875;
      padding: 8px 12px;
    }

    .rich-message :is(ul, ol) {
      padding-left: 2em;
    }

    .rich-message font[size="2"] { font-size: 13px; }
    .rich-message font[size="3"] { font-size: 16px; }
    .rich-message font[size="4"] { font-size: 18px; }
    .rich-message font[size="5"] { font-size: 24px; }
    .rich-message font[size="6"] { font-size: 32px; }

    .rich-message :is(pre, code) {
      border-radius: 4px;
      background: #f4f6f8;
      font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    }

    .rich-message pre {
      padding: 12px;
      white-space: pre-wrap;
    }

    .rich-message code {
      padding: 2px 4px;
    }

    .system-line {
      margin: 16px 0;
      text-align: center;
      color: var(--muted);
      font-size: 12px;
    }

    .chat-footer {
      padding: 0 20px 16px;
      background: var(--surface);
    }

    .quick-actions {
      display: flex;
      align-items: center;
      gap: 8px;
      min-height: 36px;
      margin-bottom: 8px;
      overflow-x: auto;
      max-width: 100%;
    }

    .quick-actions[hidden] {
      display: none;
    }

    .quick-action {
      flex: 0 0 auto;
      height: 30px;
      padding: 0 14px;
      border: 1px solid var(--line);
      border-radius: 999px;
      color: #20252d;
      background: #fff;
      font-size: 13px;
      white-space: nowrap;
      transition: border-color 160ms ease, color 160ms ease, transform 160ms ease;
    }

    .quick-action:hover:not(:disabled),
    .quick-action:focus-visible {
      border-color: var(--brand);
      color: var(--brand-dark);
      transform: translateY(-1px);
    }

    .quick-action:disabled {
      cursor: default;
      opacity: 0.5;
    }

    .composer {
      position: relative;
      display: grid;
      grid-template-rows: minmax(46px, auto) 34px;
      min-height: 140px;
      padding: 0 14px 10px;
      border: 1px solid var(--line);
      border-radius: 16px;
      box-shadow: 0 8px 26px rgba(28, 40, 55, 0.08);
      transition: border-color 160ms ease, box-shadow 160ms ease;
    }

    .composer:focus-within {
      border-color: rgba(53, 191, 182, 0.65);
      box-shadow: 0 10px 30px rgba(28, 40, 55, 0.12);
    }

    .file-input {
      display: none;
    }

    .message-editor {
      width: 100%;
      min-height: 46px;
      max-height: 120px;
      border: 0;
      outline: none;
      padding: 13px 0 7px;
      color: var(--text);
      background: transparent;
      line-height: 1.55;
      overflow-x: hidden;
      overflow-y: auto;
      white-space: pre-wrap;
      word-break: break-word;
    }

    .message-editor:empty::before {
      content: attr(data-placeholder);
      color: #a6adb6;
      pointer-events: none;
    }

    .message-editor[hidden], .voice-composer[hidden], .send-button[hidden] { display: none; }
    .voice-composer { display: grid; align-content: center; gap: 6px; padding: 10px 0; }
    .voice-record-button {
      width: 100%; min-height: 48px; padding: 10px 14px; border: 1px solid var(--line);
      border-radius: 10px; background: #f4f7f8; color: var(--text); font: inherit;
      touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
    }
    .voice-record-button.is-recording { background: #eefaf8; color: var(--brand-dark); border-color: var(--brand); }
    .voice-record-button.is-cancelling { background: #fff0f0; color: #c73540; border-color: #c73540; }
    .voice-record-button:disabled { opacity: .55; cursor: not-allowed; }
    .voice-record-button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
    .voice-record-hint { color: var(--muted); font-size: 12px; text-align: center; }

    .message-editor .emojis-item,
    .rich-message .emojis-item {
      width: 28px;
      height: 28px;
      object-fit: contain;
      vertical-align: -7px;
    }

    .composer-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
    }

    .tool-group {
      display: flex;
      align-items: center;
      gap: 4px;
    }

    .tool-button {
      width: 30px;
      height: 30px;
      display: inline-grid;
      place-items: center;
      border-radius: 8px;
      color: #222832;
      transition: background 160ms ease, color 160ms ease;
    }

    .tool-button:hover {
      color: var(--brand-dark);
      background: #eefaf8;
    }

    .tool-button.active {
      color: var(--brand-dark);
      background: #eefaf8;
    }

    .tool-image {
      display: block;
      width: 18px;
      height: 18px;
      object-fit: contain;
    }

    .emoji-popover {
      position: absolute;
      z-index: 20;
      left: 0;
      bottom: 42px;
      width: min(324px, calc(100vw - 40px));
      box-sizing: border-box;
      border: 1px solid #d8dde6;
      border-radius: 8px;
      background: #fff;
      box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
      padding: 12px;
    }

    .emoji-popover[hidden] {
      display: none;
    }

    .emoji-popover::after {
      position: absolute;
      left: 14px;
      bottom: -7px;
      width: 12px;
      height: 12px;
      border-right: 1px solid #d8dde6;
      border-bottom: 1px solid #d8dde6;
      background: #fff;
      content: "";
      transform: rotate(45deg);
    }

    .emoji-grid {
      display: flex;
      gap: 14px;
      max-width: 100%;
      overflow-x: auto;
      overflow-y: hidden;
      scroll-snap-type: x mandatory;
      scrollbar-width: thin;
      padding-bottom: 2px;
    }

    .emoji-page {
      display: grid;
      flex: 0 0 100%;
      grid-template-columns: repeat(6, 40px);
      grid-template-rows: repeat(3, 40px);
      justify-content: space-between;
      row-gap: 8px;
      scroll-snap-align: start;
    }

    .emoji-item {
      display: grid;
      width: 40px;
      height: 40px;
      place-items: center;
      border: 0;
      border-radius: 6px;
      background: transparent;
      cursor: pointer;
      padding: 0;
    }

    .emoji-item:hover {
      background: #f0f5ff;
    }

    .emoji-item img {
      display: block;
      width: 28px;
      height: 28px;
      object-fit: contain;
    }

    .image-preview {
      display: block;
      max-width: 100%;
      height: auto;
      max-height: 320px;
      border-radius: 8px;
      cursor: zoom-in;
      object-fit: contain;
    }

    .image-viewer {
      position: fixed;
      inset: 0;
      z-index: 1000;
      display: grid;
      place-items: center;
      padding: 48px 18px;
      box-sizing: border-box;
      background: rgba(8, 13, 24, 0.82);
      cursor: zoom-out;
    }

    .image-viewer[hidden] {
      display: none;
    }

    .image-viewer-img {
      display: block;
      max-width: min(96vw, 1180px);
      max-height: 90vh;
      border-radius: 10px;
      box-shadow: 0 20px 70px rgba(0, 0, 0, 0.35);
      object-fit: contain;
      cursor: default;
    }

    .image-viewer-close {
      position: absolute;
      top: 18px;
      right: 18px;
      width: 40px;
      height: 40px;
      display: grid;
      place-items: center;
      border-radius: 999px;
      color: #fff;
      background: rgba(255, 255, 255, 0.14);
      backdrop-filter: blur(8px);
      transition: background 160ms ease, transform 160ms ease;
      cursor: pointer;
    }

    .image-viewer-close:hover {
      background: rgba(255, 255, 255, 0.22);
      transform: scale(1.04);
    }

    .bubble.media-bubble,
    .bubble.card-bubble,
    .message-row.self .bubble.media-bubble,
    .message-row.self .bubble.card-bubble {
      padding: 0;
      background: transparent;
      max-width: 100%;
      overflow: hidden;
    }

    .message-video {
      display: block;
      width: min(260px, 62vw);
      max-height: 320px;
      border-radius: 8px;
      background: #111827;
    }

    .bubble.card-bubble,
    .message-row.self .bubble.card-bubble {
      border-radius: 12px;
      overflow: visible;
    }

    .message-card {
      display: flex;
      width: min(280px, 68vw);
      max-width: 100%;
      box-sizing: border-box;
      align-items: center;
      gap: 11px;
      border: 1px solid #e5e8ed;
      border-radius: 12px;
      background: #fff;
      color: #20252d;
      padding: 12px;
      text-decoration: none;
    }

    .message-card-icon {
      display: grid;
      width: 38px;
      height: 38px;
      place-items: center;
      flex: 0 0 auto;
      border-radius: 6px;
      background: #eef7f6;
      color: var(--brand-dark);
      font-size: 12px;
      font-weight: 700;
    }

    .message-card-main {
      display: grid;
      min-width: 0;
      gap: 3px;
    }

    .message-card-main strong,
    .message-card-main span {
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .message-card-main strong {
      font-size: 14px;
      white-space: nowrap;
    }

    .message-card-main span {
      color: var(--muted);
      font-size: 12px;
    }

    .bubble.voice-bubble { padding: 0; overflow: hidden; }
    .voice-message {
      display: flex; align-items: center; justify-content: space-between; gap: 24px;
      width: var(--voice-width, 112px); max-width: min(260px, 62vw); min-height: 46px;
      padding: 11px 15px; color: inherit; background: transparent; border-radius: inherit;
      font: inherit; cursor: pointer; touch-action: manipulation;
      -webkit-tap-highlight-color: transparent;
    }
    .message-row.self .voice-message { flex-direction: row-reverse; }
    .message-row.self .voice-waves { transform: rotate(180deg); }
    .voice-message:hover { background: rgba(0, 0, 0, .035); }
    .voice-message:focus-visible { outline: 2px solid var(--brand-dark); outline-offset: -3px; }
    .voice-waves { flex: 0 0 auto; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
    .voice-duration { font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }
    .voice-message.is-playing .voice-wave { animation: voiceWave 1.2s steps(1, end) infinite; }
    .voice-message.is-playing .voice-wave:nth-child(2) { animation-delay: .2s; }
    .voice-message.is-playing .voice-wave:nth-child(3) { animation-delay: .4s; }
    .voice-message.is-loading .voice-waves { opacity: .4; }
    .voice-message.is-error { color: #c73540; }
    .voice-playback-status { display: block; padding: 0 12px 8px; color: #c73540; font-size: 11px; }
    .voice-playback-status[hidden], .message-audio[hidden] { display: none; }
    @keyframes voiceWave { 0%, 65% { opacity: 1; } 66%, 100% { opacity: .2; } }
    @media (prefers-reduced-motion: reduce) {
      .voice-message.is-playing .voice-wave { animation: none; }
      .voice-message.is-playing { box-shadow: inset 0 0 0 2px var(--brand-dark); }
    }

    .address-card,
    .notice-card {
      display: grid;
      width: min(280px, 68vw);
      box-sizing: border-box;
      gap: 5px;
      overflow: hidden;
      border: 1px solid #e5e8ed;
      border-radius: 8px;
      background: #fff;
      padding: 12px;
    }

    a.address-card {
      color: inherit;
      cursor: pointer;
      text-decoration: none;
      transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
    }

    a.address-card:hover {
      border-color: var(--brand);
      box-shadow: 0 10px 26px rgba(28, 40, 55, 0.12);
      transform: translateY(-1px);
    }

    .address-card strong,
    .notice-card strong {
      font-size: 14px;
    }

    .address-card span,
    .notice-card span {
      color: var(--muted);
      font-size: 12px;
      line-height: 1.5;
    }

    .address-card img {
      width: 100%;
      height: 108px;
      margin-top: 5px;
      border-radius: 5px;
      object-fit: cover;
    }

    .notice-images {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      margin-top: 5px;
    }

    .notice-images img,
    .gift-image {
      width: 58px;
      height: 58px;
      border-radius: 5px;
      object-fit: contain;
    }

    .packet-card {
      border-color: #e99a38;
      background: #f4a340;
      color: #fff;
    }

    .packet-card.done {
      border-color: #edc692;
      background: #edc692;
    }

    .packet-card .message-card-icon {
      background: rgba(255, 255, 255, 0.2);
      color: #fff;
    }

    .packet-card .message-card-main span {
      color: rgba(255, 255, 255, 0.82);
    }

    .unknown-message {
      max-width: min(320px, 70vw);
      color: var(--muted);
      font-size: 12px;
      white-space: pre-wrap;
    }

    .send-button {
      min-width: 76px;
      height: 32px;
      padding: 0 16px;
      border-radius: 999px;
      color: #fff;
      background: var(--brand);
      font-size: 13px;
      font-weight: 700;
      transition: background 160ms ease, transform 160ms ease, opacity 160ms ease;
    }

    .send-button:hover {
      background: var(--brand-dark);
      transform: translateY(-1px);
    }

    .send-button:disabled {
      cursor: not-allowed;
      opacity: 0.48;
      transform: none;
    }

    .debug-panel {
      display: none;
      max-height: 170px;
      overflow: auto;
      margin-top: 10px;
      padding: 10px 12px;
      border-radius: 10px;
      color: #5d6570;
      background: #f7f9fb;
      font-family: Consolas, "SFMono-Regular", monospace;
      font-size: 12px;
      line-height: 1.55;
      white-space: pre-wrap;
    }

    .debug-panel.open {
      display: block;
    }

    @keyframes rise {
      from {
        opacity: 0;
        transform: translateY(14px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }

    @keyframes messageIn {
      from {
        opacity: 0;
        transform: translateY(6px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }

    @keyframes menuIn {
      from {
        opacity: 0;
        transform: translateY(-5px) scale(0.98);
      }
      to {
        opacity: 1;
        transform: translateY(0) scale(1);
      }
    }

    @keyframes languageSwitchSpin {
      to {
        transform: rotate(360deg);
      }
    }

    /* Keep embedded chat out of document flow: message growth and WebView
       document scrolling must never move the header or composer. */
    html.embedded-webview body {
      position: fixed;
      inset: 0;
      display: block;
      padding: 0;
    }

    html.embedded-webview .chat-shell {
      position: fixed;
      top: var(--viewport-top, 0px);
      left: 0;
      width: 100%;
      height: var(--viewport-height);
      max-height: none;
      min-height: 0;
      display: flex;
      flex-direction: column;
      border-radius: 0;
      box-shadow: none;
      animation: none;
    }

    html.embedded-webview .chat-header {
      flex: 0 0 64px;
    }

    html.embedded-webview .chat-main {
      flex: 1 1 0%;
    }

    html.embedded-webview .chat-footer {
      flex: 0 0 auto;
      padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    }

    @media (max-width: 720px) {
      body {
        position: fixed;
        inset: 0;
        display: block;
        padding: 0;
      }

      .chat-shell {
        position: fixed;
        top: var(--viewport-top, 0px);
        left: 0;
        width: 100%;
        height: var(--viewport-height);
        max-height: none;
        min-height: 0;
        display: flex;
        flex-direction: column;
        border-radius: 0;
        box-shadow: none;
        animation: none;
      }

      .chat-header {
        flex: 0 0 64px;
        padding: 0 14px 0 16px;
      }

      .status-pill {
        display: none;
      }

      .chat-main {
        flex: 1 1 0%;
        padding: 16px 14px 22px;
      }

      .message-stack {
        max-width: 82%;
      }

      .chat-footer {
        flex: 0 0 auto;
        padding: 0 12px 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
      }

      .quick-action {
        height: 29px;
        padding: 0 12px;
      }
    }

    .passive-call-overlay {
      position: fixed;
      inset: 0;
      z-index: 1200;
      display: grid;
      place-items: center;
      padding: 16px;
      background: rgba(8, 13, 24, 0.82);
    }

    .passive-call-overlay[hidden],
    .passive-call-overlay [hidden] { display: none !important; }

    .passive-call-stage {
      position: relative;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: min(420px, 100%);
      height: min(540px, calc(100svh - 32px));
      min-height: 280px;
      overflow: hidden;
      border-radius: 20px;
      color: #fff;
      background: #182d36;
      box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
    }

    .passive-call-identity {
      z-index: 1;
      display: grid;
      place-items: center;
      width: 88px;
      height: 88px;
      margin-bottom: 24px;
      border-radius: 50%;
      background: var(--brand);
      font-size: 32px;
      font-weight: 700;
    }

    .passive-call-summary {
      z-index: 1;
      display: grid;
      max-width: calc(100% - 32px);
      gap: 10px;
      text-align: center;
      overflow-wrap: anywhere;
    }

    #passiveCallAvatar { display: grid; place-items: center; width: 100%; height: 100%; border-radius: inherit; overflow: hidden; }

    .passive-call-summary strong { font-size: 23px; }
    .passive-call-summary span { color: #d5e2e6; font-size: 14px; font-variant-numeric: tabular-nums; }
    .passive-call-remote { position: absolute; inset: 0; }
    .passive-call-local { position: absolute; top: 16px; right: 16px; width: 25%; height: 28%; overflow: hidden; border-radius: 10px; background: #253d48; }
    .is-video .passive-call-stage { width: min(860px, 100%); height: min(640px, calc(100svh - 32px)); }
    .is-video .passive-call-summary { position: absolute; top: 20px; left: 20px; max-width: 58%; text-align: left; text-shadow: 0 1px 6px #000; }

    .passive-call-controls {
      position: absolute;
      z-index: 2;
      bottom: 28px;
      left: 20px;
      right: 20px;
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: 16px;
    }

    .passive-call-controls button,
    .passive-call-playback {
      min-height: 60px;
      padding: 14px 20px;
      border-radius: 34px;
      color: #fff;
      background: #40545f;
      font-size: 16px;
      font-weight: 600;
      line-height: 1.4;
      cursor: pointer;
      touch-action: manipulation;
    }

    .passive-call-controls button { flex: 0 1 calc((100% - 16px) / 2); min-width: 0; max-width: 148px; }
    .passive-call-controls .passive-call-danger,
    .passive-call-controls .passive-call-accept { min-height: 68px; font-size: 18px; }
    .passive-call-controls .passive-call-danger { background: #de454c; }
    .passive-call-controls .passive-call-accept { background: #168f6c; }
    .passive-call-controls button[aria-pressed="true"] { background: #5d3946; }
    .passive-call-overlay button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
    .passive-call-playback { position: absolute; z-index: 3; bottom: 196px; max-width: calc(100% - 24px); }

    @media (max-height: 480px) {
      .passive-call-stage { justify-content: flex-start; padding-top: 24px; }
      .passive-call-identity { display: none; }
      .passive-call-controls { bottom: 16px; }
    }

    .not-found-overlay {
      position: fixed;
      z-index: 950;
      inset: 0;
      display: grid;
      place-items: center;
      padding: 24px;
      background: #fff;
    }

    .not-found-overlay[hidden] {
      display: none;
    }

    .not-found-content {
      display: flex;
      flex-direction: column;
      align-items: center;
      max-width: 100%;
      /* max-width: 420px; */
      color: var(--text);
      text-align: center;
      animation: rise 360ms ease-out both;
    }

    .not-found-code {
      font-size: clamp(72px, 16vw, 112px);
      font-weight: 800;
      line-height: 1;
      letter-spacing: 0.04em;
      color: var(--brand);
      text-shadow: 0 18px 44px rgba(53, 191, 182, 0.24);
    }

    .not-found-title {
      margin-top: 18px;
      color: var(--text);
      font-size: 22px;
      line-height: 1.4;
    }

    .not-found-detail {
      margin: 12px 0 0;
      color: var(--muted);
      font-size: 14px;
      line-height: 1.7;
    }

    .not-found-button {
      min-width: 132px;
      height: 42px;
      margin-top: 28px;
      padding: 0 24px;
      border-radius: 8px;
      color: #fff;
      background: var(--brand);
      font-size: 15px;
      font-weight: 700;
      transition: background 160ms ease, transform 160ms ease;
    }

    .not-found-button:hover {
      background: var(--brand-dark);
      transform: translateY(-1px);
    }

    body.not-found-open {
      overflow: hidden;
    }
