/* Signal — calm & minimal. One accent, generous whitespace, light/dark aware. */

:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --faint: #9a9aa0;
  --line: #ece9e3;
  --accent: #5660bd;
  --accent-rgb: 86, 96, 189;
  --missed: #c0826b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.04);
  --radius: 16px;
  --maxw: 600px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161617;
    --surface: #1f1f22;
    --ink: #f1f1ef;
    --muted: #a2a2a8;
    --faint: #6c6c73;
    --line: #2c2c30;
    --accent: #8b93e6;
    --accent-rgb: 139, 147, 230;
    --missed: #cf977f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

/* `hidden` must win over component display rules (e.g. .gate uses display:grid). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* ---------- Gate ---------- */
.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  z-index: 50;
}
.gate-card {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.gate-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent);
  position: relative;
  margin-bottom: 18px;
}
.gate-mark::before,
.gate-mark::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}
.gate-mark::before { width: 11px; height: 11px; background: #fff; }
.gate-mark::after { width: 25px; height: 25px; border: 2px solid rgba(255, 255, 255, 0.55); }
.gate-title {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0;
}
.gate-sub { color: var(--muted); font-size: 14px; margin: 8px 0 28px; }
.gate-input {
  width: 100%;
  padding: 13px 16px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}
.gate-input:focus { border-color: var(--accent); }
.gate-btn {
  width: 100%;
  margin-top: 12px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  transition: opacity 0.15s;
}
.gate-btn:active { opacity: 0.85; }
.gate-error { color: var(--missed); font-size: 13px; margin-top: 14px; }

/* ---------- Shell ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px calc(16px + env(safe-area-inset-top, 0));
  padding-top: max(16px, env(safe-area-inset-top, 0));
  max-width: var(--maxw);
  margin: 0 auto;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
}
.brand {
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 14px;
}
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 9px;
  transition: color 0.15s, background 0.15s;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); background: rgba(var(--accent-rgb), 0.1); }
.lock-btn {
  border: none;
  background: transparent;
  color: var(--faint);
  font-size: 15px;
  padding: 6px 8px;
  border-radius: 8px;
  line-height: 1;
}
.lock-btn:hover { color: var(--ink); }

.main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px 20px 96px;
  animation: fade 0.3s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Headings / sections ---------- */
.eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 4px;
}
.headline { font-size: 26px; font-weight: 600; margin: 0 0 2px; letter-spacing: -0.01em; }
.subhead { color: var(--muted); font-size: 15px; margin: 0 0 24px; }
.section { margin-bottom: 34px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 12px; letter-spacing: 0.02em; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
}

/* ---------- Signal rows ---------- */
.signals { list-style: none; margin: 0; padding: 0; }
.signal {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 12px;
  border-radius: 12px;
  transition: background 0.15s;
}
.signal + .signal { border-top: 1px solid var(--line); }
.signal:hover { background: rgba(var(--accent-rgb), 0.04); }
.check {
  flex: none;
  width: 24px;
  height: 24px;
  margin-top: 1px;
  border-radius: 50%;
  border: 2px solid var(--faint);
  background: transparent;
  position: relative;
  transition: border-color 0.15s, background 0.15s;
}
.check::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 3px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  transition: transform 0.15s;
}
.signal.done .check { background: var(--accent); border-color: var(--accent); }
.signal.done .check::after { transform: rotate(45deg) scale(1); }
.signal.missed .check { border-color: var(--missed); border-style: dashed; }
.signal-body { flex: 1; min-width: 0; }
.signal-text { font-size: 16px; line-height: 1.45; }
.signal.done .signal-text { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--faint); }
.signal-meta { font-size: 12px; color: var(--faint); margin-top: 3px; display: flex; gap: 10px; align-items: center; }
.carry-badge { color: var(--accent); }
.signal-del {
  flex: none;
  border: none;
  background: transparent;
  color: var(--faint);
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.signal:hover .signal-del { opacity: 1; }
.signal-del:hover { color: var(--missed); }

/* ---------- Progress bar / count ---------- */
.daycount { display: flex; align-items: baseline; justify-content: space-between; margin: 4px 2px 14px; }
.daycount .n { font-size: 14px; color: var(--muted); }
.daycount .pct { font-size: 14px; color: var(--accent); font-weight: 600; }
.bar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 0 2px 8px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.4s ease; }

/* ---------- Empty / done states ---------- */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty h3 { color: var(--ink); font-size: 18px; margin: 0 0 6px; }
.empty p { margin: 0 0 20px; font-size: 14px; }
.allclear { text-align: center; padding: 18px; color: var(--accent); font-size: 14px; font-weight: 500; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  transition: background 0.15s, opacity 0.15s, border-color 0.15s;
}
.btn:hover { border-color: var(--faint); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); width: 100%; }
.btn-primary:active { opacity: 0.85; }
.btn-ghost { border: none; background: transparent; color: var(--accent); padding: 10px 8px; }
.btn-row { margin-top: 10px; }

/* ---------- Planner ---------- */
.planner { }
.prow { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.prow .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.pinput {
  flex: 1;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}
.pinput:focus { border-color: var(--accent); }
.prow-del {
  flex: none; border: none; background: transparent; color: var(--faint);
  font-size: 18px; padding: 4px 8px; border-radius: 8px;
}
.prow-del:hover { color: var(--missed); }
.carryover { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 999px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip::before { content: "\21A9  "; color: var(--accent); }
.hint { font-size: 13px; color: var(--faint); margin: 6px 2px 16px; min-height: 18px; }
.hint.warn { color: var(--missed); }
.reflect {
  width: 100%;
  resize: none;
  padding: 12px 14px;
  font-size: 15px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  margin-top: 6px;
  min-height: 46px;
}
.reflect:focus { border-color: var(--accent); }

/* ---------- Progress view ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 30px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}
.stat .label { font-size: 12px; color: var(--muted); letter-spacing: 0.02em; }
.stat .value { font-size: 28px; font-weight: 600; margin-top: 6px; letter-spacing: -0.02em; }
.stat .value small { font-size: 15px; color: var(--faint); font-weight: 500; }
.stat .sub { font-size: 12px; color: var(--faint); margin-top: 2px; }

.heatwrap { overflow-x: auto; padding-bottom: 6px; -webkit-overflow-scrolling: touch; }
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 4px; width: max-content; }
.hcell { width: 13px; height: 13px; border-radius: 3px; background: var(--line); }
.legend { display: flex; align-items: center; gap: 6px; justify-content: flex-end; margin-top: 10px; font-size: 11px; color: var(--faint); }
.legend .hcell { width: 11px; height: 11px; }

.recent { list-style: none; margin: 18px 0 0; padding: 0; }
.recent li { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-top: 1px solid var(--line); font-size: 14px; }
.recent .rdate { color: var(--muted); width: 92px; flex: none; }
.recent .rbar { flex: 1; height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.recent .rbar > span { display: block; height: 100%; background: var(--accent); }
.recent .rratio { color: var(--faint); width: 44px; text-align: right; flex: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom, 0));
  transform: translateX(-50%) translateY(8px);
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  padding: 11px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 420px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .headline { font-size: 23px; }
}
