/* Unified game UI — all viewports (play.html, g.html) */

:root {
  --game-action-btn-size: min(64px, calc((100vw - 56px) / 5.3));
  --game-score-chip-size: 52px;
  --game-field-action-inset: max(12px, env(safe-area-inset-bottom, 0px));
}

@media (min-width: 768px) {
  :root {
    --game-action-btn-size: 72px;
    --game-score-chip-size: 56px;
    --game-field-action-inset: max(18px, env(safe-area-inset-bottom, 0px));
  }
}

/* Site header: how-to-play ? */
.site-nav__help .site-nav__help-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
}

body.game-page .site-header__undo {
  display: none !important;
}

/* Game navbar */
.game-nav {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--glass-line);
  background: oklch(16% 0.02 260 / 92%);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
  pointer-events: auto;
}

.game-nav__tools {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: start;
}

.game-nav__status {
  margin: 0;
  justify-self: center;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-nav__end {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: end;
  flex-shrink: 0;
}

.game-nav__begin {
  min-height: 36px;
  padding: 6px 14px;
  font-size: 0.875rem;
  white-space: nowrap;
}

.game-nav__forfeit {
  flex-shrink: 0;
  border-color: oklch(58% 0.22 25);
  background: oklch(46% 0.18 25 / 90%);
  color: oklch(72% 0.24 25);
}

.game-nav__forfeit .icon-button__glyph {
  width: 18px;
  height: 18px;
  color: #ef4444;
}

.game-nav__forfeit:hover:not(:disabled) {
  background: oklch(52% 0.22 25);
  border-color: oklch(68% 0.26 25);
  color: oklch(88% 0.2 25);
}

.game-nav__forfeit:hover:not(:disabled) .icon-button__glyph {
  color: #f87171;
}

.game-nav__forfeit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Page shell */
body.game-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100svh;
  min-height: 100dvh;
  min-height: 100svh;
  min-height: -webkit-fill-available;
  overflow: hidden;
}

body.game-page .game-top-chrome {
  flex: 0 0 auto;
}

body.game-page main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  height: auto;
  max-height: none;
  padding: 0;
  overflow: hidden;
  position: relative;
  box-sizing: border-box;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: none;
  align-items: stretch;
}

body.game-page main > .board-shell {
  position: relative;
  flex: 1 1 auto;
  align-self: stretch;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: 0;
  min-width: 0;
  height: auto;
  max-height: none;
  padding: 0;
  border-radius: 0;
  overflow: hidden;
  touch-action: none;
}

body.game-page .board-shell > svg {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  width: auto;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  max-width: 100%;
  --board-max-h: 100%;
}

body.game-page main > aside {
  display: none !important;
}

/* Board HUD */
.mobile-board-hud {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

.mobile-score-chip {
  pointer-events: auto;
  position: absolute;
  top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--game-score-chip-size);
  height: var(--game-score-chip-size);
  margin: 0;
  padding: 0;
  border: 3px solid oklch(100% 0 0 / 18%);
  border-radius: 50%;
  background: oklch(14% 0.02 260 / 88%);
  backdrop-filter: blur(10px);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  box-shadow: 0 4px 14px oklch(8% 0.02 260 / 35%);
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.mobile-score-chip--p1 {
  left: 8px;
  border-color: var(--player-1-zone, oklch(62% 0.14 250 / 75%));
}

.mobile-score-chip--p2 {
  right: 8px;
  border-color: var(--player-2-zone, oklch(72% 0.16 38 / 75%));
}

.mobile-score-chip--active {
  box-shadow: 0 0 0 2px oklch(100% 0 0 / 22%), 0 0 18px oklch(78% 0.12 82 / 45%);
  transform: scale(1.04);
}

.mobile-score-chip--leading {
  font-weight: 800;
}

.mobile-score-chip__value {
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
}

.mobile-your-turn-pill {
  pointer-events: none;
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--game-nav-highlight-bg, oklch(32% 0.08 82));
  border: 1px solid var(--game-nav-highlight, oklch(72% 0.14 82));
  color: var(--game-nav-highlight-text, oklch(94% 0.04 82));
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  box-shadow: 0 4px 14px oklch(8% 0.02 260 / 30%);
}

.mobile-your-turn-pill[hidden] {
  display: none;
}

/* Field action buttons — bottom corners of the board */
.board-field-actions {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
}

.board-field-actions__corner {
  position: absolute;
  bottom: var(--game-field-action-inset);
  width: var(--game-action-btn-size);
  height: var(--game-action-btn-size);
  pointer-events: auto;
}

.board-field-actions__corner--undo {
  left: max(10px, env(safe-area-inset-left, 0px));
}

.board-field-actions__corner--primary {
  right: max(10px, env(safe-area-inset-right, 0px));
}

.board-field-actions__corner .site-header__undo,
.board-field-actions__corner .mobile-action-btn {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 4px 3px 3px;
  border-radius: 50%;
  border: 2px solid oklch(100% 0 0 / 14%);
  background: oklch(22% 0.02 260 / 92%);
  color: var(--text);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1.1;
  cursor: pointer;
  box-shadow: 0 4px 14px oklch(8% 0.02 260 / 35%);
  transition: transform 100ms ease, opacity 100ms ease, filter 120ms ease;
}

.board-field-actions__corner .site-header__undo .icon-button__glyph {
  width: 22px;
  height: 22px;
}

.board-field-actions__corner .site-header__undo::after {
  content: "Undo";
}

.board-field-actions__corner .mobile-action-btn.mode-select--accent {
  border-color: var(--game-nav-highlight, oklch(72% 0.14 82));
  background: var(--game-nav-highlight-bg, oklch(32% 0.08 82));
  color: var(--game-nav-highlight-text, oklch(94% 0.04 82));
}

.board-field-actions__corner .mobile-action-btn.is-ready {
  animation: begin-ready-pulse 1.6s ease-in-out infinite;
}

.board-field-actions__corner .site-header__undo:disabled,
.board-field-actions__corner .mobile-action-btn:disabled,
.board-field-actions__corner .mobile-action-btn[hidden],
.board-field-actions__corner .site-header__undo[hidden] {
  opacity: 0.32;
  pointer-events: none;
  cursor: not-allowed;
}

.board-field-actions__corner .site-header__undo[hidden] {
  visibility: hidden;
}

.board-field-actions__corner .mobile-action-btn[hidden] {
  visibility: hidden;
}

.board-field-actions__corner--undo .site-header__undo {
  display: flex !important;
}

/* Board overlays */
.mobile-board-overlays {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.mobile-board-overlay {
  pointer-events: auto;
  position: absolute;
  inset: auto 12px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: oklch(14% 0.02 260 / 94%);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-line);
  box-shadow: 0 8px 28px oklch(8% 0.02 260 / 45%);
  max-height: min(42%, 220px);
  overflow-y: auto;
}

.mobile-board-overlay[hidden] {
  display: none;
}

.mobile-board-overlay--cta {
  inset: unset;
  top: auto;
  right: auto;
  bottom: 50%;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 48px);
  transform: translate(-50%, 50%);
  text-align: center;
  max-height: none;
  overflow: visible;
}

.mobile-board-overlay .revival-panel__list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.mobile-board-overlay .revival-panel__pick {
  min-height: 48px;
  width: 100%;
  font-size: 15px;
  font-weight: 600;
}

.mobile-board-overlay--cta .sidebar-new-game,
.mobile-board-overlay--cta #rematch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  width: auto;
  max-width: none;
  min-width: 10rem;
  margin: 0;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
  font-size: 15px;
  font-weight: 600;
  touch-action: manipulation;
  pointer-events: auto;
}

/* Score sheet dialog */
.mobile-score-sheet {
  display: block;
  border: none;
  border-radius: 16px;
  padding: 0;
  max-width: min(100%, 420px);
  width: min(100%, 420px);
  max-height: min(85vh, 520px);
  margin: auto;
  background: var(--panel);
  color: var(--text);
  box-shadow:
    inset 0 0 0 1px oklch(100% 0 0 / 10%),
    0 24px 48px oklch(4% 0.02 260 / 55%);
  overflow: auto;
}

.mobile-score-sheet:not([open]) {
  display: none;
}

.mobile-score-sheet:modal {
  position: fixed;
  top: 50%;
  left: 50%;
  right: auto;
  bottom: auto;
  transform: translate(-50%, -50%);
  margin: 0;
}

.mobile-score-sheet::backdrop {
  background: oklch(8% 0.02 260 / 55%);
}

.mobile-score-sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--glass-line);
}

.mobile-score-sheet__title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.mobile-score-sheet__body {
  padding: 12px 16px 20px;
}

.mobile-score-sheet__lotus {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.game-controls-source {
  display: none !important;
}

.game-controls-source .turn-actions {
  display: contents;
}
