/* Football Squares styles.
 *
 * All colors are CSS variables ("custom properties") defined in :root.
 * To re-theme the app (or a single board, later), we only change these
 * values; the rest of the CSS refers to them with var(--name).
 */

:root {
  --primary: #4F2683;        /* Vikings purple */
  --accent: #FFC62F;         /* Vikings gold */
  --on-primary: #FFFFFF;     /* text on purple */
  --bg: #F7F5FA;             /* page background */
  --surface: #FFFFFF;        /* cards, table cells */
  --text: #1A1A1A;
  --muted: #5B5B66;
  --border: #D6D1DE;
  --error: #B00020;
  --flash-bg: #FFF4CC;       /* pale gold */
  --taken-bg: #E6E1EE;       /* square claimed by someone else */
  --mine-bg: #FFC62F;        /* my squares: gold */
  --mine-fg: #1A1A1A;
}

/* Dark rooms: follow the phone's dark mode setting. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15121B;
    --surface: #221D2B;
    --text: #F2F0F5;
    --muted: #B5B0BF;
    --border: #3A3346;
    --error: #FF8A80;
    --flash-bg: #3D3317;
    --taken-bg: #3A3346;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;   /* 16px stops iPhones from zooming in on form fields */
  line-height: 1.4;
  background: var(--bg);
  color: var(--text);
}

.site-header {
  background: var(--primary);
  padding: 12px 16px;
  border-bottom: 4px solid var(--accent);
  display: flex;               /* brand on the left, nav on the right */
  align-items: center;
  justify-content: space-between;
}

.nav { display: flex; align-items: center; gap: 16px; }
.nav form { margin: 0; }
/* A <button> that looks like a link (for actions that must be POST forms). */
.link-button {
  color: var(--primary);
  font: inherit;
  text-decoration: underline;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}
@media (prefers-color-scheme: dark) {
  .link-button { color: var(--accent); }
}
/* In the purple header, links and link-buttons are white. */
.nav a,
.nav .link-button { color: var(--on-primary); }

.brand {
  color: var(--on-primary);
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

a { color: var(--primary); }
@media (prefers-color-scheme: dark) {
  a { color: var(--accent); }
}

/* The hello-world status table */
.status {
  border-collapse: collapse;
  width: 100%;
  background: var(--surface);
}
.status th,
.status td {
  text-align: left;
  padding: 8px 10px;
  border: 1px solid var(--border);
}
.status th { color: var(--muted); font-weight: 600; width: 45%; }

h2 { margin-top: 28px; font-size: 1.15rem; }

/* One-time messages ("Welcome!", "You're logged out.") */
.flash {
  background: var(--flash-bg);
  border-left: 4px solid var(--accent);
  padding: 10px 12px;
}

/* Forms: big, full-width fields that are easy to tap on a phone */
.form { display: flex; flex-direction: column; gap: 14px; margin-bottom: 20px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field input {
  width: 100%;
  min-height: 44px;            /* Apple's minimum comfortable tap size */
  padding: 8px 10px;
  font-size: 16px;             /* 16px+ stops iPhones zooming in */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.field input:focus { outline: 3px solid var(--accent); border-color: var(--primary); }
.has-error input { border-color: var(--error); }
.error { color: var(--error); margin: 4px 0 0; font-size: 0.9rem; }

.button {
  min-height: 48px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--on-primary);
  background: var(--primary);
  border: 2px solid var(--primary);
  border-radius: 8px;
  cursor: pointer;
}
.button:active { transform: translateY(1px); }

/* Links styled as buttons, and a red "danger" link-button */
.button-link {
  display: inline-flex;
  align-items: center;
  padding: 0 18px;
  text-decoration: none;
}
.link-button.danger { color: var(--error); }

/* Board form */
fieldset {
  min-width: 0;                /* browsers default fieldsets to "never shrink"; let it fit the phone */
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
legend { font-weight: 700; padding: 0 4px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; min-width: 0; }
.field input[type="color"] { padding: 4px; }

select {
  min-height: 44px;
  font-size: 16px;
  padding: 6px 8px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* ------------------------------------------------------------ the board */

.matchup h1 { font-size: 1.3rem; margin: 0 0 2px; }
.matchup .vs { color: var(--muted); font-weight: 400; }
.kickoff { color: var(--muted); margin: 0 0 12px; }
.board-help, .my-count { margin: 6px 0; }
.my-count { font-weight: 600; }

.admin-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
  padding: 8px 10px;
  background: var(--flash-bg);
  border-radius: 8px;
}

/* The grid: [side name][side digits][5 squares], all sized to fit the screen.
   minmax(0, 1fr) lets the 5 square columns share the space evenly without
   ever pushing the grid wider than the phone. */
.board {
  display: grid;
  grid-template-columns: 1.5rem 2.6rem repeat(5, minmax(0, 1fr));
  gap: 3px;
  margin: 12px 0 6px;
  user-select: none;
}

.corner { grid-column: span 2; grid-row: span 2; }

/* Team headers use each team's colors, set as CSS variables on .board. */
.top-name,
.top-digit {
  background: var(--top-bg);
  color: var(--top-fg);
}
.side-name,
.side-digit {
  background: var(--side-bg);
  color: var(--side-fg);
}

.top-name {
  grid-column: span 5;
  text-align: center;
  font-weight: 700;
  padding: 6px 4px;
  border-radius: 6px 6px 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-name {
  grid-row: span 5;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px 0 0 6px;
  overflow: hidden;
}
.side-name span {
  writing-mode: vertical-rl;     /* text runs top-to-bottom... */
  transform: rotate(180deg);     /* ...flipped so it reads bottom-to-top */
  font-weight: 700;
  white-space: nowrap;
}

.top-digit,
.side-digit {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  min-height: 2rem;
}

/* A square */
.sq {
  aspect-ratio: 1;               /* always a square */
  min-height: 44px;              /* comfortable to tap */
  padding: 2px;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}
/* The name inside a square: one line; if it's too long for this phone,
   end it with "…". */
.sq-name {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sq.taken { background: var(--taken-bg); }
.sq.mine {
  background: var(--mine-bg);
  color: var(--mine-fg);
  border: 2px solid var(--primary);
  font-weight: 800;
}
.sq:focus-visible { outline: 3px solid var(--primary); outline-offset: 1px; }
.board.locked .sq { cursor: default; }
.board:not(.locked) .sq:not(.taken):not(.mine):hover { border-color: var(--primary); }

.board-message { min-height: 1.4em; font-weight: 600; }
.board-message.error { color: var(--error); }

.admin-board-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.admin-board-actions form { margin: 0; }

/* A square that won a checkpoint: thick gold outline + a little label */
.sq.win {
  position: relative;
  outline: 3px solid var(--accent);
  outline-offset: -1px;
  box-shadow: 0 0 0 5px var(--primary);
  z-index: 1;
}
.win-badge {
  position: absolute;
  bottom: 1px;
  left: 0;
  right: 0;
  font-size: 0.55rem;
  font-weight: 800;
  color: var(--primary);
}
.sq.mine .win-badge { color: var(--mine-fg); }

.draw-form { margin: 16px 0; }
.draw-button { width: 100%; background: var(--accent); color: #1A1A1A; border-color: var(--primary); }

/* Quarter results table under the grid */
.results h2 { margin: 18px 0 8px; }
.results-table { width: 100%; border-collapse: collapse; background: var(--surface); }
.results-table th,
.results-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.results-table th { color: var(--muted); font-weight: 600; }
.results-table .score { font-variant-numeric: tabular-nums; white-space: nowrap; }
.results-table .winner { font-weight: 700; }
.results-table tr.mine { background: var(--flash-bg); }

/* ------------------------------------------------------ live score bar */
.score-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 8px 0 10px;
}
.score-team {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 800;
}
.score-team .abbr { font-size: 1rem; }
.score-team .points { font-size: 1.9rem; font-variant-numeric: tabular-nums; }
.score-status {
  grid-column: span 2;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 600;
}
.score-status .updated { color: var(--muted); font-weight: 400; font-size: 0.85rem; text-align: right; }
.score-warning { color: var(--error); font-weight: 600; margin: 0 0 8px; }
.score-placeholder { color: var(--muted); }

/* Admin tools under the board */
.admin-score-actions,
.fake-game {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-top: 16px;
}
.admin-score-actions form,
.fake-game form { margin: 0; }
.fake-game { padding: 8px 10px; border: 1px dashed var(--border); border-radius: 8px; }

/* Game picker */
.game-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.game {
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  min-height: 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}
.game.vikings { border: 2px solid var(--primary); }
.game-name { font-weight: 700; }
.game-time { color: var(--muted); font-size: 0.9rem; }

/* Manual score table */
.score-entry { border-collapse: collapse; width: 100%; }
.score-entry th { padding: 4px; text-align: center; }
.score-entry td { padding: 2px; }
.score-entry input {
  width: 100%;
  min-height: 44px;
  font-size: 16px;
  text-align: center;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.hint { color: var(--muted); font-size: 0.9rem; margin: 0; }

/* Section links under the header: Board · History · Leaders */
.subnav {
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 6px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.subnav a {
  padding: 6px 14px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}
.subnav a[aria-current="page"] { background: var(--primary); color: var(--on-primary); }

.muted { color: var(--muted); }
.tag {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: #1A1A1A;
}

/* Game over banner (admin) */
.game-over {
  background: var(--flash-bg);
  border: 2px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.game-over p { margin: 0 0 8px; }
.game-over .button { width: 100%; }

/* Read-only past board: squares aren't buttons you can use */
.board.read-only .sq { cursor: default; }

/* Your squares (digit pairs) */
.my-squares h2 { margin: 18px 0 8px; }
.my-squares ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.my-squares li {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 8px 10px;
  background: var(--surface);
  border-left: 4px solid var(--mine-bg);
  border-radius: 6px;
}
.my-squares strong { font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.my-squares .won { font-weight: 700; }

/* History cards */
.history-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.history-card {
  display: block;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}
.history-top { display: flex; justify-content: space-between; align-items: center; }
.history-teams { font-weight: 800; font-size: 1.1rem; }
.history-when { color: var(--muted); font-size: 0.9rem; }
.history-score { font-weight: 700; margin-top: 4px; }
.history-winners { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: 0.9rem; }
.history-winners .mine { font-weight: 800; }

.leaderboard .num { text-align: right; font-variant-numeric: tabular-nums; }

/* The square that would win if the game ended right now: a pulsing gold
   outline and a little "NOW" tag. */
.sq.leading {
  position: relative;
  z-index: 2;
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  animation: pulse 1.6s ease-in-out infinite;
}
.sq.leading::before {
  content: "NOW";
  position: absolute;
  top: 1px;
  left: 0;
  right: 0;
  font-size: 0.55rem;
  font-weight: 800;
  color: var(--primary);
}
.sq.mine.leading::before { color: var(--mine-fg); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent); }
  50% { box-shadow: 0 0 0 5px var(--accent); }
}
/* People who turn off animations in their phone settings get a steady outline. */
@media (prefers-reduced-motion: reduce) {
  .sq.leading { animation: none; box-shadow: 0 0 0 4px var(--accent); }
}
.leader-line { margin: 0 0 8px; }

/* ---------------------------------------------------------- password reset */
.muted { color: var(--muted); font-size: 0.9rem; }
.small-button {
  margin-top: 6px;
  padding: 6px 10px;
  min-height: 36px;
  font: inherit;
  font-size: 0.85rem;
  color: var(--primary);
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 6px;
  cursor: pointer;
}
@media (prefers-color-scheme: dark) {
  .small-button { color: var(--accent); }  /* same as links in dark mode */
}
.temp-password {
  padding: 12px 14px;
  border: 2px dashed var(--accent);
  border-radius: 8px;
  overflow-wrap: anywhere;
}
.temp-password p { margin: 4px 0; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.1rem; }
.site-footer {
  max-width: 640px;
  margin: 24px auto;
  padding: 0 16px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}
.site-footer a { color: inherit; }
