:root {
  --bg-deep: #141028;
  --bg-panel: rgba(23, 18, 43, 0.82);
  --bg-panel-strong: rgba(18, 14, 34, 0.92);
  --bg-card: rgba(29, 24, 52, 0.92);
  --bg-card-back: rgba(62, 55, 82, 0.88);
  --ink: #f7f3ff;
  --ink-soft: rgba(241, 236, 255, 0.76);
  --line: rgba(255, 255, 255, 0.09);
  --red: #ef4d5d;
  --red-strong: #ff6a74;
  --gold: #ffd36a;
  --shadow-lg: 0 28px 72px rgba(8, 6, 20, 0.46);
  --shadow-md: 0 16px 32px rgba(8, 6, 20, 0.28);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font-display: "Avenir Next Condensed", "Arial Narrow", "Trebuchet MS", sans-serif;
  --font-body: "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg-deep);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

a {
  color: inherit;
}

#app {
  width: 100%;
  height: 100%;
}

.app-shell {
  position: relative;
  min-height: var(--app-height, 100dvh);
  height: var(--app-height, 100dvh);
  overflow: hidden;
  background:
    radial-gradient(circle at top center, rgba(255, 210, 106, 0.18), transparent 24%),
    linear-gradient(180deg, rgba(20, 16, 40, 0.5), rgba(20, 16, 40, 0.92));
}

.scene-backdrop,
.scene-fade {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scene-backdrop {
  transform: scale(1.03);
}

.scene-fade {
  background:
    radial-gradient(circle at 50% 20%, rgba(255, 255, 255, 0.08), transparent 32%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 28%, rgba(20, 16, 40, 0.35) 65%, rgba(20, 16, 40, 0.7));
}

.app-frame {
  position: relative;
  z-index: 1;
  width: min(1240px, calc(100vw - 32px));
  height: 100%;
  margin: 0 auto;
  padding: calc(22px + var(--safe-top)) 0 calc(18px + var(--safe-bottom));
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
}

.app-frame--game {
  grid-template-rows: auto 1fr;
}

.hero {
  display: grid;
  grid-template-columns: 150px 1fr 48px;
  align-items: center;
  gap: 18px;
  padding-inline: 18px;
}

.hero__brand {
  width: 150px;
  height: 50px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: rgba(18, 14, 34, 0.52);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(16px);
}

.hero__brand img {
  width: 150px;
  height: auto;
  object-fit: contain;
}

.hero__title {
  text-align: center;
  padding-right: 102px;
}

.eyebrow,
.panel__eyebrow {
  margin: 0 0 6px;
  color: rgba(255, 211, 106, 0.92);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  font-weight: 700;
}

.hero h1,
.game-brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 5vw, 4.3rem);
  line-height: 0.95;
  letter-spacing: 0.02em;
  text-shadow: 0 6px 24px rgba(6, 4, 15, 0.36);
}

.hero h1 span,
.game-brand h1 span {
  color: var(--red);
}

.hero__subtitle {
  max-width: 780px;
  margin: 12px auto 0;
  color: rgba(250, 245, 255, 0.86);
  font-size: clamp(0.98rem, 1.5vw, 1.14rem);
  line-height: 1.45;
  text-wrap: balance;
}

.menu-stage,
.game-stage {
  min-height: 0;
  display: grid;
}
.menu-stage { overflow: auto; }
.game-stage { overflow: auto; }
.board-grid { min-height: calc(var(--board-rows) * 44px + (var(--board-rows) - 1) * 13px); }

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-lg);
}

.menu-panel {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: clamp(20px, 2.4vw, 30px);
  display: grid;
  gap: 22px;
  align-content: center;
}

.panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.panel__header h2,
.modal-panel h2 {
  margin: 0;
  font-size: clamp(1.55rem, 2vw, 2.1rem);
}

.summary-card {
  min-width: 120px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.summary-card span,
.table-stat small {
  display: block;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.summary-card strong,
.table-stat strong {
  display: block;
  margin-top: 6px;
  font-size: 1.15rem;
}

.table-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.table-chip {
  min-height: 52px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 1.18rem;
  font-weight: 800;
  transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.table-chip:hover,
.table-chip:focus-visible,
.toggle-card:hover,
.toggle-card:focus-visible,
.primary-button:hover,
.primary-button:focus-visible,
.secondary-button:hover,
.secondary-button:focus-visible,
.icon-button:hover,
.icon-button:focus-visible,
.memory-card:hover,
.memory-card:focus-visible {
  transform: translateY(-1px);
}

.table-chip.is-selected {
  background: linear-gradient(135deg, var(--red), var(--red-strong));
  box-shadow: 0 18px 32px rgba(239, 77, 93, 0.26);
}

.menu-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.toggle-card {
  min-height: 74px;
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(15, 11, 31, 0.62);
  color: var(--ink);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  text-align: left;
  transition: background 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.toggle-card.is-active {
  background: rgba(255, 255, 255, 0.1);
}

.toggle-card.gold {
  background: linear-gradient(135deg, rgba(255, 211, 106, 0.98), rgba(255, 193, 69, 0.92));
  color: #23171d;
}

.toggle-card__icon {
  font-size: 1.15rem;
}

.toggle-card__label {
  font-weight: 700;
  font-size: 1rem;
}

.toggle-card__value {
  font-weight: 800;
  color: inherit;
}

.menu-footer {
  display: grid;
  gap: 10px;
}

.menu-footer .primary-button {
  width: 100%;
  min-height: 58px;
  font-size: 1.2rem;
}

.menu-footer p {
  text-align: center;
}

.menu-footer p,
.modal-copy {
  margin: 0;
  color: rgba(250, 245, 255, 0.84);
  line-height: 1.5;
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 52px;
  border-radius: 18px;
  padding: 0 22px;
  font-weight: 800;
  transition: transform 140ms ease, filter 140ms ease, background 140ms ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--red), var(--red-strong));
  color: white;
  box-shadow: 0 18px 32px rgba(239, 77, 93, 0.26);
}

.secondary-button {
  background: rgba(255, 211, 106, 0.96);
  color: #26191d;
}

.icon-button {
  width: 48px;
  min-width: 48px;
  padding: 0;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
}

.site-footer {
  padding-inline: 18px;
  text-align: center;
  color: rgba(250, 245, 255, 0.82);
  font-size: 0.94rem;
}

.site-footer p {
  margin: 0;
}

.game-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding-inline: 12px;
}

.game-brand h1 {
  font-size: clamp(2.1rem, 4vw, 3rem);
}

.game-status {
  min-width: 0;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.game-actions { display: flex; align-items: center; gap: 10px; }
.fullscreen-button { height: 48px; min-height: 44px; font-size: 1.5rem; }
.overlay-fullscreen { position: absolute; top: max(12px, var(--safe-top)); right: 12px; }
#runtime-notice { position: fixed; z-index: 30; bottom: max(12px, var(--safe-bottom)); left: 50%; transform: translateX(-50%); width: min(90%, 520px); padding: 12px; margin: 0; border: 2px solid var(--manga-ink); border-radius: 12px; background: #fffaf0; color: #17204a; text-align: center; }
button:focus-visible, a:focus-visible { outline: 3px solid #1479f6; outline-offset: 3px; }
.app-frame:has([inert]) { pointer-events: none; }
.app-frame[inert] .hero, .app-frame[inert] .site-footer { display: none; }
.app-frame[inert] { grid-template-rows: 1fr; }

.status-pill {
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(13, 10, 25, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: inline-flex;
  align-items: center;
  color: rgba(248, 243, 255, 0.94);
  font-weight: 700;
}

.status-pill--accent {
  background: rgba(255, 211, 106, 0.96);
  color: #26191d;
}

.board-shell {
  min-height: 0;
  width: 100%;
  /* Reserve room for the 3% match pulse instead of overflowing the scroll area. */
  padding: 8px;
  display: grid;
}

.board-grid {
  --board-columns: 5;
  --board-rows: 4;
  width: min(1080px, 100%);
  height: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(var(--board-columns), minmax(0, 1fr));
  grid-template-rows: repeat(var(--board-rows), minmax(0, 1fr));
  gap: clamp(10px, 1.2vw, 14px);
  align-content: stretch;
}

.memory-card {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  perspective: 1400px;
  background: transparent;
}

.memory-card:disabled {
  cursor: default;
}

.memory-card__inner {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  transform-style: preserve-3d;
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
}

.memory-card.is-open .memory-card__inner {
  transform: rotateY(180deg);
}

.memory-card__face {
  position: absolute;
  inset: 0;
  border-radius: 24px;
  backface-visibility: hidden;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.memory-card__face::before {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: inherit;
  pointer-events: none;
}

.memory-card__face--back {
  background:
    linear-gradient(180deg, rgba(85, 76, 111, 0.96), rgba(54, 46, 77, 0.92));
}

.memory-card__face--back::before {
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.08), transparent 24%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 42%);
}

.memory-card__face--front {
  transform: rotateY(180deg);
  background:
    linear-gradient(180deg, rgba(21, 17, 38, 0.98), rgba(26, 20, 45, 0.94));
}

.memory-card__face--front::before {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 48%),
    radial-gradient(circle at bottom right, rgba(239, 77, 93, 0.08), transparent 32%);
}

.memory-card__crest {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.8rem);
  color: rgba(239, 77, 93, 0.96);
  text-shadow: 0 10px 24px rgba(239, 77, 93, 0.18);
}

.memory-card__text {
  position: relative;
  z-index: 1;
  max-width: 90%;
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 2.5vw, 2.15rem);
  line-height: 1.05;
  letter-spacing: 0.02em;
  text-wrap: balance;
}

.memory-card__text.is-answer {
  color: rgba(255, 238, 197, 0.98);
}

.memory-card__text.is-expression {
  color: rgba(248, 243, 255, 0.98);
}

.memory-card.is-matched .memory-card__face--front {
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow:
    0 12px 24px rgba(8, 6, 20, 0.18),
    0 0 0 1px rgba(255, 255, 255, 0.04);
  background:
    linear-gradient(180deg, rgba(35, 32, 51, 0.84), rgba(43, 38, 60, 0.8));
}

.memory-card.is-matched .memory-card__face--front::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(240, 245, 255, 0.08), rgba(210, 220, 238, 0.14));
  backdrop-filter: blur(10px) saturate(0.8);
  -webkit-backdrop-filter: blur(10px) saturate(0.8);
  pointer-events: none;
}

.memory-card.is-matched .memory-card__text {
  color: rgba(240, 241, 247, 0.62);
  text-shadow: none;
  filter: saturate(0.72);
}

.memory-card.is-matched .memory-card__text.is-answer {
  color: rgba(244, 234, 204, 0.6);
}

.memory-card.is-celebrating {
  animation: matchedPulse 340ms ease;
}

.memory-card.is-wrong {
  animation: wrongShake 220ms ease;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(8, 7, 18, 0.52);
  backdrop-filter: blur(10px);
}

.modal-panel {
  width: min(760px, calc(100vw - 28px));
  max-height: min(88dvh, 860px);
  overflow: auto;
  padding: clamp(22px, 3vw, 30px);
  border-radius: 28px;
  background: rgba(18, 14, 34, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: var(--shadow-lg);
}

.modal-panel--wide {
  width: min(980px, calc(100vw - 28px));
}

.modal-panel--compact {
  width: min(620px, calc(100vw - 28px));
  text-align: center;
}

.modal-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.stats-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.table-stat {
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.table-stat__title {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  color: rgba(255, 211, 106, 0.94);
}

.rules-list {
  margin: 18px 0 0;
  padding-left: 22px;
  color: rgba(250, 245, 255, 0.9);
  line-height: 1.6;
}

.rules-list li + li {
  margin-top: 8px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 22px;
}

.modal-actions--split {
  justify-content: center;
}

.result-badge {
  display: inline-flex;
  margin-bottom: 14px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 211, 106, 0.12);
  color: rgba(255, 211, 106, 0.98);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

@keyframes matchedPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes wrongShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

@media (max-width: 1100px) {
  .menu-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .table-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .panel__header,
  .menu-footer,
  .game-topbar {
    gap: 14px;
  }

  .game-topbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }
}

@media (max-width: 760px) {
  .app-frame {
    width: min(100vw - 16px, 100%);
    padding-top: calc(14px + var(--safe-top));
    padding-bottom: calc(12px + var(--safe-bottom));
    gap: 12px;
  }

  .hero {
    grid-template-columns: 120px 1fr 48px;
    justify-items: center;
    text-align: center;
    gap: 12px;
    padding-inline: 8px;
  }

  .hero__title {
    grid-column: 1 / -1;
    grid-row: 2;
    padding-right: 0;
  }

  .menu-panel {
    padding: 18px;
    gap: 18px;
  }

  .panel__header,
  .menu-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .menu-footer,
  .game-status,
  .modal-actions,
  .modal-actions--split {
    justify-content: stretch;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .stats-summary,
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .board-grid {
    gap: 8px;
  }

  .memory-card__face {
    border-radius: 18px;
  }

  .memory-card__text {
    font-size: clamp(0.92rem, 4vw, 1.4rem);
  }

  .toggle-card {
    min-height: 66px;
    padding: 12px 14px;
  }
}

@media (max-width: 440px) {
  .app-frame {
    width: calc(100vw - 12px);
    padding-top: calc(7px + var(--safe-top));
    padding-bottom: calc(6px + var(--safe-bottom));
    gap: 7px;
  }

  .hero {
    gap: 4px;
  }

  .hero__brand {
    width: 120px;
    height: 44px;
    border-width: 2px;
    box-shadow: 3px 4px 0 var(--manga-ink);
  }

  .hero__brand img {
    width: 120px;
    height: auto;
  }

  .eyebrow,
  .panel__eyebrow {
    margin-bottom: 2px;
    font-size: 0.6rem;
  }

  .hero h1 {
    font-size: 2.15rem;
    -webkit-text-stroke-width: 1.5px;
    text-shadow: 3px 3px 0 var(--manga-ink);
  }

  .hero__subtitle {
    margin-top: 7px;
    padding: 6px 9px;
    font-size: 0.78rem;
    line-height: 1.25;
    box-shadow: 2px 3px 0 var(--manga-ink);
  }

  .menu-panel {
    padding: 10px 12px;
    gap: 9px;
    border-radius: 22px;
  }

  .panel__header {
    display: block;
  }

  .panel__header h2 {
    font-size: 1.12rem;
  }

  .table-grid {
    gap: 6px;
  }

  .table-chip {
    min-height: 36px;
    border-radius: 10px;
    box-shadow: 2px 3px 0 rgba(23, 32, 74, 0.2);
    font-size: 0.9rem;
  }

  .menu-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .toggle-card {
    min-height: 48px;
    padding: 7px 8px;
    gap: 6px;
    grid-template-columns: auto minmax(0, 1fr);
    border-width: 2px;
    border-radius: 13px;
    box-shadow: 2px 3px 0 rgba(23, 32, 74, 0.2);
  }

  .toggle-card__icon {
    width: 28px;
    height: 28px;
    border-width: 1.5px;
    font-size: 0.82rem;
  }

  .toggle-card__label {
    min-width: 0;
    font-size: 0;
    line-height: 1.08;
    text-align: center;
  }

  .toggle-card__label::after {
    content: attr(data-short-label);
    font-size: 0.72rem;
  }

  .toggle-card__value {
    display: none;
  }

  .menu-footer {
    display: block;
  }

  .menu-footer p {
    display: none;
  }

  .menu-footer .primary-button {
    min-height: 42px;
    width: 100%;
  }

  .site-footer {
    padding-inline: 4px;
    font-size: 0.7rem;
  }

  .stats-summary,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .game-status {
    gap: 8px;
  }

  .status-pill {
    font-size: 0.92rem;
    padding: 9px 12px;
  }
}

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

/* Manga cartoon redesign */
:root {
  --manga-ink: #17204a;
  --manga-blue: #1479f6;
  --manga-cyan: #42d9ff;
  --manga-red: #ff3f62;
  --manga-yellow: #ffd83d;
  --manga-green: #28d698;
  --manga-paper: #fffaf0;
  --ink: #17204a;
  --ink-soft: rgba(23, 32, 74, 0.68);
  --line: rgba(23, 32, 74, 0.16);
  --red: var(--manga-red);
  --red-strong: #ff6f43;
  --gold: var(--manga-yellow);
  --shadow-lg: 9px 10px 0 rgba(23, 32, 74, 0.2);
  --shadow-md: 5px 6px 0 rgba(23, 32, 74, 0.2);
  --font-display: "Arial Black", "Avenir Next Condensed", Impact, sans-serif;
}

body {
  color: var(--manga-ink);
  background: #7cdbff;
}

.app-shell {
  background: #7cdbff;
  isolation: isolate;
}

.scene-backdrop {
  background: url("./assets/manga-ninja-academy.webp") center center / cover no-repeat;
  transform: scale(1.015);
  filter: saturate(1.08) contrast(1.02);
}

.scene-fade {
  background:
    radial-gradient(circle at 50% 45%, rgba(255, 255, 255, 0.76) 0 22%, rgba(255, 255, 255, 0.36) 50%, transparent 76%),
    linear-gradient(180deg, rgba(66, 217, 255, 0.08), rgba(24, 58, 133, 0.12));
}

.menu-shell::before,
.game-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.2;
  background-image: radial-gradient(var(--manga-ink) 1.1px, transparent 1.1px);
  background-size: 8px 8px;
  mask-image: linear-gradient(90deg, #000, transparent 28%, transparent 72%, #000);
}

.hero__brand {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  filter: drop-shadow(0 1px 2px rgba(255,255,255,.9));
  justify-self: start;
}
.hero > .fullscreen-button { grid-column: 3; grid-row: 1; justify-self: end; }

.hero__title,
.game-brand {
  filter: drop-shadow(3px 4px 0 rgba(255, 255, 255, 0.9));
}

.eyebrow,
.panel__eyebrow {
  color: var(--manga-red);
  font-family: var(--font-display);
  font-weight: 900;
  letter-spacing: 0.13em;
  text-shadow: 1px 1px 0 #fff;
}

.hero h1,
.game-brand h1 {
  color: #fff;
  letter-spacing: -0.045em;
  -webkit-text-stroke: 2px var(--manga-ink);
  text-shadow: 4px 5px 0 var(--manga-ink);
  transform: rotate(-1deg);
}

.hero h1 span,
.game-brand h1 span {
  color: var(--manga-red);
}

.hero__subtitle {
  display: inline-block;
  margin-top: 16px;
  padding: 8px 16px;
  color: var(--manga-ink);
  background: rgba(255, 250, 240, 0.93);
  border: 2px solid var(--manga-ink);
  border-radius: 999px;
  box-shadow: 3px 4px 0 var(--manga-ink);
  font-weight: 800;
}

.panel,
.modal-panel {
  background:
    radial-gradient(circle at 15% 15%, rgba(255, 216, 61, 0.15), transparent 25%),
    rgba(255, 250, 240, 0.95);
  border: 4px solid var(--manga-ink);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(8px);
}

.menu-panel {
  position: relative;
  overflow: hidden;
}

.menu-panel::after,
.modal-panel::after {
  content: none;
}

.panel__header h2,
.modal-panel h2 {
  color: var(--manga-ink);
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: -0.035em;
}

.summary-card,
.table-stat {
  background: #fff;
  border: 2px solid var(--manga-ink);
  box-shadow: 3px 4px 0 rgba(23, 32, 74, 0.16);
}

.summary-card:nth-child(odd) {
  background: #e8f8ff;
}

.summary-card:nth-child(even) {
  background: #fff2bd;
}

.table-chip {
  color: var(--manga-ink);
  background: #f5f7f8;
  border: 2px solid var(--manga-ink);
  border-radius: 13px;
  box-shadow: 3px 4px 0 rgba(23, 32, 74, 0.2);
  font-family: var(--font-display);
}

.table-chip:hover,
.table-chip:focus-visible {
  transform: translate(-1px, -2px) rotate(-1deg);
}

.table-chip.is-selected {
  color: #fff;
  background: #df1744;
  box-shadow: 4px 5px 0 var(--manga-ink);
  transform: translate(-1px, -2px) rotate(-3deg) scale(1.05);
}

.toggle-card {
  color: var(--manga-ink);
  background: #eef9ff;
  border: 3px solid var(--manga-ink);
  border-radius: 17px;
  box-shadow: 4px 5px 0 rgba(23, 32, 74, 0.2);
}

.toggle-card:nth-child(2) { background: #e1fff1; }
.toggle-card:nth-child(3) { background: #ffe7ef; }
.toggle-card:nth-child(4) { background: #ebe5ff; }

.toggle-card.is-active,
.toggle-card.gold {
  color: var(--manga-ink);
  background: var(--manga-yellow);
}

.toggle-card__icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 2px solid var(--manga-ink);
  border-radius: 50%;
  background: #fff;
}

.menu-footer p,
.modal-copy,
.rules-list,
.site-footer {
  color: var(--manga-ink);
  font-weight: 650;
}

.site-footer p {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
}

.primary-button,
.secondary-button,
.icon-button {
  color: var(--manga-ink);
  border: 3px solid var(--manga-ink);
  border-radius: 14px;
  box-shadow: 4px 5px 0 var(--manga-ink);
  font-family: var(--font-display);
  text-transform: uppercase;
}

.primary-button {
  color: #fff;
  background: var(--manga-red);
}

.secondary-button {
  background: var(--manga-yellow);
}

.icon-button {
  background: #fff;
}

.primary-button:active,
.secondary-button:active,
.icon-button:active,
.toggle-card:active,
.table-chip:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--manga-ink);
}

.game-topbar {
  padding: 8px 14px;
  border: 3px solid var(--manga-ink);
  border-radius: 22px;
  background: rgba(255, 250, 240, 0.92);
  box-shadow: 5px 6px 0 rgba(23, 32, 74, 0.22);
}

.status-pill {
  color: var(--manga-ink);
  background: #fff;
  border: 2px solid var(--manga-ink);
  box-shadow: 2px 3px 0 rgba(23, 32, 74, 0.18);
}

.status-pill:nth-child(2) { background: #dff8ff; }
.status-pill:nth-child(3) { background: #e1fff1; }
.status-pill:nth-child(4) { background: #ffe7ef; }
.status-pill--accent { background: var(--manga-yellow); }

.board-grid {
  gap: clamp(9px, 1vw, 13px);
}

.memory-card__face {
  border: 3px solid var(--manga-ink);
  border-radius: 19px;
  box-shadow: 5px 6px 0 rgba(23, 32, 74, 0.28);
}

.memory-card__face--back {
  background: #ff3f68;
}

.memory-card:nth-child(4n + 2) .memory-card__face--back {
  background: #28aeea;
}

.memory-card:nth-child(4n + 3) .memory-card__face--back {
  background: #ffc83d;
}

.memory-card:nth-child(4n) .memory-card__face--back {
  background: #42d59a;
}

.memory-card__face--back::before {
  inset: 0;
  border-radius: 15px;
  border: 4px solid rgba(255, 255, 255, 0.52);
  background: none;
}

.memory-card__crest {
  z-index: 2;
  color: #fff;
  font-size: clamp(1.7rem, 4vw, 3rem);
  -webkit-text-stroke: 2px var(--manga-ink);
  text-shadow: 3px 4px 0 var(--manga-ink);
  transform: rotate(-8deg);
}

.memory-card__burst {
  position: absolute;
  right: 9%;
  top: 8%;
  z-index: 1;
  color: #fff;
  font-size: clamp(0.9rem, 2vw, 1.5rem);
  -webkit-text-stroke: 1px var(--manga-ink);
  transform: rotate(14deg);
}

.memory-card__face--front {
  background: #fffaf0;
}

.memory-card__face--front::before {
  background: none;
}

.memory-card__text,
.memory-card__text.is-answer,
.memory-card__text.is-expression {
  color: var(--manga-ink);
  font-weight: 900;
  letter-spacing: -0.04em;
  text-shadow: 2px 2px 0 #fff;
}

.memory-card__text.is-answer {
  color: var(--manga-red);
  font-size: clamp(1.4rem, 3vw, 2.6rem);
  -webkit-text-stroke: 1px var(--manga-ink);
}

.memory-card.is-matched .memory-card__face--front {
  border-color: rgba(23, 32, 74, 0.72);
  background: rgba(220, 241, 235, 0.82);
  box-shadow:
    inset 0 0 24px rgba(255, 255, 255, 0.72),
    3px 4px 0 rgba(23, 32, 74, 0.18);
  backdrop-filter: blur(8px) saturate(0.62);
  -webkit-backdrop-filter: blur(8px) saturate(0.62);
}

.memory-card.is-matched .memory-card__face--front::after {
  content: "✓";
  inset: auto 8px 6px auto;
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--manga-green);
  border: 2px solid var(--manga-ink);
  border-radius: 50%;
  font-weight: 900;
  backdrop-filter: none;
}

.memory-card.is-matched .memory-card__text,
.memory-card.is-matched .memory-card__text.is-answer {
  color: rgba(23, 32, 74, 0.64);
  -webkit-text-stroke-color: rgba(23, 32, 74, 0.6);
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.72);
  filter: saturate(0.35);
}

.overlay {
  background: rgba(30, 66, 144, 0.46);
  backdrop-filter: blur(8px) saturate(1.2);
}

.modal-panel {
  position: relative;
}

.result-badge {
  color: #fff;
  background: var(--manga-red);
  border: 2px solid var(--manga-ink);
  box-shadow: 3px 3px 0 var(--manga-ink);
}

.result-badge.is-record {
  color: var(--manga-ink);
  background: var(--manga-yellow);
}

.table-stat__title {
  color: var(--manga-red);
}

@media (max-width: 760px) {
  .scene-backdrop {
    background-position: 12% center;
  }

  .hero__subtitle {
    border-radius: 16px;
  }

  .panel,
  .modal-panel {
    border-width: 3px;
  }

  .memory-card__face {
    border-width: 2px;
    border-radius: 14px;
    box-shadow: 3px 4px 0 rgba(23, 32, 74, 0.25);
  }

  .memory-card__face--back::before {
    border-width: 2px;
    border-radius: 11px;
  }

  .game-topbar {
    padding: 7px 10px;
  }
}

/* Keep gameplay controls compact on portrait and mid-sized screens. */
@media (max-width: 1100px) {
  .game-topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "status actions";
    justify-items: stretch;
    gap: 8px 12px;
    text-align: left;
  }

  .game-brand {
    grid-area: brand;
    align-self: center;
  }

  .game-status {
    grid-area: status;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .game-actions {
    grid-area: actions;
    align-self: center;
  }

  .game-actions .secondary-button {
    width: auto;
  }

  .status-pill {
    min-height: 36px;
    justify-content: center;
    padding: 7px 10px;
  }
}

@media (max-width: 760px) {
  .game-brand h1 {
    font-size: clamp(1.7rem, 8vw, 2.35rem);
  }

  .game-actions .secondary-button {
    min-height: 42px;
    padding: 8px 13px;
  }

  .modal-panel--wide {
    padding: 18px;
  }

  .modal-panel--wide .modal-panel__header {
    align-items: center;
    margin-bottom: 12px;
  }

  .modal-panel--wide h2 {
    font-size: clamp(1.25rem, 5.7vw, 1.65rem);
  }

  .modal-panel--wide .stats-summary,
  .modal-panel--wide .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .modal-panel--wide .stats-grid {
    margin-top: 12px;
  }

  .modal-panel--wide .summary-card,
  .modal-panel--wide .table-stat {
    min-width: 0;
    padding: 9px 10px;
  }

  .modal-panel--wide .table-stat__title {
    margin-bottom: 3px;
  }

  .modal-panel--wide .summary-card strong,
  .modal-panel--wide .table-stat strong {
    margin-top: 3px;
    font-size: 1rem;
  }
}

@media (max-width: 440px) {
  .game-topbar {
    gap: 6px 8px;
    padding: 6px 8px;
    border-radius: 17px;
  }

  .game-brand h1 {
    font-size: clamp(1.45rem, 8vw, 1.9rem);
    -webkit-text-stroke-width: 1.2px;
    text-shadow: 2px 3px 0 var(--manga-ink);
  }

  .game-status {
    gap: 5px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-pill {
    min-height: 31px;
    padding: 5px 4px;
    font-size: clamp(0.66rem, 3vw, 0.78rem);
    white-space: nowrap;
  }

  .game-actions .secondary-button {
    min-height: 44px;
    padding: 6px 10px;
    font-size: 0.78rem;
  }

  .modal-panel--wide {
    padding: 14px;
  }

  .modal-panel--wide .panel__eyebrow {
    display: none;
  }

  .modal-panel--wide .icon-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }

  .modal-panel--wide .summary-card,
  .modal-panel--wide .table-stat {
    padding: 7px 8px;
  }

  .modal-panel--wide .summary-card span,
  .modal-panel--wide .table-stat small {
    font-size: 0.7rem;
  }

  .modal-panel--wide .table-stat__title {
    font-size: 0.82rem;
  }
}

/* Compact start menu: keep more of the illustrated world visible. */
.menu-stage {
  place-items: safe center;
}

.menu-shell .hero__title {
  transform: translateY(8px);
}

.menu-panel {
  width: min(900px, 100%);
  padding: 18px 20px;
  gap: 14px;
  align-content: initial;
}

.menu-panel .panel__header {
  padding-top: 6px;
}

.menu-panel .table-grid,
.menu-panel .menu-actions {
  gap: 9px;
}

.menu-panel .table-chip {
  min-height: 44px;
}

.menu-panel .toggle-card {
  min-height: 58px;
  padding: 10px 12px;
}

.menu-panel .primary-button,
.menu-panel .secondary-button {
  min-height: 46px;
}

.menu-panel .menu-footer .primary-button {
  min-height: 58px;
}

@media (max-width: 760px) {
  .menu-panel {
    width: min(620px, 100%);
    padding: 14px;
    gap: 11px;
  }

  .menu-panel .table-chip {
    min-height: 40px;
  }

  .menu-panel .toggle-card {
    min-height: 52px;
    padding: 8px 10px;
  }
}

@media (max-width: 440px) {
  .menu-shell .hero__title {
    transform: translateY(4px);
  }

  .menu-panel {
    padding: 10px 12px;
    gap: 9px;
  }

  .menu-panel .panel__header {
    padding-top: 3px;
  }

  .menu-panel .table-chip {
    min-height: 44px;
  }

  .menu-panel .toggle-card {
    min-height: 48px;
    padding: 7px 8px;
  }

  .menu-panel .menu-footer .primary-button {
    min-height: 46px;
  }
}

@media (max-height: 700px) and (min-width: 761px) {
  .app-frame { padding-top: calc(8px + var(--safe-top)); padding-bottom: calc(8px + var(--safe-bottom)); gap: 8px; }
  .hero h1 { font-size: 2.4rem; }
  .hero__subtitle { font-size: .85rem; margin-top: 6px; padding: 5px 12px; }
  .menu-panel { padding: 12px 16px; gap: 8px; }
  .menu-panel .panel__header { padding-top: 0; }
  .menu-panel .panel__header h2 { font-size: 1.4rem; }
  .menu-panel .toggle-card { min-height: 44px; padding: 5px 10px; }
  .menu-panel .menu-footer .primary-button { min-height: 44px; }
  .menu-footer p { margin: 4px 0 0; font-size: .8rem; }
  .site-footer { font-size: .75rem; }
}
@media (max-height: 499px), (max-width: 440px) and (max-height: 650px) {
  .menu-shell .app-frame { display: flex; flex-direction: column; overflow-y: auto; }
  .menu-shell .hero, .menu-shell .menu-stage, .menu-shell .site-footer { flex: none; }
  .menu-shell .menu-stage { overflow: visible; }
  .menu-shell .menu-panel { margin: 8px auto; }
}
@media (forced-colors: active) {
  .hero h1, .memory-card__text, .memory-card__crest { -webkit-text-stroke: 0; text-shadow: none; }
  .table-chip.is-selected { outline: 3px solid Highlight; }
}

@media (max-width: 360px) {
  .menu-panel .toggle-card {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 3px;
    min-height: 62px;
    padding: 5px;
  }
}
