:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #ece8e1;
  --text: #1c1b1f;
  --muted: #6b6870;
  --line: #d8d3cb;
  --line-strong: #1c1b1f;
  --accent: #3b5bdb;
  --accent-soft: #dbe4ff;
  --good: #2b8a3e;
  --good-soft: #d3f9d8;
  --bad: #c92a2a;
  --bad-soft: #ffe3e3;
  --warn: #e67700;
  --cell: #ffffff;
  --cell-alt: #f1ede6;
  --sel: #c5d3ff;
  --peer: #e9eefc;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16161a;
    --surface: #222228;
    --surface-2: #2c2c33;
    --text: #f1f0f3;
    --muted: #a09ea8;
    --line: #3a3a42;
    --line-strong: #d8d6de;
    --accent: #7c96ff;
    --accent-soft: #2a3358;
    --good: #69db7c;
    --good-soft: #1f3a26;
    --bad: #ff8787;
    --bad-soft: #4a2226;
    --warn: #ffa94d;
    --cell: #26262d;
    --cell-alt: #2e2e36;
    --sel: #3a4a8a;
    --peer: #2d3247;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16161a; --surface: #222228; --surface-2: #2c2c33; --text: #f1f0f3; --muted: #a09ea8;
  --line: #3a3a42; --line-strong: #d8d6de; --accent: #7c96ff; --accent-soft: #2a3358;
  --good: #69db7c; --good-soft: #1f3a26; --bad: #ff8787; --bad-soft: #4a2226; --warn: #ffa94d;
  --cell: #26262d; --cell-alt: #2e2e36; --sel: #3a4a8a; --peer: #2d3247; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; touch-action: manipulation; }

#bar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  height: 52px;
  padding: 0 8px;
  flex: none;
}
#bar #back { grid-column: 1; }
#bar #help { grid-column: 3; }
#bar h1 { grid-column: 2; grid-row: 1; margin: 0; text-align: center; font-size: 19px; font-weight: 700; letter-spacing: 0.2px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: transparent;
  display: grid; place-items: center;
  font-size: 19px; font-weight: 700; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
#help { border: 2px solid var(--line); width: 32px; height: 32px; font-size: 16px; justify-self: end; margin-right: 4px; }

#view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px 24px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

/* Hub */
.hub-date { color: var(--muted); text-align: center; margin: 0 0 14px; font-size: 14px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  border: none; border-radius: var(--radius);
  background: var(--surface);
  padding: 14px 14px 12px;
  text-align: left;
  display: flex; flex-direction: column; gap: 6px;
  min-height: 148px;
  cursor: pointer;
  box-shadow: 0 1px 0 var(--line);
  position: relative;
  overflow: hidden;
}
.tile:active { transform: scale(0.98); }
.tile .glyph {
  width: 46px; height: 46px; border-radius: 12px;
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 22px;
}
.tile .name { font-weight: 700; font-size: 17px; margin-top: 4px; }
.tile .tag { color: var(--muted); font-size: 13px; line-height: 1.3; }
.tile .meta { margin-top: auto; font-size: 12px; color: var(--muted); display: flex; gap: 10px; }
.tile .done-dot {
  position: absolute; top: 12px; right: 12px;
  font-size: 12px; font-weight: 700; color: var(--good);
}
.hub-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 22px; }

/* Shared controls */
.row { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.btn {
  border: 1.5px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 9px 16px;
  font-weight: 600; font-size: 15px;
  cursor: pointer;
}
.btn:active { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn:disabled { opacity: 0.4; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg button {
  border: none; background: transparent; border-radius: 999px;
  padding: 6px 13px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.12); }
.stat { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 15px; font-weight: 600; }
.gap-s { height: 8px; } .gap-m { height: 14px; } .gap-l { height: 22px; }
.board-wrap { display: flex; justify-content: center; }

/* Modal and toast */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: grid; place-items: center; padding: 16px; z-index: 50;
  animation: fade 0.18s ease;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface); border-radius: 20px; padding: 24px 20px 18px;
  width: 100%; max-width: 360px; text-align: center;
  animation: pop 0.22s cubic-bezier(.2,1.4,.4,1);
}
.modal-card h2 { margin: 0 0 6px; font-size: 24px; }
.modal-card p { margin: 6px 0; color: var(--muted); line-height: 1.45; text-align: left; }
.modal-card .big { font-size: 34px; font-weight: 800; color: var(--text); text-align: center; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.modal-card .sub { text-align: center; }
.modal-card .row { margin-top: 18px; }
.modal-card ul { text-align: left; color: var(--muted); padding-left: 20px; line-height: 1.5; margin: 8px 0; }
.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 14px;
  z-index: 60; max-width: 90vw; text-align: center;
}
.toast[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(0.9); opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.shake { animation: shake 0.3s; }
