/* Gridiron Bowl - retro UI. Flat colours, pixel font, minimal chrome. */

:root {
  --bg: #0b0d10;
  --panel: #14181d;
  --panel-2: #1d232a;
  --ink: #f5f5f5;
  --muted: #9aa3ad;
  --accent: #facc15;
  --danger: #f87171;
  --grass: #3a8a34;
  --font: "Press Start 2P", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  /* No double-tap-to-zoom anywhere (applies to everything inside too);
     scrolling still works. The canvas goes further with touch-action: none. */
  touch-action: manipulation;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 12px;
  line-height: 1.6;
  -webkit-font-smoothing: none;
  overscroll-behavior: none;
}

body.locked #app { visibility: hidden; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 9px; }
.warn { color: var(--accent); }

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 8px 16px;
  gap: 6px;
}

/* 16:10 stage that fits the viewport in both dimensions. */
#stage {
  position: relative;
  width: min(100%, calc((100vh - 60px) * 1.6));
  width: min(100%, calc((100dvh - 60px) * 1.6)); /* dvh: ignores mobile browser toolbars */
  aspect-ratio: 960 / 600;
  /* Overlay panels size themselves in cqw so they scale with the field, not the device. */
  container-type: inline-size;
  background: #000;
  border: 4px solid #2a2f36;
  box-shadow: 0 0 0 4px #000;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}

#toolbar { display: flex; gap: 8px; }

/* ------------------------------------------------------------------ buttons */

.btn {
  font: inherit;
  color: #111;
  background: var(--accent);
  border: 0;
  border-bottom: 4px solid #a16207;
  padding: 10px 14px;
  cursor: pointer;
  text-transform: uppercase;
}
.btn:hover:not(:disabled) { filter: brightness(1.1); }
.btn:active:not(:disabled) { transform: translateY(2px); border-bottom-width: 2px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.btn.ghost { background: var(--panel-2); color: var(--ink); border-bottom-color: #000; }
.btn.small { font-size: 9px; padding: 6px 10px; }

/* ------------------------------------------------------------ full screens */

.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 16px;
  background: rgba(11, 13, 16, 0.96);
  text-align: center;
}
#loading { display: grid; place-items: center; font-size: 16px; }

.logo {
  font-size: clamp(18px, 4vw, 32px);
  color: var(--accent);
  text-shadow: 4px 4px 0 #a16207;
  margin: 8px 0 12px;
  letter-spacing: 2px;
}
.screen h2 { font-size: 14px; margin: 10px 0; }

.menu-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 10px 0;
}
select {
  font: inherit;
  font-size: 10px;
  background: var(--panel-2);
  color: var(--ink);
  border: 2px solid #3a414a;
  padding: 8px;
}

.conf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
  max-width: 980px;
  margin: 0 auto;
  text-align: left;
}
.conf-head {
  margin: 0 0 6px;
  padding: 6px 8px;
  font-size: 14px;
  color: var(--accent);
  border-bottom: 3px solid #2a2f36;
}
.division { margin-bottom: 10px; }
.div-head { margin: 4px 0; font-size: 9px; color: var(--muted); }
.div-teams { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.team-tile {
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 2px;
  border: 0;
  border-bottom: 5px solid;
  min-width: 0;
  cursor: pointer;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6);
}
.team-tile:hover:not(:disabled) { filter: brightness(1.15); transform: translateY(-2px); }
.team-tile.is-user { opacity: 0.45; cursor: default; }
.team-tile:focus-visible { outline: 3px solid #fff; }
.team-tile .abbr { font-size: 15px; }
.team-tile .tname { font-size: 6px; }
.team-tile .ovr { font-size: 8px; opacity: 0.85; }
.team-tile .rec { font-size: 7px; opacity: 0.85; }

/* ------------------------------------------------------------- play call */

.panel {
  position: absolute;
  background: rgba(20, 24, 29, 0.94);
  border: 3px solid #000;
  box-shadow: 0 0 0 3px #3a414a;
}
.panel.bottom {
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  padding: 8px 10px;
  max-width: 96%;
}
.panel { font-size: clamp(7px, 1.15cqw, 12px); }
.pc-head { text-align: center; color: var(--accent); margin-bottom: 0.5em; font-size: 1.05em; }
.pc-buttons { display: flex; flex-wrap: wrap; gap: 0.5em; justify-content: center; max-width: 60em; }
.play-btn { display: flex; flex-direction: column; align-items: center; gap: 0.3em; min-width: 9em; font-size: 1em; padding: 0.8em 1em; }
.play-btn .key { font-size: 0.75em; opacity: 0.6; }
.play-btn small { font-size: 0.75em; }
.play-btn.special { background: #93c5fd; border-bottom-color: #1d4ed8; }
.play-btn.clock { background: #fca5a5; border-bottom-color: #b91c1c; }

/* ------------------------------------------------------- opponent drive */

.panel.side {
  top: 12%;
  right: 1.5%;
  width: min(460px, 60%);
  max-height: 84%;
  display: flex;
  flex-direction: column;
  padding: 10px;
}
.sim-head { border-bottom: 3px solid; padding-bottom: 6px; margin-bottom: 6px; font-size: 1.1em; }
.sim-team { padding: 2px 6px; margin-right: 4px; }
.sim-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.sim-list li { padding: 4px 0; border-bottom: 1px dashed #2a2f36; }
.sim-list li.big { color: var(--accent); }
.sim-list li.muted { color: var(--muted); }

/* ------------------------------------------------------------- summary */

.linescore { margin: 10px auto; border-collapse: collapse; font-size: 11px; }
.linescore th, .linescore td { padding: 6px 10px; border: 2px solid #2a2f36; }
.linescore .total { color: var(--accent); }
.sum-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: left; max-width: 900px; margin: 0 auto; }
.sum-col { background: var(--panel); padding: 0 0 8px; font-size: 9px; }
.sum-col h3 { margin: 0 0 8px; padding: 8px; font-size: 10px; }
.sum-col h4 { margin: 10px 8px 2px; color: var(--accent); font-size: 9px; }
.sum-col p { margin: 2px 8px; }
.sum-col dl { display: grid; grid-template-columns: auto auto; gap: 2px 10px; margin: 0 8px; }
.sum-col dd { margin: 0; text-align: right; }

/* ---------------------------------------------------------------- help */

#help { text-align: left; max-width: none; font-size: 10px; }
#help h2 { text-align: center; }
#help h3 { color: var(--accent); font-size: 10px; margin: 14px 0 4px; }
#help p { margin: 4px 0; max-width: 760px; }

/* --------------------------------------------------------------- login */

.login-page { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.login-card {
  background: var(--panel);
  border: 4px solid #2a2f36;
  padding: 24px;
  width: min(420px, 100%);
  text-align: center;
}
.login-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; text-align: left; }
.login-card input {
  font: inherit;
  padding: 10px;
  background: #000;
  color: var(--ink);
  border: 3px solid #3a414a;
}
.login-card input:focus { outline: none; border-color: var(--accent); }

/* ------------------------------------------------------------- mobile */

#rotate-hint { display: none; color: var(--muted); font-size: 9px; text-align: center; }
@media (orientation: portrait) and (max-width: 700px) {
  #rotate-hint { display: block; }
  .sum-cols { grid-template-columns: 1fr; }
  .panel.side { width: 92%; right: 4%; }
}

/* Phones in landscape: put HELP / LOG OUT beside the field so it can use the
   full screen height. */
@media (orientation: landscape) and (max-height: 520px) {
  #app { flex-direction: row; padding: 4px 8px; gap: 8px; }
  #stage {
    width: min(calc(100vw - 100px), calc((100vh - 12px) * 1.6));
    width: min(calc(100vw - 100px), calc((100dvh - 12px) * 1.6));
    border-width: 2px;
  }
  #toolbar { flex-direction: column; }
}

/* Belt and braces for older browsers that don't apply the html/body rule to children. */
button, .team-tile { touch-action: manipulation; }

/* Phones / small windows: menus, summary and help take over the WHOLE screen
   instead of scrolling inside the small game-field box. */
@media (max-width: 900px), (max-height: 600px) {
  .screen {
    position: fixed;
    inset: 0;
    z-index: 10;
    padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
             max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    background: var(--bg);
    -webkit-overflow-scrolling: touch;
  }
  .conf-grid { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
}

/* ------------------------------------------------------- title & season */

.logo.big { font-size: clamp(24px, 6vw, 48px); margin-top: 24px; }
.title-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; margin: 20px auto; max-width: 420px; }
.btn.big { width: 100%; font-size: 14px; padding: 14px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.btn.big small { font-size: 8px; opacity: 0.75; text-transform: none; }

.card { background: var(--panel); border: 3px solid #2a2f36; padding: 12px 16px; margin: 12px auto; max-width: 640px; text-align: center; }
.card h3 { margin: 0 0 8px; color: var(--accent); font-size: 13px; }
.card p { margin: 6px 0; }
.card.challenge { border-color: var(--accent); }
.card.challenge.won, .card.champ { border-color: #4ade80; }
.card.champ h3 { color: #4ade80; }
.card.next .matchup { font-size: 12px; }

.chip { display: inline-block; padding: 2px 5px; color: #fff; text-shadow: 1px 1px 0 rgba(0,0,0,0.6); font-size: 0.9em; }
.chip.big { font-size: 20px; padding: 10px 12px; }

.hub-head { display: flex; gap: 14px; align-items: center; justify-content: center; text-align: left; margin-top: 8px; }
.hub-head h2 { margin: 0 0 4px; }
.hub-head p { margin: 0; font-size: 9px; }
.note { color: #4ade80; }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin: 14px 0 8px; }
.tab { font: inherit; font-size: 9px; padding: 8px 10px; background: var(--panel-2); color: var(--muted); border: 0; border-bottom: 3px solid transparent; cursor: pointer; }
.tab.on { color: var(--ink); border-bottom-color: var(--accent); }
.tab-body { max-width: 980px; margin: 0 auto; text-align: left; font-size: 9px; }
.tab-body h3 { font-size: 10px; color: var(--accent); }

.standings { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
table.std, table.sched { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.std th, .std td, .sched td { padding: 5px 6px; border-bottom: 1px solid #2a2f36; text-align: left; }
.std th { color: var(--muted); font-weight: normal; }
.std tr.me, .sched tr.now { background: rgba(250, 204, 21, 0.12); }
.std td.seed { color: var(--accent); }
.sched tr.bye td { color: var(--muted); }

.scores { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; }
.score { display: flex; gap: 6px; align-items: center; background: var(--panel); padding: 6px 8px; }
.score.me { outline: 2px solid var(--accent); }
.score .won { color: #4ade80; }
.score .at { color: var(--muted); }
.season-stats p, .bracket p { margin: 3px 0; }

/* ---------------------------------------------------------- highlights */

.highlights { max-width: 760px; margin: 12px auto; text-align: left; background: var(--panel); padding: 10px 12px; font-size: 9px; }
.highlights h3 { margin: 0 0 8px; color: var(--accent); font-size: 10px; }
.highlights ul { list-style: none; margin: 0; padding: 0; }
.highlights li { display: flex; gap: 8px; align-items: center; padding: 5px 0; border-bottom: 1px dashed #2a2f36; }
.highlights li span { flex: 1; }
.hl-video { width: 100%; max-height: 50vh; background: #000; margin-bottom: 8px; image-rendering: pixelated; }

/* ?audio troubleshooting line */
.audio-debug {
  position: fixed; left: 4px; bottom: 4px; z-index: 99;
  padding: 4px 6px; background: rgba(0, 0, 0, 0.8); color: #fde047;
  font: 9px/1.4 var(--font); pointer-events: none;
}

/* Soundtrack picker */
.title-top { display: flex; justify-content: flex-end; }
.track-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; max-width: 760px; margin: 16px auto; }
.btn.track { display: flex; flex-direction: column; gap: 6px; text-align: left; font-size: 11px; }
.btn.track small { font-size: 8px; opacity: 0.8; text-transform: none; }
.btn.track.selected { outline: 3px solid #fff; }
