/* Kanji Dominos — Modern grid + high-performance animations */

:root {
  --bg: #0f0f12;
  --surface: #2a2a32;
  --surface-hover: #33333d;
  --text: #e8e6e3;
  --text-muted: #9a9590;
  --accent: #7c9cbf;
  --accent-hover: #9bb8db;
  --success: #7cb87c;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --transition-fast: 0.15s ease;
  --transition-flip: 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "SF Pro Display", "SF Pro Text", system-ui, sans-serif;
  line-height: 1.5;
}

/* ----- Start page (level selection) ----- */
body.start-page {
  background: linear-gradient(170deg, #d4e6ef 0%, #a8c8d8 50%, #8aafbf 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top, 0px) + 1.5rem) 1.5rem max(1.5rem, env(safe-area-inset-bottom, 0px));
  font-family: -apple-system, "SF Pro Display", "SF Pro Text", system-ui, sans-serif;
}

.start-page-bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.start-bg-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0.25;
  filter: blur(0.5px);
}

.start-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
}

.start-card {
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  padding: 2rem 1.5rem 1.75rem;
  box-shadow:
    0 8px 32px rgba(0, 40, 70, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  text-align: center;
}

.start-title {
  margin: 0 0 0.25rem;
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: #1a2d3d;
  line-height: 1.15;
}

.start-tagline {
  margin: 0 0 1.5rem;
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.5;
  color: #4a6274;
}

.start-tagline-credit {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.82rem;
  font-style: normal;
  font-weight: 400;
  color: #7a8e9c;
}

.start-tagline-credit a {
  color: #4a7a95;
  text-decoration: none;
}

.start-tagline-credit a:hover {
  text-decoration: underline;
}

.level-select {
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.3);
}

.level-select-heading {
  margin: 0 0 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #4a6274;
}

.level-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  align-items: stretch;
}

.level-buttons-row {
  margin-bottom: 0.85rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.level-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  width: 100%;
  min-height: 90px;
  padding: 0.9rem 1rem;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 16px;
  text-decoration: none;
  color: #1a2d3d;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 2px 0 rgba(100, 130, 155, 0.15),
    0 4px 8px rgba(30, 60, 80, 0.08),
    0 8px 24px rgba(30, 60, 80, 0.04);
  transition:
    transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.25s ease,
    background 0.2s ease;
}

.level-card:hover {
  background: rgba(255, 255, 255, 0.92);
  transform: translateY(-3px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 3px 0 rgba(100, 130, 155, 0.12),
    0 8px 16px rgba(30, 60, 80, 0.10),
    0 16px 32px rgba(30, 60, 80, 0.06);
}

.level-card:active {
  transform: translateY(1px) scale(0.98);
  transition-duration: 0.08s;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 1px 0 rgba(100, 130, 155, 0.15),
    0 2px 4px rgba(30, 60, 80, 0.06);
}

.level-badge {
  display: inline-block;
  margin-bottom: 0.3rem;
  padding: 0.2rem 0.7rem;
  background: #3a7ca5;
  color: #fff;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.level-n4 .level-badge {
  background: #2e6e8a;
}

.level-n3 .level-badge {
  background: #3a7a95;
}

.level-n2 .level-badge {
  background: #40677d;
}

.level-n1 .level-badge {
  background: #4a6070;
}

.level-beyond .level-badge {
  background: #5a6a78;
}

.level-disabled {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
  filter: grayscale(0.15);
}

.level-disabled:hover {
  transform: none;
}

.level-name {
  font-size: 0.92rem;
  font-weight: 700;
}

.level-desc {
  font-size: 0.75rem;
  font-weight: 400;
  color: #4a6274;
  margin-top: 0.1rem;
}

.level-count {
  font-size: 0.75rem;
  font-weight: 400;
  color: #7a8e9c;
  margin-top: 0.08rem;
}

.level-coming {
  font-size: 0.72rem;
  font-weight: 400;
  color: #7a8e9c;
  margin-top: 0.15rem;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem;
}

/* Game page (2nd page): light blue canvas so dark dominos stand out */
body.game-page {
  background: linear-gradient(180deg, #e8f0f6 0%, #f0f5f9 40%, #e8f0f6 100%);
  color: #1a2d3d;
  font-family: -apple-system, "SF Pro Display", "SF Pro Text", system-ui, sans-serif;
  margin: 0;
}

body.game-page #app {
  min-height: 100vh;
  min-height: 100dvh;
  /* Dynamic Island / notch: safe area + modest breathing room */
  padding-top: calc(env(safe-area-inset-top, 0px) + 0.45rem);
  padding-bottom: max(1.2rem, env(safe-area-inset-bottom, 0px));
  /*
   * Same horizontal inset on BOTH sides (max of L/R + 1.5rem) — iOS can report
   * asymmetric safe-area values; matching sides keeps the column visually centered.
   */
  --game-pad: max(1.5rem, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  padding-left: var(--game-pad);
  padding-right: var(--game-pad);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-x: clip;
}

/*
 * Single wrapper: one flex-centered column (more reliable on iPhone than 3-col grid).
 * Header + main share width with the domino grid.
 */
body.game-page .game-column {
  width: 100%;
  max-width: 420px;
  min-width: 0;
  flex-shrink: 0;
}

body.game-page .header,
body.game-page main {
  width: 100%;
  max-width: none;
  margin-left: 0;
  margin-right: 0;
  box-sizing: border-box;
  min-width: 0;
}

body.game-page main {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
}

.progress-panel {
  width: 100%;
  /* Bumped from 0.4rem so the gauge doesn't touch the domino grid. */
  margin: 0 0 1.25rem;
}

.progress-meta {
  display: flex;
  justify-content: flex-start;
  align-items: baseline;
  margin-bottom: 0.35rem;
  padding: 0 0.05rem;
}

.progress-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: #37566a;
}

.progress-track {
  position: relative;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  /* Blue → yellow → red (matches goi/css base; goi's body.game-page
     override cascades on top here for the muted Mahjong Hall variant). */
  background: linear-gradient(90deg, #3a8ec5 0%, #f0d852 50%, #d95050 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.progress-indicator {
  position: absolute;
  top: 3px;
  left: 0%;
  width: 3px;
  height: 20px;
  border-radius: 2px;
  background: #2f3238;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transform: translateX(-50%);
  transition: left 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.progress-indicator::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 8px solid #2f3238;
}

.progress-indicator::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -5px;
  transform: translateX(-50%);
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #f2f3f6;
  border: 2px solid #2f3238;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5);
}

body.game-page .grid-container.grid-c3r8,
body.game-page .grid-container.grid-c3r5 {
  max-width: 100%;
  width: 100%;
  margin-left: 0;
  margin-right: 0;
}

/*
 * Grid had padding: 56px on all sides (for enlarged flip). That inset the domino
 * cells horizontally vs. the header text (full width of the column), so the
 * grid looked misaligned. Use vertical padding only on the game page; flip
 * still has room via overflow + safe areas.
 */
body.game-page .grid-container {
  padding-left: 0;
  padding-right: 0;
  padding-top: 8px;
  padding-bottom: 8px;
  box-sizing: border-box;
}

@media (max-width: 480px) {
  body.game-page .grid-container {
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .header {
    margin-bottom: 1.35rem;
  }

  .header h1 {
    font-size: 1.62rem;
    margin-bottom: 0.2rem;
  }

  .subtitle {
    margin-bottom: 0.9rem;
    font-size: 0.87rem;
  }

  .controls {
    gap: 0.62rem;
    margin-bottom: 0.6rem;
  }

  .btn {
    min-height: 42px;
    padding: 0.58rem 1.05rem;
  }

  .status {
    font-size: 0.82rem;
  }

  .progress-panel {
    margin-bottom: 0.85rem;
  }

  .progress-label {
    font-size: 0.79rem;
  }

  .progress-track {
    height: 11px;
  }

  .progress-indicator {
    height: 18px;
  }
}

body.game-page .header h1 {
  color: #1a2d3d;
  font-weight: 600;
}

body.game-page .subtitle {
  color: #4a6274;
  font-weight: 400;
}

body.game-page .status {
  color: #7a8e9c;
  font-weight: 400;
}

body.game-page .btn-secondary {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #1a2d3d;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 12px;
  font-weight: 600;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 2px 0 rgba(100, 130, 155, 0.12),
    0 3px 6px rgba(30, 60, 80, 0.06);
}

body.game-page .btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.92);
  transform: translateY(-1px);
}

body.game-page .btn-secondary:active:not(:disabled) {
  transform: translateY(1px);
  transition-duration: 0.08s;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 1px 0 rgba(100, 130, 155, 0.12),
    0 1px 3px rgba(30, 60, 80, 0.04);
}

body.game-page .examples-panel {
  max-width: min(100%, 420px);
  margin-left: auto;
  margin-right: auto;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(100, 140, 170, 0.35);
  box-shadow: 0 4px 18px rgba(40, 70, 90, 0.1);
}

body.game-page .examples-title {
  color: #1c3d52;
}

body.game-page .examples-hint {
  color: #5a7080;
}

body.game-page .examples-table thead th {
  color: #2d4a5c;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

body.game-page .examples-table tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.03);
}

body.game-page .examples-word-meaning {
  color: #2a3a48;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 2rem;
  width: 100%;
  max-width: 720px;
}

.header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.controls {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.btn {
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.status {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Grid + examples layout */
.grid-container {
  display: grid;
  row-gap: 0.35rem;
  column-gap: 0.25rem;
  width: 100%;
  margin: 0 auto 1rem;
  padding: 4px 0;
  overflow: visible;
  /* No `contain: layout style` — see goi/css/style.css comment for why. */

  /* Constant cell width across grid variants — see goi/css/style.css for
   * full rationale. (Challenge inherits goi/css cascade, but defining the
   * variables here defensively too in case load order changes.) */
  --grid-max: min(100%, 420px);
  --grid-gap: 0.25rem;
  --cell-w: calc((var(--grid-max) - 2 * var(--grid-gap)) / 3);
}

.grid-container.grid-6 {
  grid-template-columns: repeat(6, 1fr);
  max-width: 720px;
}

.grid-container.grid-5 {
  grid-template-columns: repeat(5, 1fr);
  max-width: 600px;
}

/* Baseline 3-col grids — fill container, 1fr distributes evenly. */
.grid-container.grid-c3r8,
.grid-container.grid-c3r5 {
  grid-template-columns: repeat(3, 1fr);
  max-width: 420px;
}

/* Shrunk variants — fixed cell width matching the 3×8 baseline; cells
 * centered within the 100%-wide container via justify-content: center.
 * See goi/css/style.css for why we don't use `width: fit-content`. */
.grid-container.grid-4 {
  grid-template-columns: repeat(4, var(--cell-w));
  justify-content: center;
}

.grid-container.grid-3 {
  grid-template-columns: repeat(3, var(--cell-w));
  justify-content: center;
}

.grid-container.grid-2 {
  grid-template-columns: repeat(2, var(--cell-w));
  justify-content: center;
}

.examples-panel {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1.25rem 1.2rem;
  background: #181820;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.examples-title {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #f5f5f7;
}

.examples-hint {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.examples-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.examples-table th,
.examples-table td {
  padding: 0.35rem 0.4rem;
  text-align: left;
}

.examples-table thead th {
  font-weight: 600;
  color: #d0d0d5;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.examples-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

.examples-word-kanji {
  font-weight: 600;
  font-size: 0.9rem;
}

.examples-word-reading {
  color: #9ec5ff;
}

.examples-word-meaning {
  color: #e6e6ea;
}

.examples-empty {
  text-align: center;
  padding: 0.5rem 0.4rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Domino block — card with two faces */
.domino {
  position: relative;
  /* Wide horizontal dominos for vocabulary */
  width: 100%;
  aspect-ratio: 2.2 / 1;
  justify-self: stretch;
  min-height: 0;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  /* Performance: promote to own layer for flip/shuffle */
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
  transition: transform var(--transition-flip), box-shadow var(--transition-fast);
  isolation: isolate;
}

/*
 * Flipped highlight: do NOT use border on .domino — descendants paint on top of the
 * parent's border in CSS, so the dark back face covered the blue ring on iPhone/WebKit.
 * A ::after ring is painted after the faces and stays visible.
 */
.domino.flipped {
  transform: translateZ(0) scale(2.2) translateY(-4px);
  z-index: 30;
  box-shadow:
    0 16px 40px rgba(0, 30, 60, 0.25),
    0 4px 12px rgba(0, 30, 60, 0.15);
}

/* Left column: shift right when flipped so popup stays on screen */
.grid-container > .domino.flipped:nth-child(3n+1) {
  transform: translateZ(0) translateX(30%) scale(2) translateY(-4px);
}

/* Right column: shift left when flipped so popup stays on screen */
.grid-container > .domino.flipped:nth-child(3n+3) {
  transform: translateZ(0) translateX(-30%) scale(2) translateY(-4px);
}

.domino.flipped::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 40;
  border-radius: inherit;
  box-sizing: border-box;
  border: 2px solid rgba(255, 255, 255, 0.6);
  pointer-events: none;
}

.domino:hover {
  background: var(--surface-hover);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

/* Right-click peek: after flip-back, glow advances (edge → wide → full) */
.domino--glow-edge .domino-face-front {
  box-shadow: inset 0 0 0 4px rgba(200, 45, 45, 0.55);
}

.domino--glow-edge {
  box-shadow: var(--shadow),
    0 0 0 2px rgba(220, 60, 60, 0.9),
    0 0 14px rgba(255, 70, 70, 0.5),
    0 0 24px rgba(255, 50, 50, 0.25);
}

.domino--glow-wide .domino-face-front {
  box-shadow: inset 0 0 0 12px rgba(200, 45, 45, 0.55);
}

.domino--glow-full .domino-face-front {
  background: rgba(200, 45, 45, 0.55);
  box-shadow: inset 0 0 0 0 transparent;
}

/* Placeholder for removed slot in 2×2 */
.domino-placeholder {
  background: transparent;
  border: none;
  box-shadow: none;
  cursor: default;
  min-height: 0;
}

.domino-placeholder:hover {
  background: transparent;
  transform: none;
  box-shadow: none;
}

.domino.removed {
  visibility: hidden;
  pointer-events: none;
  position: absolute;
  opacity: 0;
  transform: scale(0);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
}

/* Shuffle: brief pulse when grid reorders. Exclude .flipped — the
   centered-modal popup uses transform: translate(-50%, -50%) which
   shufflePulse's scale() would override, causing a jump. */
.grid-container.shuffling .domino:not(.flipped) {
  animation: shufflePulse 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes shufflePulse {
  0% { transform: scale(1); }
  50% { transform: scale(0.96); }
  100% { transform: scale(1); }
}

/* Inner wrapper for 3D flip */
.domino-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.domino.flipped .domino-inner {
  transform: rotateY(180deg);
}

.domino-face {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.domino-face-front {
  background: var(--surface);
  z-index: 1;
}

/* Front: word display — sized for multi-character vocabulary */
.domino-face-front .domino-kanji {
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
  white-space: nowrap;
}

.domino-face-back {
  background: linear-gradient(180deg, #1e2a35 0%, #253340 100%);
  transform: rotateY(180deg);
  z-index: 0;
  text-align: center;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.6rem;
}

.domino-face-back .domino-readings {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.domino-reading-kun {
  color: #7cc4ff;
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.3;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: nowrap;
  display: block;
  text-align: center;
  letter-spacing: 0.02em;
}

.domino-reading-on {
  color: #ff8a8a;
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.15;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: nowrap;
  display: block;
  text-align: center;
  letter-spacing: 0.02em;
}

.domino-meaning {
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.85rem;
  font-weight: 400;
  line-height: 1.15;
  margin-top: 0.1rem;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
  display: block;
  text-align: center;
}


/* Game Over overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 20, 40, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  animation: fadeIn 0.3s ease;
}

.overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.game-over-card {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  padding: 2.25rem 2rem;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 12px 40px rgba(0, 30, 60, 0.15);
  text-align: center;
  max-width: 320px;
  color: #1a2d3d;
}

.game-over-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.4rem;
  font-weight: 600;
  color: #1a2d3d;
}

.game-over-card p {
  margin: 0 0 1.25rem;
  color: #4a6274;
  font-weight: 400;
}

/* Victory overlay: light blue */
.overlay.victory {
  background: rgba(170, 210, 255, 0.5);
}

.overlay.victory .game-over-default {
  display: none;
}

.overlay.victory .game-over-victory {
  display: block;
}

.game-over-victory {
  display: none;
  background: rgba(220, 240, 255, 0.95);
  border: 1px solid rgba(150, 200, 240, 0.5);
}

.overlay.victory .game-over-victory {
  color: #1a3a5c;
}

.game-over-prompt {
  margin: 0 0 1.25rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: inherit;
}

.game-over-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.game-over-actions .btn {
  min-width: 5.5rem;
}

.overlay.victory .game-over-victory p {
  color: #2a4a6c;
}

/* Reduce motion preference */
@media (prefers-reduced-motion: reduce) {
  .domino,
  .domino-inner,
  .domino.shuffling,
  .progress-indicator {
    transition-duration: 0.15s;
  }
}

/* ----- Challenge Box specific ----- */

/* Reset button (was "Empty" until 2026-05-03 — id stays btn-empty for
   minimal-diff reasons, but the visible label and visual treatment are
   now Reset). Three-tier button hierarchy in the Challenge Box controls:
     - Finish: bone-outline default (low emphasis, just go back)
     - Reset:  vermilion outline + vermilion text (DANGER, prominent)
     - Go Home: solid vermilion fill on bone text (modal primary)
   The previous legacy styling here used #8a3a3a dark red on a 12%-
   opacity red bg — unreadable against the dark Mahjong Hall canvas. */
.btn-empty {
  background: rgba(212, 74, 58, 0.10) !important;
  color: var(--vermilion) !important;
  border: 1.5px solid var(--vermilion) !important;
  font-weight: 600 !important;
}

.btn-empty:hover:not(:disabled) {
  background: rgba(212, 74, 58, 0.22) !important;
  border-color: #e85544 !important;
  color: #ee6e5e !important;
}

.btn-empty:active:not(:disabled) {
  background: rgba(212, 74, 58, 0.30) !important;
}

/* Empty confirmation overlay */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 20, 40, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  animation: fadeIn 0.3s ease;
}

.confirm-overlay.hidden {
  display: none;
}

.confirm-card {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  padding: 2rem 1.75rem;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 12px 40px rgba(0, 30, 60, 0.15);
  text-align: center;
  max-width: 300px;
  color: #1a2d3d;
}

.confirm-card h3 {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
  font-weight: 600;
  color: #1a2d3d;
}

.confirm-card p {
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
  color: #4a6274;
  font-weight: 400;
}

.confirm-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.confirm-actions .btn {
  min-width: 5rem;
}

.btn-danger {
  background: rgba(200, 70, 70, 0.85);
  color: #fff;
  border: none;
}

.btn-danger:hover {
  background: rgba(200, 70, 70, 1);
}

/* Empty state (no items) */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: #4a6274;
}

.empty-state h2 {
  font-size: 1.3rem;
  font-weight: 600;
  color: #1a2d3d;
  margin: 0 0 0.5rem;
}

.empty-state p {
  font-size: 0.9rem;
  font-weight: 400;
  margin: 0 0 1.5rem;
}

.empty-state .btn {
  display: inline-block;
  text-decoration: none;
}


/* ============================================================
 * MAHJONG HALL OVERRIDES (Step 9 — Challenge Box page redesign)
 *
 * The bulk of the chrome (body, header, buttons, progress) is inherited
 * from goi/css/style.css's override block via the stylesheet chain in
 * challenge/game.html. Domino front faces inherit per-app from
 * .domino-goi (goi overrides) and .domino-bunpou (bunpou overrides).
 *
 * Below: only the rules unique to the Challenge page (empty state, the
 * Empty-confirmation modal, and the danger-tinted Empty button).
 * ============================================================ */

body.game-page .empty-state {
  background: rgba(232, 220, 196, 0.04);
  border: 1px dashed var(--rule);
  border-radius: 14px;
  color: var(--text-soft);
  padding: 2rem 1.5rem;
  text-align: center;
  margin-top: 1rem;
}
body.game-page .empty-state h2 {
  font-family: var(--font-jp);
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--text);
  margin: 0 0 0.6rem;
}
body.game-page .empty-state p {
  font-family: var(--font-en);
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-soft);
  margin: 0 0 1.2rem;
}

/* Empty-confirmation modal */
.confirm-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 23, 33, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.confirm-overlay.hidden { display: none; }
.confirm-card {
  background: linear-gradient(155deg, #2a2e44 0%, #1f2335 100%);
  border: 1px solid var(--rule);
  border-radius: 16px;
  padding: 1.5rem 1.5rem 1.25rem;
  max-width: 320px;
  margin: 0 1rem;
  text-align: center;
  color: var(--text);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
}
.confirm-card h3 {
  font-family: var(--font-jp);
  font-weight: 700;
  font-size: 1.2rem;
  margin: 0 0 0.5rem;
}
.confirm-card p {
  font-family: var(--font-en);
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-soft);
  margin: 0 0 1.2rem;
}
.confirm-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

/* Danger button (used for "Yes, empty") */
body.game-page .btn-danger {
  background: var(--vermilion);
  border: 1px solid var(--vermilion);
  color: var(--bone);
  padding: 0.5rem 1.1rem;
  border-radius: 100px;
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
body.game-page .btn-danger:hover { background: #e85544; border-color: #e85544; }

/* Empty button in the controls row sits with the others (no special styling). */


/* ============================================================
 * Challenge — back-face overrides for goi/kanji items
 *
 * Items sourced from Goi or Kanji use the legacy compact back-face
 * structure (.domino-readings > .domino-reading-kun + .domino-meaning).
 * Re-skin those for the Mahjong Hall dark palette. Bunpou items use
 * their own modal back face (handled by bunpou/css/style.css overrides).
 * ============================================================ */

.domino.domino-goi .domino-face-back,
.domino.domino-kanji .domino-face-back {
  background: linear-gradient(180deg, #2a2e44 0%, #1f2335 100%);
  border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(232, 220, 196, 0.05);
}
.domino.domino-goi .domino-face-back .domino-reading-kun,
.domino.domino-kanji .domino-face-back .domino-reading-kun {
  color: var(--brass);
  font-family: var(--font-jp);
  font-weight: 500;
}
.domino.domino-goi .domino-face-back .domino-reading-on,
.domino.domino-kanji .domino-face-back .domino-reading-on {
  color: var(--vermilion);
  font-family: var(--font-jp);
}
.domino.domino-goi .domino-face-back .domino-meaning,
.domino.domino-kanji .domino-face-back .domino-meaning {
  color: var(--text);
  font-family: var(--font-en);
  font-style: italic;
}

/* Game-over / "all due reviewed" card — re-skinned to use --canvas-elev
   background + --text (bright bone) foreground. !important is used to
   guarantee the override wins over the legacy light-pastel rules earlier
   in the file regardless of cache state. NO blue tokens anywhere — every
   color resolves to a warm bone / brass / vermilion token. */
.overlay.victory {
  background: rgba(20, 23, 33, 0.78) !important;
}
.overlay .game-over-card,
.overlay.victory .game-over-card,
.overlay.victory .game-over-victory {
  background: var(--canvas-elev) !important;
  border: 1px solid var(--rule) !important;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5) !important;
  color: var(--text) !important;
}
.overlay .game-over-card h2,
.overlay.victory .game-over-card h2 {
  color: var(--text) !important;
  font-family: var(--font-jp);
}
.overlay .game-over-card p,
.overlay.victory .game-over-card p,
.overlay.victory .game-over-victory p {
  color: var(--text) !important;
  font-family: var(--font-en);
}
.overlay .game-over-card p strong,
.overlay.victory .game-over-card p strong,
.overlay.victory .game-over-victory p strong {
  color: var(--brass) !important;
  font-weight: 600;
}
.overlay .game-over-prompt,
.overlay.victory .game-over-prompt {
  color: var(--text) !important;
  font-family: var(--font-jp);
  font-weight: 600;
}
.overlay .game-over-card .btn-primary {
  background: var(--vermilion) !important;
  color: var(--bone) !important;
  border: 1px solid var(--vermilion) !important;
}
.overlay .game-over-card .btn-primary:hover:not(:disabled) {
  background: #e85544 !important;
  border-color: #e85544 !important;
}

/* Reset-confirmation modal (the scary "this deletes everything" warning).
   Renamed from "Empty" to "Reset" 2026-05-03 — Joshua noted that "Empty"
   undersells what the action actually does (wipes ALL Challenge Box items
   + their SRS state). Reset is clearer; the modal copy below is also
   sterner. NO blue tokens. */
.confirm-card.confirm-card-warning {
  background: var(--canvas-elev) !important;
  border: 2px solid var(--vermilion) !important;
  color: var(--text) !important;
}
.confirm-card.confirm-card-warning h3 {
  color: var(--vermilion) !important;
  font-size: 1.25rem !important;
  font-family: var(--font-jp);
  font-weight: 700;
}
.confirm-card.confirm-card-warning p {
  color: var(--text) !important;
  font-family: var(--font-en);
}
.confirm-card.confirm-card-warning .warning-headline {
  color: var(--vermilion) !important;
  font-weight: 700 !important;
  font-size: 1rem !important;
  margin-top: 0.4rem !important;
}
.confirm-card.confirm-card-warning .warning-final {
  color: var(--text) !important;
  font-weight: 600 !important;
  font-style: italic;
  margin-top: 0.4rem !important;
}
