:root {
  --blue: #1c6fc4;
  --blue-dark: #124a86;
  --white: #ffffff;
  --sky: #e8f2fc;
  --line: #cfe0f3;
  --ink: #0b2f57;
    --raute: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='28'%3E%3Crect width='48' height='28' fill='%23fff'/%3E%3Cpath d='M0 14L24 0L48 14L24 28Z' fill='%231c6fc4'/%3E%3C/svg%3E");
  --danger: #c0392b;
  --radius: 14px;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;          /* no double-tap zoom */
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--blue) var(--raute) center top / 48px 28px;
}

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.screen { display: none; }
.screen.active { display: block; }

/* White-blue lozenge strip on top of each card */
#screen-start::before, #screen-over::before, #screen-board::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 14px;
  background: var(--raute) 0 0 / 24px 14px;
}

#screen-start, #screen-over, #screen-board {
  background: var(--white);
  border: 4px solid var(--blue);
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  padding: 34px 20px 24px;
  box-shadow: 0 10px 40px rgba(11, 47, 87, .45);
  max-width: 620px;
  margin: 4vh auto 0;
  text-align: center;
}

h1, h2 {
  font-family: Georgia, "Times New Roman", serif;
  color: var(--blue-dark);
  margin: 0 0 8px;
}
h1 { font-size: clamp(2.2rem, 7vw, 3.4rem); letter-spacing: .02em; }
h2 { font-size: 2rem; }

/* Logo image replaces the text title; alt text shows if the file is missing. */
/* 4:3 logo: capped by viewport height too, so the form stays visible on short phones. */
h1.logo { margin: 0 auto 8px; width: min(100%, 420px, 44vh); line-height: 0; }
h1.logo img { display: block; width: 100%; height: auto; }

.tagline { margin: 0 0 20px; color: #2d5a8a; }

.field { display: block; text-align: left; margin-bottom: 18px; }
.field span, legend { display: block; font-weight: 700; margin-bottom: 6px; }
.field input {
  width: 100%;
  font-size: 1.1rem;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.field input:focus { outline: none; border-color: var(--blue); }

.beers { border: 0; padding: 0; margin: 0 0 18px; text-align: left; }
.beer-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.beer-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  border: 3px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  transition: transform .12s, border-color .12s;
  font-size: .85rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
}
.beer-card:hover { transform: translateY(-2px); }
.beer-card input { position: absolute; opacity: 0; pointer-events: none; }
.beer-card img { height: 90px; }
.beer-card:has(input:checked) {
  border-color: var(--beer, var(--blue));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--beer, var(--blue)) 25%, transparent);
}
.beer-card:has(input:focus-visible) { outline: 2px solid var(--blue); outline-offset: 2px; }

.btn {
  appearance: none;
  border: 2px solid var(--blue);
  background: #fff;
  color: var(--blue);
  font-weight: 700;
  font-size: 1.05rem;
  padding: 12px 26px;
  border-radius: 999px;
  cursor: pointer;
}
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn.link { border: 0; background: none; text-decoration: underline; margin-top: 12px; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 20px; }

.error { color: var(--danger); font-weight: 600; }
.muted { color: #5b7ea6; }

/* Game: full screen, playfield letterboxed on navy */
body.playing { overflow: hidden; overscroll-behavior: none; }
#screen-game.active {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0b2f57;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.stage {
  --ratio: 4 / 3;
  position: relative;
  width: min(100%, calc(100dvh * var(--ratio)));
  max-height: 100%;
  aspect-ratio: var(--ratio);
  overflow: hidden;
}
@media (pointer: fine) and (min-width: 900px) {
  .stage { width: min(100% - 48px, calc((100dvh - 48px) * var(--ratio))); border-radius: var(--radius); border: 4px solid #fff; }
}
#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: none;
}

/* Pause button sits centered in the gap between score and lives (set from game.js);
   --k = CSS px per game px, --x = its center in game px. */
.pause-btn {
  --k: 1;
  position: absolute;
  --x: 400;
  top: calc(var(--k) * 12px);
  left: calc(var(--k) * var(--x) * 1px);
  transform: translateX(-50%);
  width: calc(var(--k) * 48px);
  height: calc(var(--k) * 54px);
  min-width: 40px;
  min-height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: rgba(11, 47, 87, .8);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
}
.pause-btn svg { width: 55%; height: 55%; fill: currentColor; }
.pause-btn:hover { background: rgba(11, 47, 87, .95); }
.pause-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.pause-menu {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(11, 47, 87, .6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.pause-card {
  width: min(100%, 340px);
  padding: 24px 20px 16px;
  border: 4px solid var(--blue);
  border-radius: var(--radius);
  background: #fff;
  text-align: center;
  box-shadow: 0 10px 40px rgba(11, 47, 87, .45);
}
.pause-card p { margin: 0 0 16px; }
.pause-actions { display: flex; flex-direction: column; gap: 10px; }
.pause-actions .btn.link { margin-top: 4px; font-size: .95rem; }

/* Settings: link under the start form + modal dialog */
.start-links { display: flex; justify-content: center; gap: 28px; margin-top: 12px; }
.start-links .btn.link { margin-top: 0; }
.btn.with-icon { display: inline-flex; align-items: center; gap: 6px; }
.btn.with-icon svg { width: 20px; height: 20px; fill: currentColor; }

.settings {
  width: min(100% - 32px, 380px);
  padding: 24px 20px 20px;
  border: 4px solid var(--blue);
  border-radius: var(--radius);
  color: var(--ink);
  box-shadow: 0 10px 40px rgba(11, 47, 87, .45);
}
.settings::backdrop { background: rgba(11, 47, 87, .6); }
.settings h2 { text-align: center; }
.settings .btn { display: block; width: 100%; margin-top: 18px; }
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  cursor: pointer;
}
.set-row output { color: #5b7ea6; font-weight: 400; font-variant-numeric: tabular-nums; }
.set-row input[type="range"] { flex: 1; max-width: 180px; accent-color: var(--blue); }

.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  position: relative;
  width: 50px;
  height: 30px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background .15s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .15s;
}
.switch:checked { background: var(--blue); }
.switch:checked::after { transform: translateX(20px); }
.switch:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* Result */
.result { margin: 16px 0; }
.result-label { text-transform: uppercase; letter-spacing: .15em; font-size: .8rem; color: #5b7ea6; }
.result-score {
  font-family: Georgia, serif;
  font-size: clamp(3rem, 12vw, 5rem);
  font-weight: 700;
  color: var(--blue);
  line-height: 1.1;
}
.result-sub { color: #2d5a8a; }
.result-rank { margin-top: 14px; font-size: 1.4rem; font-weight: 700; color: var(--blue-dark); }

/* Leaderboard */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 12px 0 16px; }
.tab {
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--blue); border-color: var(--blue); color: #fff; }

.table-wrap { overflow-x: auto; }
.board { width: 100%; border-collapse: collapse; text-align: left; }
.board th, .board td { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.board th { font-size: .8rem; text-transform: uppercase; color: #5b7ea6; }
.board .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.board td:first-child { font-weight: 700; width: 3em; }
.board tr.me td { background: var(--sky); font-weight: 700; }
.board tr:nth-child(1) td:first-child { color: #c9a227; }
.board tr:nth-child(2) td:first-child { color: #8e9aa6; }
.board tr:nth-child(3) td:first-child { color: #b0703a; }
.beer-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.board td.name { max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.beer-short { display: none; }

/* ---------- Phones ---------- */
@media (max-width: 560px) {
  #app { padding-inline: 10px; }
  #screen-start, #screen-over, #screen-board {
    margin-top: 8px;
    padding: 28px 14px 18px;
    border-width: 3px;
  }
  h1 { margin-bottom: 4px; }
  .tagline { margin-bottom: 14px; font-size: .95rem; }
  .field { margin-bottom: 14px; }
  .field input { font-size: 17px; }   /* >=16px: iOS won't zoom on focus */
  .beer-list { grid-template-columns: 1fr 1fr; gap: 8px; }
  .beer-card { padding: 10px 6px; font-size: .8rem; }
  .beer-card img { height: 72px; }
  .actions { flex-direction: column; }
  .actions .btn { width: 100%; padding-block: 14px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; padding-bottom: 4px; scrollbar-width: none; }
  .tab { flex: none; }
  .board th, .board td { padding: 8px 6px; font-size: .92rem; }
  .beer-long { display: none; }
  .beer-short { display: inline; }
}
@media (max-width: 560px) and (max-height: 700px) {
  .beer-card img { height: 56px; }
  h1 { font-size: 2rem; }
}

/* Round banner + claim code */
.round-banner {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--sky);
  border: 2px solid var(--blue);
  color: var(--blue-dark);
  font-size: .95rem;
  line-height: 1.4;
}
.round-left { font-variant-numeric: tabular-nums; font-size: 1.1em; }
.round-prize { font-weight: 600; }
.claim {
  margin: 4px auto 16px;
  padding: 12px 16px;
  max-width: 360px;
  border: 2px dashed var(--blue);
  border-radius: 12px;
}
.claim strong { font-size: 1.6rem; letter-spacing: .2em; color: var(--blue-dark); }
.claim small { display: block; color: #5b7ea6; margin-top: 4px; }

[hidden] { display: none !important; }
