/* ============================================================
   Clay — claymorphism design system for the Makerspace scoreboard
   ============================================================ */

:root {
  /* Palette */
  --bg: #eef0fb;
  --bg-2: #fdf3ec;
  --ink: #3b3a51;
  --ink-soft: #77758f;
  --clay: #f6f4ff;
  --accent: #7c6cf0;
  --accent-soft: #d9d3ff;
  --good: #4ec98c;
  --warn: #f7b955;
  --danger: #f2708a;

  /* Puffy clay shadows */
  --clay-out:
    0 14px 28px rgba(80, 70, 140, 0.16),
    0 4px 8px rgba(80, 70, 140, 0.08),
    inset 6px 6px 12px rgba(255, 255, 255, 0.85),
    inset -6px -8px 14px rgba(96, 84, 160, 0.14);
  --clay-out-sm:
    0 6px 14px rgba(80, 70, 140, 0.14),
    inset 3px 3px 7px rgba(255, 255, 255, 0.85),
    inset -3px -4px 8px rgba(96, 84, 160, 0.14);
  --clay-in:
    inset 6px 8px 14px rgba(96, 84, 160, 0.18),
    inset -4px -4px 10px rgba(255, 255, 255, 0.9);

  --radius: 28px;
  --radius-sm: 18px;

  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Quicksand",
    "Comfortaa", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

/* Lucide sprite icons: size and color follow the surrounding text */
.icon {
  width: 1.15em;
  height: 1.15em;
  display: inline-block;
  vertical-align: -0.2em;
  flex-shrink: 0;
}

html, body { margin: 0; min-height: 100%; }

body {
  background:
    radial-gradient(1200px 700px at 85% -10%, var(--bg-2) 0%, transparent 60%),
    radial-gradient(1000px 800px at -10% 110%, #e4f4ee 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0 0 .5em; font-weight: 800; letter-spacing: -0.02em; }

/* ---------- Cards ---------- */

.clay {
  background: var(--clay);
  border-radius: var(--radius);
  box-shadow: var(--clay-out);
  padding: 24px;
}

.clay-sm {
  background: var(--clay);
  border-radius: var(--radius-sm);
  box-shadow: var(--clay-out-sm);
  padding: 14px 18px;
}

.clay-inset {
  background: #ecebf7;
  border-radius: var(--radius-sm);
  box-shadow: var(--clay-in);
  padding: 12px 16px;
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  color: var(--ink);
  background: var(--clay);
  border-radius: 999px;
  padding: 12px 26px;
  box-shadow: var(--clay-out-sm);
  transition: transform .08s ease, box-shadow .08s ease, filter .12s ease;
  user-select: none;
}
.btn:hover { filter: brightness(1.03); }
.btn:active, .btn.is-pressed {
  box-shadow: var(--clay-in);
  transform: translateY(1px) scale(.99);
}
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-accent { background: linear-gradient(145deg, #8f80f6, var(--accent)); color: #fff; }
.btn-good   { background: linear-gradient(145deg, #63d89d, var(--good));   color: #fff; }
.btn-warn   { background: linear-gradient(145deg, #ffcb74, var(--warn));   color: #6b4d13; }
.btn-danger { background: linear-gradient(145deg, #ff8ba1, var(--danger)); color: #fff; }

.btn-big { font-size: 1.25rem; padding: 16px 34px; }
.btn-icon {
  padding: 10px 16px;
  min-width: 48px;
  font-size: 1.1rem;
  line-height: 1;
}

/* ---------- Forms ---------- */

.field {
  width: 100%;
  border: 0;
  font: inherit;
  color: var(--ink);
  background: #ecebf7;
  border-radius: var(--radius-sm);
  box-shadow: var(--clay-in);
  padding: 12px 16px;
  outline: none;
}
.field:focus { box-shadow: var(--clay-in), 0 0 0 3px var(--accent-soft); }

label.lbl { display: block; font-weight: 700; color: var(--ink-soft); margin: 0 0 6px 6px; font-size: .9rem; }

input[type="color"].field { padding: 6px; height: 48px; cursor: pointer; }

/* ---------- Layout helpers ---------- */

.wrap { max-width: 1100px; margin: 0 auto; padding: 28px 20px 60px; }
.row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }
.stack { display: flex; flex-direction: column; gap: 14px; }
.muted { color: var(--ink-soft); }
.center { text-align: center; }
.spacer { flex: 1; }

/* ---------- Top nav ---------- */

.nav {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 18px 24px;
  margin: 20px auto 8px;
  max-width: 1100px;
}
.nav .brand { font-size: 1.3rem; font-weight: 900; letter-spacing: -0.02em; }
.nav a.btn { text-decoration: none; }

/* ---------- Chips & badges ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #ecebf7;
  box-shadow: var(--clay-in);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 700;
  font-size: .9rem;
}

.dot { width: 14px; height: 14px; border-radius: 50%; box-shadow: inset -2px -2px 4px rgba(0,0,0,.18), inset 2px 2px 3px rgba(255,255,255,.6); }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 12px 24px;
  border-radius: 999px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 99;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

/* ============================================================
   TV display view
   ============================================================ */

.tv {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 2.2vh 2.2vw;
  gap: 2vh;
  overflow: hidden;
}

.tv-header { display: grid; grid-template-columns: 1fr auto 1fr; gap: 2vw; align-items: stretch; }

.tv-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .6vh;
  padding: 2.4vh 2vw;
  border-radius: var(--radius);
  box-shadow: var(--clay-out);
  background: var(--clay);
  position: relative;
  overflow: hidden;
}
.tv-team::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 12px;
  background: var(--team-color, var(--accent));
  opacity: .85;
}
.tv-team .t-name { font-size: min(3.4vh, 6vw); font-weight: 900; letter-spacing: -0.02em; text-align: center; }
.tv-team .t-score { font-size: min(9.5vh, 13vw); font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; color: var(--team-color, var(--accent)); }
.tv-team .t-player { font-size: min(2.4vh, 4.5vw); font-weight: 700; color: var(--ink-soft); text-align: center; }
.tv-team.winner { outline: 6px solid var(--good); }

.tv-vs {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .4vh;
  min-width: 16vw;
}
.tv-vs .vs-word { font-size: min(3vh, 5vw); font-weight: 900; color: var(--ink-soft); }

.tv-timer {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5vh;
  border-radius: var(--radius);
  box-shadow: var(--clay-out);
  background: var(--clay);
  padding: 2vh;
}
.tv-timer .round-label { font-size: min(3.2vh, 5vw); font-weight: 800; color: var(--ink-soft); }
.tv-timer .clock {
  font-size: min(22vh, 26vw);
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.tv-timer .clock.low { color: var(--danger); animation: pulse 1s infinite; }
.tv-timer .clock.paused { color: var(--warn); }
.tv-timer .clock.pre { color: var(--accent); animation: pop .95s infinite; }
@keyframes pop { 0% { transform: scale(.8); opacity: .4; } 25% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }

/* Sound toggle on the TV display */
.snd-btn {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  border: 0;
  cursor: pointer;
  font-size: 1.5rem;
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--clay);
  box-shadow: var(--clay-out-sm);
  opacity: .9;
}
.snd-btn.armed { animation: pulse 1.4s infinite; }
.snd-btn:active { box-shadow: var(--clay-in); }
.tv-timer .status-line { font-size: min(2.6vh, 4.5vw); font-weight: 700; color: var(--ink-soft); text-align: center; }
@keyframes pulse { 50% { transform: scale(1.045); } }

.tv-rounds { display: flex; gap: 1vw; justify-content: center; flex-wrap: wrap; }
.tv-round-chip {
  background: #ecebf7;
  box-shadow: var(--clay-in);
  border-radius: 16px;
  padding: 1vh 1.2vw;
  text-align: center;
  min-width: max(6.5vw, 58px);
}
.tv-round-chip .rc-n { font-size: max(min(1.6vh, 3vw), 11px); font-weight: 800; color: var(--ink-soft); }
.tv-round-chip .rc-s { font-size: max(min(2.6vh, 5vw), 14px); font-weight: 900; font-variant-numeric: tabular-nums; }
.tv-round-chip.current { outline: 3px solid var(--accent); background: var(--clay); box-shadow: var(--clay-out-sm); }
.tv-round-chip.more { display: flex; align-items: center; justify-content: center; min-width: 0; color: var(--ink-soft); font-weight: 900; }

.tv-idle {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2vh;
}
.tv-idle .big { font-size: min(7vh, 8vw); font-weight: 900; }

.tv-winner-banner {
  text-align: center;
  font-size: min(5vh, 6.5vw);
  font-weight: 900;
  padding: 2vh;
  border-radius: var(--radius);
  background: linear-gradient(145deg, #63d89d, var(--good));
  color: #fff;
  box-shadow: var(--clay-out);
}

/* ============================================================
   Control view bits
   ============================================================ */

.score-pad { display: flex; align-items: center; gap: 12px; justify-content: center; }
.score-pad .score-val {
  font-size: 3rem;
  font-weight: 900;
  width: 130px;      /* number inputs have no fixed width by default and grow huge with font-size */
  min-width: 0;
  max-width: 45vw;
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: #ecebf7;
  box-shadow: var(--clay-in);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  border: 0;
  -moz-appearance: textfield;
  appearance: textfield;
}
.score-pad .score-val::-webkit-outer-spin-button,
.score-pad .score-val::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.lineup li {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #ecebf7;
  box-shadow: var(--clay-in);
  border-radius: var(--radius-sm);
}
.lineup { padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.lineup .slot-n {
  font-weight: 900;
  color: #fff;
  background: var(--team-color, var(--accent));
  border-radius: 50%;
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.ctl-clock {
  font-size: 4rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-align: center;
  line-height: 1;
}
.ctl-clock.low { color: var(--danger); }
.ctl-clock.paused { color: var(--warn); }

.round-history td, .round-history th { padding: 8px 12px; text-align: center; }
.round-history { border-collapse: collapse; width: 100%; }
.round-history th { color: var(--ink-soft); font-size: .85rem; }
.round-history tr:not(:last-child) td { border-bottom: 2px solid #e3e1f2; }

/* ============================================================
   Responsive
   ============================================================ */

.nav { flex-wrap: wrap; }

/* TV display in portrait (or narrow screens): stack the header —
   round chip + VS on top, the two team cards side by side below,
   and let the page scroll if it runs out of height. */
@media (orientation: portrait), (max-width: 720px) {
  .tv { height: auto; min-height: 100vh; min-height: 100dvh; overflow: visible; }
  .tv-header { grid-template-columns: 1fr 1fr; gap: 3vw; }
  .tv-vs {
    grid-column: 1 / -1;
    order: -1;
    flex-direction: row;
    justify-content: center;
    min-width: 0;
    gap: 3vw;
  }
  .tv-timer { min-height: 34vh; }
  .tv-team { padding: 2vh 3vw; }
}

/* Phones: tighter chrome, smaller controls, scrollable tables. */
@media (max-width: 640px) {
  h1 { font-size: 1.5rem; }
  .wrap { padding: 16px 12px 48px; }
  .nav { margin: 10px 8px 6px; padding: 10px 12px; gap: 8px; }
  .nav .brand { font-size: 1.05rem; }
  .btn { padding: 10px 18px; }
  .btn-big { font-size: 1.05rem; padding: 12px 22px; }
  .btn-icon { min-width: 40px; padding: 8px 10px; }
  .clay { padding: 18px; }
  .ctl-clock { font-size: 3.2rem; }
  .score-pad { gap: 8px; }
  .score-pad .score-val { font-size: 2.2rem; min-width: 0; width: 84px; }
  .lineup li { gap: 6px; padding: 8px 10px; }
  .lineup li .btn-icon { min-width: 34px; padding: 7px 8px; font-size: 1rem; }
  .lineup li > span[style] { font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lineup .slot-n { width: 26px; height: 26px; font-size: .85rem; }
  .round-history { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .round-history td, .round-history th { padding: 6px 6px; font-size: .9rem; }
  #toast { max-width: 92vw; text-align: center; }
}
