:root {
  --hex-highlight: #2e8b57;
  --hex-radius: 56px;
  --hex-width: calc(var(--hex-radius) * 2);
  --hex-height: calc(var(--hex-radius) * 1.732);
  --games-list-row-height: 40px;
  --board-radius: calc(var(--hex-radius) * 0.36);
  --board-frame-inset: calc(var(--hex-radius) * 0.32);
  --board-frame-border: calc(var(--hex-radius) * 0.07);
  --board-frame-radius: calc(var(--hex-radius) * 0.21);
  --board-logo-offset-x: calc(var(--hex-radius) * 0.36);
  --board-logo-offset-y: calc(var(--hex-radius) * 0.27);
  --font-family-ui: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-family: var(--font-family-ui);
  --color-gold: #D4AF37;
  --color-brown-strong: #654321;
  --color-brown-muted: #6C4B2B;
  --color-brown-warm: #5B3D24;
  --color-brown-dark: #3D2817;
  --color-brown-deep: #3B220F;
  --color-parchment: #f6e7c3;
  --color-parchment-card: #fffdf6;
  --color-hex-highlight: var(--hex-highlight);
  --color-success: #4CAF50;
  --color-error: #F44336;
  --color-alert: #D9534F;
  --gradient-button-primary: linear-gradient(135deg, #583286 0%, #7a4ba8 100%);
  --gradient-button-hover: linear-gradient(135deg, #7a4ba8 0%, #9a6bc8 100%);
  --gradient-button-disabled: linear-gradient(135deg, #555 0%, #777 100%);
  --gradient-panel-dark: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
  --gradient-panel-mid: linear-gradient(135deg, #333 0%, #2a2a2a 100%);
  --gradient-input: linear-gradient(135deg, #3a3a3a 0%, #2a2a2a 100%);
  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.15);
  --shadow-button: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-button-hover: 0 6px 12px rgba(0, 0, 0, 0.4);
  --shadow-button-disabled: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-modal: 0 10px 30px rgba(0, 0, 0, 0.8);
  --control-border: 2px solid var(--color-gold);
  --control-radius: 6px;
  --control-font: clamp(13px, 1.6vmin, 16px);
  --font-size-control: var(--control-font);
  --control-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);

  /* ── Spacing scale ─────────────────────────────────────── */
  --space-1: 4px;
  --space-2: 6px;
  --space-3: 8px;
  --space-4: 10px;
  --space-5: 12px;
  --space-6: 16px;
  --space-7: 20px;
  --space-8: 24px;
  --space-9: 30px;

  /* ── Radii scale ───────────────────────────────────────── */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 15px;
  --radius-round: 50%;

  /* ── Typography scale ──────────────────────────────────── */
  --font-size-xxs: 0.68rem;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.85rem;
  --font-size-md: 0.9rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.1rem;
  --font-size-xl: 1.25rem;

  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  --font-weight-heavy: 800;

  --letter-spacing-caps: 0.05em;
  --letter-spacing-display: 0.02em;
  --letter-spacing-code: 0.22em;

  --line-height-tight: 1.2;
  --line-height-body: 1.45;
  --line-height-loose: 1.5;
  --surface-panel-soft: rgba(255, 255, 255, 0.55);
  --surface-panel-soft-alt: rgba(255, 255, 255, 0.62);
  --surface-panel-card: rgba(255, 253, 246, 0.95);
  --surface-panel-card-bright: rgba(255, 253, 246, 0.98);
  --border-subtle: 1px solid rgba(0, 0, 0, 0.08);
  --modal-surface-bg: var(--gradient-panel-dark);
  --modal-surface-border: 3px solid var(--color-gold);
  --modal-surface-shadow: var(--shadow-modal);
  --modal-surface-radius: 15px;
  --modal-surface-padding: 30px;
  --modal-surface-max-width: min(720px, 90vw);
  --modal-surface-max-height: min(85%, 90vh);
  --modal-surface-text: #f0e3cb;
  --modal-surface-light-bg: rgba(255, 253, 246, 0.98);
  --modal-surface-light-border: 1px solid rgba(0, 0, 0, 0.10);
  --modal-surface-light-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  --modal-surface-light-radius: 12px;
  --menu-surface-radius: 12px;
  --menu-btn-padding: 8px 12px;
  --menu-btn-radius: 6px;
  --menu-btn-font-size: 0.85rem;
  --menu-btn-font-weight: 600;
  --menu-btn-color: var(--color-brown-strong);
  --menu-panel-border-strong: 1px solid rgba(101, 67, 33, 0.24);
  --menu-panel-highlight: rgba(198, 155, 90, 0.14);
  --menu-panel-highlight-strong: rgba(198, 155, 90, 0.15);
  --menu-button-hover: rgba(198, 155, 90, 0.24);
  --menu-button-active: rgba(198, 155, 90, 0.36);
  --menu-button-active-strong: rgba(198, 155, 90, 0.54);
  --menu-tab-bg: rgba(255, 255, 255, 0.28);
  --menu-tab-bg-hover: rgba(255, 255, 255, 0.42);
  --menu-tab-active-bg: rgba(74, 47, 24, 0.9);
  --menu-tab-active-bg-hover: rgba(58, 36, 18, 0.92);
  --menu-tab-active-color: #fff6e5;
  --menu-selected-bg: rgba(228, 198, 164, 0.7);
  --games-list-row-alt-bg: rgba(198, 155, 90, 0.05);
  --games-list-row-selected-bg: rgba(198, 155, 90, 0.28);
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  padding: calc(env(safe-area-inset-top) + 40px) 20px 40px;
  width: 100vw;
  height: 100svh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background: var(--color-parchment);
}

.game-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  height: 100%;
}

.game-title {
  margin: var(--space-8) 0;
  width: 200px;
  color: #6b4b2a;
  letter-spacing: var(--letter-spacing-display);
  flex-shrink: 0;
}

.status-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  max-width: 100%;
}

@media (orientation: landscape) {
  /* Join the rating pill and status pill into a single capsule so the row
     reads as one element. Pill styling lives on .status-row; children render
     as inline content separated by a thin seam. Frees vertical space for
     the board and makes the top of the page look less cluttered. */
  .status-row {
    flex-direction: row;
    gap: 0;
    align-items: stretch;
    background: var(--surface-panel-card);
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  }

  .status-row > .rating-display {
    background: transparent;
    border: none;
    border-right: 1px solid rgba(101, 67, 33, 0.15);
    border-radius: 0;
    box-shadow: none;
    padding: 0 var(--space-5);
    line-height: 1;
  }

  .status-row > #status {
    background: transparent;
    border-radius: 0;
    box-shadow: none;
  }

  /* On game-end, lift the win/lose treatment from #status onto the wrapper so
     the colored border, halo and pulse hug the whole rating+status capsule —
     otherwise the rating sits outside the bordered area and reads as a
     separate component. */
  .status-row:has(#status.status--win),
  .status-row:has(#status.status--lose),
  .status-row:has(#status.status--winner) {
    border: 2px solid currentColor;
    animation: pulse-winner 2s infinite;
  }

  .status-row:has(#status.status--win) {
    color: var(--color-hex-highlight);
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 4px 16px rgba(46, 139, 87, 0.22);
  }

  .status-row:has(#status.status--lose),
  .status-row:has(#status.status--winner) {
    color: var(--color-alert);
    background: rgba(255, 253, 246, 1);
    box-shadow: 0 4px 16px rgba(217, 83, 79, 0.3);
  }

  .status-row:has(#status.status--win) > .rating-display,
  .status-row:has(#status.status--lose) > .rating-display,
  .status-row:has(#status.status--winner) > .rating-display {
    border-right-color: currentColor;
  }

  /* Suppress the per-pill border, halo and pulse so they don't double up with
     the wrapper. */
  .status-row:has(#status.status--win) > #status,
  .status-row:has(#status.status--lose) > #status,
  .status-row:has(#status.status--winner) > #status {
    border: none;
    background: transparent;
    box-shadow: none;
    animation: none;
  }
}

#board {
  margin: 0;
}

.board-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-5);
  width: 100%;
  height: 100%;
  position: relative;
  margin-top: auto;
  margin-bottom: clamp(0vh, 12vh, 18vh);
  justify-content: space-between;
}

@media (orientation: portrait) and (max-height: 700px) {
  .board-stack {
    margin-bottom: clamp(0vh, 4vh, 8vh);
  }
}

@media (orientation: landscape) {
  /* Portrait reserves 12–18vh at the bottom so the board sits within thumb
     reach on a phone held upright. In landscape the device is held by the
     sides (no thumb-reach concern), so reclaim that space for the board. */
  .board-stack {
    margin-bottom: clamp(0vh, 2vh, 4vh);
  }

  /* Landscape-only: pin the board against flex-shrink. Hex cells are
     absolutely positioned assuming the full board box, so shrinking
     would decenter the grid — most visible when board--rotated on short
     landscape viewports where the board-stack is tighter than the
     board's natural height, clipping the top row. Portrait keeps the
     default shrink behavior because its board-stack has generous
     thumb-reach margin so shrinking never engages there. */
  #board {
    flex-shrink: 0;
  }
}

.board-spacer {
  height: 200px;
  width: 100%;
}

@media (orientation: landscape) {
  .board-spacer {
    display: none;
  }
}

/* ── Loading overlay (app bootstrap + error fallback) ────────────────── */

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--color-parchment);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.loading-overlay.loading-overlay--hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
}

.loading-spinner svg {
  width: 60px;
  height: 60px;
  color: var(--color-brown-strong);
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.loading-spinner p {
  margin: 0;
  font-size: var(--font-size-base);
  color: var(--color-brown-strong);
  font-weight: var(--font-weight-medium);
}

.loading-overlay--error .loading-spinner {
  max-width: min(92vw, 560px);
  padding: 0 20px;
  text-align: center;
}

.loading-overlay--error .loading-spinner svg {
  display: none;
}

.loading-error-detail {
  margin: 0;
  font-size: 0.95rem;
  color: #6a4e2e;
  font-weight: var(--font-weight-regular);
  line-height: var(--line-height-body);
}

.loading-error-retry {
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-4) 18px;
  background: var(--color-brown-strong);
  color: #fff6df;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: var(--font-weight-semibold);
  transition: background-color 0.15s ease;
}

.loading-error-retry:hover {
  background: #5a3a1f;
}

.loading-error-retry:focus-visible {
  outline: 2px solid #2f6dfc;
  outline-offset: 2px;
}

/* ── Status badge (base; game-end variants live in board.css) ────────── */

#status {
  padding: var(--space-4) 18px;
  font-size: var(--font-size-lg);
  color: var(--color-brown-strong);
  background: var(--surface-panel-card);
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-align: center;
  line-height: 1.3;
  max-width: min(90vw, 520px);
  margin: 0;
  flex-shrink: 0;
}

.layout-compact .game-title {
  display: none;
}

.layout-compact #status {
  padding: var(--space-1) var(--space-4);
  font-size: 0.95rem;
}

/* ── Mobile overrides for core layout / root sizing ──────────────────── */

@media (max-width: 640px) {
  body {
    padding: calc(env(safe-area-inset-top) + 12px) 12px calc(env(safe-area-inset-bottom) + 4px);
  }

  .game-title {
    margin: var(--space-6) 0 var(--space-5);
    font-size: 2.1rem;
  }

  .game-layout {
    gap: var(--space-5);
  }

  :root {
    --hex-radius: 44px;
  }

  #status {
    font-size: 0.95rem;
    padding: var(--space-2) var(--space-5);
  }
}
