:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #1f2630;
  --border: #2a313c;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --blue: #3b82f6;
  --cook: #f97316;
  --study: #a855f7;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,.3);
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Inter", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); min-height: 100%; }
body { font-size: 14px; line-height: 1.5; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg-3); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent-2); }
h2, h3 { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }

/* topbar */
.app-shell { min-height: 100vh; }
.auth-gate {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(circle at 50% 0%, rgba(249,115,22,.16), transparent 34%),
    linear-gradient(180deg, #111827 0%, var(--bg) 58%);
}
.auth-card {
  width: min(390px, 100%); background: var(--bg-2); border: 1px solid var(--border);
  border-top: 3px solid var(--cook); border-radius: 10px; box-shadow: var(--shadow);
  padding: 24px;
}
.auth-brand { color: var(--cook); font-weight: 700; letter-spacing: .4px; margin-bottom: 16px; }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: 0; }
.auth-card p { margin: 0 0 18px; color: var(--muted); }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input { width: 100%; padding: 9px 10px; }
.auth-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 2px; }
.auth-actions button { padding: 8px 10px; }
.auth-error { color: var(--red); font-size: 12px; min-height: 18px; }
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: var(--bg-2); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 600; font-size: 16px; letter-spacing: .3px; }
.search-wrap { flex: 1 1 260px; position: relative; max-width: 500px; }
.search-wrap input { width: 100%; padding: 8px 14px; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: 420px; overflow-y: auto; padding: 8px; z-index: 20;
}
.search-results .group-title { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; padding: 6px 8px; }
.search-results .res-item { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.search-results .res-item:hover { background: var(--bg-3); }
.streaks { display: flex; align-items: center; gap: 12px; }
.streak { display: flex; flex-direction: column; align-items: center; padding: 4px 10px; background: var(--bg-3); border-radius: 8px; min-width: 56px; }
.streak-num { font-weight: 700; font-size: 16px; color: var(--accent-2); }
.streak-lbl { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; }
.auth-current {
  display: flex; align-items: center; gap: 8px; background: var(--bg-3);
  border: 1px solid var(--border); border-radius: 8px; padding: 5px 6px;
}
.auth-current button { padding: 4px 8px; font-size: 12px; white-space: nowrap; }
#auth-user-name { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { background: transparent; border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 4px 10px; }
.icon-btn:hover { background: var(--bg-3); }
.notification-wrap { position: relative; }
.notification-btn.enabled { border-color: rgba(34,197,94,.55); color: var(--green); }
.notification-btn.blocked { border-color: rgba(239,68,68,.55); color: var(--red); }
.notification-btn.unsupported { opacity: .45; cursor: not-allowed; }
.notification-menu {
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 210px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); padding: 10px; z-index: 30;
}
.notification-status { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.notification-sound-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.notification-sound-field span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .7px; }
.notification-sound-field select { width: 100%; }
.notification-menu button { width: 100%; }
.btn-primary { background: var(--accent); border: none; color: white; padding: 6px 12px; border-radius: 6px; }
.btn-primary:hover { background: var(--accent-2); }
.btn-secondary { background: var(--bg-3); border: 1px solid var(--border); color: var(--text); padding: 6px 12px; border-radius: 6px; }
.btn-secondary:hover { background: var(--border); }

/* layout */
.grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; padding: 16px;
}
@media (max-width: 1100px) { .grid { grid-template-columns: 1fr; } }
.panel { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; min-height: 0; }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { font-size: 15px; flex: 1; }
.inline-form { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-form input[type=text] { min-width: 140px; }

/* calendar */
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; color: var(--muted); font-size: 11px; text-transform: uppercase; padding: 4px 0; }
.cal-day {
  aspect-ratio: 1 / 1; background: var(--bg-3); border-radius: 6px; padding: 4px 6px;
  display: flex; flex-direction: column; cursor: pointer; border: 1px solid transparent;
  font-size: 12px; transition: background .15s, border-color .15s;
}
.cal-day:hover { background: var(--border); }
.cal-day.other { opacity: .35; }
.cal-day.today { border-color: var(--accent-2); }
.cal-day.selected { background: var(--accent); color: white; }
.cal-num { font-weight: 600; }
.cal-dots { display: flex; gap: 2px; margin-top: auto; flex-wrap: wrap; }
.cal-dot { width: 5px; height: 5px; border-radius: 50%; }

.day-events { margin-top: 14px; }
.day-events h3 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; margin-bottom: 8px; }
.event-list li {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--bg-3);
  border-radius: 6px; margin-bottom: 6px;
}
.event-list .ev-time { color: var(--muted); font-size: 12px; min-width: 60px; }
.event-list .ev-name { flex: 1; }
.event-list .ev-actions { display: flex; gap: 4px; }
.tag-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* tasks */
.task-list li, .overdue .task-list li {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--bg-3);
  border-radius: 6px; margin-bottom: 6px;
}
.task-list li.done .task-name { text-decoration: line-through; color: var(--muted); }
.task-list .task-name { flex: 1; }
.task-list .strip { width: 4px; align-self: stretch; border-radius: 2px; }
.overdue { background: rgba(239,68,68,.08); border: 1px solid rgba(239,68,68,.3); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; }
.overdue h3 { color: var(--red); font-size: 12px; text-transform: uppercase; letter-spacing: .8px; margin-bottom: 8px; }
.overdue .task-list li { border-left: 3px solid var(--red); }
.overdue .task-date { font-size: 11px; color: var(--muted); }

/* deadlines */
.deadline-list li {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 6px;
  margin-bottom: 6px; background: var(--bg-3); border-left: 4px solid var(--border);
}
.deadline-list li.urg-green { border-left-color: var(--green); }
.deadline-list li.urg-yellow { border-left-color: var(--yellow); }
.deadline-list li.urg-red { border-left-color: var(--red); background: rgba(239,68,68,.07); }
.deadline-list li.done { opacity: .5; }
.deadline-list li.done .dl-name { text-decoration: line-through; }
.dl-name { flex: 1; }
.dl-date { font-size: 12px; color: var(--muted); }

/* misc */
.hidden { display: none !important; }
.row-actions { display: flex; gap: 4px; }
.row-actions button { padding: 2px 6px; font-size: 11px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { color: var(--muted); font-size: 12px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 100; animation: fade .15s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; width: min(440px, 92vw); box-shadow: var(--shadow); }
.modal-card h2 { font-size: 16px; margin-bottom: 14px; }
.modal-copy { margin: 0; color: var(--text); }
.modal-error { color: var(--red); font-size: 12px; margin-top: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.modal-card .field input, .modal-card .field select { width: 100%; }
.choice-stack { display: flex; flex-direction: column; gap: 8px; }
.choice-stack .choice-btn { width: 100%; padding: 8px 10px; text-align: left; }

input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }

/* ---------- tracking widget (header) ---------- */
.tracking-widget {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 8px;
}
.tracking-widget select {
  background: transparent; border: none; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: .6px; padding: 2px 4px; cursor: pointer;
}
.tracking-widget select:hover { color: var(--text); }
.trk-rows { display: flex; flex-direction: column; gap: 1px; min-width: 110px; }
.trk-row { display: grid; grid-template-columns: 8px auto 1fr; align-items: center; gap: 6px; }
.trk-dot { width: 8px; height: 8px; border-radius: 50%; }
.trk-cook { background: var(--cook); }
.trk-study { background: var(--study); }
.trk-name { color: var(--muted); font-size: 11px; letter-spacing: .4px; }
.trk-val { font-family: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, monospace; font-size: 12px; text-align: right; }
.trk-row.live .trk-val { color: var(--accent-2); }

/* ---------- col-stack (right column with deadlines + timer) ---------- */
.col-stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.col-stack .panel { margin: 0; }

/* ---------- timer panel ---------- */
#panel-timer { gap: 0; }
.mode-toggle { display: inline-flex; background: var(--bg-3); border: 1px solid var(--border); border-radius: 6px; padding: 2px; }
.mode-btn {
  background: transparent; border: none; color: var(--muted); padding: 4px 10px;
  border-radius: 4px; font-size: 12px;
}
.mode-btn.active { background: var(--accent); color: white; }
.mode-btn:not(.active):hover { color: var(--text); }

.idle-prompt {
  background: rgba(99,102,241,.1); border: 1px dashed rgba(129,140,248,.4);
  border-radius: 6px; padding: 8px 10px; color: var(--muted); font-size: 13px;
  margin-bottom: 12px;
}
.btn-link {
  background: transparent; border: none; color: var(--accent-2); padding: 0;
  text-decoration: underline; font: inherit; cursor: pointer;
}
.btn-link:hover { color: var(--text); }

.timer-display {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 0;
}
.timer-digits {
  font-family: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, monospace;
  font-size: 42px; font-weight: 600; letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}
.timer-digits.flash { animation: flash 0.6s ease-in-out 4; }
@keyframes flash { 0%,100% { color: var(--text); } 50% { color: var(--accent-2); } }
.cat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border);
}
.cat-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.cat-pill.cat-cook { color: var(--cook); border-color: rgba(249,115,22,.4); }
.cat-pill.cat-cook::before { background: var(--cook); }
.cat-pill.cat-study { color: var(--study); border-color: rgba(168,85,247,.4); }
.cat-pill.cat-study::before { background: var(--study); }
.cat-pill.paused { opacity: .5; }

.timer-form { display: flex; flex-direction: column; gap: 8px; }
.timer-form .field-row { display: flex; align-items: center; gap: 8px; }
.timer-form .field-row label { color: var(--muted); font-size: 12px; min-width: 70px; }
.timer-form .field-row select { flex: 1; }
.quick-starts { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; }
.quick-starts button { padding: 10px 12px; }
.btn-cook-main {
  background: var(--cook); color: #111827; font-weight: 700;
}
.btn-cook-main:hover { background: #fb923c; }
.timer-hint { color: var(--muted); font-size: 12px; }
.dur-fields { display: flex; align-items: center; gap: 4px; flex: 1; }
.dur-fields input { width: 56px; }
.dur-fields span { color: var(--muted); font-size: 12px; }
.btn-wide { width: 100%; padding: 8px; }
.running-actions { display: flex; gap: 8px; }
.running-actions button { flex: 1; padding: 8px; }

/* ---------- leaderboard ---------- */
.leaderboard-panel {
  border-color: rgba(249,115,22,.35);
  background: linear-gradient(180deg, rgba(249,115,22,.08), rgba(22,27,34,0) 56%), var(--bg-2);
}
.range-tabs { display: inline-flex; background: var(--bg-3); border: 1px solid var(--border); border-radius: 6px; padding: 2px; }
.range-tab {
  background: transparent; border: none; color: var(--muted); padding: 4px 9px;
  border-radius: 4px; font-size: 12px;
}
.range-tab.active { background: var(--cook); color: #111827; }
.range-tab:not(.active):hover { color: var(--text); }
.cook-stats {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px;
}
.cook-stats div {
  background: rgba(249,115,22,.08); border: 1px solid rgba(249,115,22,.18);
  border-radius: 6px; padding: 7px 8px;
}
.cook-stats span {
  display: block; color: var(--cook); font-family: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, monospace;
  font-size: 14px;
}
.cook-stats small { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .6px; }
.leaderboard-list { display: flex; flex-direction: column; gap: 6px; }
.leaderboard-list li {
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 8px;
  background: var(--bg-3); border-radius: 6px; padding: 9px 10px;
}
.leaderboard-list li::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: var(--score-pct, 0);
  background: rgba(249,115,22,.14); pointer-events: none;
}
.leaderboard-list li > * { position: relative; z-index: 1; }
.leaderboard-list li.leaderboard-first {
  border: 1px solid rgba(249,115,22,.45);
}
.leaderboard-rank {
  display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px;
  border-radius: 50%; background: rgba(249,115,22,.16); color: var(--cook);
  font-family: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, monospace; font-size: 12px;
}
.leaderboard-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.leaderboard-live {
  display: inline-flex; align-items: center; gap: 4px; margin-left: 7px;
  color: var(--green); font-size: 10px; text-transform: uppercase; letter-spacing: .6px;
}
.leaderboard-live::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 3px rgba(34,197,94,.12);
}
.leaderboard-time {
  color: var(--accent-2); font-family: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, monospace;
}

/* ---------- activity ---------- */
.activity-list, .audit-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.activity-item, .activity-empty, .audit-item {
  background: var(--bg-3); border-left: 4px solid var(--border); border-radius: 6px;
  padding: 8px 10px;
}
.activity-item.cat-cook { border-left-color: var(--cook); }
.activity-item.cat-study { border-left-color: var(--study); }
.activity-item.active { outline: 1px solid rgba(129,140,248,.35); }
.activity-title { font-weight: 600; }
.activity-meta { color: var(--muted); font-size: 12px; font-family: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, monospace; }
.activity-note {
  margin-top: 5px; color: var(--text); white-space: pre-wrap; font-size: 12px;
  border-top: 1px solid var(--border); padding-top: 5px;
}
.activity-note-label {
  display: block; color: var(--cook); font-size: 10px; text-transform: uppercase;
  letter-spacing: .7px; margin-bottom: 3px;
}
.activity-empty { color: var(--muted); }
.audit-item { border-left-color: var(--yellow); }
.profile-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px;
}
.profile-grid div {
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 6px; padding: 7px 8px;
}
.profile-grid span {
  display: block; color: var(--cook); font-family: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, monospace;
}
.profile-grid small { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .6px; }
.profile-section { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.profile-section h3 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .7px; margin-bottom: 6px; }
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-flex; align-items: center; border: 1px solid rgba(249,115,22,.35);
  color: var(--cook); background: rgba(249,115,22,.08); border-radius: 999px; padding: 3px 8px; font-size: 12px;
}
.profile-list { display: flex; flex-direction: column; gap: 6px; }
.profile-list li { background: var(--bg-3); border-radius: 6px; padding: 7px 8px; }
.profile-list strong { margin-right: 8px; color: var(--accent-2); font-family: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, monospace; }
.profile-list span, .profile-line, .profile-empty { color: var(--muted); }
.profile-note { margin-top: 4px; white-space: pre-wrap; font-size: 12px; }

@media (max-width: 520px) {
  .cook-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .profile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quick-starts { grid-template-columns: 1fr; }
}
