/* ---------------------------------------------------------------------------
   Ember — warm editorial. Cream paper, ink outlines, hard offset shadows,
   serif display type, bold flat wheel colours.

   The canvas wheel can't read CSS directly, so app.js pulls the --seg-* /
   --wheel-* / --hub-* values from here at draw time. Restyle the wheel by
   editing these variables.
--------------------------------------------------------------------------- */

:root {
  color-scheme: light;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
  --radius: 12px;
  --radius-sm: 8px;
  --border-w: 2px;

  --bg: #f6f0e4;
  --panel: #fffdf7;
  --border: #1d1a16;
  --border-strong: #1d1a16;
  --text: #1d1a16;
  --muted: #6e675c;
  --accent: #e4572e;
  --accent-ink: #fffdf7;
  --primary-bg: #e4572e;
  --primary-shadow: none;
  --good: #2e7d5b;
  --bad: #c0392b;
  --input-bg: #fffdf7;
  --shadow: 5px 5px 0 #1d1a16;
  --btn-shadow: 3px 3px 0 #1d1a16;
  --hairline: #e5dcc9;

  --pointer: #1d1a16;
  --wheel-filter: drop-shadow(6px 8px 0 rgba(29, 26, 22, 0.9));
  --wheel-stroke: #1d1a16;
  --wheel-stroke-w: 2.5;
  --wheel-label: #17140f;
  /* Regular weight — bold ink on these saturated fills reads heavy and muddy. */
  --wheel-label-weight: 400;
  --wheel-hover: rgba(255, 255, 255, 0.35);
  --wheel-empty: #efe7d6;
  --wheel-empty-stroke: #1d1a16;
  --hub-fill: #f6f0e4;
  --hub-stroke: #1d1a16;
  --seg-1: #e4572e; --seg-2: #29a19c; --seg-3: #f4b41a; --seg-4: #8464c6;
  --seg-5: #db5a8c; --seg-6: #4e9f5d; --seg-7: #4a7fd4; --seg-8: #c97e2c;
}

/* ---------------------------------------------------------------------------
   Base
--------------------------------------------------------------------------- */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 32px;
}

/* Main app header: wordmark + settings gear share the top row, and the nav
   sits centered on its own row below. (The admin page keeps the plain row.) */
.app-header {
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
}
.app-header .header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.app-header > nav { align-self: center; }

h1 {
  font-family: var(--font-display);
  font-size: 21px;
  margin: 0;
  letter-spacing: -0.02em;
}

h3 {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}

main { max-width: 820px; margin: 0 auto; padding: 24px 28px 56px; }

.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------------------
   Buttons
--------------------------------------------------------------------------- */

button {
  font: inherit;
  font-weight: 500;
  border: var(--border-w) solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 9px 17px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: var(--btn-shadow);
  transition: background 0.15s, border-color 0.15s, transform 0.06s, box-shadow 0.15s, color 0.15s;
}
button:hover:not(:disabled) { border-color: var(--border-strong); }
button:active:not(:disabled) { transform: translate(1px, 1px); box-shadow: none; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button.primary {
  background: var(--primary-bg);
  border-color: var(--border);
  color: var(--accent-ink);
  font-weight: 600;
}
button.primary:hover:not(:disabled) { filter: brightness(1.07); }

button.danger { background: var(--bad); border-color: var(--border); color: #fff; font-weight: 600; }
button.ghost { background: transparent; color: var(--muted); box-shadow: none; }
button.ghost:hover:not(:disabled) { color: var(--text); }

button.big {
  padding: 15px 52px;
  font-size: 17px;
  border-radius: calc(var(--radius-sm) + 4px);
}

/* Nav — dark segmented pill. Deliberately inverted from the cream content
   pills (slots, filter) so it reads as navigation/chrome, not another control. */
nav {
  display: flex;
  gap: 4px;
  background: var(--text);
  border: var(--border-w) solid var(--border);
  border-radius: 999px;
  padding: 4px;
  box-shadow: var(--btn-shadow);
}
.tab { border: 0; background: transparent; border-radius: 999px; padding: 7px 18px; box-shadow: none; color: rgba(246, 240, 228, 0.6); }
.tab:hover:not(.active) { color: #f6f0e4; border-color: transparent; }
.tab.active { background: var(--primary-bg); color: var(--accent-ink); font-weight: 600; }

.header-actions { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  width: 42px; height: 42px; padding: 0;
  border-radius: 50%;
  display: grid; place-items: center;
}

/* First-run tour.
   The card is deliberately inverted — a warm near-black coach-mark with a soft
   shadow and an arrow tail — so it reads as a guide floating above the app,
   not as another cream content panel. */
.tour-overlay {
  position: fixed; inset: 0;
  background: rgba(24, 21, 17, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 24;
}
.tour-spot {
  position: relative !important;
  z-index: 25 !important;
  border-radius: var(--radius);
  box-shadow: 0 0 0 4px var(--accent), 0 0 0 10px rgba(228, 87, 46, 0.25) !important;
}
.tour-card {
  --tour-bg: #221e19;
  --tour-fg: #f4eee1;
  position: fixed; z-index: 26;
  background: var(--tour-bg);
  color: var(--tour-fg);
  border-radius: 15px;
  box-shadow: 0 20px 44px -14px rgba(0, 0, 0, 0.6);
  padding: 20px 22px;
  animation: modal-pop 0.22s cubic-bezier(0.2, 1.4, 0.4, 1);
}
/* Arrow tail — --arrow-x (set in JS) aligns it with the target's centre. */
.tour-card::after {
  content: '';
  position: absolute;
  left: var(--arrow-x, 50%);
  transform: translateX(-50%);
  width: 0; height: 0;
  border: 9px solid transparent;
}
.tour-card--below::after { top: -18px; border-bottom-color: var(--tour-bg); }
.tour-card--above::after { bottom: -18px; border-top-color: var(--tour-bg); }
.tour-count {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 8px;
}
.tour-card h4 { font-family: var(--font-display); font-size: 20px; margin: 0 0 8px; color: #fffdf7; }
.tour-card p { margin: 0 0 16px; font-size: 14px; line-height: 1.6; color: rgba(244, 238, 225, 0.82); }
.tour-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
/* Ghost button's default muted grey is invisible on the dark card. */
.tour-card .ghost { color: rgba(244, 238, 225, 0.6); }
.tour-card .ghost:hover:not(:disabled) { color: var(--tour-fg); }
.tour-card .primary { box-shadow: none; border-color: transparent; }

/* ---------------------------------------------------------------------------
   Auth gate
--------------------------------------------------------------------------- */

/* Loading states --------------------------------------------------------- */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Full-screen loader for the initial data fetch. The 0.15s delayed fade-in
   means instant (local / cached) loads dismiss it before it ever shows, so
   only genuinely slow loads flash a spinner. */
.app-loading {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 29;
  animation: loader-fade 0.25s ease 0.15s both;
}
@keyframes loader-fade { from { opacity: 0; } to { opacity: 1; } }

.spinner {
  width: 42px; height: 42px;
  border: 4px solid rgba(29, 26, 22, 0.14);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Inline button spinner — text hides, a ring spins in its place. */
button.loading { color: transparent !important; pointer-events: none; position: relative; }
button.loading::after {
  content: ''; position: absolute; inset: 0; margin: auto;
  width: 17px; height: 17px;
  border: 2px solid rgba(255, 253, 247, 0.4);
  border-top-color: var(--accent-ink);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.auth-gate {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 30;
}

.auth-card {
  background: var(--panel);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(400px, 100%);
  padding: 32px 28px;
  text-align: center;
}
.auth-card h1 { font-size: 28px; margin-bottom: 4px; }
.auth-sub { color: var(--muted); margin: 0 0 24px; }

.auth-card form { display: flex; flex-direction: column; gap: 10px; }
.auth-card input {
  font: inherit;
  background: var(--input-bg); color: var(--text);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }
.auth-card button.primary { margin-top: 6px; padding: 12px; }

.auth-error { color: var(--bad); font-size: 13px; margin: 2px 0 0; }
.auth-toggle { color: var(--muted); font-size: 13px; margin: 18px 0 0; }
.auth-toggle a { color: var(--accent); font-weight: 600; text-decoration: none; }
.auth-toggle a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------------------
   Settings modal
--------------------------------------------------------------------------- */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(29, 26, 22, 0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 20;
}

.modal {
  background: var(--panel);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(480px, 100%);
  padding: 22px 24px;
  animation: modal-pop 0.22s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes modal-pop {
  0% { transform: scale(0.92) translateY(8px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.modal-head h2 { font-family: var(--font-display); font-size: 22px; margin: 0; letter-spacing: -0.01em; }

.setting {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-top: 1px solid var(--hairline);
}
.setting-name { font-weight: 600; font-size: 15px; }
.setting-desc { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* Toggle switch */
.switch { flex: none; cursor: pointer; }
.switch input { display: none; }
.switch .track {
  display: block; width: 50px; height: 28px;
  border: var(--border-w) solid var(--border);
  border-radius: 999px;
  background: var(--input-bg);
  position: relative;
  transition: background 0.15s;
}
.switch .track::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--border);
  transition: left 0.15s, background 0.15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { left: 25px; background: var(--accent-ink); }

/* Segmented control */
.seg {
  flex: none;
  display: flex; gap: 2px;
  border: var(--border-w) solid var(--border);
  border-radius: 999px;
  padding: 3px;
  background: var(--input-bg);
}
.seg button {
  border: 0; box-shadow: none;
  background: transparent;
  padding: 6px 13px;
  font-size: 13px;
  border-radius: 999px;
  color: var(--muted);
}
.seg button.active { background: var(--primary-bg); color: var(--accent-ink); font-weight: 600; }

/* ---------------------------------------------------------------------------
   Spin view
--------------------------------------------------------------------------- */

.slots { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 18px; }
.slots button { border-radius: 999px; }
.slots button.selected { background: var(--primary-bg); border-color: var(--border); color: var(--accent-ink); font-weight: 600; }

/* Category filter — a multi-select dropdown, the same on every viewport. */
.cat-filter { position: relative; display: flex; justify-content: center; margin-bottom: 28px; }
.cat-filter-trigger {
  display: inline-flex; align-items: center; gap: 10px;
  min-width: 200px; max-width: 320px;
  padding: 9px 16px; font-size: 14px;
  border-radius: 999px;
}
.cat-filter-value { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-filter-caret {
  flex: none; width: 0; height: 0;
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-top: 6px solid var(--muted);
  transition: transform 0.15s;
}
.cat-filter.open .cat-filter-caret { transform: rotate(180deg); }

.cat-filter-menu {
  position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  z-index: 20;
  width: max-content; min-width: 220px; max-width: min(320px, calc(100vw - 32px));
  max-height: 320px; overflow-y: auto;
  background: var(--panel);
  border: var(--border-w) solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 6px;
  animation: cat-menu-in 0.16s cubic-bezier(0.2, 1.2, 0.4, 1);
}
.cat-filter-menu[hidden] { display: none; }
@keyframes cat-menu-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.cat-opt {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; box-shadow: none; background: transparent;
  border-radius: 9px; padding: 8px 10px;
  font-size: 14px; color: var(--text); text-align: left;
}
.cat-opt:hover:not(:disabled) { background: rgba(29, 26, 22, 0.06); border-color: transparent; }
.cat-opt-box {
  flex: none; width: 18px; height: 18px;
  border: 2px solid var(--border); border-radius: 5px;
  position: relative;
}
.cat-opt.checked .cat-opt-box { background: var(--accent); border-color: var(--accent); }
.cat-opt.checked .cat-opt-box::after {
  content: ''; position: absolute; left: 4px; top: 0;
  width: 5px; height: 9px;
  border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.cat-opt-label { flex: 1; }
.cat-opt-count { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }

.wheel-area { display: flex; flex-direction: column; align-items: center; gap: 26px; }
.wheel-wrap { position: relative; width: 460px; max-width: 100%; }
#wheel { width: 100%; height: auto; display: block; filter: var(--wheel-filter); }

.pointer {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 13px solid transparent;
  border-right: 13px solid transparent;
  border-top: 26px solid var(--pointer);
  z-index: 2;
}

.empty { color: var(--muted); text-align: center; }
.hint { color: var(--muted); font-size: 13px; text-align: center; margin: -14px 0 0; }

/* Result */
.result { margin-top: 36px; text-align: center; border-top: var(--border-w) solid var(--border); padding-top: 32px; }
.result-label { color: var(--muted); margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; font-weight: 600; }
.result h2 { font-family: var(--font-display); margin: 0 0 16px; font-size: 30px; letter-spacing: -0.02em; }
.timer {
  font-size: 58px;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  margin-bottom: 24px;
}
.timer.overtime { color: var(--bad); }
.timer.idle { color: var(--muted); }
.timer.celebrate {
  color: var(--good);
  font-family: var(--font-display);
  animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes pop {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 10; }

/* Today's completed tasks, under the wheel */
.done-today {
  display: flex; flex-wrap: wrap; gap: 8px;
  align-items: center; justify-content: center;
  margin-top: 36px;
}
.done-today:empty { display: none; }
.done-label {
  color: var(--muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600;
  margin-right: 4px;
}
.done-chip {
  font-size: 13px; padding: 4px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--good); font-weight: 500;
}
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 12px; }
.result-actions:last-child { margin-bottom: 0; }

/* ---------------------------------------------------------------------------
   Panels, lists, accordions
--------------------------------------------------------------------------- */

.panel {
  background: var(--panel);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.list { list-style: none; margin: 0 0 14px; padding: 0; }
.list li {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--hairline);
}
.list li:last-child { border-bottom: 0; }
.list .meta { color: var(--muted); font-size: 13px; }

/* Forms */
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input, .inline-form select {
  font: inherit; flex: 1; min-width: 120px;
  background: var(--input-bg); color: var(--text);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  transition: border-color 0.15s;
}
.inline-form input::placeholder { color: var(--muted); }
.inline-form input:focus, .inline-form select:focus { outline: none; border-color: var(--accent); }

/* Short explainer under a panel heading. */
.panel-intro { margin: -4px 0 16px; color: var(--muted); font-size: 14px; }

/* Task rows: name on the left, its chunk + category + Remove on the right. */
.task-row .task-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row-controls { display: flex; align-items: center; gap: 8px; flex: none; }

.row-edit {
  font: inherit; font-size: 13px;
  background: var(--input-bg); color: var(--muted);
  border: 1px solid #cfc4ab; border-radius: 8px; padding: 4px 10px;
}
.row-edit:focus { outline: none; border-color: var(--accent); color: var(--text); }
.slot-edit { max-width: 140px; }
.cat-edit { width: 140px; }

.del { background: transparent; border-color: transparent; color: var(--muted); padding: 4px 8px; box-shadow: none; }
.del:hover:not(:disabled) { color: var(--bad); border-color: transparent; }

/* ---------------------------------------------------------------------------
   Stats
--------------------------------------------------------------------------- */

.stat-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.stat {
  flex: 1; min-width: 128px;
  background: var(--panel);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat .value {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat .label { color: var(--muted); font-size: 13px; margin-top: 2px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--hairline); }
.table th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.table tr:last-child td { border-bottom: 0; }

.table th.num, .table td.num { text-align: right; width: 84px; }
.table th.rate, .table td.rate { width: 68px; }
.table td.num { font-variant-numeric: tabular-nums; }
.table td:first-child { width: auto; }

.badge { font-size: 12px; padding: 3px 10px; border-radius: 999px; font-weight: 500; }
.badge.success { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.badge.fail { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.badge.skip { background: color-mix(in srgb, var(--muted) 16%, transparent); color: var(--muted); }

/* ---------------------------------------------------------------------------
   Responsive
--------------------------------------------------------------------------- */

@media (max-width: 560px) {
  main { padding: 16px 18px 40px; }
  header { padding: 14px 18px; flex-direction: column; align-items: stretch; }
  .header-actions { justify-content: space-between; }
  .setting { flex-wrap: wrap; }
  .timer { font-size: 46px; }

  .panel { padding: 16px; }

  /* Spin view: keep the wheel and its button above the fold — the Spin
     button sits above the wheel, and the category filter is a compact
     dropdown (styled the same as on desktop). */
  .cat-filter { margin-bottom: 18px; }
  .cat-filter-trigger { min-width: 220px; }
  #spin-btn { order: -1; }

  /* Task rows: the name gets its own line; the chunk selector, category
     input, and Remove button share the line below instead of squeezing in
     beside it. */
  .task-row { flex-wrap: wrap; row-gap: 8px; }
  .task-row .task-name { flex: 1 1 100%; }
  .row-controls { width: 100%; }
  /* min-width:0 lets the flex controls shrink below their intrinsic size so
     the chunk selector, category input, and Remove button share one line. */
  .slot-edit, .cat-edit { flex: 1; min-width: 0; max-width: none; width: auto; }

  /* Narrower numeric columns so task/category names keep some room. */
  .table th.num, .table td.num { width: 54px; padding-left: 4px; }
  .table th.rate, .table td.rate { width: 48px; }
}
