/* ============================================================
   Rail — Focus Timer
   Design tokens
   ============================================================ */
:root {
  --bg: #F6F3EC;
  --panel: #FFFFFF;
  --text: #1B2325;
  --muted: #6B7679;
  --border: rgba(27, 35, 37, 0.10);

  --work: #C97A22;      /* amber, darkened for AA contrast on light bg */
  --brk: #2F8F73;       /* teal, darkened for AA contrast on light bg */
  --meal: #C24B3F;      /* coral, darkened for AA contrast on light bg */
  --idle: #9AA6A8;

  --ring-track: rgba(27, 35, 37, 0.08);
  --shadow: 0 1px 2px rgba(20,20,20,0.04), 0 8px 24px rgba(20,20,20,0.06);

  --radius: 18px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12181B;
    --panel: #1A2226;
    --text: #F3F1EA;
    --muted: #93A1A4;
    --border: rgba(243, 241, 234, 0.08);

    --work: #E8A33D;
    --brk: #4FA98C;
    --meal: #E2665A;
    --idle: #4A5658;

    --ring-track: rgba(243, 241, 234, 0.08);
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 30px rgba(0,0,0,0.35);
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input { font-family: inherit; }

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------------- Day rail (signature element) ----------------
   A literal timeline of the working day: work blocks, breaks,
   scheduled meal breaks, and a cursor showing "now". Encodes the
   day's real structure rather than decorating it. */
.day-rail {
  position: relative;
  height: 10px;
  width: 100%;
  background: var(--ring-track);
  flex-shrink: 0;
}
.rail-track {
  position: absolute;
  inset: 0;
  display: flex;
}
.rail-block {
  height: 100%;
}
.rail-block.work { background: var(--work); opacity: 0.55; }
.rail-block.brk { background: var(--brk); opacity: 0.55; }
.rail-block.meal { background: var(--meal); opacity: 0.8; }
.rail-block.done { opacity: 0.22 !important; }
.rail-cursor {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 16px;
  background: var(--text);
  border-radius: 2px;
  transform: translateX(-1px);
  transition: left 1s linear;
}

/* ---------------- Top bar ---------------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px 0;
}
.brand {
  font-weight: 700;
  letter-spacing: 0.01em;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 12px;
}
.clock {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------------- Stage ---------------- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px 20px 8px;
  text-align: center;
}

.mode-label {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--work);
  transition: color 0.3s ease;
}
.mode-label[data-mode="break"] { color: var(--brk); }
.mode-label[data-mode="meal"]  { color: var(--meal); }
.mode-label[data-mode="idle"]  { color: var(--idle); }
.mode-label[data-mode="ended"] { color: var(--idle); }

.ring-wrap {
  position: relative;
  width: min(78vw, 300px);
  height: min(78vw, 300px);
}
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track {
  fill: none;
  stroke: var(--ring-track);
  stroke-width: 10;
}
.ring-progress {
  fill: none;
  stroke: var(--work);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 829.38; /* 2*pi*132 */
  stroke-dashoffset: 829.38;
  transition: stroke-dashoffset 1s linear, stroke 0.3s ease;
}
.ring-progress[data-mode="break"] { stroke: var(--brk); }
.ring-progress[data-mode="meal"]  { stroke: var(--meal); }
.ring-progress[data-mode="idle"]  { stroke: var(--idle); }

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.time {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(48px, 12vw, 64px);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
}
.sub {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.next-up {
  font-size: 13px;
  color: var(--muted);
}

.controls {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:disabled:active { transform: none; }
.btn-primary {
  background: var(--text);
  color: var(--bg);
  border-color: transparent;
}
.btn-ghost {
  background: transparent;
  box-shadow: none;
}

.foot-row {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--muted);
  flex-wrap: wrap;
  justify-content: center;
}
.sound-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.sound-toggle input { accent-color: var(--work); }
.link-btn {
  appearance: none;
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: 12.5px;
  cursor: pointer;
  padding: 0;
}

.legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 20px 20px;
  font-size: 11.5px;
  color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-work { background: var(--work); }
.dot-break { background: var(--brk); }
.dot-meal { background: var(--meal); }
.dot-done { background: var(--idle); }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(16px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 13.5px;
  max-width: 90vw;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  box-shadow: var(--shadow);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------------- Reduced motion ---------------- */
@media (prefers-reduced-motion: reduce) {
  .ring-progress, .rail-cursor, .toast { transition: none; }
}

/* ---------------- Small screens ---------------- */
@media (max-width: 360px) {
  .controls { flex-wrap: wrap; }
  .btn { padding: 11px 18px; }
}
