/* SRJJ brand font — clock, phase labels, round counter, settings headings. */
@font-face {
  font-family: 'Suisse Intl Cond';
  src: url('fonts/SuisseIntlCond-Bold.otf') format('opentype');
  font-weight: 700;
  font-display: swap;
}

:root {
  /* Phase colors — tuned for high contrast on a gym TV */
  --bg-idle:   #0a0a0b;
  --bg-prep:   #1a1410;
  --bg-work:   #053524;   /* deep emerald */
  --bg-rest:   #2a1a05;   /* deep amber */
  --bg-warn:   #3a0a0a;   /* deep red */
  --bg-done:   #0a0a0b;

  --fg-idle:   #e8e8ea;
  --fg-prep:   #ffb86b;
  --fg-work:   #00e58a;
  --fg-rest:   #ffb946;
  --fg-warn:   #ff5a5a;
  --fg-done:   #e8e8ea;

  --muted:     #6b6b75;
  --panel:     #15161a;
  --panel-2:   #1d1e24;
  --line:      #2a2b33;

  --font-display: 'Satoshi', system-ui, -apple-system, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --font-brand:   'Suisse Intl Cond', 'Satoshi', system-ui, sans-serif;

  /* Fluid sizing — vmin term scales with the smaller screen edge for TVs;
     the vw cap keeps "00:00" (≈2.8em in Suisse tabular) inside phones.
     ONE value for every phase: the clock must never resize or shift. */
  --size-time: min(clamp(7rem, 36vmin, 28rem), 30vw);
  --size-phase: clamp(1.25rem, 4vmin, 3rem);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-display);
  background: var(--bg-idle);
  color: var(--fg-idle);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  transition: background-color 280ms ease;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* --- Phase backgrounds & accent colors --- */
#app.phase-idle  { background: var(--bg-idle); }
#app.phase-prep  { background: var(--bg-prep); }
#app.phase-work  { background: var(--bg-work); }
#app.phase-rest  { background: var(--bg-rest); }
#app.phase-warn  { background: var(--bg-warn); }
#app.phase-done  { background: var(--bg-done); }

#app.phase-idle .time, #app.phase-idle .phase { color: var(--fg-idle); }
#app.phase-prep .time, #app.phase-prep .phase { color: var(--fg-prep); }
#app.phase-work .time, #app.phase-work .phase { color: var(--fg-work); }
#app.phase-rest .time, #app.phase-rest .phase { color: var(--fg-rest); }
#app.phase-warn .time, #app.phase-warn .phase { color: var(--fg-warn); }
#app.phase-done .time, #app.phase-done .phase { color: var(--fg-done); }

/* --- Topbar --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: clamp(0.75rem, 2vmin, 1.5rem) clamp(1rem, 3vmin, 2rem);
  gap: 1rem;
}
/* Brand mark lives in the topbar center, every phase, fixed size.
   Deliberately big (~24vmin ≈ 197px on iPad landscape) — Ben wants the
   brand to own the top of the mirrored TV picture. */
.brand {
  height: clamp(6rem, 24vmin, 13rem);
  width: auto;
  opacity: 0.95;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg-idle);
  width: clamp(2.75rem, 6vmin, 4rem);
  height: clamp(2.75rem, 6vmin, 4rem);
  border-radius: 999px;
  display: grid; place-items: center;
  cursor: pointer;
  transition: background-color 150ms ease, transform 150ms ease, border-color 150ms ease;
}
.icon-btn:hover { background: rgba(255,255,255,0.05); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: clamp(1.25rem, 3vmin, 1.75rem); height: clamp(1.25rem, 3vmin, 1.75rem); }

/* --- Stage (the big readout) --- */
.stage {
  display: grid;
  place-items: center;
  align-content: center;
  gap: clamp(0.5rem, 2vmin, 2rem);
  text-align: center;
  padding: clamp(0.5rem, 2vmin, 2rem);
  min-height: 0;
}

.phase {
  font-family: var(--font-brand);
  font-size: var(--size-phase);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  opacity: 0.9;
  transition: color 280ms ease;
}
.time {
  font-family: var(--font-brand);
  font-size: var(--size-time);
  font-weight: 700;
  line-height: 0.9;
  /* tnum only: every digit gets one fixed advance width, freezing slot and
     colon positions. Do NOT add 'case' here — its case figures replace the
     tabular ones and are proportional, which un-freezes the digits. */
  font-variant-numeric: tabular-nums;
  transition: color 280ms ease, transform 200ms ease;
}
/* Colon centered by geometry, not font features */
.tcolon { position: relative; top: -0.07em; }
.upnext {
  font-size: clamp(0.85rem, 1.8vmin, 1.25rem);
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  /* FIXED height (not min-height): an empty line box and a filled one
     differ by ~2px otherwise, which nudges the centered stack. */
  line-height: 1.2;
  height: 1.2em;
  overflow: hidden;
}

#app.phase-warn .time { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.04); }
}

/* --- Controls --- */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(1.25rem, 4vmin, 3rem);
  padding: clamp(1rem, 3vmin, 2.5rem);
}
.ctrl-btn {
  border: none;
  cursor: pointer;
  border-radius: 999px;
  display: grid; place-items: center;
  transition: transform 120ms ease, background-color 150ms ease, box-shadow 150ms ease;
  color: #0a0a0b;
}
.ctrl-btn:active { transform: scale(0.95); }
.ctrl-primary {
  width: clamp(5.5rem, 16.5vmin, 11rem);
  height: clamp(5.5rem, 16.5vmin, 11rem);
  background: #f4f4f5;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.04);
}
.ctrl-primary:hover { background: #fff; }
#app.phase-work .ctrl-primary { background: var(--fg-work); }
#app.phase-rest .ctrl-primary { background: var(--fg-rest); }
#app.phase-warn .ctrl-primary { background: var(--fg-warn); color: #fff; }
#app.phase-prep .ctrl-primary { background: var(--fg-prep); }

.ctrl-secondary {
  width: clamp(3.75rem, 10vmin, 6.5rem);
  height: clamp(3.75rem, 10vmin, 6.5rem);
  background: var(--panel);
  color: var(--fg-idle);
  border: 1px solid var(--line);
}
.ctrl-secondary:hover { background: var(--panel-2); }

.ctrl-primary svg { width: 75%; height: 75%; }
.ctrl-secondary svg { width: 58%; height: 58%; }

/* --- Settings panel --- */
/* Settings is a full-screen view, not a floating modal — the instructor
   picks a class mode on an iPad; everything should be visible at once. */
.settings {
  position: fixed; inset: 0;
  background: var(--panel);
  display: none;
  z-index: 50;
}
.settings[aria-hidden="false"] { display: flex; }
.settings-card {
  background: var(--panel);
  color: var(--fg-idle);
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.settings-head, .settings-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem clamp(1.25rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--line);
}
.settings-foot {
  border-bottom: none;
  border-top: 1px solid var(--line);
  gap: 0.75rem;
}
.settings-head h2 {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 1.4rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.set-section {
  padding: 1.25rem clamp(1.25rem, 3vw, 2.5rem) 1.5rem;
  border-bottom: 1px solid var(--line);
}
.set-section:last-child { border-bottom: none; }
.set-section h3 {
  margin: 0 0 1rem;
  font-family: var(--font-brand);
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.presets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 0.75rem;
}
.preset-btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--fg-idle);
  border-radius: 0.85rem;
  padding: 0.9rem 1rem;
  font-family: inherit;
  text-align: left;
  display: flex; flex-direction: column; gap: 0.3rem;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}
.preset-btn .preset-name {
  font-family: var(--font-brand);
  font-size: 1.15rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.preset-btn .preset-detail {
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.preset-btn:hover { background: #25262d; }
.preset-btn.active {
  background: var(--fg-work);
  border-color: var(--fg-work);
  color: #0a0a0b;
}
.preset-btn.active .preset-detail { color: rgba(10,10,11,0.7); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem 1.25rem;
}
.toggles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 0.75rem;
}
@media (max-width: 480px) {
  .grid, .toggles { grid-template-columns: 1fr; }
}

/* iPad landscape / big screens: two columns, everything visible at once.
   Modes run down the left as one-per-row tap targets; timing + sound
   stack on the right. (Must stay AFTER the base .presets/.grid rules —
   equal specificity, source order decides.) */
@media (orientation: landscape) and (min-width: 900px) {
  .settings-body {
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    grid-template-rows: auto 1fr;
    overflow: hidden;
  }
  .sec-modes { grid-row: 1 / span 2; border-right: 1px solid var(--line); overflow-y: auto; }
  .sec-sound { border-bottom: none; overflow-y: auto; }
  .presets { grid-template-columns: 1fr; }
  .preset-btn {
    flex-direction: row; align-items: center; justify-content: space-between;
    padding: 1.1rem 1.25rem;
  }
  .preset-btn .preset-name { font-size: 1.35rem; }
  .preset-btn .preset-detail { font-size: 1rem; }
  .grid { grid-template-columns: 1fr; gap: 0.8rem; }
  .grid .field:not(.switch-field) {
    flex-direction: row; align-items: center; justify-content: space-between;
    gap: 1rem;
  }
  .grid .field:not(.switch-field) > .stepper { width: 12rem; flex: 0 0 auto; }
  .grid .field:not(.switch-field) > .time-fields { width: 17rem; flex: 0 0 auto; }
  .toggles { grid-template-columns: 1fr; }
}
.field {
  display: flex; flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 500;
}
.field.switch-field {
  flex-direction: row; align-items: center; justify-content: space-between;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  text-transform: none;
  font-size: 0.95rem;
  letter-spacing: 0;
  color: var(--fg-idle);
}

.stepper {
  display: flex; align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  overflow: hidden;
}
.stepper button {
  background: transparent;
  border: none;
  color: var(--fg-idle);
  width: 3rem; height: 3.25rem;
  font-size: 1.5rem;
  cursor: pointer;
  font-family: inherit;
}
.stepper button:hover { background: rgba(255,255,255,0.05); }
.stepper input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--fg-idle);
  text-align: center;
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 700;
  width: 100%;
  min-width: 0;
  -moz-appearance: textfield;
}
.stepper input:focus { outline: none; background: rgba(255,255,255,0.04); }
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.time-fields {
  display: flex; align-items: center; gap: 0.4rem;
}
.time-fields .stepper { flex: 1; }
.colon { font-family: var(--font-mono); font-weight: 700; color: var(--muted); }

.switch {
  position: relative; display: inline-block;
  width: 48px; height: 28px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background-color: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: 200ms;
}
.slider::before {
  content: "";
  position: absolute;
  height: 20px; width: 20px;
  left: 3px; top: 50%;
  transform: translateY(-50%);
  background: var(--fg-idle);
  border-radius: 50%;
  transition: 200ms;
}
.switch input:checked + .slider { background: var(--fg-work); border-color: var(--fg-work); }
.switch input:checked + .slider::before { transform: translate(20px, -50%); background: #0a0a0b; }

.apply-btn, .link-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  border-radius: 0.75rem;
  padding: 0.75rem 1.25rem;
  cursor: pointer;
  transition: background-color 150ms ease, transform 120ms ease;
}
.apply-btn {
  background: var(--fg-work);
  color: #0a0a0b;
  border: none;
}
.apply-btn:hover { background: #00ffa0; }
.apply-btn:active { transform: scale(0.97); }
.link-btn {
  background: transparent;
  color: var(--fg-idle);
  border: 1px solid var(--line);
}
.link-btn:hover { background: var(--panel-2); }

/* --- Toast --- */
.toast {
  position: fixed;
  left: 50%; bottom: 5%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel);
  color: var(--fg-idle);
  border: 1px solid var(--line);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- 16:9 mode tweaks for TV mirroring --- */
/* Big-screen mode. Target rig: iPad landscape (~4:3, e.g. 1180x820)
   screen-mirrored to a 16:9 TV — so this must fire on landscape iPads,
   not just wide 16:9 viewports. Sized so the clock + always-on logo +
   controls all fit at both 4:3-landscape and true 16:9. */
@media (orientation: landscape) and (min-width: 900px) {
  :root {
    --size-time: min(clamp(8rem, 42vmin, 32rem), 32vw);
    --size-phase: clamp(1.5rem, 5vmin, 3.5rem);
  }
  .topbar { padding: 0.75rem 3rem; }
  .controls { padding: 1rem 3rem 2rem; }
}

/* --- Fullscreen polish --- */
:fullscreen #app, :-webkit-full-screen #app { background: var(--bg-idle); }
