/* MattChat web app. Colours and layout follow the remote-v2 home website. */
:root {
  color-scheme: light;
  --bg: #fbf8f3;
  --surface: #ffffff;
  --surface-2: #f3efe8;
  --line: #e4ded3;
  --text: #1d1b18;
  --text-2: #5c5850;
  --text-3: #8a857b;
  --say: #2a78d6;
  --say-ink: #1d5fae;
  --say-tint: #e3eefb;
  --sign: #d95926;
  --sign-ink: #b4461a;
  --sign-tint: #fce9df;
  --good: #1f8a4c;
  --danger: #c23a3a;
  --shadow: 0 1px 2px rgba(40,30,10,.06), 0 2px 8px rgba(40,30,10,.05);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141413; --surface: #1f1e1c; --surface-2: #2a2926; --line: #3a3834;
    --text: #f4f2ec; --text-2: #c3c0b6; --text-3: #8f8b81;
    --say: #3987e5; --say-ink: #8fbcf3; --say-tint: #1c2c42;
    --sign: #e0703f; --sign-ink: #f2a882; --sign-tint: #3d2418;
    --good: #4cc27c; --danger: #ec6b6b;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141413; --surface: #1f1e1c; --surface-2: #2a2926; --line: #3a3834;
  --text: #f4f2ec; --text-2: #c3c0b6; --text-3: #8f8b81;
  --say: #3987e5; --say-ink: #8fbcf3; --say-tint: #1c2c42;
  --sign: #e0703f; --sign-ink: #f2a882; --sign-tint: #3d2418;
  --good: #4cc27c; --danger: #ec6b6b;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px; }

/* ---------- header */
header.top {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.top-row { display: flex; align-items: center; gap: 12px; padding: 12px 0 8px; }
.top-row h1 { font-size: 20px; margin: 0; line-height: 1.15; }
.top-row .age { color: var(--text-2); font-size: 13px; }
.sync { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 12px; font-weight: 600;
  color: var(--sign-ink); background: var(--sign-tint); border: 0; border-radius: 999px; padding: 3px 10px; cursor: pointer; }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.sync.ok { color: var(--say-ink); background: var(--say-tint); }
.top-row .spacer { flex: 1; }
.total { text-align: right; }
.total b { font-size: 26px; font-variant-numeric: tabular-nums; display: block; line-height: 1; }
.total span { font-size: 12px; color: var(--text-2); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }

.controls { padding: 0 0 10px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.mode { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); background: var(--surface-2); border-radius: 12px; padding: 4px; }
.mode button {
  border: 0; background: transparent; padding: 9px 8px; border-radius: 9px; font-weight: 600;
  color: var(--text-2); display: flex; gap: 6px; justify-content: center; align-items: center;
}
.mode button.on[data-mode="say"]  { background: var(--say);  color: #fff; }
.mode button.on[data-mode="sign"] { background: var(--sign); color: #fff; }
.search-row { display: flex; gap: 8px; }
.search {
  flex: 1; min-width: 0; padding: 10px 12px 10px 36px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238a857b' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l3.5 3.5'/%3E%3C/svg%3E") no-repeat 12px center;
}
.search:focus { outline: 2px solid var(--say); outline-offset: -1px; }
.filter { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 0 10px; }
.cat-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.cat-chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 5px 11px; font-size: 13px; color: var(--text-2); white-space: nowrap;
}

/* ---------- word grid */
section.cat { margin: 18px 0 6px; scroll-margin-top: 210px; }
.cat-head {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none;
  padding: 4px 0 8px; text-align: left;
}
.cat-head h2 { font-size: 15px; margin: 0; flex: 1; }
.cat-head .count { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.cat-head .bar { width: 64px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.cat-head .bar i { display: block; height: 100%; background: var(--say); border-radius: 3px; }
.cat-head .chev { transition: transform .15s; color: var(--text-3); }
section.cat.collapsed .chev { transform: rotate(-90deg); }
section.cat.collapsed .grid { display: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.tile {
  position: relative; min-height: 54px; padding: 8px 8px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); text-align: center;
  font-size: 15px; line-height: 1.2; display: flex; align-items: center; justify-content: center;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
  transition: transform .08s;
  overflow-wrap: anywhere;
}
.tile:active { transform: scale(.96); }
.tile.said { background: var(--say-tint); border-color: var(--say); color: var(--say-ink); font-weight: 600; }
.tile.signed:not(.said) { background: var(--sign-tint); border-color: var(--sign); color: var(--sign-ink); font-weight: 600; }
.tile .marks { position: absolute; left: 0; right: 0; bottom: 4px; display: flex; justify-content: center; gap: 6px; font-size: 11px; font-weight: 600; }
.tile .marks .s { color: var(--say-ink); }
.tile .marks .g { color: var(--sign-ink); }
.tile.pop { animation: pop .45s ease; }
@keyframes pop { 0%{transform:scale(1)} 30%{transform:scale(1.08)} 100%{transform:scale(1)} }
.empty { color: var(--text-2); text-align: center; padding: 30px 0; }
.add-suggest { margin: 12px auto; display: block; }

/* ---------- generic */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 14px; font-weight: 600;
}
a.btn { text-decoration: none; display: inline-block; color: var(--text); }
.btn.primary { background: var(--say); border-color: var(--say); color: #fff; }
.btn.sign { background: var(--sign); border-color: var(--sign); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
label.f { display: grid; gap: 4px; font-size: 14px; color: var(--text-2); }
label.f input, label.f select { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 16px; }
.muted { color: var(--text-2); }
.tiny { font-size: 12px; color: var(--text-3); }
h3 { font-size: 16px; margin: 0 0 10px; }

/* ---------- bottom nav */
nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  border: 0; background: none; padding: 8px 0 10px; display: grid; justify-items: center; gap: 2px;
  font-size: 12px; color: var(--text-3); font-weight: 600;
}
nav.tabs button svg { width: 24px; height: 24px; }
nav.tabs button.on { color: var(--say); }

/* ---------- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #1d1b18; color: #fff; border-radius: 14px; padding: 10px 10px 10px 16px; z-index: 50;
  display: flex; align-items: center; gap: 12px; width: min(92vw, 440px);
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
:root[data-theme="dark"] .toast { background: #f4f2ec; color: #1d1b18; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toast { background: #f4f2ec; color: #1d1b18; } }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast .msg { flex: 1; min-width: 0; }
.toast .msg b { display: block; }
.toast .msg small { opacity: .75; }
.toast.first { background: var(--good) !important; color: #fff !important; }
.toast button { border: 0; background: rgba(255,255,255,.18); color: inherit; padding: 8px 12px; border-radius: 10px; font-weight: 700; }
.toast:not(.first) button { background: rgba(127,127,127,.25); }

/* ---------- sheet (word details / settings) */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 700px) { .scrim { align-items: center; } .sheet { border-radius: 20px; } }
.sheet-head { display: flex; align-items: start; gap: 10px; margin-bottom: 12px; }
.sheet-head > div:first-child { flex: 1; min-width: 0; }
.sheet-head h2 { margin: 0; font-size: 24px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 16px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fact { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.fact .k { font-size: 12px; color: var(--text-2); }
.fact .v { font-weight: 600; }

/* ---------- log */
.day-head { font-size: 13px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; margin: 20px 0 6px; }
.ev { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 6px; }
.ev .time { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 13px; width: 62px; flex: none; }
.ev .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.ev .w { flex: 1; min-width: 0; font-weight: 600; }
.ev .w small { display: block; font-weight: 400; color: var(--text-3); font-size: 12px; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.badge.say { background: var(--say-tint); color: var(--say-ink); }
.badge.sign { background: var(--sign-tint); color: var(--sign-ink); }
.badge.new { background: var(--good); color: #fff; }
.ev .del { border: 0; background: none; color: var(--text-3); width: 32px; height: 32px; border-radius: 8px; font-size: 18px; }
.ev .del:hover { color: var(--danger); background: var(--surface-2); }

/* ---------- progress */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 16px 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat .k { font-size: 13px; color: var(--text-2); }
.stat .v { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .d { font-size: 12px; color: var(--text-3); }
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-wrap .grid-line { stroke: var(--line); stroke-width: 1; }
.chart-wrap .axis-label { fill: var(--text-3); font-size: 11px; }
.chart-wrap .series { stroke: var(--say); stroke-width: 2; fill: none; stroke-linejoin: round; }
.chart-wrap .area { fill: var(--say); opacity: .08; }
.chart-wrap .pt { fill: var(--say); stroke: var(--surface); stroke-width: 2; }
.chart-wrap .xhair { stroke: var(--text-3); stroke-width: 1; }
.tip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; font-size: 13px; box-shadow: var(--shadow); white-space: nowrap; z-index: 2;
}
.tip strong { font-size: 15px; }
.catrow { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.catrow:last-child { border-bottom: 0; }
.catrow .bar { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; display: flex; gap: 2px; }
.catrow .bar i { display: block; height: 100%; }
.catrow .bar i.s { background: var(--say); border-radius: 4px 0 0 4px; }
.catrow .bar i.g { background: var(--sign); }
.catrow .bar i:last-child { border-radius: 0 4px 4px 0; }
.catrow .bar i:only-child { border-radius: 4px; }
.newest { display: flex; flex-wrap: wrap; gap: 6px; }
.newest span { background: var(--say-tint); color: var(--say-ink); padding: 4px 10px; border-radius: 999px; font-size: 14px; font-weight: 600; }
.newest span.g { background: var(--sign-tint); color: var(--sign-ink); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data td, table.data th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }

/* ---------- next words */
.next-head { padding-top: 16px; display: grid; gap: 10px; }
.next-head h2 { margin: 0; font-size: 20px; }
.next-head p { margin: 0; font-size: 14px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.seg button { border: 0; background: transparent; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.next-tools { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.next-tools .filter { padding: 8px 10px; flex: 1; min-width: 160px; }
.chip.on { background: var(--say-tint); border-color: var(--say); color: var(--say-ink); }
.rank-list { display: grid; gap: 6px; margin-top: 12px; }
.rank-row {
  display: grid; grid-template-columns: 44px 1fr 72px auto; align-items: center; gap: 10px; text-align: left;
  padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.rank-row.known { opacity: .7; }
.rank-row .rank { color: var(--text-3); font-variant-numeric: tabular-nums; font-size: 13px; }
.rank-row .rw { min-width: 0; }
.rank-row .rw-word { font-weight: 600; display: block; }
.rank-row .rw small { color: var(--text-3); font-size: 12px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-row .fbar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.rank-row .fbar i { display: block; height: 100%; background: var(--say); border-radius: 3px; }
.rank-row .badge { justify-self: end; }
@media (max-width: 380px) { .rank-row { grid-template-columns: 38px 1fr 48px auto; gap: 8px; } }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 400px; display: grid; gap: 14px; }
.login h1 { margin: 0; font-size: 26px; }
.err { color: var(--danger); font-size: 14px; min-height: 1.2em; }

/* ---------- sign-in, first child, invites */
.login .brand { display: flex; align-items: center; gap: 12px; }
.login .brand img { width: 48px; height: 48px; border-radius: 12px; }
.gbtn { min-height: 44px; display: flex; justify-content: center; }
.notice { background: var(--say-tint); color: var(--say-ink); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.notice.warn { background: var(--sign-tint); color: var(--sign-ink); }
.or { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.code-box { font: 600 28px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .12em; text-align: center;
  padding: 16px; border: 1px dashed var(--line); border-radius: 12px; background: var(--surface); }
input.code-in { text-transform: uppercase; letter-spacing: .1em; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* ---------- child switcher */
.child-btn { border: 0; background: none; padding: 0; text-align: left; display: grid; gap: 1px; min-width: 0; }
.child-btn h1 { display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.child-btn h1 .chev { color: var(--text-3); font-size: 14px; flex: none; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--say); }
.list-row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px; margin-bottom: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.list-row.on { border-color: var(--say); box-shadow: 0 0 0 1px var(--say) inset; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .grow small { color: var(--text-3); font-size: 12px; }
.list-row select { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 8px; }
.role { font-size: 12px; font-weight: 700; color: var(--text-2); background: var(--surface-2); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stack { display: grid; gap: 10px; }
.section { margin-bottom: 12px; }
.readonly-bar { background: var(--surface-2); color: var(--text-2); font-size: 13px; padding: 8px 12px; border-radius: 10px; margin-bottom: 10px; }
.ev.pending { border-style: dashed; }
.chart-wrap .series-sign { stroke: var(--sign); stroke-width: 2; fill: none; stroke-dasharray: 5 4; }
.list-row .del { border: 0; background: none; color: var(--text-3); width: 32px; height: 32px; border-radius: 8px; font-size: 18px; flex: none; }
.list-row .del:hover { color: var(--danger); background: var(--surface-2); }
