/* Visual Timer — deliberately single (dark) visual world (spec §6/§7). */
:root {
  --accent: #842BD2;
  --accent-2: #A855F7;

  --bg: #0b0b0f;
  --panel: #141419;
  --surface: #16161d;
  --surface-2: #101015;
  --track: #26262f;
  --line: #23232c;
  --text: #f3f3f7;
  --dim: #8b8b97;
  --faint: #5c5c68;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --glow: color-mix(in srgb, var(--accent) 55%, transparent);
  --glow-soft: color-mix(in srgb, var(--accent) 22%, transparent);
}

/* Named accent themes (spec §7). Purple is the default (:root). */
[data-accent="red"]    { --accent: #ef4444; --accent-2: #f87171; }
[data-accent="green"]  { --accent: #22c55e; --accent-2: #4ade80; }
[data-accent="blue"]   { --accent: #3b82f6; --accent-2: #60a5fa; }
[data-accent="orange"] { --accent: #f97316; --accent-2: #fb923c; }
[data-accent="yellow"] { --accent: #eab308; --accent-2: #facc15; }
[data-accent="teal"]   { --accent: #14b8a6; --accent-2: #2dd4bf; }
[data-accent="pink"]   { --accent: #ec4899; --accent-2: #f472b6; }

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

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
}

#app {
  position: relative;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 55% at 50% -8%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%),
    var(--bg);
}

/* ---- screens ---- */
.screen { display: none; flex: 1; min-height: 0; flex-direction: column; }
.screen.active { display: flex; }

/* ---- timer screen ---- */
.fs-toggle {
  position: absolute; top: max(12px, env(safe-area-inset-top)); right: 14px; z-index: 3;
  display: inline-flex; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--accent-2); padding: 7px 11px; border-radius: 20px; font-size: 12px; font-weight: 600;
  cursor: pointer;
}
.fs-toggle .sw { width: 24px; height: 14px; border-radius: 20px; background: var(--track); position: relative; transition: background .15s ease; }
.fs-toggle .sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--faint); transition: transform .15s ease, background .15s ease; }
.fs-toggle[aria-pressed="true"] .sw { background: var(--accent); }
.fs-toggle[aria-pressed="true"] .sw::after { transform: translateX(10px); background: #fff; }

.timer-stage { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 20px 20px 20px; min-height: 0; }
.ring-area { flex: 1; display: flex; align-items: center; justify-content: center; width: 100%; }

.ring-wrap {
  position: relative; width: min(74vw, 300px); aspect-ratio: 1; display: grid; place-items: center;
  background: none; border: none; cursor: pointer; padding: 0;
}
.ring-glow { position: absolute; inset: 10px; border-radius: 50%; box-shadow: 0 0 70px 8px var(--glow-soft); opacity: 0; transition: opacity .3s ease; }
.has-ring .ring-glow { opacity: 1; }

.ring-wrap svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--track); stroke-width: 10; }
.ring-progress {
  fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round;
  filter: drop-shadow(0 0 6px var(--glow)); opacity: 0;
  transition: opacity .3s ease;
}
.has-ring .ring-progress { opacity: 1; }

.digits {
  font-weight: 800; font-size: clamp(46px, 15vw, 66px); letter-spacing: .06em; padding-left: .06em;
  font-variant-numeric: tabular-nums; color: var(--text); line-height: 1; z-index: 1;
}
.digits.muted { color: var(--faint); }

/* Large pause glyph behind the digits, shown only when paused. A softer,
   lighter shade of the accent so it reads as "paused" without competing. */
.pause-glyph {
  position: absolute; inset: 0; z-index: 0;
  display: none; align-items: center; justify-content: center; gap: 13%;
  opacity: .5; filter: blur(6px); transition: opacity .2s ease;
}
.timer-stage.paused .pause-glyph { display: flex; }
.pause-glyph i { display: block; width: 17%; height: 60%; border-radius: 16px; background: color-mix(in srgb, var(--accent) 62%, #000); }

.controls { display: flex; gap: 16px; align-items: center; justify-content: center; padding-bottom: 6px; }
.rbtn {
  width: 58px; height: 58px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--dim); display: grid; place-items: center;
  font-size: 14px; font-weight: 700; cursor: pointer;
}
.rbtn:active { transform: scale(.94); }
.rbtn.preset { color: var(--text); }
.rbtn svg { width: 22px; height: 22px; }

/* ---- bottom nav ---- */
.nav {
  height: calc(62px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  flex: none; border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-around;
  background: color-mix(in srgb, #000 25%, var(--surface-2));
}
.nav button { background: none; border: none; cursor: pointer; display: grid; place-items: center; gap: 4px; color: var(--faint); font-size: 10px; letter-spacing: .04em; font-family: var(--font); }
.nav button svg { width: 23px; height: 23px; }
.nav button.active { color: var(--accent); }

/* ---- headers (tasks / settings) ---- */
.scr-head { padding: max(18px, env(safe-area-inset-top)) 22px 8px; display: flex; align-items: baseline; justify-content: space-between; }
.scr-head h2 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.scr-head .sub { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }

/* ---- tasks ---- */
.task-list { flex: 1; padding: 8px 16px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.task {
  display: flex; align-items: center; gap: 12px; padding: 15px 16px; border-radius: 16px;
  background: var(--surface-2); border: 1px solid var(--line); cursor: pointer;
}
.task:active { background: var(--surface); }
.task .name { flex: 1; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task .time { font-size: 14px; color: var(--accent-2); font-variant-numeric: tabular-nums; font-weight: 700; }
.task .pen { color: var(--faint); display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; }
.task .pen:active { background: var(--surface); color: var(--dim); }
.task .pen svg { width: 17px; height: 17px; }
.task.add { justify-content: center; color: var(--dim); border-style: dashed; font-weight: 600; gap: 8px; }
.task.add svg { width: 16px; height: 16px; }

/* ---- settings ---- */
.set-body { flex: 1; padding: 14px 22px; }
.set-label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); margin-bottom: 14px; }
.color-row { display: flex; gap: 20px; flex-wrap: wrap; }
.color-pick { display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; }
.color-dot { width: 52px; height: 52px; border-radius: 50%; border: 2px solid transparent; }
.color-pick.sel .color-dot { border-color: var(--text); box-shadow: 0 0 0 3px rgba(255,255,255,.08); }
.color-pick span { font-size: 11px; color: var(--dim); }

/* ---- number pad ---- */
.numpad-scrim { position: fixed; inset: 0; z-index: 48; background: rgba(0,0,0,.6); display: flex; flex-direction: column; justify-content: flex-end; }
.numpad { max-width: 480px; width: 100%; margin: 0 auto; background: var(--surface-2); border-top-left-radius: 26px; border-top-right-radius: 26px; border-top: 1px solid var(--line); padding: 18px 18px calc(20px + env(safe-area-inset-bottom)); }
.pad-readout { text-align: center; font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .04em; margin: 6px 0 16px; }
.pad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.key { height: 56px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); display: grid; place-items: center; font-size: 22px; font-weight: 600; color: var(--text); cursor: pointer; font-family: var(--font); }
.key:active { background: var(--panel); }
.key.enter { background: var(--accent); border-color: var(--accent); color: #fff; }
.key.clear { color: var(--dim); font-size: 18px; }

/* ---- full-screen ambient (accent recedes downward as time elapses) ---- */
.ambient { position: fixed; inset: 0; z-index: 50; background: #000; overflow: hidden; display: grid; place-items: center; }
.ambient .fill {
  position: absolute; left: 0; right: 0; bottom: 0; height: 100%;
  background: linear-gradient(0deg, var(--accent), color-mix(in srgb, var(--accent) 80%, #000));
  box-shadow: 0 -14px 44px var(--glow);
  will-change: height;
}
.ambient .a-digits { position: relative; font-size: clamp(52px, 17vw, 76px); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .06em; padding-left: .06em; color: rgba(255,255,255,.92); }
.ambient .a-hint { position: absolute; bottom: calc(28px + env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; font-size: 11px; color: rgba(255,255,255,.45); letter-spacing: .12em; text-transform: uppercase; }

/* ---- time's-up flash ---- */
.flash { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: #000; animation: flash 0.7s steps(1, end) infinite; }
.flash-label { font-size: 22px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: rgba(255,255,255,.85); }
@keyframes flash { 0% { background: #000; } 50% { background: var(--accent); } 100% { background: #000; } }
@media (prefers-reduced-motion: reduce) {
  .flash { animation: none; background: var(--accent); }
}

/* ---- task edit ---- */
.edit-scrim { position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 24px; }
.edit-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.edit-name { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px; color: var(--text); font-size: 16px; font-family: var(--font); font-weight: 600; }
.edit-name:focus { outline: none; border-color: var(--accent); }
.edit-time { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px; color: var(--accent-2); font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .04em; cursor: pointer; font-family: var(--font); text-align: center; }
.edit-actions { display: flex; align-items: center; gap: 8px; }
.edit-actions .spacer { flex: 1; }
.btn { border: 1px solid var(--line); background: var(--surface-2); color: var(--text); border-radius: 10px; padding: 9px 14px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: var(--font); display: inline-flex; align-items: center; gap: 6px; }
.btn svg { width: 15px; height: 15px; }
.btn.ghost { background: transparent; color: var(--dim); border-color: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: #f87171; }

/* ---- full-screen style ---- */
.a-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: none; }
.ambient.anim .a-canvas { display: block; }
.ambient.anim .fill { display: none; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn.sel { border-color: var(--accent); color: var(--accent-2); }

/* ---- create link ---- */
.fs-toggle.inline { position: static; align-self: flex-start; }
.link-out { font-size: 11px; color: var(--faint); word-break: break-all; user-select: all; }
.link-actions { display: flex; gap: 8px; }
.link-actions .btn { flex: 1; justify-content: center; padding: 10px 6px; font-size: 13px; }
#linkClose { align-self: center; }
.timer-title { font-size: 18px; font-weight: 700; color: var(--dim); text-align: center; padding-top: 28px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70; background: #2a2a33; color: var(--text); border: 1px solid var(--line); padding: 11px 16px; border-radius: 12px; font-size: 13px; font-weight: 600; box-shadow: 0 12px 30px rgba(0,0,0,.5); max-width: 88%; text-align: center; }

[hidden] { display: none !important; }
