:root {
  /* warm paper neutrals: coolors.co/palette/e7decd-efe8db-f4efe6-faf7f0-fbfaf8, buttons a step deeper so they stand out */
  --bg: #f4efe6; --surface: #fbfaf8; --surface-2: #faf7f0; --line: #e4dccc;
  --text: #3a3128; --muted: #857a6b; --accent: #d9cdb6; --accent-2: #efe8db; --on-accent: #3a3128; --accent-ink: #7d6b52;
  --danger: #b42318; --warn-bg: #fbecc8; --warn: #7a4a0e; --ok: #3f7d3a;
  --shadow: 0 10px 30px rgba(58, 49, 40, .1);
  color-scheme: light dark;
}
/* dark: the device's choice unless the home menu picked one (data-theme on <html>, set by js/i18n.js) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1916; --surface: #25221e; --surface-2: #2d2a25; --line: #3e3a33;
    --text: #f4efe6; --muted: #b3aa9b; --accent: #e7decd; --accent-2: #3f3a31; --on-accent: #2a251f; --accent-ink: #e7decd;
    --danger: #f08a7e; --warn-bg: #3b2c12; --warn: #f3c969; --ok: #8fc98a;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  --bg: #1b1916; --surface: #25221e; --surface-2: #2d2a25; --line: #3e3a33;
  --text: #f4efe6; --muted: #b3aa9b; --accent: #e7decd; --accent-2: #3f3a31; --on-accent: #2a251f; --accent-ink: #e7decd;
  --danger: #f08a7e; --warn-bg: #3b2c12; --warn: #f3c969; --ok: #8fc98a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
/* no double-tap zoom (taps respond at once); pinch zoom still works */
html { touch-action: manipulation; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}
body.busy { cursor: progress; }
body.busy .btn.primary { opacity: .6; pointer-events: none; }
body.nodb #createBtn, body.nodb #joinForm button { opacity: .5; pointer-events: none; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
code { font-size: .9em; }

/* ---------- buttons and fields ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 10px 16px; font-weight: 600; min-height: 44px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 14px; border-radius: 10px; position: relative; }
.btn:active { transform: scale(.98); }
.field {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 44px;
}
.field:focus, .codein:focus, #text:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.lbl { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 6px; }
.link { background: none; border: 0; color: var(--accent-ink); padding: 4px 0; font-weight: 600; }

/* ---------- home ---------- */
.home { max-width: 520px; margin: 0 auto; padding: max(20px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom)); }
.brand { display: flex; align-items: center; gap: 12px; margin: 8px 0 20px; }
.brand .logo { font-size: 30px; width: 52px; height: 52px; display: grid; place-items: center; background: var(--accent-2); border-radius: 16px; overflow: hidden; flex: none; border: 0; padding: 0; cursor: pointer; }
.brand .logo:active { transform: scale(.94); }
.brand h1 { font-size: 22px; }
.brand .tag { margin: 0; color: var(--muted); font-size: 14px; }
.me { margin-left: auto; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 14px 4px 6px; min-height: 44px; flex: none; }
.me .av { font-size: 22px; }
.me .burger { font-size: 18px; line-height: 1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 17px; margin-bottom: 10px; }
.card p { margin: 0 0 12px; }
.resume { border-color: var(--accent); }
.roomlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.roomrow { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.roomrow .txt, .merow .txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.encnote { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.encnote p { margin: 4px 0 0; }
.roomrow .txt { align-items: flex-start; gap: 3px; }
.roomrow .txt b { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roomrow small, .merow small { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roomrow .go { flex: none; color: var(--accent-ink); font-weight: 600; font-size: 14px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.pager .pg { color: var(--muted); font-size: 14px; }
.pager button:disabled { opacity: .4; }
.joinrow { display: flex; gap: 10px; }
.codein {
  flex: 1; min-width: 0; font: 600 24px/1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .25em; text-align: center;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 8px; min-height: 52px;
}
.codein::placeholder { font: 16px system-ui, sans-serif; letter-spacing: 0; }
.joinrow .btn { min-width: 88px; }
.features { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0 12px; }
.features div { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.features b { display: block; margin-bottom: 2px; }
.features span { font-size: 13px; color: var(--muted); }
.features .wide { grid-column: 1 / -1; }
.note { border-radius: 12px; padding: 10px 12px; margin: 0 0 14px; font-size: 14px; }
.note.warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- chat ---------- */
/* pinned to all four edges rather than a 100dvh height, which can come out short in an iPhone home-screen app */
.chat { position: fixed; inset: 0; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; background: var(--bg); }
.bar {
  display: flex; align-items: center; gap: 4px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.icon { background: none; border: 0; min-width: 44px; height: 44px; border-radius: 12px; font-size: 22px; display: grid; place-items: center; position: relative; }
.icon:active { background: var(--surface-2); }
.people { display: flex; gap: 3px; font-size: 15px; padding: 0 8px; }
.people .dot { position: absolute; top: 8px; right: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }
.ttl { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.ttl b { font-size: 16px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.codechip { border: 0; background: var(--accent-2); color: var(--accent-ink); font: 600 13px ui-monospace, Menlo, monospace; letter-spacing: .08em; border-radius: 999px; padding: 2px 10px; margin-top: 1px; }
.dmbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 6px 14px; background: var(--accent-2); font-size: 13px; }
.list { flex: 1; overflow-y: auto; padding: 12px 12px 4px; overscroll-behavior: contain; }
.indm .list { background: color-mix(in srgb, var(--accent-2) 45%, var(--bg)); }
.empty { color: var(--muted); text-align: center; margin: 30px 20px; font-size: 14px; }
.msg { display: flex; flex-direction: column; align-items: flex-start; margin-top: 12px; max-width: 86%; }
.msg.cont { margin-top: 3px; }
.msg.mine { margin-left: auto; align-items: flex-end; }
.who { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin: 0 4px 3px; }
.who .av { font-size: 18px; }
.who .nm { color: var(--text); font-weight: 600; }
.who time { font-size: 12px; }
.mine .who .av, .mine .who .nm { display: none; }
.bub {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 8px 13px;
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; cursor: pointer; user-select: text;
}
.mine .bub { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.bub a { color: inherit; text-decoration: underline; }
.re { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.re:empty { display: none; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 1px 8px; font-size: 13px; min-height: 26px; }
.chip.on { border-color: var(--accent); background: var(--accent-2); }
.chip.big { font-size: 24px; padding: 4px 10px; min-height: 46px; min-width: 46px; }
.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.composer.off { opacity: .5; pointer-events: none; }
#text {
  flex: 1; resize: none; font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 20px; padding: 9px 14px; min-height: 42px; max-height: 160px; line-height: 1.4;
}
.send { flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent); font-size: 18px; }

/* ---------- sheets ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(40, 28, 22, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  width: 100%; max-width: 520px; max-height: 88dvh; overflow-y: auto; background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: var(--shadow); animation: up .18s ease-out;
}
@media (min-width: 600px) { .overlay { align-items: center; } .sheet { border-radius: 20px; } }
.sheet h2 { font-size: 18px; margin-bottom: 10px; }
.sheet p { margin: 0 0 10px; }
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
@media (min-width: 600px) { .actions { flex-direction: row-reverse; flex-wrap: wrap; } .actions .btn { flex: 1; } }
.avatars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin: 10px 0; }
.avbtn { font-size: 24px; aspect-ratio: 1; border: 2px solid transparent; background: var(--surface-2); border-radius: 12px; padding: 0; }
.avbtn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-2); }
.seg { display: flex; flex-direction: column; gap: 6px; }
.seg button { text-align: left; border: 2px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.seg button[aria-checked="true"] { border-color: var(--accent); background: var(--accent-2); font-weight: 600; }
.share { text-align: center; }
.bigcode { font: 700 52px/1.1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .18em; margin: 4px 0 8px; color: var(--accent-ink); }
.linkrow { margin: 10px 0; }
.linkrow .field { font-size: 16px; text-align: center; } /* under 16px, iPhone zooms in when it gets focus */
.qr { width: 200px; height: 200px; margin: 6px auto 0; background: #fff; border-radius: 12px; padding: 6px; }
.qr svg { width: 100%; height: 100%; display: block; }
.plist { list-style: none; margin: 0; padding: 0; }
ul.plist li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
ul.plist li.away { opacity: .55; }
ul.plist .av { font-size: 26px; }
ul.plist .nm { flex: 1; min-width: 0; display: flex; flex-direction: column; }
ul.plist .nm b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
ul.plist small { color: var(--muted); }
.badge { position: absolute; top: -6px; right: -6px; background: var(--danger); color: #fff; font: 600 11px/18px system-ui; min-width: 18px; height: 18px; border-radius: 9px; font-style: normal; }
.quote { margin: 0 0 12px; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 8px; white-space: pre-wrap; word-break: break-word; color: var(--muted); }
.reactrow { display: flex; justify-content: space-between; gap: 6px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 0; right: 0; top: calc(64px + env(safe-area-inset-top)); z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 16px; }
.toast { background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow); max-width: 100%; transition: opacity .3s, transform .3s; }
.toast.out { opacity: 0; transform: translateY(-6px); }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); } }

/* ---------- emoji / GIF ---------- */
.tool { flex: none; width: 40px; height: 42px; border: 0; background: none; border-radius: 12px; font-size: 22px; padding: 0; }
.tool.giftool { font: 700 12px/1 system-ui, sans-serif; letter-spacing: .02em; }
.tool[aria-pressed="true"] { background: var(--accent-2); color: var(--accent-ink); }
.composer .tool + .tool { margin-left: -6px; }
.picker { background: var(--surface); border-top: 1px solid var(--line); height: min(300px, 42dvh); display: flex; flex-direction: column; padding: 8px 10px 0; }
.cats { display: flex; gap: 4px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.cats button { border: 0; background: none; font-size: 20px; width: 40px; height: 34px; border-radius: 10px; }
.cats button[aria-selected="true"] { background: var(--accent-2); }
.emojigrid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 2px; padding: 6px 0; }
.emo { border: 0; background: none; font-size: 26px; height: 42px; border-radius: 10px; padding: 0; }
.emo:active, .emo:hover { background: var(--surface-2); }
.gifq-in { min-height: 40px; }
.gifgrid { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; display: flex; align-items: flex-start; gap: 6px; padding: 8px 0; }
.gifgrid p { flex: 1; text-align: center; }
.gifcol { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.gifpick { display: block; width: 100%; border: 0; padding: 0; margin: 0; background: var(--surface-2); border-radius: 10px; overflow: hidden; }
.gifpick img { display: block; width: 100%; height: auto; }
.gifby { font-size: 11px; color: var(--muted); text-align: right; padding: 2px 2px 6px; }
.bub.gifbub { padding: 0; background: none; border: 0; overflow: hidden; border-radius: 14px; }
.mine .bub.gifbub { background: none; }
.bub.gifbub img { background: var(--surface-2); display: block; max-width: min(240px, 62vw); height: auto; border-radius: 14px; }
.quote.gifq img { display: block; max-width: 160px; height: auto; border-radius: 10px; }

/* ---------- saved records ---------- */
.reclist { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rec { width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; }
.rec small { color: var(--muted); }
.hmenu h3 { font-size: 15px; margin: 18px 0 8px; }
.hmenu .reclist { max-height: 40dvh; overflow-y: auto; }
.merow { width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.merow .av { font-size: 28px; }
.merow .chev { color: var(--muted); font-size: 20px; }
.ttl small { font-size: 12px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
.tab { flex: none; border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 4px 12px; font-size: 14px; }
.tab[aria-selected="true"] { border-color: var(--accent); background: var(--accent-2); color: var(--accent-ink); font-weight: 600; }
.bub.ro { cursor: default; }
.rofoot { margin: 0; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); text-align: center; font-size: 13px; color: var(--muted); background: var(--surface); border-top: 1px solid var(--line); }

/* pinned announcements: one line until opened */
.pins { background: var(--surface); border-bottom: 1px solid var(--line); font-size: 14px; }
.pins .pinhead { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; color: inherit; font: inherit; padding: 8px 14px; text-align: left; cursor: pointer; }
.pins .pinhead .one { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pins .pinhead .n { color: var(--muted); font-size: 12px; flex: none; }
.pins .pinhead .chev { color: var(--muted); flex: none; transition: transform .15s; }
.pins.open .pinhead .chev { transform: rotate(180deg); }
.pins ul { list-style: none; margin: 0; padding: 0 14px 8px; display: grid; gap: 6px; max-height: 40dvh; overflow-y: auto; }
.pins li { display: flex; align-items: flex-start; gap: 8px; background: var(--accent-2); border-radius: 10px; padding: 7px 10px; }
.pins li .go { flex: 1; min-width: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; padding: 0; white-space: pre-wrap; word-break: break-word; cursor: pointer; }
.pins li small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.pins li .unpin { flex: none; }
/* replies */
.rpq { display: block; max-width: 100%; border: 0; border-left: 3px solid var(--accent); background: var(--surface-2); color: var(--muted); font: inherit; font-size: 13px;
  text-align: left; border-radius: 8px; padding: 4px 9px; margin: 0 2px 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.rpq b { color: var(--text); font-weight: 600; }
.replybar { display: flex; align-items: center; gap: 8px; padding: 6px 10px 6px 14px; background: var(--surface); border-top: 1px solid var(--line); font-size: 13px; }
.replybar .rtxt { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); border-left: 3px solid var(--accent); padding-left: 8px; }
.replybar .rtxt b { color: var(--text); }
.icon.small { min-width: 32px; width: 32px; height: 32px; font-size: 14px; }
.msg.flash .bub { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }
/* a pinned GIF is a small thumbnail that never pushes the bar wider than the screen */
.pins li .go { overflow: hidden; }
.pins li .go img { display: block; max-width: 100%; max-height: 120px; width: auto; height: auto; border-radius: 8px; }
.pins ul { grid-template-columns: minmax(0, 1fr); overflow-x: hidden; }
.pins li { min-width: 0; }

/* opened from the home screen: a little extra room under the status bar (and clear of the blur band, should an
   older install still draw under it) */
@media (display-mode: standalone) {
  .home { padding-top: calc(env(safe-area-inset-top) + 20px); }
  .bar { padding-top: calc(env(safe-area-inset-top) + 14px); }
  .toasts { top: calc(76px + env(safe-area-inset-top)); }
  /* iOS reports no bottom inset here, so leave room for the home indicator ourselves, like Messenger does */
  .composer { padding-bottom: max(28px, calc(8px + env(safe-area-inset-bottom))); }
  body.typing .composer { padding-bottom: 8px; }
  .rofoot { padding-bottom: max(28px, calc(10px + env(safe-area-inset-bottom))); }
  .sheet { padding-bottom: max(32px, calc(16px + env(safe-area-inset-bottom))); }
}


/* language: the page is written in Traditional Chinese, so other languages stay hidden until js/i18n.js fills them in */
html.l10n body { visibility: hidden; }
.hmenu .merow + .merow { margin-top: 8px; }
.langs { display: flex; flex-direction: column; gap: 6px; }
.langs .btn[aria-checked="true"] { border-color: var(--accent); background: var(--accent-2); font-weight: 600; }
.brand .logo img { width: 100%; height: 100%; display: block; }
