/*
 * Game board, from the approved royal-blue and gold mockup (1448 × 1086).
 *
 * Every size is written in mockup pixels times --u, so the whole interface
 * keeps the mockup's proportions at any window size:
 *   sidebar 290 wide · logo 340 × 201 · info panel 519 tall · button panel 303
 *   board frame 22 thick, starting 75 below the top of the logo.
 * Wide screens: --u follows the window height (the sidebar fits top to bottom)
 * and the board takes all the remaining width.
 * Portrait phones: a different arrangement (see the end of this file).
 *
 * Gold frames are gradients drawn in the border box (smooth, anti-aliased
 * curves at every zoom) — no raster frame is stretched.
 */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

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

:root {
  --navy: #0c1633;
  --gold-hi: #fff59a;
  --gold: #ffd60a;
  --gold-mid: #fbc707;
  --gold-lo: #e89a06;
  --gold-edge: #a9520a;
  --cream: #fce9b0;
  --cream-hi: #fff4d2;
}

body {
  font-family: var(--font-sans);
  color: var(--navy);
  background: #0a3f95 url("../assets/felt-blue.webp") center / cover no-repeat fixed;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

.app {
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
}

/* ---- wide screens ---- */
.stage {
  --pad: clamp(6px, 1.4vh, 16px);
  /* 1045 mockup px of sidebar must fit the height; never wider than 22 % of the window */
  --u: min(calc((100dvh - 2 * var(--pad)) / 1045), calc(22vw / 290), 1.2px);
  height: 100%;
  display: grid;
  grid-template-columns: calc(290 * var(--u)) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  column-gap: calc(4 * var(--u));
  padding: var(--pad) calc(var(--pad) + 4px);
  max-width: 2200px;
  margin: 0 auto;
}

.side {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: calc(14 * var(--u));
  min-height: 0;
  padding-top: calc(203 * var(--u)); /* room for the logo */
}

/* ---- logo: the approved picture, overlapping the board's corner as in the mockup ---- */
.logo {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
  width: calc(340 * var(--u));
  margin: 0;
  line-height: 0;
}
.logo-btn {
  appearance: none;
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: 12px;
  transition: transform var(--t-press) var(--ease-out);
}
.logo-btn img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}
.logo-btn:active { transform: scale(0.98); }
.logo-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* ---- cream panels with a gold frame ---- */
.panel {
  --bw: calc(11 * var(--u));
  position: relative;
  border: var(--bw) solid transparent;
  border-radius: calc(30 * var(--u));
  background:
    linear-gradient(180deg, #ffe7a4 0%, var(--cream) 12%, #fde4a6 100%) padding-box,
    linear-gradient(180deg, var(--gold-hi) 0%, var(--gold) 22%, var(--gold-mid) 65%, var(--gold-lo) 100%) border-box;
  box-shadow:
    0 0 0 calc(2.2 * var(--u)) var(--gold-edge),
    inset 0 0 0 calc(2 * var(--u)) #e3a020,
    inset 0 calc(4 * var(--u)) calc(6 * var(--u)) rgba(255, 255, 255, 0.55);
}

/* ---- info panel ---- */
.panel-hud {
  flex: none;
  padding: calc(14 * var(--u)) calc(22 * var(--u)) calc(6 * var(--u));
}
.hud { margin: 0; display: grid; gap: calc(12 * var(--u)); }
.hud-item { gap: 0; }
.hud-item { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.hud dt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(8 * var(--u));
  font-size: calc(25 * var(--u));
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1;
  white-space: nowrap;
  color: var(--navy);
}
.hud dt svg { width: calc(30 * var(--u)); height: calc(30 * var(--u)); flex: none; overflow: visible; }
.i-red { fill: #e3282a; stroke: #8f0f12; stroke-width: 0.8; }
.i-gold { fill: #ffc80a; stroke: #b5630a; stroke-width: 1; stroke-linejoin: round; }

/* value box: light cream pill with a warm lower lip */
.hud dd {
  width: 100%;
  margin: calc(8 * var(--u)) 0 0;
  padding: calc(3 * var(--u)) 0 calc(2 * var(--u));
  border-radius: calc(22 * var(--u));
  background: linear-gradient(180deg, #fffdf0 0%, #fff5dc 45%, #fbe7bb 100%);
  box-shadow:
    inset 0 0 0 calc(2 * var(--u)) #f1c36a,
    0 calc(4 * var(--u)) 0 #e09a30,
    0 calc(5.5 * var(--u)) calc(3 * var(--u)) rgba(150, 70, 0, 0.35);
  text-align: center;
  font-size: calc(45 * var(--u));
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--navy);
}
/* Last 30 seconds: the clock turns red (colour only, no motion). */
.hud-time.low dd { color: #c81e1e; }

.hud-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(20 * var(--u));
  margin-top: calc(12 * var(--u));
  padding-top: calc(12 * var(--u));
  border-top: calc(2.5 * var(--u)) solid #e9b85a;
}

/* 1 Card / 3 Cards */
.draw-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  padding: calc(3 * var(--u));
  border-radius: 999px;
  background: linear-gradient(180deg, #fff3d0, #fbe4b0);
  box-shadow: inset 0 0 0 calc(2 * var(--u)) #e8b456, 0 calc(3 * var(--u)) 0 #dc9530;
}
.draw-toggle button {
  appearance: none;
  min-width: 0;
  margin: 0;
  padding: calc(12 * var(--u)) 0 calc(11 * var(--u));
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--navy);
  font: 800 calc(22 * var(--u)) / 1 var(--font-sans);
  letter-spacing: -0.01em;
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--t-press) var(--ease-out), color 150ms ease;
}
.draw-toggle button[aria-checked="true"] {
  color: #fff;
  background: linear-gradient(180deg, #4fb0ff 0%, #1477ff 40%, #0056f0 100%);
  box-shadow:
    inset 0 0 0 calc(2 * var(--u)) #0a3cad,
    inset 0 calc(3 * var(--u)) 0 rgba(255, 255, 255, 0.35),
    0 calc(2 * var(--u)) calc(3 * var(--u)) rgba(0, 30, 110, 0.35);
  text-shadow: 0 1px 0 rgba(0, 20, 90, 0.5);
}
.draw-toggle button:active { transform: scale(0.96); }
.draw-toggle button:focus-visible { outline: 3px solid var(--navy); outline-offset: 1px; }

/* green pause button with a gold ring */
.pause-btn {
  appearance: none;
  flex: none;
  display: grid;
  place-items: center;
  width: calc(78 * var(--u));
  height: calc(78 * var(--u));
  margin: 0 0 calc(10 * var(--u));
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, #5fe04c 0%, #18b512 42%, #079207 72%, #056b05 100%);
  color: #fff;
  cursor: pointer;
  box-shadow:
    inset 0 calc(-4 * var(--u)) 0 rgba(0, 60, 0, 0.35),
    0 0 0 calc(3 * var(--u)) #0b5c0a,
    0 0 0 calc(8 * var(--u)) #ffd21a,
    0 0 0 calc(10 * var(--u)) #a8520a,
    0 calc(6 * var(--u)) calc(8 * var(--u)) rgba(120, 60, 0, 0.35);
  transition: transform var(--t-press) var(--ease-out), filter 150ms ease;
}
.pause-btn svg { width: 56%; height: 56%; fill: none; stroke: currentColor; stroke-width: 3.6; stroke-linecap: round; filter: drop-shadow(0 1px 0 rgba(0, 60, 0, 0.6)); }
.pause-btn:active { transform: scale(0.94); }
.pause-btn:focus-visible { outline: 3px solid var(--navy); outline-offset: calc(12 * var(--u)); }

/* ---- button panel ---- */
.toolbar {
  flex: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: calc(10 * var(--u)) calc(12 * var(--u));
  padding: calc(8 * var(--u)) calc(14 * var(--u)) calc(16 * var(--u));
}
.tool {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(3 * var(--u));
  min-width: 0;
  height: calc(78 * var(--u));
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: calc(20 * var(--u));
  background: linear-gradient(180deg, #fffaf0 0%, #fdf0d4 50%, #fbe3b4 100%);
  color: var(--navy);
  box-shadow:
    inset 0 0 0 calc(2 * var(--u)) #ecbd62,
    0 calc(4 * var(--u)) 0 #d98b22,
    0 calc(6 * var(--u)) calc(4 * var(--u)) rgba(140, 60, 0, 0.3);
  font: 800 calc(19 * var(--u)) / 1 var(--font-sans);
  letter-spacing: -0.01em;
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--t-press) var(--ease-out), box-shadow var(--t-press) var(--ease-out), opacity 150ms ease;
}
.tool svg {
  width: calc(36 * var(--u));
  height: calc(36 * var(--u));
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool-menu { grid-column: 1 / -1; justify-self: center; width: calc(130 * var(--u)); }
.tool:active:not(:disabled) {
  transform: translateY(calc(3 * var(--u)));
  box-shadow: inset 0 0 0 calc(2 * var(--u)) #ecbd62, 0 calc(1 * var(--u)) 0 #d98b22;
}
.tool:disabled { opacity: 0.5; cursor: default; }
.tool:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }
@media (hover: hover) and (pointer: fine) {
  .tool:hover:not(:disabled), .pause-btn:hover { filter: brightness(1.04); }
}

/* ---- the board: gold frame, royal-blue felt ---- */
.board {
  position: relative;
  min-width: 0;
  min-height: 0;
  margin-top: calc(75 * var(--u));
  border: calc(22 * var(--u)) solid transparent;
  border-radius: calc(44 * var(--u));
  background:
    linear-gradient(transparent, transparent) padding-box,
    linear-gradient(180deg, #fffbd0 0%, var(--gold-hi) 1.5%, var(--gold) 4%, var(--gold-mid) 60%, #f3b708 97%, var(--gold-lo) 100%) border-box;
  box-shadow:
    0 0 0 calc(2.5 * var(--u)) var(--gold-edge),
    inset 0 0 0 calc(3 * var(--u)) #2a0a00;
  display: flex;
}
.felt {
  position: relative;
  flex: 1;
  display: flex;
  min-width: 0;
  min-height: 0;
  margin: calc(3 * var(--u));
  padding: calc(14 * var(--u)) calc(14 * var(--u)) calc(8 * var(--u));
  border-radius: calc(20 * var(--u));
  background:
    radial-gradient(120% 95% at 50% 40%, rgba(0, 20, 90, 0) 45%, rgba(0, 8, 40, 0.5) 100%),
    linear-gradient(rgba(0, 14, 70, 0.42), rgba(0, 14, 70, 0.42)),
    #0a3f95 url("../assets/felt-blue.webp") center / cover no-repeat;
  box-shadow: inset 0 calc(6 * var(--u)) calc(14 * var(--u)) rgba(0, 0, 20, 0.55);
}

.table {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  touch-action: none;          /* we handle drags ourselves; no scroll/zoom on the felt */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ---- portrait phones and narrow windows ----
   Row 1: logo · draw toggle + pause.  Row 2: TIME LEFT · SCORE · HIGH SCORE.
   Row 3: the board.  Row 4: the five buttons. */
@media (orientation: portrait), (max-width: 639px) {
  .stage {
    --u: min(calc(100vw / 760), calc(100dvh / 1400), 1px);
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "logo foot" "hud hud" "board board" "tools tools";
    gap: calc(14 * var(--u)) calc(14 * var(--u));
    padding: 8px 8px 10px;
    max-width: 900px;
  }
  .side, .panel-hud { display: contents; }

  .logo { position: static; grid-area: logo; width: calc(330 * var(--u)); align-self: center; }

  .hud-foot {
    grid-area: foot;
    align-self: center;
    flex-direction: row;
    justify-content: space-between;
    gap: calc(18 * var(--u));
    margin: 0;
    padding: calc(14 * var(--u)) calc(22 * var(--u)) calc(14 * var(--u)) calc(16 * var(--u));
    --bw: calc(10 * var(--u));
    border: var(--bw) solid transparent;
    border-top-width: var(--bw);
    border-radius: calc(30 * var(--u));
    background:
      linear-gradient(180deg, #ffe7a4 0%, var(--cream) 12%, #fde4a6 100%) padding-box,
      linear-gradient(180deg, var(--gold-hi) 0%, var(--gold) 22%, var(--gold-mid) 65%, var(--gold-lo) 100%) border-box;
    box-shadow:
      0 0 0 calc(2.2 * var(--u)) var(--gold-edge),
      inset 0 0 0 calc(2 * var(--u)) #e3a020;
  }
  .draw-toggle { flex: 1; }
  .draw-toggle button { min-height: 40px; font-size: max(13px, calc(26 * var(--u))); padding-block: 0; }
  .pause-btn { width: max(44px, calc(70 * var(--u))); height: max(44px, calc(70 * var(--u))); margin: 6px 4px 6px 6px; }

  .hud {
    grid-area: hud;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: calc(14 * var(--u));
    padding: calc(12 * var(--u)) calc(16 * var(--u)) calc(20 * var(--u));
    border: calc(10 * var(--u)) solid transparent;
    border-radius: calc(30 * var(--u));
    background:
      linear-gradient(180deg, #ffe7a4 0%, var(--cream) 12%, #fde4a6 100%) padding-box,
      linear-gradient(180deg, var(--gold-hi) 0%, var(--gold) 22%, var(--gold-mid) 65%, var(--gold-lo) 100%) border-box;
    box-shadow:
      0 0 0 calc(2.2 * var(--u)) var(--gold-edge),
      inset 0 0 0 calc(2 * var(--u)) #e3a020;
  }
    .hud dt { font-size: calc(24 * var(--u)); gap: calc(6 * var(--u)); }
  .hud dt svg { width: calc(30 * var(--u)); height: calc(30 * var(--u)); }
  .hud dd { font-size: calc(44 * var(--u)); margin-top: calc(10 * var(--u)); }

  .board {
    grid-area: board;
    margin-top: 0;
    border-width: calc(16 * var(--u));
    border-radius: calc(36 * var(--u));
  }
  .felt { padding: calc(10 * var(--u)) calc(6 * var(--u)) calc(6 * var(--u)); border-radius: calc(18 * var(--u)); }

  .toolbar {
    grid-area: tools;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: calc(12 * var(--u));
    padding: calc(12 * var(--u)) calc(14 * var(--u)) calc(18 * var(--u));
    border-width: calc(10 * var(--u));
  }
  .tool { height: max(50px, calc(100 * var(--u))); font-size: max(11px, calc(22 * var(--u))); gap: calc(6 * var(--u)); }
  .tool svg { width: calc(40 * var(--u)); height: calc(40 * var(--u)); }
  .tool-menu { grid-column: auto; width: auto; justify-self: stretch; }
}

/* Phones on their side: the sidebar stays, a little tighter. */
@media (orientation: landscape) and (max-height: 520px) {
  .stage { --pad: 6px; }
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.noscript { position: fixed; inset: auto 16px 16px; padding: 12px; background: var(--cream); border-radius: 12px; }
