:root {
  --bg: #0b0c0e;
  --surface: #16181d;
  --surface-2: #22252c;
  --line: rgba(244, 241, 234, 0.045);
  --text: #f4f1ea;          /* gi white */
  --muted: #8b9099;
  --ink: #0b0c0e;

  --idle: #f4f1ea;
  --prep: #f2b632;          /* gold */
  --roll: #e8392b;          /* competition red */
  --warn: #ff8a00;
  --rest: #2f80ed;          /* mat blue */
  --accent: var(--idle);

  --display: "Barlow Condensed", "Oswald", "Arial Narrow", Impact, sans-serif;
  --ui: "Barlow", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: var(--ui);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body[data-phase="idle"] { --accent: var(--idle); }
body[data-phase="prep"] { --accent: var(--prep); }
body[data-phase="roll"] { --accent: var(--roll); }
body[data-phase="rest"] { --accent: var(--rest); }
body[data-warn="true"]  { --accent: var(--warn); }

/* Dark tatami: phase glow over a grid of mat seams */
body {
  background-color: var(--bg);
  background-image:
    radial-gradient(90% 60% at 50% 42%, color-mix(in srgb, var(--accent) 20%, transparent), transparent 72%),
    radial-gradient(140% 100% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.65)),
    linear-gradient(var(--line) 2px, transparent 2px),
    linear-gradient(90deg, var(--line) 2px, transparent 2px);
  background-size: 100% 100%, 100% 100%, 160px 160px, 160px 160px;
  background-position: center, center, center, center;
  background-attachment: fixed;
  transition: background-color 0.4s;
}

/* 3D mat background (scene.js). When it runs, it replaces the CSS tatami grid. */
.mat3d {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

html[data-bg="3d"] body {
  background-image: none;
}

/* Soft vignette + phase glow over the 3D scene, keeps the clock readable */
html[data-bg="3d"] body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(80% 50% at 50% 42%, rgba(11, 12, 14, 0.55), transparent 75%),
    radial-gradient(140% 100% at 50% 50%, transparent 50%, rgba(0, 0, 0, 0.7));
}

.app {
  position: relative;
  z-index: 1;
}

/* Full-screen colour flash on every phase change, readable from across the mat */
.flash {
  position: fixed;
  inset: 0;
  background: var(--accent);
  opacity: 0;
  pointer-events: none;
  z-index: 10;
}

/* CSS fallbacks, only used when GSAP is unavailable or reduced motion is on */
html[data-fx="css"] .flash.on { animation: flash 0.7s ease-out; }

@keyframes flash {
  0% { opacity: 0.5; }
  100% { opacity: 0; }
}

.app {
  min-height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---------- Header / round counter ---------- */

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.round {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  column-gap: 12px;
  align-items: end;
}

.label {
  grid-column: 1 / -1;
  color: var(--muted);
  font-family: var(--display);
  font-weight: 700;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.22em;
}

.round-num {
  display: inline-block;
  transform-origin: left bottom;
  font-family: var(--display);
  font-size: clamp(3rem, 11vw, 4.5rem);
  font-weight: 800;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}

/* Rounds as tape stripes on a black belt bar */
.stripes {
  display: flex;
  gap: 4px;
  align-self: center;
  padding: 6px 7px;
  background: #000;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(244, 241, 234, 0.08);
}

.stripes:empty { display: none; }

.stripes span {
  width: 6px;
  height: 22px;
  background: var(--text);
  border-radius: 1px;
}

.top-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
}

.icon-btn[aria-pressed="false"] { opacity: 0.45; }

/* ---------- Clock ---------- */

.clock {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  min-height: 42vh;
}

.phase {
  padding: 0.3em 1em 0.25em;
  background: var(--accent);
  color: var(--ink);
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(1.1rem, 4.5vw, 1.8rem);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  border-radius: 4px;
  transform: skewX(-10deg);
  transition: background 0.3s;
}

.time {
  font-family: var(--display);
  font-size: clamp(7rem, 40vw, 26rem);
  font-weight: 800;
  line-height: 0.85;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  color: var(--text);
  text-shadow: 0 0 60px color-mix(in srgb, var(--accent) 35%, transparent);
}

body[data-warn="true"] .time { color: var(--warn); }

html[data-fx="css"] body[data-warn="true"] .time { animation: pulse 1s ease-in-out infinite; }

body[data-paused="true"] .time { opacity: 0.4; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

/* Progress bar styled as a belt: stitched fabric with a black rank bar */
.belt {
  position: relative;
  width: 100%;
  height: 28px;
  margin-top: 14px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6);
}

.belt-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left center;
  transition: background 0.3s;
}

.belt::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(to bottom, transparent 0 4px, rgba(0, 0, 0, 0.22) 4px 5px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.12), transparent 40%, rgba(0, 0, 0, 0.25));
  pointer-events: none;
}

.belt-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 7%;
  width: 13%;
  background: #000;
  box-shadow: -1px 0 0 rgba(255, 255, 255, 0.1), 1px 0 0 rgba(255, 255, 255, 0.1);
}

/* ---------- Controls ---------- */

.controls {
  display: grid;
  grid-template-columns: 1fr 1.6fr 1fr;
  gap: 12px;
}

.btn {
  height: 76px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
  touch-action: manipulation;
  transition: transform 0.08s, background 0.3s;
}

.btn:active { transform: scale(0.97); }

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--ink);
  font-size: 1.75rem;
  box-shadow: 0 8px 30px color-mix(in srgb, var(--accent) 35%, transparent);
}

body[data-phase="idle"] .btn.primary {
  --accent: var(--roll);
  color: var(--text);
}

body[data-phase="roll"]:not([data-warn="true"]) .btn.primary { color: var(--text); }
body[data-phase="rest"] .btn.primary { color: var(--text); }

.btn.secondary { background: var(--surface); }
.btn:disabled { opacity: 0.3; cursor: default; }

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

.settings {
  display: grid;
  gap: 18px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

.settings { overflow: hidden; }

html[data-fx="css"] body[data-running="true"] .settings { display: none; }

.setting { display: grid; gap: 10px; }

.setting-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.stepper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stepper output {
  min-width: 3.6ch;
  text-align: center;
  font-family: var(--display);
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.step {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  flex: 1 0 auto;
  min-width: 58px;
  height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  border: 2px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  border-color: var(--roll);
  background: color-mix(in srgb, var(--roll) 18%, var(--surface-2));
}

/* Landscape phones */
@media (orientation: landscape) and (max-height: 520px) {
  .app { gap: 10px; }
  .clock { min-height: auto; gap: 6px; }
  .time { font-size: clamp(5rem, 46vh, 16rem); }
  .belt { height: 20px; margin-top: 6px; }
  .btn { height: 58px; }
}

@media (prefers-reduced-motion: reduce) {
  .flash.on, body[data-warn="true"] .time { animation: none !important; }
}
