:root {
  --bg: #0a0a0a;
  --fg: #ffffff;
  --muted: #a1a1aa;
  --panel: #141418;
  --border: #27272a;
  --accent: #ffffff;
  --accent-work: #ef4444;
  --accent-rest: #22c55e;
  --accent-station: #3b82f6;
  --focus: #fde047;
  --safe: 5vh 5vw;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

/* overflow-x: clip avoids making the body a scroll container, which
   would break position: sticky on the timer. Clip is visually the same
   as hidden here. */
html { overflow-x: clip; }

body {
  /* TV overscan safe area */
  padding: var(--safe);
}

.app {
  display: grid;
  grid-template-rows: auto auto auto auto auto;
  gap: clamp(0.5rem, 1.2vh, 1.25rem);
  max-width: 1600px;
  margin: 0 auto;
  transition: --accent 400ms ease;
}

/* --- Timer --- */

.timer-area {
  text-align: center;
  padding: 1rem 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  /* Soft fade into the content below so scrolling text doesn't butt up hard */
  box-shadow: 0 8px 12px -8px rgba(0, 0, 0, 0.9);
}

.timer {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: clamp(8rem, 22vw, 20rem);
  font-weight: 700;
  line-height: 0.9;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  transition: color 250ms ease;
  text-shadow: 0 0 40px rgba(255,255,255,0.05);
}

.status-line {
  margin-top: 0.5rem;
  display: flex;
  justify-content: center;
  gap: clamp(1rem, 3vw, 3rem);
  align-items: baseline;
  flex-wrap: wrap;
}

.segment-label {
  font-size: clamp(1.5rem, 3vw, 3rem);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  transition: color 250ms ease;
}

.round-info {
  font-size: clamp(1rem, 2vw, 2rem);
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Segment-kind accents */
.app[data-kind="work"]    { --accent: var(--accent-work); }
.app[data-kind="rest"]    { --accent: var(--accent-rest); }
.app[data-kind="station"] { --accent: var(--accent-station); }
.app[data-kind="done"]    { --accent: var(--accent-rest); }
.app[data-kind="pre"]     { --accent: var(--focus); }

/* Pulsing in last 3 seconds of a segment */
.app[data-warn="true"] .timer { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

/* --- Workout card --- */

.workout-area {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: clamp(0.75rem, 2.5vw, 2rem);
  text-align: center;
}

/* Date row: ‹  TODAY — 2026-04-22  › */
.date-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.workout-date {
  font-size: clamp(0.95rem, 1.5vw, 1.35rem);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.date-arrow {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.75rem;
  border-radius: 0.5rem;
  font-family: inherit;
  transition: color 120ms ease, background 120ms ease;
}
.date-arrow:hover { color: var(--fg); background: rgba(255, 255, 255, 0.05); }
.date-arrow:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  color: var(--fg);
}

.workout-title {
  font-size: clamp(2rem, 4vw, 4rem);
  margin: 0 0 0.5rem 0;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.workout-body {
  font-size: clamp(1.25rem, 2vw, 2.5rem);
  white-space: pre-wrap;
  margin: 0;
  font-family: inherit;
  line-height: 1.3;
  color: var(--fg);
}

/* --- Buttons --- */

.controls, .day-nav {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(0.5rem, 1vw, 1rem);
  justify-content: center;
}

.btn {
  appearance: none;
  background: var(--panel);
  color: var(--fg);
  border: 2px solid var(--border);
  border-radius: 0.75rem;
  padding: clamp(0.75rem, 1.5vh, 1.25rem) clamp(1rem, 2.5vw, 2rem);
  font-size: clamp(1rem, 1.6vw, 1.5rem);
  font-weight: 600;
  cursor: pointer;
  min-width: 7rem;
  min-height: 3.5rem;
  transition: transform 100ms ease, border-color 150ms ease, background 150ms ease;
  font-family: inherit;
}

.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:active:not(:disabled) { transform: scale(0.97); }

.btn:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
  border-color: var(--focus);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.btn-primary:hover:not(:disabled) { border-color: var(--focus); }

/* Icon-only button (speaker mute toggle).
   Width is narrower than a label-text button and the two SVGs share
   the same slot, with aria-pressed driving which one is visible. */
.btn-icon {
  min-width: 4rem;
  padding-left: 1rem;
  padding-right: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon .icon { display: block; }
#btn-mute[aria-pressed="false"] .icon-sound-off { display: none; }
#btn-mute[aria-pressed="true"]  .icon-sound-on  { display: none; }
#btn-mute[aria-pressed="true"]  { color: var(--muted); }

/* --- Paste box --- */

.paste-area {
  display: grid;
  gap: 0.5rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.paste-label {
  font-size: clamp(0.9rem, 1.4vw, 1.1rem);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

.paste-box {
  width: 100%;
  background: var(--panel);
  color: var(--fg);
  border: 2px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem;
  font-size: clamp(1rem, 1.4vw, 1.25rem);
  font-family: inherit;
  resize: vertical;
}

.paste-box:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 2px;
  border-color: var(--focus);
}

.paste-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

/* --- Admin mode banner (only visible with ?admin=1) --- */

.admin-banner[hidden] { display: none; }

.admin-banner {
  /* Negative margin escapes the body's safe-area padding so the bar
     spans the full viewport. Inner padding keeps the text inside the
     5% TV-safe zone. */
  margin: -5vh -5vw 1.5rem;
  padding: 0.6rem 5vw;
  background: var(--accent-work);
  color: #fff;
  text-align: center;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: clamp(0.8rem, 1.2vw, 1rem);
}

/* --- Admin area (only visible with ?admin=1) --- */

/* [hidden] must win over display: grid below. */
.admin-area[hidden] { display: none; }

.admin-area {
  display: grid;
  gap: 0.5rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  padding: 1rem;
  border: 2px dashed var(--accent-work);
  border-radius: 0.75rem;
}

.admin-status {
  color: var(--muted);
  font-size: clamp(0.9rem, 1.4vw, 1.1rem);
  margin-left: 0.5rem;
}
.admin-status[data-state="ok"]   { color: var(--accent-rest); }
.admin-status[data-state="err"]  { color: var(--accent-work); }

/* --- Config dialog --- */

.config-dialog {
  background: var(--panel);
  color: var(--fg);
  border: 2px solid var(--border);
  border-radius: 1rem;
  padding: clamp(1rem, 3vw, 2rem);
  max-width: min(90vw, 700px);
  width: 100%;
  max-height: 90vh;
  overflow: auto;
}

.config-dialog::backdrop {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.config-dialog h2 {
  margin: 0 0 1rem 0;
  font-size: clamp(1.5rem, 2.5vw, 2rem);
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.preset-btn {
  appearance: none;
  background: var(--bg);
  color: var(--fg);
  border: 2px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.85rem 0.75rem;
  font-size: clamp(0.95rem, 1.5vw, 1.1rem);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  min-height: 3rem;
  transition: border-color 120ms ease, background 120ms ease;
}
.preset-btn:hover:not([aria-selected="true"]) { border-color: var(--muted); }

.preset-btn:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.preset-btn[aria-selected="true"] {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

.config-fields {
  display: grid;
  gap: 0.875rem;
  margin-bottom: 1.25rem;
}
.config-fields:empty { margin-bottom: 0; }

.config-fields label {
  display: grid;
  gap: 0.35rem;
  font-size: clamp(0.95rem, 1.4vw, 1.05rem);
  font-weight: 500;
}

.config-fields .hint {
  color: var(--muted);
  font-size: 0.9em;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.config-fields input[type="number"],
.config-fields input[type="text"] {
  background: var(--bg);
  color: var(--fg);
  border: 2px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.6rem 0.75rem;
  font-size: clamp(1rem, 1.4vw, 1.1rem);
  font-family: inherit;
}

.config-fields input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-color: var(--focus);
}

.stations-list {
  display: grid;
  gap: 0.5rem;
}

.station-row {
  display: grid;
  grid-template-columns: 1fr 6rem auto;
  gap: 0.5rem;
  align-items: center;
}

.station-row input[type="text"] { min-width: 0; }

.station-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.btn-sm {
  min-width: auto;
  min-height: auto;
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
}

.config-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* --- Responsive --- */

@media (max-width: 640px) {
  /* No TV overscan on phones — reclaim the edge padding for content. */
  :root { --safe: 1.25vh 3vw; }
  .timer { font-size: clamp(5rem, 28vw, 10rem); }
  .timer-area { padding: 0.5rem 0 0.75rem; }
  .btn { min-width: 5.5rem; min-height: 3rem; padding: 0.6rem 1rem; }
  .station-row { grid-template-columns: 1fr 5rem auto; }
  .app { gap: 0.6rem; }
  .workout-area { padding: 0.75rem 1rem; }
  .workout-title { font-size: clamp(1.5rem, 6vw, 2.5rem); }
  .workout-body { font-size: clamp(1rem, 4.5vw, 1.5rem); }
  .controls, .day-nav, .paste-actions { gap: 0.4rem; }
  .paste-box { padding: 0.6rem; }
}

@media (min-width: 1200px) {
  /* Likely a TV — keep generous spacing */
  .controls, .day-nav { gap: 1.25rem; }
}

/* --- Page footer (link to /wod library, kept low-key on purpose) --- */

.page-footer {
  margin-top: 1rem;
  padding: 0.75rem 0;
  text-align: center;
}

.footer-link {
  color: var(--muted);
  text-decoration: none;
  font-size: clamp(0.85rem, 1.2vw, 1rem);
  letter-spacing: 0.05em;
  border-bottom: 1px solid transparent;
  padding-bottom: 1px;
  transition: color 120ms ease, border-color 120ms ease;
}
.footer-link:hover { color: var(--fg); border-bottom-color: var(--muted); }
.footer-link:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
  color: var(--fg);
}

/* --- Workout library (/wod page) --- */

.library-area[hidden] { display: none; }

.library-area {
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  padding: 1rem 0;
}

.library-back {
  display: inline-block;
  color: var(--muted);
  text-decoration: none;
  font-size: clamp(0.9rem, 1.3vw, 1.05rem);
  margin-bottom: 1rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  transition: color 120ms ease, background 120ms ease;
}
.library-back:hover { color: var(--fg); background: rgba(255, 255, 255, 0.05); }
.library-back:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  color: var(--fg);
}

.library-title {
  font-size: clamp(2rem, 4.5vw, 3.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
}

.library-sub {
  color: var(--muted);
  font-size: clamp(0.95rem, 1.4vw, 1.15rem);
  margin: 0 0 1.5rem 0;
}

.library-list {
  display: grid;
  gap: clamp(0.75rem, 2vw, 1.25rem);
}

.library-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: clamp(1rem, 2.5vw, 1.75rem);
  display: grid;
  gap: 0.5rem;
}

.library-date {
  font-size: clamp(0.8rem, 1.2vw, 0.95rem);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-variant-numeric: tabular-nums;
}

.library-card-title {
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
}

.library-card-body {
  font-size: clamp(1rem, 1.6vw, 1.25rem);
  white-space: pre-wrap;
  margin: 0.25rem 0 0.5rem 0;
  font-family: inherit;
  line-height: 1.4;
}

.library-open {
  justify-self: start;
  color: var(--muted);
  text-decoration: none;
  font-size: clamp(0.9rem, 1.3vw, 1.05rem);
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  transition: color 120ms ease, border-color 120ms ease;
}
.library-open:hover { color: var(--fg); border-color: var(--muted); }
.library-open:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  color: var(--fg);
}

.library-empty {
  color: var(--muted);
  font-size: clamp(1rem, 1.5vw, 1.2rem);
  text-align: center;
  padding: 2rem 0;
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .app[data-warn="true"] .timer { animation: none; }
  * { transition: none !important; }
}
