:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1f242c;
  --line: #2a313b;
  --text: #e9edf2;
  --muted: #8b95a3;
  --accent: #5fd3a8;
  --accent-ink: #0b2a1f;
  --warn: #f2b45c;
  --danger: #ef7b7b;
  --p4: #ef7b7b;
  --p3: #f2b45c;
  --p2: #7fb2f0;
  --radius: 16px;
  --tap: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  body.phone, body.login-page {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --panel-2: #eef0f3;
    --line: #dde1e6;
    --text: #15191e;
    --muted: #5f6977;
    --accent: #1f9e72;
    --accent-ink: #ffffff;
    --warn: #b9750f;
    --danger: #c43d3d;
    --p4: #c43d3d;
    --p3: #b9750f;
    --p2: #2f6fc0;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------- buttons */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 12px;
  padding: 0 18px;
  min-height: 48px;
  cursor: pointer;
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn:active { transform: scale(0.97); }

/* ------------------------------------------------------------- header */
.top {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  padding: max(16px, env(safe-area-inset-top)) 20px 12px;
}
.time { font-size: 44px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.date { color: var(--muted); margin-top: 6px; font-size: 16px; }
.top-right { display: flex; align-items: center; gap: 16px; text-align: right; }
.weather { color: var(--muted); font-size: 15px; line-height: 1.35; }
.weather b { color: var(--text); font-size: 22px; font-weight: 650; }
.streak {
  display: flex; flex-direction: column; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px 14px;
}
.streak-num { font-size: 26px; font-weight: 700; color: var(--accent); line-height: 1; }
.streak-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

.banner {
  margin: 0 20px 10px; padding: 10px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); font-size: 14px;
}

/* ------------------------------------------------------------- panels */
.grid { padding: 0 20px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; min-height: 0;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-head h2 { font-size: 20px; }
.count { color: var(--muted); font-variant-numeric: tabular-nums; }

.progress { height: 8px; border-radius: 99px; background: var(--panel-2); overflow: hidden; margin-bottom: 12px; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s ease; }

.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; }
.item {
  display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: var(--tap); padding: 10px 12px; margin-bottom: 8px;
  background: var(--panel-2); border: 1px solid transparent; border-radius: 12px;
  text-align: left; cursor: pointer; transition: opacity .25s, background .2s;
}
.item:active { background: color-mix(in srgb, var(--accent) 14%, var(--panel-2)); }
.check {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--muted); display: grid; place-items: center;
}
.item.p4 .check { border-color: var(--p4); }
.item.p3 .check { border-color: var(--p3); }
.item.p2 .check { border-color: var(--p2); }
.item.done .check, .item.pending .check { background: var(--accent); border-color: var(--accent); }
.item.done .check::after, .item.pending .check::after {
  content: ""; width: 8px; height: 14px; border: solid var(--accent-ink);
  border-width: 0 3px 3px 0; transform: translate(0, -2px) rotate(45deg);
}
.item.done, .item.pending { opacity: .5; }
.item.done .label, .item.pending .label { text-decoration: line-through; }
.item.done { cursor: default; }
.label { flex: 1; font-size: 18px; line-height: 1.3; overflow-wrap: anywhere; }
.meta { flex: none; font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.tag { padding: 2px 8px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); }
.tag.overdue { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.empty { color: var(--muted); padding: 16px 4px; font-size: 16px; }

/* ------------------------------------------------------------- forms */
.add { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.add input {
  min-height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); min-width: 0; font-size: 16px;
}
.add input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.add-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.goal-form .add-row input { flex: 1 1 70px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.chip {
  border: 1px solid var(--line); background: transparent; border-radius: 99px;
  padding: 6px 12px; font-size: 14px; cursor: pointer; color: var(--muted);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ------------------------------------------------------------- goals */
.goals { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.goal { background: var(--panel-2); border-radius: 12px; padding: 14px; margin-bottom: 10px; }
.goal-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.goal-title { font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.goal-pct { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.goal .progress { margin: 10px 0; height: 10px; }
.goal-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.goal-num { color: var(--muted); font-variant-numeric: tabular-nums; }
.goal-btns { display: flex; gap: 8px; }
.goal-btns .btn { min-width: 56px; min-height: 48px; font-size: 20px; }
.goal.complete .goal-pct::after { content: " ✓"; }
.goal-btns .goal-del { color: var(--danger); min-width: 0; font-size: 14px; border: 0; padding: 0 8px; }

/* ------------------------------------------------------------- footer + toast */
.foot {
  display: flex; justify-content: space-between; color: var(--muted); font-size: 13px;
  padding: 10px 20px max(10px, env(safe-area-inset-bottom));
}
.foot a { color: var(--muted); }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 20;
  display: flex; gap: 14px; align-items: center;
  background: var(--text); color: var(--bg); padding: 10px 10px 10px 18px; border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35); max-width: calc(100vw - 32px);
}
.toast .btn { color: var(--bg); border-color: color-mix(in srgb, var(--bg) 30%, transparent); }

/* ------------------------------------------------------------- night screen */
.night {
  position: fixed; inset: 0; z-index: 50; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
}
.night-time { font-size: 72px; color: #2d3338; font-weight: 700; font-variant-numeric: tabular-nums; }
.night-hint { color: #1c2024; font-size: 14px; }

/* ------------------------------------------------------------- KIOSK (Pi touchscreen) */
body.kiosk {
  height: 100vh; overflow: hidden; display: flex; flex-direction: column;
  cursor: none; user-select: none; -webkit-user-select: none;
  touch-action: manipulation; overscroll-behavior: none;
}
body.kiosk * { cursor: none !important; }
body.kiosk .phone-only, body.kiosk .add { display: none !important; }
body.kiosk .grid {
  flex: 1; min-height: 0; display: grid; gap: 16px;
  grid-template-columns: 1fr 1.25fr 1fr;
}
body.kiosk .time { font-size: clamp(44px, 7vh, 84px); }
body.kiosk .date { font-size: clamp(16px, 2.4vh, 24px); }
body.kiosk .label { font-size: clamp(17px, 2.3vh, 24px); }
body.kiosk .panel-head h2 { font-size: clamp(18px, 2.6vh, 26px); }
body.kiosk .foot { padding-top: 8px; padding-bottom: 8px; }
@media (max-height: 640px) {
  body.kiosk .top { padding-top: 10px; padding-bottom: 8px; }
  body.kiosk { --tap: 54px; }
}

/* ------------------------------------------------------------- PHONE */
body.phone .grid { padding-bottom: 96px; }
body.phone .panel { display: none; min-height: 60vh; }
body.phone .panel.active { display: flex; }
body.phone .tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--panel); border-top: 1px solid var(--line);
  padding: 6px 8px max(6px, env(safe-area-inset-bottom));
}
body.phone .tab {
  background: none; border: 0; min-height: 52px; border-radius: 12px;
  color: var(--muted); font-weight: 600; cursor: pointer;
}
body.phone .tab.on { color: var(--accent); background: var(--panel-2); }
body.phone .foot { padding-bottom: 90px; }
body.phone .toast { bottom: 90px; }
@media (max-width: 420px) {
  body.phone .top { padding-left: 16px; padding-right: 16px; }
  body.phone .grid { padding-left: 16px; padding-right: 16px; }
  body.phone .top { align-items: center; }
  body.phone .time { font-size: 32px; white-space: nowrap; }
  body.phone .date { font-size: 14px; white-space: nowrap; }
  body.phone .top-right { gap: 10px; }
  body.phone .weather { font-size: 13px; }
  body.phone .weather > div + div { display: none; }
  body.phone .weather b { font-size: 18px; }
  body.phone .streak { padding: 6px 10px; }
  body.phone .streak-num { font-size: 20px; }
  body.phone .streak-label { font-size: 11px; white-space: nowrap; }
  body.phone .label { font-size: 17px; }
}
/* Phone in landscape / tablet: show all three like the kiosk */
@media (min-width: 900px) {
  body.phone .grid { display: grid; grid-template-columns: 1fr 1.25fr 1fr; gap: 16px; padding-bottom: 20px; }
  body.phone .panel { display: flex; }
  body.phone .tabs { display: none; }
  body.phone .foot { padding-bottom: 16px; }
  body.phone .toast { bottom: 24px; }
}

/* ------------------------------------------------------------- login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px;
}
.login-card h1 { font-size: 22px; margin-bottom: 8px; }
.login-card label { color: var(--muted); font-size: 14px; }
.login-card input {
  min-height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); font-size: 16px;
}
.error { color: var(--danger); margin: 0; font-size: 14px; }
