:root {
  color-scheme: light;
  --primary: #2196f3;
  --primary-dark: #1565c0;
  --primary-soft: #e3f2fd;
  --secondary: #ff9800;
  --secondary-dark: #e65100;
  /* Operator glyphs on ivory tiles: at least 4.5:1 on the darkest tile shade (#efe8d8) and on valid green. */
  --operator-ink: #a33600;
  /* Board coordinates on the sage frame: at least 4.5:1 on its darkest shade (#7f9873). */
  --frame-ink: #1f2d17;
  --secondary-soft: #fff3e0;
  --success: #4caf50;
  --success-dark: #2e7d32;
  --success-soft: #e8f5e9;
  --error: #f44336;
  --error-dark: #c62828;
  --error-soft: #ffebee;
  --background: #fafafa;
  --surface: #ffffff;
  --line: #e0e0e0;
  --muted: #757575;
  --ink: #212121;

  --square-plain: #d7edc6;
  --square-bonus2: #dfa000;
  --square-bonus3: #2e7d32;
  --square-booster2: #2196f3;
  --square-booster3: #f44336;
  --board-line: #9bb08f;
  --board-frame: linear-gradient(150deg, #b7cba8 0%, #93ab86 55%, #7f9873 100%);

  /* Gradients give buttons and badges a little depth instead of flat fills. */
  --grad-primary: linear-gradient(135deg, #4fb3ff 0%, #2196f3 48%, #1565c0 100%);
  --grad-secondary: linear-gradient(135deg, #ffc061 0%, #ff9800 52%, #f57c00 100%);
  --grad-success: linear-gradient(135deg, #7ccf7f 0%, #4caf50 50%, #2e7d32 100%);
  --grad-danger: linear-gradient(135deg, #ff7a6e 0%, #f44336 50%, #c62828 100%);
  --grad-ink: linear-gradient(140deg, #3a4a5c 0%, #212121 100%);
  --tile-face: linear-gradient(165deg, #ffffff 0%, #fbf8f1 55%, #efe8d8 100%);
  --wood: linear-gradient(180deg, #b08968 0%, #8d6e63 45%, #6d4c41 100%);
  --glass: rgba(255, 255, 255, 0.78);
  --glass-line: rgba(255, 255, 255, 0.9);

  --radius-card: 20px;
  --radius-button: 14px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(22, 44, 84, 0.06), 0 4px 12px rgba(22, 44, 84, 0.07);
  --shadow-md: 0 2px 4px rgba(22, 44, 84, 0.06), 0 10px 26px rgba(22, 44, 84, 0.12);
  --shadow-lg: 0 6px 16px rgba(22, 44, 84, 0.10), 0 28px 64px rgba(22, 44, 84, 0.22);
  --focus-ring: 0 0 0 3px rgba(33, 150, 243, 0.45);
  --cell: 44px;

  font-family: "Inter", "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

html,
body {
  min-height: 100%;
  margin: 0;
  /* Nothing (a tilted picture, a long word) may widen the page past the phone's screen. */
  overflow-x: clip;
}

body {
  color: var(--ink);
  /* Soft washes of the palette over the light base, so pages are not flat grey. */
  background:
    radial-gradient(1100px 620px at -8% -10%, rgba(33, 150, 243, 0.13), transparent 62%),
    radial-gradient(900px 560px at 108% 4%, rgba(255, 152, 0, 0.12), transparent 60%),
    radial-gradient(1000px 700px at 50% 118%, rgba(76, 175, 80, 0.10), transparent 62%),
    var(--background);
  background-attachment: fixed;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 48px; line-height: 1.1; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 36px; line-height: 1.15; font-weight: 800; letter-spacing: -0.01em; }
h3 { font-size: 18px; font-weight: 700; }

button,
input { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--primary-dark);
  outline-offset: 2px;
}

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

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 200;
  padding: 10px 16px;
  border-radius: var(--radius-button);
  color: #fff;
  background: var(--primary-dark);
  font-weight: 700;
}
.skip-link:focus { top: 12px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

.eyebrow {
  margin-bottom: 6px;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

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

.btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-button);
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease, border-color 160ms ease, filter 160ms ease;
}
.btn:not(:disabled):hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.btn:not(:disabled):active { transform: translateY(0); filter: brightness(0.97); }
.btn:disabled { cursor: not-allowed; opacity: 0.5; box-shadow: none; }
.btn[aria-busy="true"] { cursor: progress; opacity: 0.7; }

/* Filled buttons: a gradient, a soft coloured glow, and a highlight along the top edge. */
.btn--primary {
  color: #fff;
  background: var(--grad-primary);
  box-shadow: 0 6px 18px rgba(33, 150, 243, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.btn--primary:not(:disabled):hover { filter: brightness(1.06); box-shadow: 0 10px 26px rgba(33, 150, 243, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.35); }
.btn--outline {
  color: var(--primary-dark);
  background: linear-gradient(180deg, #ffffff, #f4f9ff);
  border-color: rgba(33, 150, 243, 0.45);
}
.btn--outline:not(:disabled):hover { border-color: var(--primary); background: var(--primary-soft); }
.btn--ghost { color: var(--ink); background: rgba(255, 255, 255, 0.72); border-color: var(--line); backdrop-filter: blur(6px); }
.btn--ghost:not(:disabled):hover { background: #ffffff; border-color: #cfd8e3; }
.btn--danger {
  color: #fff;
  background: var(--grad-danger);
  box-shadow: 0 6px 18px rgba(244, 67, 54, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.btn--danger:not(:disabled):hover { filter: brightness(1.06); }
.btn--large { min-height: 54px; padding: 12px 30px; border-radius: 18px; font-size: 18px; }
.btn--block { width: 100%; }

.btn--confirm {
  min-width: 180px;
  min-height: 50px;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(135deg, #bdbdbd, #9e9e9e);
  font-size: 17px;
}
.btn--confirm:disabled { opacity: 0.75; }
.btn--confirm.is-ready {
  background: var(--grad-success);
  box-shadow: 0 0 0 4px rgba(76, 175, 80, 0.28), 0 8px 22px rgba(46, 125, 50, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  animation: ready-glow 1.6s ease-in-out infinite;
}
.btn--confirm.is-ready:hover { filter: brightness(1.06); }
/* Without the live check nothing is known to be valid yet, so no green. */
.btn--confirm.is-unchecked { background: var(--grad-primary); box-shadow: 0 6px 18px rgba(33, 150, 243, 0.34); }
.btn--confirm.is-unchecked:hover { filter: brightness(1.06); }

.link-button {
  padding: 6px 4px;
  border: 0;
  color: var(--primary-dark);
  background: transparent;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link-button:hover { color: var(--secondary-dark); }
.link-button--danger { color: var(--error-dark); }
.link-button--danger:hover { color: var(--error); }

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--line);
  border-radius: 13px;
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff, #f5f7fa);
  box-shadow: var(--shadow-sm);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}
.icon-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

/* ------------------------------------------------------------------ */
/* Site header and landing page                                        */
/* ------------------------------------------------------------------ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 12px clamp(16px, 4vw, 56px);
  background: rgba(255, 255, 255, 0.72);
  border-bottom: 1px solid rgba(224, 224, 224, 0.7);
  box-shadow: 0 6px 24px rgba(22, 44, 84, 0.06);
  backdrop-filter: blur(14px) saturate(1.3);
}
.site-header > .btn { justify-self: end; }

.logo {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px;
  border: 0;
  background: transparent;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.01em;
  cursor: pointer;
}

/* The Quotalyx mark: four operator tiles and a star (2026-11-20). */
.logo-img { display: block; width: 36px; height: 36px; transition: transform 220ms ease; }
.logo:hover .logo-img { transform: rotate(-4deg) scale(1.05); }
.logo-img--small { width: 30px; height: 30px; }

.site-nav { display: flex; gap: 6px; }
.nav-link {
  padding: 8px 18px;
  border: 0;
  border-radius: var(--radius-pill);
  color: var(--ink);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}
.nav-link:hover { background: var(--primary-soft); color: var(--primary-dark); }
.nav-link.is-current { color: var(--primary-dark); background: linear-gradient(180deg, #e9f4ff, #d6eafd); box-shadow: inset 0 0 0 1px rgba(33, 150, 243, 0.25); }

.home-view {
  position: relative;
  overflow: hidden;
  min-height: calc(100dvh - 69px);
  display: flex;
  flex-direction: column;
}
/* Two soft colour blobs behind the hero. */
.home-view::before,
.home-view::after {
  content: "";
  position: absolute;
  z-index: 0;
  border-radius: 50%;
  filter: blur(8px);
  pointer-events: none;
}
.home-view::before { width: 520px; height: 520px; right: -140px; top: -120px; background: radial-gradient(circle at 35% 35%, rgba(33, 150, 243, 0.22), rgba(33, 150, 243, 0) 68%); }
.home-view::after { width: 460px; height: 460px; left: -160px; top: 300px; background: radial-gradient(circle at 60% 40%, rgba(255, 152, 0, 0.13), rgba(255, 152, 0, 0) 66%); }
.home-view > * { position: relative; z-index: 1; }
.home-view > .math-backdrop { position: absolute; z-index: 0; }

.math-backdrop { position: absolute; inset: 0; pointer-events: none; }
.math-backdrop span {
  position: absolute;
  color: rgba(33, 150, 243, 0.1);
  font-size: 30px;
  font-weight: 800;
  white-space: nowrap;
  transform: rotate(-8deg);
}
.math-backdrop span:nth-child(1) { left: 3%; top: 9%; }
.math-backdrop span:nth-child(2) { left: 40%; top: 4%; color: rgba(255, 152, 0, 0.13); transform: rotate(5deg); }
.math-backdrop span:nth-child(3) { right: 4%; top: 12%; color: rgba(76, 175, 80, 0.14); }
.math-backdrop span:nth-child(4) { left: 7%; top: 47%; color: rgba(255, 152, 0, 0.12); transform: rotate(7deg); }
.math-backdrop span:nth-child(5) { right: 2%; top: 52%; transform: rotate(9deg); }
.math-backdrop span:nth-child(6) { left: 30%; top: 62%; color: rgba(76, 175, 80, 0.12); }
.math-backdrop span:nth-child(7) { left: 2%; top: 82%; }
.math-backdrop span:nth-child(8) { right: 9%; top: 86%; color: rgba(255, 152, 0, 0.12); transform: rotate(4deg); }

.hero {
  position: relative;
  width: min(1180px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(32px, 6vw, 88px);
  padding: clamp(36px, 7vh, 80px) clamp(16px, 4vw, 40px) 40px;
}

.hero-copy { display: flex; flex-direction: column; align-items: flex-start; }
.hero h1 {
  font-size: clamp(56px, 7vw, 92px);
  line-height: 1;
  letter-spacing: -0.035em;
  color: var(--primary-dark);
  background: linear-gradient(110deg, #0d47a1 0%, #1e88e5 40%, #00a3a3 72%, #43a047 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  padding-bottom: 0.06em;
}
/* Second row under the name: what the product is. */
.hero-tagline {
  margin-top: 10px;
  color: #263238;
  font-size: clamp(22px, 2.4vw, 30px);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
}
.hero-lede { margin-top: 14px; color: #424242; font-size: 22px; }
.hero-actions { display: flex; align-items: center; gap: 20px; margin-top: 30px; }
.hero-actions .btn--large { min-width: 210px; min-height: 60px; border-radius: 20px; font-size: 20px; box-shadow: 0 12px 28px rgba(33, 150, 243, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.35); }

.resume-card {
  width: min(560px, 100%);
  margin-top: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 20px;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  border-radius: var(--radius-card);
  box-shadow: inset 5px 0 0 var(--secondary), var(--shadow-md);
  backdrop-filter: blur(10px);
}
.resume-card h2 { font-size: 18px; }
.resume-card p:not(.eyebrow) { color: var(--muted); font-size: 14px; }
.resume-actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.stats-line { margin-top: 18px; color: var(--muted); font-size: 14px; }
.storage-note { margin-top: 18px; padding: 10px 14px; border-radius: 14px; color: #5d3a00; background: var(--secondary-soft); font-size: 14px; font-weight: 600; }
/* A long action label wraps instead of widening the dialog past the screen (0.10.4). */
.info-action { justify-self: start; max-width: 100%; margin-top: 6px; white-space: normal; text-align: center; }

.hero-preview {
  padding: 16px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.75));
  border: 1px solid var(--glass-line);
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
  transform: rotate(2.5deg);
  backdrop-filter: blur(8px);
}

.features {
  position: relative;
  width: min(1180px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px;
  padding: 24px clamp(16px, 4vw, 40px) 56px;
}

.feature-card {
  position: relative;
  overflow: hidden;
  /* Icon and title share the top row; the description runs the full width below. */
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  align-content: start; /* shorter cards keep their rows at the top */
  column-gap: 16px;
  padding: 30px 26px;
  background: linear-gradient(170deg, #ffffff 0%, #fbfdff 100%);
  border: 1px solid rgba(224, 224, 224, 0.8);
  border-radius: 24px;
  box-shadow: var(--shadow-sm);
  transition: transform 200ms ease, box-shadow 200ms ease;
}
/* A colour strip along the top edge, matching the card's icon. */
.feature-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 5px; background: var(--grad-primary); }
.feature-card:nth-child(2)::before { background: var(--grad-secondary); }
.feature-card:nth-child(3)::before { background: var(--grad-success); }
.feature-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.feature-card h2 { margin: 0; font-size: 22px; line-height: 1.2; }
.feature-card p { grid-column: 1 / -1; margin-top: 16px; color: #424242; }

.feature-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: #fff;
  box-shadow: 0 8px 18px rgba(22, 44, 84, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transform: rotate(-4deg);
}
.feature-icon--blue { background: var(--grad-primary); }
.feature-icon--orange { background: var(--grad-secondary); transform: rotate(3deg); }
.feature-icon--green { background: var(--grad-success); }

.site-footer {
  position: relative;
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px clamp(16px, 4vw, 56px);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  border-top: 1px solid rgba(224, 224, 224, 0.7);
  backdrop-filter: blur(10px);
  font-size: 14px;
}
.footer-links { display: flex; gap: 18px; }

/* ------------------------------------------------------------------ */
/* How to Play                                                         */
/* ------------------------------------------------------------------ */

.how-view {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 48px clamp(16px, 4vw, 40px) 72px;
}
.how-header { max-width: 720px; margin-bottom: 36px; }
.how-header p:last-child { margin-top: 14px; color: #424242; font-size: 18px; }

.how-sections { display: grid; gap: 24px; margin: 0; padding: 0; list-style: none; }
.how-section {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 36px;
  padding: 32px;
  background: linear-gradient(170deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.86));
  border: 1px solid var(--glass-line);
  border-radius: 26px;
  box-shadow: var(--shadow-md);
}
.how-text h2 { margin: 10px 0 10px; font-size: 28px; }
.how-text p { color: #424242; }
.how-text ul { margin: 12px 0 0; padding-left: 20px; color: #424242; }
.how-text li + li { margin-top: 6px; }
.how-number {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  background: var(--grad-secondary);
  box-shadow: 0 8px 18px rgba(255, 152, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  font-size: 21px;
  font-weight: 800;
  transform: rotate(-5deg);
}
.how-figure { margin: 0; max-width: 420px; }
.how-figure figcaption { margin-top: 10px; color: var(--muted); font-size: 14px; text-align: center; }

.example-list { padding-left: 0 !important; list-style: none; }
.example { display: grid; grid-template-columns: 24px auto 1fr; align-items: baseline; gap: 10px; }
.example-mark { font-weight: 800; }
.example-text { font-weight: 700; font-variant-numeric: tabular-nums; }
.example-note { color: var(--muted); font-size: 14px; }
.example--valid .example-mark { color: var(--success-dark); }
.example--invalid .example-mark { color: var(--error-dark); }
.example--invalid .example-text { color: var(--error-dark); }

.legend-list { display: grid; gap: 8px; padding-left: 0 !important; list-style: none; }
.legend-list li { display: flex; align-items: center; gap: 10px; margin: 0 !important; }
.swatch { width: 22px; height: 22px; flex: 0 0 auto; border-radius: 7px; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 1px 3px rgba(22, 44, 84, 0.2); }
.swatch--bonus2 { background: var(--square-bonus2); }
.swatch--bonus3 { background: var(--square-bonus3); }
.swatch--booster2 { background: var(--square-booster2); }
.swatch--booster3 { background: var(--square-booster3); }
.swatch { display: grid; place-items: center; }
.swatch-icon { width: 70%; height: 70%; fill: #fff; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35)); }
.swatch--bonus2 .swatch-icon { fill: #3a2700; filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.45)); }
.key-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; margin: 10px 0 0; padding: 0; list-style: none; }
.key-list li { display: flex; align-items: center; gap: 8px; font-size: 13px; line-height: 1.25; }
.key-list strong { display: block; font-size: 14px; }
.sound-card { display: grid; gap: 10px; }
.sound-card .switch-row { align-items: center; }
.sound-track { display: grid; gap: 4px; font-size: 14px; font-weight: 700; }
.sound-track select { min-height: 40px; padding: 6px 10px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; font: inherit; font-weight: 600; }
.sound-track select:disabled { opacity: 0.55; }

.score-walkthrough {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 16px;
  background: linear-gradient(160deg, #f1faf1, #e3f3e4);
  box-shadow: inset 4px 0 0 var(--success);
  color: var(--ink) !important;
}

.how-extra { margin-top: 36px; }
.how-extra > h2 { font-size: 28px; }
.how-extra-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.how-extra-grid article {
  padding: 20px;
  background: linear-gradient(170deg, #ffffff, #f8fbff);
  border: 1px solid var(--glass-line);
  border-radius: 20px;
  box-shadow: var(--shadow-sm);
  transition: transform 200ms ease, box-shadow 200ms ease;
}
.how-extra-grid article:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.how-extra-grid p { margin-top: 6px; color: #424242; font-size: 15px; }

.how-cta {
  position: relative;
  overflow: hidden;
  margin-top: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 48px 24px;
  border-radius: 30px;
  color: #fff;
  background: linear-gradient(125deg, #0d47a1 0%, #1e88e5 55%, #42a5f5 100%);
  box-shadow: 0 20px 50px rgba(21, 101, 192, 0.35);
  text-align: center;
}
/* Big soft circles drifting off the edges of the banner. */
.how-cta::before,
.how-cta::after { content: ""; position: absolute; border-radius: 50%; pointer-events: none; }
.how-cta::before { width: 260px; height: 260px; left: -70px; bottom: -120px; background: radial-gradient(circle, rgba(255, 152, 0, 0.45), rgba(255, 152, 0, 0) 70%); }
.how-cta::after { width: 320px; height: 320px; right: -90px; top: -150px; background: radial-gradient(circle, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0) 70%); }
.how-cta > * { position: relative; z-index: 1; }
.how-cta .btn--primary { color: var(--primary-dark); background: #fff; box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18); }
.how-cta .btn--primary:hover { background: #fffaf2; }

/* ------------------------------------------------------------------ */
/* Board squares and tiles (shared by the game and the mini boards)    */
/* ------------------------------------------------------------------ */

.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: linear-gradient(160deg, #e3f3d6 0%, var(--square-plain) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), inset 0 0 0 1px rgba(33, 33, 33, 0.05);
}
button.cell { cursor: pointer; transition: filter 120ms ease, box-shadow 120ms ease; }
button.cell:hover { filter: brightness(1.06); }
button.cell:focus-visible { z-index: 3; outline: 3px solid var(--ink); outline-offset: 1px; }
button.cell.is-cursor { box-shadow: inset 0 0 0 2px rgba(33, 33, 33, 0.75); }
/* Sequential placement (0.10.0): the square where the next tapped rack tile will go. An orange outline marks it,
   and a small arrow badge on its leading edge shows the direction (0.10.2), so the square itself, and a hint tile
   in it, stay fully visible. */
.cell.is-next { z-index: 2; box-shadow: inset 0 0 0 2px var(--secondary); }
.cell.is-next::after {
  content: "→";
  position: absolute;
  top: 50%;
  right: 0;
  width: max(14px, calc(var(--cell) * 0.36));
  height: max(14px, calc(var(--cell) * 0.36));
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--secondary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  font-size: max(10px, calc(var(--cell) * 0.26));
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
  transform: translate(50%, -50%);
  animation: next-pulse 1.4s ease-in-out infinite;
}
.cell.is-next[data-axis="vertical"]::after { content: "↓"; top: auto; right: auto; bottom: 0; left: 50%; transform: translate(-50%, 50%); }
@keyframes next-pulse { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .cell.is-next::after { animation: none; } }
button.cell.is-drop-target { z-index: 2; box-shadow: inset 0 0 0 3px var(--primary-dark); filter: brightness(1.12); }

/* Special squares keep their PRD colours, with a gentle sheen. */
.cell--bonus2 { background: linear-gradient(155deg, #f2c037 0%, var(--square-bonus2) 60%, #c88c00 100%); }
.cell--bonus3 { background: linear-gradient(155deg, #43a047 0%, var(--square-bonus3) 60%, #1b5e20 100%); }
.cell--booster2,
.cell--star { background: linear-gradient(155deg, #4fb3ff 0%, var(--square-booster2) 55%, #1976d2 100%); }
.cell--booster3 { background: linear-gradient(155deg, #ff6f61 0%, var(--square-booster3) 55%, #d32f2f 100%); }
.cell--bonus2,
.cell--bonus3,
.cell--booster2,
.cell--star,
.cell--booster3 { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), inset 0 -2px 0 rgba(0, 0, 0, 0.12); }

/* Special squares show one small icon (0.8.0): a gem on BONUS, a lightning bolt on BOOSTER. The colour gives the
   factor; the Board key in the info panel explains it. Soft white, so the tiles' equations stand out. */
/* 0.10.3: solid and larger, so gem (BONUS) and bolt (BOOSTER) are easy to tell apart at a glance. */
.cell-icon { width: calc(var(--cell) * 0.56); height: calc(var(--cell) * 0.56); fill: #fff; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35)); pointer-events: none; }
.cell--bonus2 .cell-icon { fill: #3a2700; filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.45)); }
.board--tiny .cell-icon { width: calc(var(--cell) * 0.62); height: calc(var(--cell) * 0.62); }
.cell-star { color: #fff; font-size: calc(var(--cell) * 0.62); line-height: 1; pointer-events: none; text-shadow: 0 0 10px rgba(255, 255, 255, 0.85), 0 1px 2px rgba(13, 71, 161, 0.5); }

.tile {
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  /* Ivory game pieces: a lit top edge and a darker bevel underneath. */
  background: var(--tile-face);
  box-shadow: inset 0 1px 0 #ffffff, inset 0 -3px 0 rgba(120, 96, 60, 0.16), 0 2px 4px rgba(60, 40, 20, 0.22), 0 6px 12px rgba(60, 40, 20, 0.10);
  font-weight: 800;
  line-height: 1;
  user-select: none;
}
.tile--operator .tile-face { color: var(--operator-ink); }
.tile--equals .tile-face { color: var(--primary-dark); }
.tile--point .tile-face { font-size: 1.5em; transform: translateY(-0.18em); }
.tile-value {
  position: absolute;
  right: 0.3em;
  bottom: 0.18em;
  color: #616161;
  font-size: 0.34em;
  font-weight: 700;
}

/* Board tiles: digits fill 88% of the square's height (0.10.1; digits are 0.74 em tall in the game font), so the
   equation reads at a glance. The score keeps 0.19 of a square, on a light backing where it meets a big digit. */
.cell .tile {
  width: 100%;
  height: 100%;
  font-size: calc(var(--cell) * 1.19);
}
.cell .tile:not(.tile--point) .tile-face { transform: translateY(-0.025em); }
/* The decimal point is a small glyph on the baseline: on a board tile it stays at the tile's own size, lifted to the
   middle of the square. */
.cell .tile--point .tile-face { font-size: 1em; transform: translateY(-0.3em); }
.cell .tile-value {
  right: 0.05em;
  bottom: 0.035em;
  padding: 0 0.18em;
  border-radius: 0.4em;
  background: rgba(251, 248, 241, 0.88);
  font-size: 0.16em;
  line-height: 1.15;
}
.cell .tile[draggable="true"] { cursor: grab; }

.tile--draft { box-shadow: inset 0 1px 0 #ffffff, inset 0 -3px 0 rgba(120, 96, 60, 0.16), 0 0 0 2px var(--secondary), 0 4px 10px rgba(33, 33, 33, 0.25); animation: tile-pop 200ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.tile.is-valid { background: linear-gradient(165deg, #ffffff 0%, #f1faee 60%, #dff0d8 100%); box-shadow: inset 0 -3px 0 rgba(46, 125, 50, 0.18), 0 0 0 3px var(--success), 0 4px 12px rgba(46, 125, 50, 0.35); }
.tile.is-invalid { box-shadow: inset 0 -3px 0 rgba(120, 96, 60, 0.16), 0 0 0 2px var(--error), 0 3px 8px rgba(198, 40, 40, 0.2); }
.tile--pending { box-shadow: inset 0 -3px 0 rgba(120, 96, 60, 0.16), 0 0 0 3px var(--secondary), 0 4px 12px rgba(230, 81, 0, 0.35); animation: tile-pop 220ms ease-out, pending-pulse 1.4s ease-in-out 220ms infinite; }
.tile--hint { opacity: 0.65; background: linear-gradient(165deg, #f3f9ff, #dcecfc); box-shadow: inset 0 0 0 2px var(--primary); }
.tile.is-latest { animation: tile-settle 900ms ease-out; }
.tile.is-dragging { opacity: 0.35; }

.mini-board {
  --cell: 40px;
  display: grid;
  grid-template-columns: repeat(var(--mini-columns, 7), var(--cell));
  gap: 3px;
  padding: 7px;
  width: max-content;
  border-radius: 16px;
  background: var(--board-frame);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 6px 16px rgba(60, 80, 50, 0.18);
}
.mini-board--hero { --cell: 46px; }
.tile--loop { animation: tile-loop 4s ease-in-out infinite both; }

/* ------------------------------------------------------------------ */
/* Game view                                                           */
/* ------------------------------------------------------------------ */

.game-view {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: transparent;
}

.top-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.72);
  border-bottom: 1px solid rgba(224, 224, 224, 0.7);
  box-shadow: 0 6px 24px rgba(22, 44, 84, 0.06);
  backdrop-filter: blur(14px) saturate(1.3);
}
.top-bar-side { display: flex; align-items: center; gap: 12px; }
.top-bar-side--right { justify-content: flex-end; }
.top-bar .btn { min-height: 40px; padding: 8px 14px; }

.scoreboard { display: grid; grid-template-columns: minmax(230px, 1fr) auto minmax(230px, 1fr); align-items: center; gap: 12px; }

.player-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 16px;
  background: linear-gradient(180deg, #ffffff, #f7f9fc);
  border: 2px solid rgba(224, 224, 224, 0.9);
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
  transition: border-color 220ms ease, box-shadow 220ms ease, background 220ms ease, transform 220ms ease;
}
.player-panel.is-active {
  border-color: rgba(33, 150, 243, 0.7);
  background: linear-gradient(180deg, #f1f8ff, #dceefe);
  box-shadow: 0 0 0 4px rgba(33, 150, 243, 0.14), 0 10px 24px rgba(33, 150, 243, 0.18);
  transform: translateY(-1px);
}
.player-text { display: flex; flex-direction: column; line-height: 1.2; flex: 1; min-width: 0; }
.player-panel--right .player-text { text-align: right; }
.player-name { font-size: 17px; }
.player-note { color: var(--muted); font-size: 12px; font-weight: 600; }
.player-panel.is-active .player-note { color: var(--primary-dark); }
.player-score { min-width: 56px; font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; }
.player-panel--right .player-score { text-align: left; }
.player-score.is-counting { color: var(--success-dark); }

.avatar {
  position: relative;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
}
.avatar--human { color: #fff; background: var(--grad-primary); box-shadow: 0 4px 10px rgba(33, 150, 243, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.4); }
.avatar--pip { background: var(--grad-secondary); border-radius: 46% 54% 44% 46%; box-shadow: 0 4px 10px rgba(255, 152, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.4); }
.avatar--pip i {
  position: absolute;
  top: 11px;
  width: 11px;
  height: 13px;
  border: 2.5px solid #fff;
  border-radius: 50%;
  background: var(--ink);
}
.avatar--pip i:first-child { left: 8px; }
.avatar--pip i:nth-child(2) { right: 8px; }
.avatar--pip b { position: absolute; left: 14px; bottom: 7px; width: 14px; height: 6px; border-radius: 0 0 8px 8px; background: #5d2c00; }

.timer {
  min-width: 108px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5px 18px;
  border-radius: 18px;
  color: #fff;
  background: var(--grad-ink);
  box-shadow: 0 8px 20px rgba(33, 33, 33, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  line-height: 1.15;
}
.timer-label { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.75; }
.timer-value { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer.is-idle { color: var(--ink); background: linear-gradient(180deg, #ffffff, #eef1f5); box-shadow: var(--shadow-sm); }
.timer.is-low { background: var(--error); animation: low-time 1s ease-in-out infinite; }

.game-main {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  padding: 12px 16px;
}

.board-area {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  /* When even the smallest squares do not fit, the board scrolls instead of being cut off. */
  overflow: auto;
}
/* Auto margins centre the board, and unlike place-items they never push it out of the scrollable area. */
.board-area > .board { margin: auto; }

.board {
  /* fitBoard reads these three to size the squares. */
  --coord: 22px;
  --board-gap: 2px;
  --board-pad: 8px;
  display: grid;
  grid-template-columns: var(--coord) repeat(15, var(--cell));
  grid-template-rows: var(--coord) repeat(15, var(--cell));
  gap: var(--board-gap);
  padding: var(--board-pad);
  border-radius: 20px;
  /* A sage frame with a white outer ring, like a printed board on a table. */
  background: var(--board-frame);
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.35), var(--shadow-lg);
}
/* Rows exist for assistive technology only; their cells stay items of the board grid. */
.board-row { display: contents; }
.board-corner,
.board-header {
  display: grid;
  place-items: center;
  color: var(--frame-ink);
  font-size: 12px;
  font-weight: 800;
}

.turn-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 10;
  padding: 16px 40px;
  border-radius: 24px;
  color: #fff;
  background: linear-gradient(135deg, rgba(13, 71, 161, 0.92), rgba(30, 136, 229, 0.9));
  box-shadow: 0 18px 40px rgba(13, 71, 161, 0.35);
  backdrop-filter: blur(6px);
  font-size: 28px;
  font-weight: 800;
  /* One centred line: with left: 50% the box could otherwise shrink to half the board and wrap the words. */
  width: max-content;
  max-width: calc(100% - 32px);
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.turn-banner.is-showing { animation: banner-show 1.5s ease both; }

.side-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-right: 2px;
}

.panel-card {
  padding: 16px 18px;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
}
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 15px;
  font-weight: 800;
}
.count-badge {
  min-width: 26px;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  color: #fff;
  background: var(--grad-primary);
  box-shadow: 0 3px 8px rgba(33, 150, 243, 0.3);
  font-size: 13px;
  text-align: center;
}

/* An accent strip inside the left edge; its colour follows the verdict. */
.status-card { --tone: var(--primary); box-shadow: inset 6px 0 0 var(--tone), var(--shadow-md); transition: background 220ms ease, box-shadow 220ms ease; }
.status-card h2 { font-size: 22px; line-height: 1.25; overflow-wrap: anywhere; }
.status-message { margin-top: 6px; color: #424242; font-size: 15px; }
.status-score {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  background: rgba(245, 247, 250, 0.9);
  font-size: 14px;
  font-weight: 600;
}
.status-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.status-actions .btn { flex: 1 1 120px; }
.status-card[data-tone="valid"] { --tone: var(--success); background: linear-gradient(165deg, #f4fbf3, #e2f3e3); }
.status-card[data-tone="valid"] h2 { color: var(--success-dark); }
.status-card[data-tone="valid"] .status-score { background: #fff; color: var(--success-dark); }
.status-card[data-tone="invalid"] { --tone: var(--error); background: linear-gradient(165deg, #fff6f5, #fde4e2); }
.status-card[data-tone="invalid"] .status-message { color: var(--error-dark); font-weight: 600; }
.status-card[data-tone="pending"] { --tone: var(--secondary); background: linear-gradient(165deg, #fffaf1, #ffeccc); }

.pool-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 0; }
.pool-list div { padding: 9px 8px; border-radius: 14px; background: linear-gradient(170deg, #eef6fe, #e1eefc); text-align: center; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8); }
.pool-list div:nth-child(2) { background: linear-gradient(170deg, #fff5e6, #ffe8c7); }
.pool-list div:nth-child(3) { background: linear-gradient(170deg, #eef8ee, #dcf0dd); }
.pool-list dt { color: var(--muted); font-size: 12px; font-weight: 600; }
.pool-list dd { margin: 0; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }

.history-card { min-height: 150px; display: flex; flex-direction: column; flex: 1 1 180px; }
.history-list { flex: 1; min-height: 0; overflow-y: auto; margin: 10px 0 0; padding: 0; list-style: none; }
.history-item { padding: 9px 0; border-top: 1px dashed rgba(0, 0, 0, 0.09); }
.history-item:first-child { border-top: 0; }
.history-head { display: flex; justify-content: space-between; font-size: 14px; }
.history-points { color: var(--success-dark); font-weight: 800; }
.history-equation { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.history-equation--struck { color: var(--error-dark); text-decoration: line-through; }
.history-item--slip .history-equation { color: var(--error-dark); }
.history-item--slip .history-points { color: var(--muted); text-decoration: line-through; }
.history-flag { color: var(--error-dark); font-size: 13px; font-weight: 700; }
.history-note { color: var(--muted); font-size: 13px; }
.history-card > .muted { margin-top: 10px; font-size: 14px; }

.rules-card { flex: 0 0 auto; }
.rules-card summary { cursor: pointer; }
.rules-body { margin-top: 10px; font-size: 14px; }
.rules-body h3 { margin-top: 12px; font-size: 14px; color: var(--primary-dark); }
.rules-body ul { margin: 6px 0 0; padding-left: 18px; }
.rules-body li + li { margin-top: 4px; }
.rules-body .swatch { width: 16px; height: 16px; }
.tile-values { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px 10px; margin: 8px 0 0; padding: 0; list-style: none; }
.rules-body .tile-values li + li { margin-top: 0; }
.tile-value-item { display: flex; align-items: center; gap: 6px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile--legend { width: 26px; height: 28px; flex: 0 0 auto; border-radius: 6px; font-size: 16px; }
.tile--legend .tile-value { display: none; }

.rack-bar {
  display: grid;
  /* Tool groups take the room they need; the tray sits centred in what is left. */
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.72);
  border-top: 1px solid rgba(224, 224, 224, 0.7);
  box-shadow: 0 -8px 26px rgba(22, 44, 84, 0.07);
  backdrop-filter: blur(14px) saturate(1.3);
}
.rack-tools { display: flex; align-items: center; gap: 8px; }
.rack-tools .btn { padding-inline: 16px; }
.rack-tools--right { justify-content: flex-end; }

.rack-zone {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 22px;
  /* A wooden tray: grain-like stripes over a warm gradient, with a lip along the bottom. */
  background:
    repeating-linear-gradient(92deg, rgba(255, 255, 255, 0.035) 0 2px, rgba(0, 0, 0, 0.03) 2px 7px),
    var(--wood);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), inset 0 -6px 0 rgba(0, 0, 0, 0.18), 0 10px 24px rgba(77, 52, 40, 0.28);
  transition: box-shadow 160ms ease;
}
.rack-bar > .rack-zone { justify-self: center; }
.rack-zone.is-drop-target { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), inset 0 -6px 0 rgba(0, 0, 0, 0.18), 0 0 0 4px rgba(33, 150, 243, 0.7), 0 10px 24px rgba(77, 52, 40, 0.28); }
.rack { display: flex; gap: 7px; }
.rack-slot { display: flex; align-items: center; gap: 8px; }
.rack-divider { width: 2px; align-self: stretch; border-radius: 2px; background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.4), transparent); }
.equals-slot { display: flex; align-items: center; gap: 8px; }
.equals-count { padding: 3px 9px; border-radius: var(--radius-pill); color: #fff; background: rgba(0, 0, 0, 0.18); font-size: 12px; font-weight: 700; white-space: nowrap; }

.tile--rack {
  width: 56px;
  height: 60px;
  border-radius: 10px;
  font-size: 32px;
  cursor: grab;
  transition: transform 160ms cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 160ms ease, opacity 160ms ease;
}
@media (hover: hover) { .tile--rack:not(:disabled):hover { transform: translateY(-5px) rotate(-2deg) scale(1.05); box-shadow: inset 0 1px 0 #ffffff, inset 0 -3px 0 rgba(120, 96, 60, 0.16), 0 10px 18px rgba(40, 24, 10, 0.35); } }
.tile--rack:disabled { cursor: default; opacity: 0.72; }
.tile--rack.is-selected { transform: translateY(-7px); box-shadow: inset 0 -3px 0 rgba(120, 96, 60, 0.16), 0 0 0 3px var(--primary), 0 12px 20px rgba(40, 24, 10, 0.35); }
@media (hover: hover) { .tile--rack.is-selected:not(:disabled):hover { transform: translateY(-7px); box-shadow: inset 0 -3px 0 rgba(120, 96, 60, 0.16), 0 0 0 3px var(--primary), 0 12px 20px rgba(40, 24, 10, 0.35); } }
/* A tile already on the board: a readable dashed outline that can still be clicked to take it back. */
.tile--rack.is-placed { opacity: 1; background: rgba(255, 255, 255, 0.45); box-shadow: none; outline: 2px dashed rgba(255, 255, 255, 0.95); outline-offset: -4px; cursor: pointer; }
.tile--rack.is-placed .tile-value { color: #3e2723; }
@media (hover: hover) { .tile--rack.is-placed:not(:disabled):hover { transform: none; } }

/* ------------------------------------------------------------------ */
/* Dialogs, toast                                                      */
/* ------------------------------------------------------------------ */

.modal {
  width: min(480px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  padding: 30px;
  overflow: auto;
  border: 1px solid var(--glass-line);
  border-radius: 28px;
  color: var(--ink);
  background: linear-gradient(170deg, #ffffff 0%, #f8fbff 100%);
  box-shadow: var(--shadow-lg);
}
.modal--wide { width: min(760px, calc(100% - 32px)); }
.modal::backdrop { background: rgba(16, 32, 64, 0.42); backdrop-filter: blur(4px); }
.modal[open] { animation: modal-in 200ms ease-out; }
.modal h2 { font-size: 26px; }
.modal-form { display: grid; gap: 14px; }
.modal-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; margin-top: 8px; }
.stack { display: grid; gap: 8px; }
.info-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; color: #424242; overflow-wrap: anywhere; }

.mode-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.mode-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  border: 2px solid rgba(224, 224, 224, 0.9);
  border-radius: 20px;
  background: #ffffff;
  transition: transform 200ms ease, box-shadow 200ms ease;
}
.mode-card p { flex: 1; color: #424242; font-size: 14px; }
.mode-card--active { border-color: rgba(33, 150, 243, 0.7); background: linear-gradient(170deg, #f1f8ff, #dceefe); box-shadow: 0 10px 24px rgba(33, 150, 243, 0.18); }
.mode-card--soon { opacity: 0.62; }
.tag {
  align-self: flex-start;
  padding: 2px 10px;
  border-radius: 999px;
  color: #424242;
  background: #eeeeee;
  font-size: 12px;
  font-weight: 700;
}
.tag--green { color: #fff; background: var(--grad-success); box-shadow: 0 3px 8px rgba(46, 125, 50, 0.3); }

.option-group { margin: 0; padding: 0; border: 0; }
.option-group legend { padding: 0; margin-bottom: 8px; font-weight: 800; }
.option-group .muted { margin-top: 8px; font-size: 14px; }
.choice-row { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  min-width: 84px;
  min-height: 40px;
  padding: 8px 18px;
  border: 1.5px solid var(--line);
  border-radius: 13px;
  background: linear-gradient(180deg, #ffffff, #f5f7fa);
  font-weight: 700;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}
.choice:hover { border-color: var(--primary); transform: translateY(-1px); }
.choice[aria-pressed="true"] { color: #fff; background: var(--grad-primary); border-color: transparent; box-shadow: 0 6px 14px rgba(33, 150, 243, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.35); }

.switch-row { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.switch-row input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--primary); }
.switch-row span { display: grid; }
.switch-row small { color: var(--muted); font-size: 14px; }

.order-draws { display: flex; justify-content: center; gap: 36px; padding: 8px 0; }
.order-draw { display: grid; justify-items: center; gap: 8px; font-weight: 700; }
.order-draw.is-first .tile { box-shadow: 0 0 0 3px var(--success), 0 4px 10px rgba(33, 33, 33, 0.25); }
.order-result { font-size: 18px; font-weight: 700; text-align: center; }

.result-modal { position: relative; overflow: hidden auto; text-align: center; }
.result-modal h2 { font-size: 40px; }
.result-modal.is-win h2 { color: var(--success-dark); }
.result-scores { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0; }
.result-score { display: grid; padding: 16px; border: 2px solid rgba(224, 224, 224, 0.9); border-radius: 22px; background: #ffffff; }
.result-score span { color: var(--muted); font-weight: 700; }
.result-score strong { font-size: 44px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.result-score.is-winner { border-color: rgba(76, 175, 80, 0.7); background: linear-gradient(170deg, #f4fbf3, #dff2e0); box-shadow: 0 12px 26px rgba(46, 125, 50, 0.2); }

.score-sheet { width: 100%; border-collapse: collapse; font-size: 15px; }
.score-sheet th,
.score-sheet td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
.score-sheet th:first-child { text-align: left; font-weight: 600; }
.score-sheet thead th { color: var(--muted); font-size: 13px; }
.score-sheet .is-total th,
.score-sheet .is-total td { border-bottom: 0; font-size: 17px; font-weight: 800; }

.result-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.stat { display: grid; gap: 2px; padding: 12px; border-radius: 16px; background: linear-gradient(170deg, #f5f8fc, #eaf0f7); }
.stat span { color: var(--muted); font-size: 12px; font-weight: 600; }
.stat strong { font-size: 15px; overflow-wrap: anywhere; }
.result-reveal { margin-top: 14px; padding: 12px 14px; border-radius: 14px; background: linear-gradient(165deg, #fffaf1, #ffeccc); font-size: 14px; text-align: left; }
.result-modal .modal-actions { justify-content: center; margin-top: 20px; }

.confetti { position: absolute; inset: 0; pointer-events: none; display: none; }
.result-modal.is-win .confetti { display: block; }
.confetti i { position: absolute; top: -24px; width: 10px; height: 18px; border-radius: 4px; background: var(--secondary); animation: confetti-fall 2.8s linear infinite; }
.confetti i:nth-child(1) { left: 6%; }
.confetti i:nth-child(2) { left: 18%; background: var(--primary); animation-delay: -1.1s; }
.confetti i:nth-child(3) { left: 31%; background: var(--success); animation-delay: -2s; }
.confetti i:nth-child(4) { left: 45%; background: var(--error); animation-delay: -0.5s; }
.confetti i:nth-child(5) { left: 58%; animation-delay: -1.7s; }
.confetti i:nth-child(6) { left: 70%; background: var(--primary); animation-delay: -2.4s; }
.confetti i:nth-child(7) { left: 83%; background: var(--success); animation-delay: -0.9s; }
.confetti i:nth-child(8) { left: 94%; background: var(--error); animation-delay: -1.4s; }

.toast {
  position: fixed;
  left: 50%;
  /* Just below the game's top bar, however tall it is (a second row of players in 3- and 4-player games);
     --top-bar-h is measured in app.mjs. */
  top: max(84px, calc(var(--top-bar-h, 0px) + 8px));
  z-index: 100;
  max-width: min(560px, calc(100% - 32px));
  padding: 12px 24px;
  border-radius: var(--radius-pill);
  color: #fff;
  background: linear-gradient(135deg, rgba(38, 50, 66, 0.96), rgba(23, 31, 42, 0.96));
  box-shadow: var(--shadow-lg);
  font-weight: 700;
  text-align: center;
  transform: translateX(-50%);
  animation: modal-in 180ms ease-out;
}

.noscript {
  position: fixed;
  inset: 20px;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 30px;
  border-radius: var(--radius-card);
  color: #fff;
  background: var(--primary-dark);
  font-size: 20px;
  text-align: center;
}

/* ------------------------------------------------------------------ */
/* Motion                                                              */
/* ------------------------------------------------------------------ */

@keyframes tile-pop {
  from { transform: scale(0.6); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes tile-settle {
  0% { transform: scale(1.18); box-shadow: 0 0 0 4px var(--success), 0 6px 14px rgba(46, 125, 50, 0.4); }
  100% { transform: scale(1); }
}
@keyframes pending-pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--secondary), 0 3px 10px rgba(230, 81, 0, 0.35); }
  50% { box-shadow: 0 0 0 5px rgba(255, 152, 0, 0.45), 0 3px 10px rgba(230, 81, 0, 0.35); }
}
@keyframes ready-glow {
  0%, 100% { box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.3), 0 4px 14px rgba(33, 33, 33, 0.12); }
  50% { box-shadow: 0 0 0 7px rgba(76, 175, 80, 0.18), 0 4px 14px rgba(33, 33, 33, 0.12); }
}
@keyframes low-time {
  0%, 100% { background: var(--error); }
  50% { background: var(--error-dark); }
}
@keyframes tile-loop {
  0% { opacity: 0; transform: translateY(-14px) scale(0.6); }
  7%, 86% { opacity: 1; transform: translateY(0) scale(1); }
  96%, 100% { opacity: 0; transform: translateY(0) scale(0.9); }
}
@keyframes banner-show {
  0% { opacity: 0; transform: translate(-50%, -30%); }
  15%, 75% { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(-50%, -70%); }
}
@keyframes modal-in {
  from { opacity: 0; translate: 0 10px; }
  to { opacity: 1; translate: 0 0; }
}
@keyframes confetti-fall {
  from { transform: translateY(0) rotate(0deg); opacity: 1; }
  to { transform: translateY(560px) rotate(540deg); opacity: 0; }
}

/* ------------------------------------------------------------------ */
/* Smaller screens                                                     */
/* ------------------------------------------------------------------ */

@media (max-height: 800px) {
  .tile--rack { width: 48px; height: 52px; font-size: 28px; }
  .rack-bar { padding-block: 6px; }
  .top-bar { padding-block: 5px; }
  .game-main { padding-block: 8px; }
  .player-score { font-size: 26px; }
}

@media (max-width: 1280px) {
  .game-main { grid-template-columns: minmax(0, 1fr) 300px; }
  .scoreboard { grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr); }
  .rack-bar { gap: 10px; }
  .rack-tools .btn { padding-inline: 12px; }
  .btn--confirm { min-width: 160px; }
}

@media (max-width: 1200px) {
  /* Not enough width for tools, tray and tools on one line: tray on top, tools below. */
  .rack-bar { grid-template-columns: auto auto; justify-content: space-between; row-gap: 8px; }
  .rack-bar > .rack-zone { grid-column: 1 / -1; grid-row: 1; }
}

@media (max-width: 1400px) and (min-height: 801px) {
  /* Full-size rack tiles need about 1400px for tools, tray and tools on one line. */
  .rack-bar { grid-template-columns: auto auto; justify-content: space-between; row-gap: 8px; }
  .rack-bar > .rack-zone { grid-column: 1 / -1; grid-row: 1; }
}

@media (max-width: 1000px) {
  h1 { font-size: 32px; }
  h2 { font-size: 24px; }
  .site-header { grid-template-columns: auto 1fr auto; }
  .site-nav { justify-content: center; }
  .hero { grid-template-columns: 1fr; }
  .hero-preview { justify-self: center; }
  .features { grid-template-columns: 1fr; }
  .how-section { grid-template-columns: 1fr; }
  .how-figure { justify-self: center; }
  .how-extra-grid { grid-template-columns: 1fr 1fr; }
  .mode-grid { grid-template-columns: 1fr; }
  .result-stats { grid-template-columns: 1fr 1fr; }

  .game-view { height: auto; min-height: 100dvh; }
  .top-bar { grid-template-columns: auto 1fr auto; }
  .scoreboard { grid-template-columns: 1fr auto 1fr; }
  .game-main { grid-template-columns: 1fr; }
  .board-area { height: min(100vw, 78dvh); }
  .side-panel { overflow: visible; }
  .rack-bar { position: sticky; bottom: 0; grid-template-columns: 1fr; justify-items: center; }
  .rack-tools { flex-wrap: wrap; justify-content: center; }
}

@media (max-width: 620px) {
  .nav-link { padding: 8px 12px; white-space: nowrap; }
  #login-button { display: none; }
  .logo-name,
  .site-nav .nav-link[data-nav="home"],
  .player-note,
  .avatar { display: none; }
  .hero-actions { flex-direction: column; align-items: stretch; width: 100%; }
  .resume-card { flex-direction: column; align-items: flex-start; }
  .mini-board { --cell: 30px; }
  /* The hero board shrinks on very narrow phones (320px) instead of widening the page. */
  .mini-board--hero { --cell: min(32px, calc((100vw - 124px) / 7)); }
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero-copy { min-width: 0; }
  .hero-actions .btn--large { min-width: 0; }
  /* The scores take their own row, so the top bar fits a phone without sideways scrolling. */
  .top-bar { grid-template-columns: auto 1fr; row-gap: 6px; padding-inline: 12px; }
  .top-bar .scoreboard { grid-column: 1 / -1; grid-row: 2; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
  .game-view { grid-template-columns: minmax(0, 1fr); }
  .game-main { grid-template-columns: minmax(0, 1fr); padding-inline: 12px; }
  .player-panel { padding: 4px 8px; gap: 6px; min-width: 0; }
  .player-score { min-width: 0; font-size: 22px; }
  .timer { min-width: 76px; padding-inline: 8px; }
  .tile--rack { width: 30px; height: 38px; font-size: 19px; }
  .rack { gap: 3px; }
  .rack-zone { max-width: 100%; padding: 6px 8px; gap: 6px; }
  /* The Tile pools card shows how many equals tiles are left. */
  .equals-count { display: none; }
  .how-extra-grid { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------------------
   Online play (Play with Friend)
   --------------------------------------------------------------------------- */
.online-view { display: grid; place-items: start center; padding: 32px 16px 64px; }
.online-card {
  width: min(640px, 100%);
  display: grid;
  gap: 18px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow-sm);
}
.online-card h1 { font-size: 34px; }
.online-connection { color: var(--muted); font-size: 14px; min-height: 1.2em; }
.online-connection.is-error { color: var(--error-dark); }
.online-form, .online-rooms, .online-lobby { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-weight: 700; }
.field input {
  min-height: 44px;
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-weight: 500;
  background: #fff;
}
.field input:focus-visible { outline: 3px solid rgba(33, 150, 243, 0.4); border-color: var(--primary); }
.online-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.online-error { color: var(--error-dark); font-weight: 600; min-height: 1.2em; }
.online-note { color: var(--muted); font-size: 14px; }
.online-form h2 { font-size: 22px; }
.recovery-code {
  margin: 4px 0;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  /* One line on a phone too: a code broken mid-group is easy to copy wrongly. */
  font-size: clamp(17px, 5.2vw, 26px);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  user-select: all;
  white-space: nowrap;
}
.online-who { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.online-join { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.online-join .field { flex: 1 1 220px; }
.online-back { justify-self: start; }
.room-code {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--primary-soft);
}
.room-code span { color: var(--primary-dark); font-weight: 700; }
.room-code strong { font-size: 24px; letter-spacing: 0.06em; font-variant-numeric: tabular-nums; }
.lobby-players { display: grid; gap: 8px; padding: 0; margin: 0; list-style: none; }
.lobby-players li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
}
.lobby-players .badge { margin-left: auto; color: var(--muted); font-size: 13px; font-weight: 700; }
.lobby-players .is-away { opacity: 0.6; }
.choice[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }
.choice:disabled { cursor: default; opacity: 0.6; transform: none; }
.mode-card--link { text-align: left; font: inherit; color: inherit; cursor: pointer; }
.mode-card--link:hover, .mode-card--link:focus-visible { border-color: rgba(33, 150, 243, 0.7); transform: translateY(-2px); box-shadow: 0 10px 24px rgba(33, 150, 243, 0.18); }

.top-bar > .more-players { grid-column: 1 / -1; grid-row: 2; display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; }
.top-bar > .top-bar-side--right { grid-column: -2 / -1; grid-row: 1; }
.player-panel--compact { padding: 4px 12px; }
.player-panel--compact .player-score { font-size: 22px; min-width: 40px; }
.avatar--friend {
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  background: var(--grad-success);
  box-shadow: 0 4px 10px rgba(46, 125, 50, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.game-view.is-online .avatar--pip { display: none; }
.player-panel.is-away { opacity: 0.6; }
.online-room-line { font-size: 13px; text-align: center; }

.chat-phrases { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.chat-mute-title { font-size: 16px; margin-top: 4px; }
.chat-mute { display: grid; gap: 6px; }
.chat-mute label { display: flex; align-items: center; gap: 10px; }

@media (max-width: 620px) {
  .top-bar > .more-players { grid-row: 3; gap: 6px; }
  .online-card { padding: 20px 16px; }
  .online-card h1 { font-size: 28px; }
  .chat-phrases { grid-template-columns: 1fr; }
}

/* Phones and narrow windows: the side panel sits below the board, out of sight while
   playing. When the game waits for an answer (Accept or Challenge, the swap choice, the
   results), the status card floats just above the rack so the decision is never hidden. */
@media (max-width: 1000px) {
  .status-card.has-actions {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(var(--rack-visible-h, 180px) + 8px);
    z-index: 40;
    max-height: 48dvh;
    overflow-y: auto;
    padding: 14px 16px;
    box-shadow: inset 6px 0 0 var(--tone), 0 12px 40px rgba(22, 44, 84, 0.28);
  }
  .status-card.has-actions h2 { font-size: 20px; }
}

/* Phones: the rack's buttons take two rows (Shuffle, Recall, Hint, Pass / Swap, then Confirm). */
@media (max-width: 620px) {
  .rack-bar { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding-block: 8px; }
  .rack-bar > .rack-zone { order: -1; flex: 0 0 100%; justify-content: center; }
  .rack-bar > .rack-tools { display: contents; }
  .rack-tools .btn { min-height: 40px; padding: 6px 12px; font-size: 15px; }
  #confirm-move { flex: 1 1 100%; max-width: 360px; }
}

/* The rack flies in and out on narrow screens: a bottom sheet that slides down to a slim handle
   when it is not this player's move, so the board, the opponents and the decision card get the
   screen. Wide screens always show it. */
.rack-toggle { display: none; }
@media (max-width: 1000px) {
  .rack-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 35;
    transition: transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: transform;
  }
  .game-view { padding-bottom: var(--rack-visible-h, 200px); }
  .game-view.rack-hidden .rack-bar { transform: translateY(calc(100% - var(--rack-handle-h, 44px))); }
  .rack-toggle {
    grid-column: 1 / -1;
    justify-self: stretch;
    display: grid;
    justify-items: center;
    gap: 2px;
    margin: -4px 0 0;
    padding: 2px 12px 4px;
    border: 0;
    background: transparent;
    color: var(--primary-dark);
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
  }
  .rack-toggle-grip { width: 44px; height: 5px; border-radius: 999px; background: #bdbdbd; }
  /* The handle takes the swipe itself, so the page does not scroll under the finger. */
  .rack-toggle { touch-action: none; user-select: none; -webkit-user-select: none; min-height: 44px; }
  .rack-bar.is-dragging { transition: none; }
  .rack-toggle:focus-visible { outline: 3px solid rgba(33, 150, 243, 0.4); border-radius: 12px; }
}
@media (max-width: 620px) {
  .rack-bar > .rack-toggle { order: -2; flex: 0 0 100%; }
}

/* Phones and narrow windows: the board fills the screen's width, with a thin frame and fine gaps.
   The row and column names (A–O, 1–15) are hidden unless the player turns them on with the
   floating button; each square still names its reference to assistive technology. */
.board-coords-fab { display: none; }
@media (max-width: 1000px) {
  .game-main { padding-inline: 0; }
  .game-main > .side-panel { padding-inline: 12px; }
  .board-area > .board {
    --coord: 14px;
    --board-gap: 1px;
    --board-pad: 3px;
    border-radius: 10px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), var(--shadow-md);
  }
  .board.no-coords { --coord: 0px; grid-template-columns: repeat(15, var(--cell)); grid-template-rows: repeat(15, var(--cell)); }
  .board.no-coords .board-corner,
  .board.no-coords .board-header { display: none; }
  .board-area > .board .board-header { font-size: 10px; }
  /* In the top bar, beside the logo, so it never covers a square of the board. */
  .board-coords-fab {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1.5px solid rgba(21, 101, 192, 0.35);
    border-radius: 50%;
    background: #fff;
    color: var(--primary-dark);
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
  }
  .board-coords-fab[aria-pressed="true"] { background: var(--grad-primary); color: #fff; border-color: transparent; }
  .board-coords-fab:focus-visible { outline: 3px solid rgba(33, 150, 243, 0.45); outline-offset: 2px; }
}

/* Touch drag and drop: a touch on a tile never scrolls or opens the iOS callout; the lifted tile
   floats above the finger. */
.rack-zone [data-tile-id],
.cell .tile--draft {
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
/* The hidden switch whose toggle plays the iPhone's haptic tick (haptic() in app.mjs). */
.haptic-switch { position: fixed; left: -9999px; top: 0; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.tile--ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 300;
  width: 46px;
  height: 54px;
  font-size: 28px;
  pointer-events: none;
  opacity: 0.95;
  box-shadow: 0 14px 30px rgba(22, 44, 84, 0.35), 0 0 0 3px rgba(33, 150, 243, 0.55);
  will-change: translate;
  /* Tiles ease their transform with a springy overshoot; the lifted tile must follow the finger exactly,
     so it has no transition. The lift is a short scale, a property of its own that never moves it. */
  transition: none;
  animation: tile-lift 140ms ease-out;
}
@keyframes tile-lift { from { scale: 0.85; } to { scale: 1; } }

/* Rack tools carry an icon; phones show the icons alone so the whole tray fits in two short rows
   (tiles, then buttons), and the handle is just its grab bar. */
.btn-icon { display: none; flex: 0 0 auto; }
@media (max-width: 1000px) {
  .btn-icon { display: inline-block; }
  .btn--tool, .btn--confirm { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
}
@media (max-width: 620px) {
  .rack-bar { gap: 6px; padding: 2px 10px 8px; background: rgba(255, 255, 255, 0.97); }
  .rack-bar > .rack-toggle { min-height: 22px; padding: 6px 12px 4px; margin: 0; }
  .rack-bar .btn--tool { flex: 0 0 auto; width: 44px; min-height: 42px; padding: 0; }
  .rack-bar .btn--tool .btn-label { display: none; }
  #confirm-move { flex: 1 1 0; min-width: 0; max-width: none; min-height: 42px; padding: 0 10px; font-size: 15px; white-space: nowrap; }
  #confirm-move .btn-label { overflow: hidden; text-overflow: ellipsis; }
  .rack-zone { padding: 5px 8px; }
}

/* Phones: a compact top bar, so the whole board fits between it and the tray on small iPhones too. */
@media (max-width: 620px) {
  .top-bar { padding-block: 4px; row-gap: 4px; }
  .top-bar .btn { min-height: 36px; padding: 6px 12px; }
  .top-bar .icon-btn { width: 36px; height: 36px; }
  .top-bar .player-panel { padding-block: 2px; }
  .top-bar .player-score { font-size: 20px; }
  .top-bar .timer { padding-block: 2px; }
  .top-bar .timer-value { font-size: 18px; }
  .board-coords-fab { width: 36px; height: 36px; }
  .game-main { padding-block: 4px; }
}

/* Pinch to zoom: on narrow screens the board area takes two-finger gestures itself (the page does not
   zoom there) and scrolls the zoomed board with one finger. */
@media (max-width: 1000px) {
  .board-area { touch-action: pan-x pan-y; overscroll-behavior: contain; }
}

/* Phones and narrow windows: the panel under the board (status, pools, history, rules, chat) is a
   drop-down under the top bar, opened with the info button, so the game screen is just the top bar,
   the board and the tray, without scrolling. Visibility only (no opacity or transform): a floating
   decision card inside it stays visible while the panel is closed. */
@media (max-width: 1000px) {
  .game-main > .side-panel {
    position: fixed;
    top: var(--top-bar-h, 96px);
    left: 0;
    right: 0;
    z-index: 38;
    max-height: calc(100dvh - var(--top-bar-h, 96px) - var(--rack-visible-h, 140px) - 6px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 10px 12px 14px;
    background: rgba(250, 250, 250, 0.98);
    border-radius: 0 0 18px 18px;
    box-shadow: 0 18px 40px rgba(22, 44, 84, 0.25);
    visibility: hidden;
  }
  .game-view.info-open .game-main > .side-panel { visibility: visible; }
  /* With the panel out of the flow, the game screen is exactly one screen tall: the board area takes
     the space between the top bar and the tray, and fitBoard sizes the board to it, so nothing scrolls. */
  .game-view { height: 100dvh; min-height: 0; overflow: hidden; }
  .game-main { grid-template-rows: minmax(0, 1fr); }
  .board-area { height: auto; }
  .game-main > .side-panel .status-card.has-actions { visibility: visible; }
  .info-toggle { position: relative; }
}
@media (max-width: 620px) {
  /* The rules are in the info panel; without this button the top row fits a 375px phone. */
  #open-rules { display: none; }
}
@media (max-width: 1000px) {
  .info-toggle[aria-expanded="true"] { background: var(--grad-primary); color: #fff; border-color: transparent; }
  .info-toggle[data-alert]::after {
    content: "";
    position: absolute;
    top: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--error);
    box-shadow: 0 0 0 2px #fff;
  }
}

/* Phones: dialogs use the full width, and their buttons share the row or stack, never overflow. */
@media (max-width: 620px) {
  .modal { width: calc(100% - 24px); padding: 22px 18px; }
  .modal-actions > .btn { flex: 1 1 auto; }
}

/* Narrow tablets and windows (621-1000px): buttons on the first row, scores on their own second row,
   as on phones, so the top bar never runs off the right edge. */
@media (max-width: 1000px) {
  .top-bar { grid-template-columns: auto 1fr; row-gap: 6px; }
  .top-bar > .top-bar-side:last-of-type { justify-self: end; }
  .top-bar .scoreboard { grid-column: 1 / -1; grid-row: 2; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
}

/* Very narrow phones (320px, or Display Zoom): the game's top row drops the small logo and tightens
   New game, so every button stays on screen. */
@media (max-width: 360px) {
  .top-bar .logo-img--small { display: none; }
  .top-bar #new-match { padding-inline: 10px; font-size: 14px; }
  .top-bar-side { gap: 6px; }
  .tile--rack { width: 25px; height: 34px; font-size: 17px; }
  .rack { gap: 2px; }
  .rack-zone { padding: 5px 6px; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .tile--loop { animation: none; }
}

/* The standalone privacy policy page (privacy.html, 0.8.2). */
.policy-page { min-height: 100dvh; }
.policy { max-width: 720px; margin: 0 auto; padding: 32px 16px 64px; line-height: 1.6; }
.policy h1 { margin: 20px 0 8px; font-size: 36px; }
.policy h2 { margin: 28px 0 8px; font-size: 22px; }
.policy p, .policy ul { margin: 0 0 12px; }
.policy li + li { margin-top: 6px; }
.policy-home { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-size: 20px; font-weight: 800; text-decoration: none; }
.policy a { color: var(--primary-dark); }
.policy .policy-home { color: var(--ink); }
.policy-back { margin-top: 32px; font-weight: 700; }
