:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --ink: #1d1c18;
  --muted: #6c6a62;
  --line: #e3dfd5;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe5;
  --gold: #b07d1f;
  --gold-soft: #f4e8cf;
  --warn: #b4472d;
  --shadow: 0 1px 2px rgba(30, 25, 10, .06), 0 4px 16px rgba(30, 25, 10, .05);
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11130f;
    --surface: #1a1d18;
    --surface-2: #22261f;
    --ink: #ebeae4;
    --muted: #9b9a91;
    --line: #2d322a;
    --accent: #4fb79a;
    --accent-ink: #0d1a15;
    --accent-soft: #1f3b32;
    --gold: #e0b45a;
    --gold-soft: #3a3020;
    --warn: #e2795f;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11130f; --surface: #1a1d18; --surface-2: #22261f; --ink: #ebeae4; --muted: #9b9a91; --line: #2d322a;
  --accent: #4fb79a; --accent-ink: #0d1a15; --accent-soft: #1f3b32; --gold: #e0b45a; --gold-soft: #3a3020; --warn: #e2795f;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font);
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* header */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; letter-spacing: -.01em; }
.logo { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); position: relative; }
.logo::after { content: ""; position: absolute; inset: 7px 6px 8px 7px; border: solid var(--accent-ink); border-width: 0 3px 3px 0; transform: rotate(40deg) translate(-1px, -2px); width: 7px; height: 12px; }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .5; }
.live.on { background: #2fbf71; opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, #2fbf71 25%, transparent); }
.me { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer; max-width: 55vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* tabs */
.tabs { display: flex; gap: 8px; padding: 4px 16px 12px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px;
  cursor: pointer; white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tab .draft { font-size: 11px; opacity: .7; margin-left: 4px; }

main { max-width: 860px; margin: 0 auto; padding: 0 16px; display: grid; gap: 14px; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.about { color: var(--muted); margin: 0 2px; }
.note { margin: 0; padding: 10px 14px; border-radius: 12px; background: var(--gold-soft); color: var(--ink); font-size: 14px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.card h3 { margin: 18px 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-sub { color: var(--muted); font-size: 13px; }
.programs { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }

/* counter */
.big { display: flex; align-items: baseline; gap: 6px; margin: 14px 0 8px; }
.big b { font-size: 44px; line-height: 1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.big span { color: var(--muted); font-size: 18px; font-variant-numeric: tabular-nums; }
.meter { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s ease; }
.next { margin: 10px 0 0; color: var(--muted); }
.next b { color: var(--ink); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.actions { margin-top: 14px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.stepper button { border: 0; background: var(--surface-2); width: 38px; height: 40px; cursor: pointer; font-size: 18px; }
.stepper input { width: 64px; height: 40px; border: 0; text-align: center; background: var(--surface); color: var(--ink); font: inherit; font-variant-numeric: tabular-nums; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 8px 12px; cursor: pointer; font-variant-numeric: tabular-nums; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); }
.recent { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.who { font-size: 12px; background: var(--surface-2); border-radius: 99px; padding: 3px 9px; color: var(--muted); }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 0 16px; height: 40px;
  cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, .cell:focus-visible, .tab:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* parts grid */
.round { margin-top: 14px; }
.round-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 0 12px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.round-head b { color: var(--ink); font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }
.cell {
  aspect-ratio: 1; border-radius: 9px; border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; font-size: 13px; font-weight: 600; cursor: pointer; position: relative;
  font-variant-numeric: tabular-nums; padding: 0; min-width: 0;
}
.cell.taken { background: var(--gold-soft); border-color: color-mix(in srgb, var(--gold) 45%, var(--line)); color: var(--gold); }
.cell.done { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.cell.mine { box-shadow: inset 0 0 0 2px var(--ink); }
.cell.sel { background: var(--ink); color: var(--bg); border-color: var(--ink); transform: scale(.94); }
.cell.free:hover { border-color: var(--accent); }
.legend { display: flex; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; border: 1px solid var(--line); }
.legend .l-taken { background: var(--gold-soft); }
.legend .l-done { background: var(--accent); border-color: var(--accent); }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); align-items: flex-start; }
.list li:first-child { border-top: 0; }
.ava { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff; }
.li-main { flex: 1; min-width: 0; }
.li-main .t { overflow-wrap: anywhere; }
.li-side { flex: none; text-align: right; font-size: 12px; color: var(--muted); }
.src { display: inline-block; font-size: 11px; border-radius: 6px; padding: 1px 6px; margin-left: 6px; background: var(--surface-2); color: var(--muted); vertical-align: 1px; }
.src.wa { background: color-mix(in srgb, #25d366 18%, var(--surface)); color: color-mix(in srgb, #128c4b 80%, var(--ink)); }
.raw { font-size: 12px; color: var(--muted); white-space: pre-line; margin-top: 2px; overflow-wrap: anywhere; }
.flags { font-size: 11px; color: var(--warn); }
.more { margin-top: 8px; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 0; }

.duas textarea {
  width: 100%; min-height: 64px; resize: vertical; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  background: var(--surface); color: var(--ink); font: inherit;
}
.dua { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); margin-bottom: 8px; white-space: pre-line; overflow-wrap: anywhere; }
.dua small { display: block; color: var(--muted); margin-top: 4px; }

.hist li .t b { font-variant-numeric: tabular-nums; }

/* bottom bar */
.bar {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 20;
  max-width: 640px; margin: 0 auto; background: var(--ink); color: var(--bg); border-radius: 18px; padding: 10px 10px 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.25);
}
.bar[hidden] { display: none; }
.bar-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-actions { display: flex; gap: 6px; flex: none; }
.bar .btn { background: transparent; color: var(--bg); border-color: color-mix(in srgb, var(--bg) 35%, transparent); }
.bar .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.pop {
  position: fixed; z-index: 30; background: var(--ink); color: var(--bg); padding: 8px 12px; border-radius: 10px;
  font-size: 13px; max-width: 260px; box-shadow: 0 6px 20px rgba(0,0,0,.25); pointer-events: none;
}
.pop[hidden] { display: none; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 40;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px);
}
.toast[hidden] { display: none; }

dialog { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--ink); padding: 20px; width: min(92vw, 380px); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
dialog input { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; margin: 12px 0 16px; font: inherit; background: var(--surface); color: var(--ink); }

@media (max-width: 420px) {
  .grid { gap: 4px; }
  .cell { font-size: 12px; border-radius: 7px; }
  .big b { font-size: 38px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
