:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev2: #1c232d;
  --line: #27303b;
  --text: #e6edf3;
  --muted: #8b98a7;
  --accent: #f0b429;
  --accent-dim: #b9860f;
  --good: #3fb950;
  --bad: #f06060;
  --ring-track: #27303b;
  --radius: 16px;
  --tap: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --maxw: 480px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
}

#app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---------- top bar ---------- */
#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: linear-gradient(var(--bg), rgba(13, 17, 23, 0.86));
  backdrop-filter: blur(8px);
}
.brand {
  font-weight: 800;
  letter-spacing: 0.5px;
  font-size: 18px;
}
.brand b {
  color: var(--accent);
}

.sync-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 11px;
  cursor: pointer;
}
.sync-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.sync-chip[data-state="synced"] .dot { background: var(--good); }
.sync-chip[data-state="syncing"] .dot { background: var(--accent); animation: pulse 1s infinite; }
.sync-chip[data-state="offline"] .dot { background: var(--muted); }
.sync-chip[data-state="error"] .dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- main view ---------- */
.view {
  flex: 1;
  padding: 8px 16px 96px;
  width: 100%;
}

h1 { font-size: 22px; margin: 6px 0 2px; }
h2 { font-size: 16px; margin: 20px 0 10px; color: var(--muted); font-weight: 600; letter-spacing: .3px; }
p.sub { color: var(--muted); margin: 0 0 16px; font-size: 14px; }

/* ---------- cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.affirm-card {
  text-align: center;
  background: linear-gradient(160deg, var(--bg-elev2), var(--bg-elev));
}
.affirm-card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.affirm-card .text { font-size: 18px; line-height: 1.4; margin-top: 8px; font-weight: 600; }

.daystat { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.daystat .big { font-size: 26px; font-weight: 800; }
.daystat .big b { color: var(--accent); }
.streak { color: var(--accent); font-weight: 700; }

/* ---------- session cards (home) ---------- */
.sessions { display: grid; gap: 12px; }
.session-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  width: 100%;
}
.session-card:active { transform: scale(0.99); }
.session-card.done { border-color: var(--accent-dim); }
.session-meta { flex: 1; }
.session-meta .name { font-size: 17px; font-weight: 700; }
.session-meta .count { color: var(--muted); font-size: 13px; margin-top: 2px; }
.session-card .chev { color: var(--muted); font-size: 20px; }

/* ---------- progress ring ---------- */
.ring { display: block; }
.ring .track { stroke: var(--ring-track); }
.ring .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .35s ease; }
.ring-label { fill: var(--text); font-weight: 700; }
.ring-wrap { position: relative; display: inline-grid; place-items: center; }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit;
  cursor: pointer;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg-elev2);
  color: var(--text);
  font-weight: 600;
  width: 100%;
}
.btn.primary { background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 800; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: #4a2626; }
.btn:active { transform: scale(0.99); }
.btn.small { min-height: 42px; width: auto; padding: 0 14px; font-size: 14px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { width: auto; flex: 1; }

/* ---------- big tap target (session) ---------- */
.tap-stage { display: grid; place-items: center; gap: 22px; padding: 10px 0 4px; }
.tap-btn {
  width: 230px; height: 230px; border-radius: 50%;
  border: 1px solid var(--line);
  background: radial-gradient(circle at 50% 38%, var(--bg-elev2), var(--bg-elev));
  position: relative;
  display: grid; place-items: center;
}
.tap-btn:active { transform: scale(0.98); }
.tap-btn .n { font-size: 40px; font-weight: 800; }
.tap-btn .of { color: var(--muted); font-size: 15px; margin-top: 2px; }
.tap-hint { color: var(--muted); font-size: 13px; text-align: center; }

.line-input {
  width: 100%;
  min-height: var(--tap);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  padding: 14px 16px;
  font-size: 16px;
}
.line-input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.line-input::placeholder { color: var(--muted); opacity: 0.9; }
textarea::placeholder { color: var(--muted); opacity: 0.9; }

.type-target {
  width: 100%;
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: center;
}
.type-target-label { font-size: 10px; letter-spacing: 1px; color: var(--muted); text-transform: uppercase; }
.type-target-text { font-size: 17px; font-weight: 600; margin-top: 5px; line-height: 1.38; }

/* ---------- forms ---------- */
label.field { display: block; margin: 12px 0; }
label.field .lab { font-size: 13px; color: var(--muted); display: block; margin-bottom: 6px; }
input[type="text"], input[type="date"], input[type="time"], input[type="password"], textarea, select {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
}
textarea { min-height: 72px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

.check-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check-row:last-child { border-bottom: 0; }
.check-row input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.check-row input[type="text"] { border: none; background: transparent; padding: 4px 0; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: var(--bg-elev2); border: 1px solid var(--line); border-radius: 999px; transition: .2s; }
.switch .slider::before { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: var(--muted); border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(22px); background: #1a1205; }

.times-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

/* ---------- history calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal .cell {
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  font-size: 12px; color: var(--muted);
  position: relative;
}
.cal .cell.done { background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 800; }
.cal .cell.partial { border-color: var(--accent-dim); color: var(--text); }
.cal .cell.repaired::after { content: "✚"; position: absolute; top: 2px; right: 4px; font-size: 9px; color: #1a1205; }
.cal .cell.today { box-shadow: 0 0 0 2px var(--accent-dim); }
.cal .cell.future { opacity: 0.4; }
.cal .cell.repairable { cursor: pointer; border-style: dashed; }

.pill { display: inline-block; font-size: 12px; color: var(--muted); background: var(--bg-elev); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; }

.center { text-align: center; }
.muted { color: var(--muted); }
.spacer { height: 10px; }
.hr { height: 1px; background: var(--line); margin: 16px 0; border: 0; }

/* ---------- bottom nav ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  max-width: var(--maxw);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(22, 27, 34, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bot);
}
.tab {
  background: none; border: 0; color: var(--muted);
  display: grid; place-items: center; gap: 2px;
  padding: 10px 0 8px; font-size: 11px;
}
.tab .ico { font-size: 20px; line-height: 1; }
.tab.active { color: var(--accent); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: calc(80px + var(--safe-bot));
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
  max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- cycle-complete ---------- */
.celebrate { text-align: center; padding: 30px 0; }
.celebrate .big369 { font-size: 54px; font-weight: 900; color: var(--accent); letter-spacing: 4px; }

@media (min-width: 520px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); min-height: 100dvh; }
}
