:root {
  --bg: #f4f6f9; --fg: #111; --muted: #4a4f57; --mine: #0b5cad; --mine-fg: #fff;
  --theirs: #fff; --theirs-fg: #111; --line: #d5dae1; --err: #b3261e;
  --surface: #fff; --field: #fff; --tip-bg: #fff8d6; --tip-line: #e6d98a; --tip-fg: #111;
  --banner-bg: #fdecea; --tab-bg: #e6ebf2; --link: #0b5cad; --placeholder: #6b717a;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1115; --fg: #eceff4; --muted: #b2b8c2; --mine: #2f6fd6; --mine-fg: #fff;
  --theirs: #1f232b; --theirs-fg: #eceff4; --line: #353b46; --err: #ff8a80;
  --surface: #171a20; --field: #22262e; --tip-bg: #2b2716; --tip-line: #5c5326; --tip-fg: #f3e9b8;
  --banner-bg: #3a1d1b; --tab-bg: #2a2f38; --link: #8ab4ff; --placeholder: #8d94a0;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 18px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; }
#app { height: 100%; height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
[hidden] { display: none !important; }
#loading { margin: auto; font-size: 24px; color: var(--muted); }
button { font: inherit; border: 0; border-radius: 14px; cursor: pointer; }
button.big { min-height: 52px; padding: 0 22px; background: var(--mine); color: var(--mine-fg); font-weight: 600; font-size: 18px; }
button.small { min-height: 44px; padding: 0 16px; background: var(--mine); color: var(--mine-fg); font-size: 17px; }
button.ghost { background: transparent; color: var(--link); text-decoration: underline; }
button:disabled { opacity: .5; }
.error { color: var(--err); font-size: 17px; }

#signin { padding: calc(32px + env(safe-area-inset-top)) 22px 22px; max-width: 520px; margin: 0 auto; width: 100%; }
#signin h1 { font-size: 28px; margin: 0 0 12px; }
#signin p { font-size: 18px; }
#si-form { display: flex; flex-direction: column; gap: 14px; }
#si-input { font: inherit; font-size: 17px; padding: 14px; border: 2px solid var(--line); border-radius: 14px; width: 100%; background: var(--field); color: var(--fg); }

#top { padding: calc(6px + env(safe-area-inset-top)) 56px 6px; padding-left: max(16px, env(safe-area-inset-left));
  position: relative; background: var(--surface); border-bottom: 1px solid var(--line); text-align: center; font-size: 17px; font-weight: 700; min-height: 44px; display: flex; flex-direction: column; justify-content: center; }
#tip { background: var(--tip-bg); color: var(--tip-fg); border-bottom: 1px solid var(--tip-line); padding: 10px 16px; font-size: 17px; }
#tip p { margin: 0 0 6px; }
.tip-actions { display: flex; gap: 10px; justify-content: flex-end; }
#banner { background: var(--banner-bg); padding: 10px 16px; text-align: center; }

#thread { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 10px;
  padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right));
  display: flex; flex-direction: column; gap: 2px; }
#empty { margin: auto; max-width: 340px; text-align: center; color: var(--muted); font-size: 19px; }

.msg { max-width: 80%; display: flex; flex-direction: column; }
.msg.first { margin-top: 8px; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }
.bubble { padding: 6px 11px; border-radius: 17px; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.3; }
.mine .bubble { background: var(--mine); color: var(--mine-fg); }
.theirs .bubble { background: var(--theirs); color: var(--theirs-fg); border: 1px solid var(--line); }
.main-text { font-size: 16px; }
.sub-text { font-size: 14px; opacity: .75; margin-top: 4px; padding-top: 4px; border-top: 1px solid currentColor; border-top-color: rgba(127,127,127,.4); }
.mine .sub-text { border-top-color: rgba(255,255,255,.35); }
.meta { font-size: 11px; color: var(--muted); opacity: .8; margin: 2px 6px 2px; }
.meta.err { color: var(--err); font-size: 13px; font-weight: 600; opacity: 1; }
.msg.failed { cursor: pointer; }
.msg.failed .bubble, .msg.sending .bubble { opacity: .6; }

#composer { display: flex; gap: 8px; align-items: flex-end; background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
#input { flex: 1; font: inherit; font-size: 16px; min-height: 40px; max-height: 40vh; padding: 9px 14px; resize: none; line-height: 1.3;
  border: 1px solid var(--line); border-radius: 20px; background: var(--field); color: var(--fg); }
#input:focus, #si-input:focus { outline: none; border-color: var(--mine); }

#si-step1, #si-step2 { display: flex; flex-direction: column; gap: 14px; }
.si-text { font-size: 19px; }
#si-names { display: flex; flex-direction: column; gap: 14px; }
#si-names button { min-height: 64px; font-size: 22px; }
#si-pin { font: inherit; font-size: 32px; letter-spacing: 12px; text-align: center; padding: 12px; border: 2px solid var(--line); border-radius: 14px; background: var(--field); color: var(--fg); }
#si-pin:focus { outline: none; border-color: var(--mine); }
#tabs { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
#tabs button { min-height: 44px; padding: 0 16px; font-size: 17px; background: var(--tab-bg); color: var(--fg); }
#tabs button.on { background: var(--mine); color: #fff; }
::placeholder { color: var(--placeholder); opacity: 1; }
.theme-btn { position: absolute; right: max(8px, env(safe-area-inset-right)); bottom: 6px; width: 48px; height: 48px;
  min-height: 0; padding: 0; border-radius: 24px; background: transparent; color: var(--fg); font-size: 24px; line-height: 48px; }
#signin { position: relative; }
#signin .theme-btn { top: calc(20px + env(safe-area-inset-top)); bottom: auto; right: 14px; }
#composer #send { min-height: 40px; padding: 0 16px; border-radius: 20px; font-size: 16px; }
#top .theme-btn { bottom: auto; top: calc(env(safe-area-inset-top) + 2px); width: 44px; height: 44px; line-height: 44px; font-size: 20px; }
#tabs { margin-top: 4px; } #tabs button { min-height: 32px; font-size: 15px; }
