/* Layout: fixed top tab bar, one scrolling main area. Count view scrolls; weeks view fits the grid to the screen. */
:root {
  --bg: #edf0f3;
  --surface: #f8fafb;
  --ink: #131c2e;
  --muted: #586274;
  --line: #cdd4dd;
  --sand: #a8741f;
  --past: #2b3652;
  --future: #b4bdca;

  --f-display: "Bricolage Grotesque", "IBM Plex Sans JP", system-ui, sans-serif;
  --f-body: "IBM Plex Sans JP", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1422; --surface: #141d2e; --ink: #e7eaf0; --muted: #8f99aa;
    --line: #26314a; --sand: #e2b565; --past: #45547a; --future: #34415c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1422; --surface: #141d2e; --ink: #e7eaf0; --muted: #8f99aa;
  --line: #26314a; --sand: #e2b565; --past: #45547a; --future: #34415c;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 15px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--sand); outline-offset: 2px; }

/* Top bar */
.top {
  flex: none;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.top-inner {
  max-width: 880px;
  margin: 0 auto;
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 52px;
}
.tabs { display: flex; gap: 4px; height: 100%; }
.tabs button {
  background: none;
  border: 0;
  padding: 0 14px;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  position: relative;
}
.tabs button:first-child { padding-left: 0; }
.tabs button[aria-selected="true"] { color: var(--ink); }
.tabs button[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 14px; right: 14px; bottom: -1px;
  height: 2px;
  background: var(--sand);
}
.tabs button:first-child[aria-selected="true"]::after { left: 0; }
.icon-btn {
  background: none;
  border: 0;
  width: 40px; height: 40px;
  margin-right: -8px;
  display: grid;
  place-items: center;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
}
.icon-btn:hover { color: var(--ink); }

.scroller {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.wrap {
  max-width: 880px;
  margin: 0 auto;
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
  padding-block: 32px calc(48px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 44px;
}

.eyebrow {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin: 0;
}

/* Hero */
.hero { display: flex; flex-direction: column; gap: 12px; }
.days {
  font-family: var(--f-display);
  font-weight: 750;
  font-size: clamp(72px, 19vw, 168px);
  line-height: 0.9;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 0.12em;
  flex-wrap: wrap;
}
.days .u { font-family: var(--f-body); font-size: 0.24em; font-weight: 500; letter-spacing: 0; color: var(--muted); }
.clock {
  font-family: var(--f-mono);
  font-size: clamp(26px, 6.4vw, 44px);
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.15em 0.5em;
}
.clock .u { font-family: var(--f-body); font-size: 0.4em; color: var(--muted); margin-left: 0.15em; }
.clock .s { color: var(--sand); }
.secs { font-family: var(--f-mono); font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; margin: 0; }

/* Progress */
.progress { display: flex; flex-direction: column; gap: 8px; }
.progress-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.pct { font-family: var(--f-display); font-weight: 650; font-size: 22px; font-variant-numeric: tabular-nums; }
.pct small { font-family: var(--f-body); font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.bar { height: 6px; background: var(--future); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--past); position: relative; }
.bar > i::after { content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 3px; background: var(--sand); }
.ends { display: flex; justify-content: space-between; font-family: var(--f-mono); font-size: 12px; color: var(--muted); }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.stat { padding: 16px 16px 16px 0; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat + .stat { padding-left: 16px; border-left: 1px solid var(--line); }
.stat .k { font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
.stat .v { font-family: var(--f-display); font-weight: 700; font-size: clamp(26px, 5vw, 34px); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .v small { font-family: var(--f-body); font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.stat .note { font-size: 12px; color: var(--muted); }
@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(3) { padding-left: 0; border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
}

/* Weeks grid */
h2 {
  font-family: var(--f-display);
  font-weight: 650;
  font-size: 24px;
  letter-spacing: -0.01em;
  margin: 0;
  text-wrap: balance;
}
.grid-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.grid-head p { margin: 0; color: var(--muted); max-width: 60ch; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend b { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.legend .lp { background: var(--past); }
.legend .ln { background: var(--sand); }
.legend .lf { border: 1.5px solid var(--future); }
.board { position: relative; }
.board canvas { display: block; width: 100%; touch-action: manipulation; }
.now-cell {
  position: absolute;
  background: var(--sand);
  border-radius: 1px;
  pointer-events: none;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .now-cell { animation: none; } }
.readout {
  margin-top: 12px;
  font-family: var(--f-mono);
  font-size: 13px;
  color: var(--muted);
  min-height: 1.6em;
  font-variant-numeric: tabular-nums;
}
.readout b { color: var(--ink); font-weight: 500; }

.foot { color: var(--muted); font-size: 13px; max-width: 60ch; }
.foot p { margin: 0; }

/* Weeks view: fills the remaining screen height */
.view-weeks {
  height: 100%;
  gap: 14px;
  padding-block: 18px calc(12px + env(safe-area-inset-bottom, 0px));
}
.view-weeks .readout { margin-top: 0; flex: none; }
.weeks-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px 16px; flex-wrap: wrap; flex: none; }
.weeks-sum { margin: 0; font-family: var(--f-mono); font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.weeks-sum b { font-family: var(--f-display); font-size: 26px; font-weight: 700; color: var(--ink); }
.weeks-sum .sep { margin: 0 4px; }
.board-fit { flex: 1; min-height: 0; }
.board-fit canvas { width: auto; }

/* Forms (shared) */
.fields { display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
.field input {
  font: 500 17px var(--f-mono);
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 9px 10px;
  min-height: 44px;
  min-width: 10em;
}
.field input[type="number"] { min-width: 0; width: 6.5em; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.error { margin: 0; font-size: 13px; color: var(--sand); min-height: 0; }
.error:empty { display: none; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.settings button:not(.icon-btn), .onboard button {
  font: 500 15px var(--f-body);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
}
button.primary { background: var(--ink) !important; color: var(--bg) !important; border-color: var(--ink) !important; }

/* Onboarding */
.onboard {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  overflow-y: auto;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.onboard-inner {
  max-width: 560px;
  margin: 0 auto;
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
  padding-block: 12vh 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.onboard-title {
  font-family: var(--f-display);
  font-weight: 750;
  font-size: clamp(32px, 8vw, 48px);
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0;
  text-wrap: balance;
}
.lede { margin: 0; color: var(--muted); max-width: 46ch; }
.onboard .primary { align-self: flex-start; margin-top: 4px; }

/* Settings dialog */
.settings {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}
.settings::backdrop { background: rgb(8 12 20 / 0.5); }
.settings form { padding: 18px 20px 22px; display: flex; flex-direction: column; gap: 16px; }
.settings-head { display: flex; justify-content: space-between; align-items: center; }
.settings h2 { font-size: 20px; }
.widget-param, .danger { border-top: 1px solid var(--line); padding-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.widget-param .k { font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
.widget-param code {
  font: 500 15px var(--f-mono);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 9px 10px;
  user-select: all;
  -webkit-user-select: all;
}
.danger button { align-self: flex-start; color: var(--muted) !important; }
.danger button.armed { color: var(--sand) !important; border-color: var(--sand) !important; }
