:root {
  --bg-ink: #102033;
  --bg-ink-soft: rgba(16, 32, 51, 0.76);
  --shell: rgba(251, 247, 239, 0.82);
  --shell-strong: rgba(255, 252, 246, 0.92);
  --panel-border: rgba(36, 57, 80, 0.12);
  --text-main: #17263d;
  --text-soft: #566579;
  --accent: #ffb54d;
  --accent-strong: #ff8f38;
  --primary: #273c75;
  --primary-strong: #1b2c5a;
  --primary-soft: rgba(39, 60, 117, 0.12);
  --success: #23b26d;
  --danger: #dc5d56;
  --neutral: #dfe5ec;
  --neutral-dark: #b4c0cf;
  --shadow-lg: 0 24px 56px rgba(19, 32, 48, 0.18);
  --shadow-md: 0 16px 34px rgba(19, 32, 48, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --transition-fast: 120ms ease;
  --transition-medium: 180ms ease;
  --scene-image: none;
  color-scheme: light;
  font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: var(--viewport-height, 100svh);
  overflow: hidden;
  color: var(--text-main);
  background: var(--scene-image) center/cover fixed no-repeat;
}

body[data-screen="play"] {
  overflow: hidden;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid #ff9f43;
  outline-offset: 3px;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.page-shell {
  min-height: var(--viewport-height, 100svh);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.site-header {
  position: relative;
  z-index: 3;
  width: min(1320px, calc(100% - 24px));
  min-height: 68px;
  margin: 10px auto 0;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 0;
  border-radius: 20px;
  background: transparent;
  box-shadow: none;
}

.site-logo {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.site-logo img {
  display: block;
  width: clamp(77px, 9.5vw, 105px);
  height: auto;
  filter: brightness(0) invert(1) drop-shadow(0 2px 6px rgba(0, 0, 0, 0.7));
}

.site-title {
  display: none;
}

#app {
  min-height: 0;
}

.site-footer {
  position: relative;
  z-index: 3;
  min-height: 32px;
  padding: 5px 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.85rem;
  background: transparent;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.82);
}

.site-footer a {
  color: #fff;
  font-weight: 400;
}

body[data-screen="play"] .page-shell,
body[data-modal="open"] .page-shell {
  grid-template-rows: 0 minmax(0, 1fr) 0;
}

body[data-screen="play"] .site-header,
body[data-screen="play"] .site-footer,
body[data-modal="open"] .site-header,
body[data-modal="open"] .site-footer {
  visibility: hidden;
  overflow: hidden;
  min-height: 0;
  height: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.app-shell {
  position: relative;
  height: 100%;
  min-height: 0;
  padding: clamp(8px, 1.4vw, 18px);
  display: grid;
  overflow: hidden;
  isolation: isolate;
}

.scene-backdrop,
.scene-glow {
  position: absolute;
  inset: 0;
}

.scene-backdrop {
  background: transparent;
}

.scene-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: none;
}

.scene-glow {
  pointer-events: none;
  filter: blur(30px);
}

.scene-glow-left {
  background: radial-gradient(circle at 22% 38%, rgba(255, 136, 84, 0.3), transparent 34%);
}

.scene-glow-right {
  background: radial-gradient(circle at 78% 18%, rgba(255, 214, 110, 0.2), transparent 30%);
}

.app-frame {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  width: min(1320px, 100%);
  height: auto;
  min-height: 0;
  margin: 0 auto;
}

.brand-bar {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 18px;
  padding: 18px 22px;
  border: 1px solid rgba(255, 255, 255, 0.48);
  background: rgba(250, 245, 236, 0.52);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-md);
}

.brand-mark {
  width: clamp(54px, 6vw, 72px);
  height: clamp(54px, 6vw, 72px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-copy h1,
.brand-copy p,
.menu-heading h2,
.option-group h3,
.keypad-header h2,
.modal-head h2,
.completion-modal h2 {
  margin: 0;
}

.eyebrow,
.section-kicker,
.question-label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.73rem;
  font-weight: 700;
  color: rgba(23, 38, 61, 0.62);
}

.brand-copy h1 {
  font-size: clamp(2rem, 5vw, 3.7rem);
  line-height: 0.95;
}

.tagline {
  margin-top: 6px;
  color: var(--text-soft);
  font-size: clamp(0.96rem, 1.35vw, 1.12rem);
}

.viewport {
  min-height: 0;
  height: 100%;
}

.screen {
  height: 100%;
}

.is-hidden {
  display: none !important;
}

.menu-layout,
.play-layout {
  display: grid;
  gap: clamp(14px, 2vw, 20px);
  height: 100%;
  min-height: 0;
}

.menu-layout {
  place-items: center;
}

.play-layout {
  grid-template-columns: 1fr;
}

.panel {
  min-height: 0;
  padding: clamp(18px, 2vw, 28px);
  border-radius: var(--radius-xl);
  border: 1px solid rgba(255, 255, 255, 0.54);
  background: linear-gradient(180deg, var(--shell-strong), var(--shell));
  backdrop-filter: blur(22px);
  box-shadow: var(--shadow-lg);
}

.menu-panel,
.play-stage,
.keypad-panel {
  display: flex;
  flex-direction: column;
}

.menu-panel {
  width: min(540px, 100%);
  justify-content: center;
  gap: clamp(6px, 0.9vh, 10px);
  padding: clamp(8px, 1.2vh, 14px);
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
}

.menu-flow {
  display: grid;
  gap: 6px;
  width: min(540px, 100%);
  margin: 0 auto;
}

.menu-heading {
  text-align: center;
}

.menu-heading h1 {
  margin-top: 3px;
  font-size: clamp(3.1rem, 5.2vw, 4.3rem);
  line-height: 1;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.78);
}

.menu-heading p {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, 0.92);
  font-size: clamp(0.92rem, 1.1vw, 1rem);
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.7);
}

.menu-section {
  display: grid;
  gap: 6px;
  padding: 10px;
  border-radius: 22px;
  background: rgba(255, 252, 247, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 14px 28px rgba(20, 31, 45, 0.1);
  backdrop-filter: blur(16px);
}

.menu-section-primary {
  padding: 12px;
}

.menu-section-options,
.menu-section-stats {
  gap: 8px;
}

.menu-section-stats .section-head p {
  display: none;
}

.menu-section-options {
  align-content: start;
}

.menu-section-stats {
  padding-top: 8px;
}

.section-head {
  display: grid;
  gap: 1px;
}

.section-head h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--text-main);
}

.section-head p {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.84rem;
}

.mode-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.mini-pill,
.live-readout,
.status-chip,
.record-chip,
.ghost-button,
.toggle-button,
.table-button,
.primary-button,
.keypad-button {
  transition:
    transform var(--transition-fast),
    background-color var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    color var(--transition-fast);
}

.mini-pill,
.live-readout,
.status-chip,
.record-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(37, 57, 81, 0.09);
  background: rgba(255, 255, 255, 0.65);
  color: var(--text-main);
  font-weight: 700;
}

.modal-head,
.play-topbar,
.record-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 76px;
  width: 100%;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.55);
  border: 1px dashed rgba(37, 57, 81, 0.18);
  color: var(--text-soft);
  text-align: center;
}

.menu-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.secondary-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
}

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

.menu-panel .table-button,
.menu-panel .toggle-button {
  min-height: 46px;
  padding: 6px 12px;
}

.menu-panel .text-button {
  min-height: 28px;
}

.table-button,
.toggle-button,
.ghost-button,
.text-button,
.primary-button,
.keypad-button {
  min-height: 52px;
  padding: 8px 14px;
  border-radius: 16px;
  border: 1px solid rgba(37, 57, 81, 0.12);
  background: rgba(255, 255, 255, 0.62);
  color: var(--text-main);
  font-weight: 800;
  touch-action: manipulation;
}

.table-button:hover,
.toggle-button:hover,
.ghost-button:hover,
.text-button:hover,
.primary-button:hover,
.keypad-button:hover {
  transform: translateY(-1px);
}

.table-button:active,
.toggle-button:active,
.ghost-button:active,
.text-button:active,
.primary-button:active,
.keypad-button:active {
  transform: scale(0.98);
}

.table-button.is-selected,
.toggle-button.is-selected {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, #7b4dff, #945dff);
  box-shadow: 0 16px 32px rgba(123, 77, 255, 0.26);
}

.option-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.option-group h3 {
  font-size: 0.96rem;
}

.menu-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.toggle-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.primary-button {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary), #3756a3);
  box-shadow: 0 18px 34px rgba(39, 60, 117, 0.28);
}

.start-button {
  min-height: 54px;
  font-size: 1.02rem;
}

.ghost-button {
  min-height: 46px;
  background: rgba(255, 255, 255, 0.4);
  font-weight: 700;
}

.text-button {
  min-height: 32px;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.94);
  font-weight: 400;
  text-decoration: underline;
  text-underline-offset: 0.18em;
  box-shadow: none;
}

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

.menu-stat-card {
  display: grid;
  gap: 2px;
  align-content: center;
  min-height: 54px;
  padding: 8px;
  border-radius: 18px;
  border: 1px solid rgba(37, 57, 81, 0.08);
  background: rgba(255, 255, 255, 0.72);
  text-align: center;
}

.menu-stat-label {
  color: var(--text-soft);
  font-size: 0.72rem;
  font-weight: 700;
}

.menu-stat-value {
  font-size: clamp(1rem, 1.6vw, 1.32rem);
  line-height: 1;
  color: var(--primary);
}

@media (min-width: 901px) {
  .menu-panel {
    width: min(560px, 100%);
  }
}

.play-stage {
  gap: 16px;
  justify-content: flex-start;
}

.play-topbar {
  flex-wrap: wrap;
}

.play-meta,
.play-actions,
.keypad-status,
.completion-actions,
.completion-stats,
.record-card-meta {
  display: flex;
  gap: 10px;
}

.question-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: clamp(18px, 2vw, 28px);
  border-radius: 24px;
  border: 1px solid rgba(37, 57, 81, 0.1);
  background: linear-gradient(180deg, rgba(255, 248, 237, 0.9), rgba(255, 255, 255, 0.7));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.question-card.is-incorrect {
  border-color: rgba(220, 93, 86, 0.45);
  background: linear-gradient(180deg, rgba(255, 235, 233, 0.95), rgba(255, 245, 244, 0.8));
  animation: shake 220ms ease-in-out;
}

.question-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 14px;
}

.question-prompt {
  font-size: clamp(2rem, 6vw, 4.2rem);
  font-weight: 900;
  line-height: 0.95;
}

.answer-display {
  min-width: 120px;
  padding: 12px 16px;
  border-radius: 18px;
  background: rgba(39, 60, 117, 0.08);
  text-align: center;
  font-size: clamp(1.9rem, 4vw, 3rem);
  font-weight: 900;
  color: rgba(23, 38, 61, 0.42);
}

.answer-display.has-value {
  color: var(--primary);
}

.question-hint {
  margin: 0;
  color: var(--text-soft);
}

.progress-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.progress-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 86px;
  padding: 10px 8px;
  border-radius: 18px;
  border: 1px solid rgba(37, 57, 81, 0.08);
  background: rgba(224, 230, 239, 0.92);
  color: #64748b;
  font-size: clamp(1rem, 2vw, 1.45rem);
  font-weight: 800;
  text-align: center;
}

.progress-cell.is-active {
  background: linear-gradient(180deg, rgba(255, 214, 112, 0.96), rgba(255, 196, 82, 0.94));
  color: var(--text-main);
  border-color: rgba(255, 164, 82, 0.5);
  box-shadow: 0 0 0 3px rgba(124, 96, 255, 0.28);
}

.progress-cell.is-solved {
  background: linear-gradient(180deg, rgba(83, 230, 146, 0.98), rgba(35, 178, 109, 0.96));
  color: #fff;
  border-color: rgba(20, 120, 77, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 10px 22px rgba(24, 143, 86, 0.2);
}

.progress-cell.is-incorrect {
  background: linear-gradient(180deg, rgba(255, 222, 219, 0.98), rgba(255, 207, 203, 0.96));
  border-color: rgba(220, 93, 86, 0.35);
  box-shadow: 0 0 0 3px rgba(220, 93, 86, 0.16);
}

.keypad-panel {
  justify-content: space-between;
  gap: 18px;
}

.keypad-status {
  flex-wrap: wrap;
}

.status-chip {
  flex: 1;
  justify-content: space-between;
  min-height: 54px;
  padding: 0 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.74);
}

.status-chip span {
  color: var(--text-soft);
}

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

.keypad-button {
  min-height: clamp(64px, 9vw, 92px);
  font-size: clamp(1.45rem, 3vw, 2.4rem);
  background: rgba(220, 229, 237, 0.95);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.keypad-button:active {
  transform: scale(0.97);
  background: rgba(205, 216, 227, 1);
}

.keypad-utility {
  font-size: clamp(1rem, 2vw, 1.45rem);
}

.modal-layer {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 24, 37, 0);
  pointer-events: none;
  transition: background-color var(--transition-medium);
  z-index: 20;
}

.modal-layer.is-visible {
  background: rgba(12, 24, 37, 0.42);
  pointer-events: auto;
  backdrop-filter: blur(12px);
}

.modal-card {
  width: min(940px, calc(100vw - 24px));
  max-height: min(86svh, 920px);
  overflow: auto;
  padding: 22px;
  border-radius: 28px;
  background: rgba(255, 250, 244, 0.95);
  box-shadow: 0 30px 60px rgba(7, 17, 27, 0.28);
}

.record-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.record-card {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(37, 57, 81, 0.08);
}

.record-card-meta {
  flex-direction: column;
  margin-top: 12px;
  color: var(--text-soft);
}

.completion-modal {
  width: min(480px, calc(100vw - 24px));
  text-align: center;
}

.completion-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 181, 77, 0.2);
  color: var(--accent-strong);
  font-weight: 800;
}

.completion-subtitle,
.completion-message,
.completion-countdown {
  color: var(--text-soft);
}

.completion-stats {
  justify-content: center;
  margin: 20px 0;
}

.completion-stat {
  min-width: 132px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(37, 57, 81, 0.08);
}

.completion-stat span {
  color: var(--text-soft);
}

.completion-stat strong {
  display: block;
  margin-top: 8px;
  font-size: 1.8rem;
}

.completion-actions {
  justify-content: center;
  margin-top: 18px;
}

.rules-modal {
  width: min(600px, calc(100vw - 24px));
}

.rules-list {
  margin: 20px 0 0;
  padding-left: 24px;
  color: var(--text-soft);
  line-height: 1.65;
}

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

@media (max-width: 900px) {
  .menu-layout {
    grid-template-columns: 1fr;
    height: 100%;
  }

  .app-frame {
    height: auto;
    min-height: 0;
  }

  .viewport {
    height: 100%;
    min-height: 0;
  }

  .menu-panel {
    gap: 12px;
  }

  .play-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .play-stage {
    min-height: 0;
    overflow: hidden;
  }

}

@media (max-width: 820px) {
  .app-shell {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .app-frame {
    height: auto;
    min-height: 0;
  }

  .site-header {
    width: calc(100% - 16px);
    min-height: 58px;
    margin-top: 8px;
    padding: 6px 10px;
  }

  .site-logo img {
    width: clamp(132px, 25vw, 180px);
  }

  .site-title h1 {
    font-size: 1.3rem;
  }

  .toggle-row,
  .record-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .menu-stat-grid {
    grid-template-columns: 1fr;
  }

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

  .progress-grid {
    gap: 8px;
  }

  .progress-cell {
    min-height: 68px;
    font-size: 1rem;
  }

  .keypad-button {
    min-height: 74px;
  }
}

@media (min-width: 700px) and (max-width: 900px) {
  .menu-panel {
    width: min(560px, 100%);
  }
}

@media (min-width: 561px) and (max-width: 900px) {
  .play-layout {
    gap: 10px;
  }

  .play-stage,
  .keypad-panel {
    padding: 14px;
  }

  .play-stage {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    justify-content: stretch;
  }

  .question-card {
    justify-content: center;
    min-height: 0;
  }

  .keypad-panel {
    display: block;
  }

  .keypad-header,
  .keypad-status {
    display: none;
  }

  .keypad {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
  }

  .keypad-button {
    min-height: 56px;
    font-size: 1.5rem;
  }

  .progress-cell {
    min-height: 64px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 8px;
  }

  .site-header {
    justify-content: center;
  }

  .site-logo img {
    width: 142px;
  }

  .site-title {
    display: none;
  }

  .menu-heading h2 {
    font-size: 1.35rem;
  }

  .play-screen .panel {
    padding: 12px;
  }

  .play-stage,
  .keypad-panel {
    gap: 12px;
  }

  .keypad-header,
  .keypad-status {
    display: none;
  }

  .play-topbar {
    gap: 8px;
  }

  .question-card {
    gap: 8px;
    padding: 12px;
    border-radius: 18px;
  }

  .question-prompt {
    font-size: 1.8rem;
  }

  .question-hint {
    font-size: 0.88rem;
  }

  .keypad-header h2 {
    font-size: 1.7rem;
  }

  .status-chip {
    min-height: 44px;
    padding: 0 12px;
  }

  .status-chip strong {
    font-size: 1rem;
  }

  .mini-pill,
  .live-readout {
    min-height: 34px;
    padding: 0 10px;
    font-size: 0.78rem;
  }

  .ghost-button {
    min-height: 44px;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.9rem;
  }

  .menu-flow,
  .play-topbar,
  .play-screen .progress-grid,
  .keypad-shell {
    width: 100%;
  }

  .panel {
    padding: 16px;
    border-radius: 24px;
  }

  .table-grid,
  .progress-grid,
  .keypad {
    gap: 8px;
  }

  .table-button,
  .toggle-button,
  .keypad-button {
    min-height: 48px;
    padding: 10px 12px;
    border-radius: 14px;
  }

  .table-button {
    font-size: 0.95rem;
  }

  .toggle-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .menu-stat-grid {
    grid-template-columns: 1fr;
  }

  .record-grid {
    grid-template-columns: 1fr;
  }

  .question-row {
    grid-template-columns: 1fr;
  }

  .answer-display {
    width: 100%;
  }

  .progress-cell {
    min-height: 48px;
    font-size: 0.75rem;
    border-radius: 14px;
  }

  .keypad-button {
    min-height: 52px;
    font-size: 1.3rem;
  }

  .start-button {
    min-height: 54px;
    font-size: 1rem;
  }

  .secondary-actions {
    justify-content: center;
    gap: 4px 14px;
  }

  .text-button {
    min-height: 24px;
    font-size: 0.94rem;
  }

}

@media (max-height: 840px) {
  .app-frame {
    gap: 10px;
  }

  .brand-bar,
  .panel {
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .menu-panel {
    gap: 7px;
    padding: 12px 16px;
  }

  .menu-panel .table-button,
  .menu-panel .toggle-button,
  .menu-panel .ghost-button {
    min-height: 44px;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .menu-panel .text-button {
    min-height: 24px;
  }

  .menu-panel .start-button {
    min-height: 48px;
  }

  .menu-heading p,
  .menu-panel .section-head p {
    display: none;
  }

  .menu-panel .table-grid,
  .menu-panel .toggle-row,
  .menu-panel .secondary-actions,
  .menu-panel .menu-options,
  .menu-panel .menu-stat-grid,
  .menu-panel .menu-actions {
    gap: 7px;
  }

  .menu-panel .option-group {
    gap: 5px;
  }

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

  .menu-panel .menu-stat-card {
    min-height: 48px;
    padding: 6px;
  }

  .question-card {
    gap: 10px;
    padding: 16px;
  }

  .progress-cell {
    min-height: 74px;
  }

  .keypad-button {
    min-height: 68px;
  }
}

@media (max-height: 900px) {
  .app-shell {
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .menu-layout {
    align-items: start;
    justify-items: center;
  }

  .menu-section-stats {
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
    backdrop-filter: none;
  }

  .menu-section-stats .section-head {
    display: none;
  }

  .menu-stat-card {
    min-height: 42px;
    padding: 4px 6px;
    border-radius: 16px;
  }

  .menu-stat-label {
    font-size: 0.68rem;
  }

  .menu-stat-value {
    font-size: 1rem;
  }
}

@media (max-height: 720px) and (min-width: 821px) {
  .brand-copy h1 {
    font-size: 2.2rem;
  }

  .tagline {
    display: none;
  }

  .table-button,
  .toggle-button {
    min-height: 48px;
  }

  .progress-cell {
    min-height: 62px;
  }

  .keypad-button {
    min-height: 60px;
  }

  .menu-panel {
    gap: 8px;
  }

  .start-button {
    min-height: 48px;
  }
}

@media (max-width: 560px) and (max-height: 900px) {
  .app-shell {
    padding: 6px;
  }

  body[data-screen="play"] .app-shell {
    padding-top: 18px;
  }

  .app-frame {
    gap: 6px;
  }

  .brand-bar,
  .panel {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .brand-bar {
    padding-left: 10px;
    padding-right: 10px;
  }

  .menu-panel {
    gap: 8px;
  }

  .menu-options {
    gap: 8px;
  }

  .menu-heading .section-kicker {
    display: none;
  }

  .menu-heading h2 {
    font-size: 1.15rem;
  }

  .play-screen .panel {
    padding: 10px;
  }

  .question-card {
    padding: 10px;
    gap: 6px;
  }

  .question-hint,
  .keypad-status {
    display: none;
  }

  .progress-grid {
    gap: 6px;
  }

  .progress-cell {
    min-height: 42px;
    font-size: 0.7rem;
  }

  .keypad {
    gap: 6px;
  }

  .keypad-button {
    min-height: 46px;
    font-size: 1.15rem;
  }
}

/* Unified gameplay composition */
.play-layout {
  width: min(576px, 100%);
  height: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto auto;
  align-content: center;
  justify-items: center;
  gap: clamp(8px, 1.4vh, 12px);
}

.play-topbar {
  width: min(528px, 100%);
  padding: 0 4px;
}

.play-meta {
  display: flex;
}

.play-screen .live-readout {
  border: 0;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow-md);
}

.play-screen .progress-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  width: min(528px, 100%);
}

.play-screen .progress-cell {
  min-height: clamp(48px, 7.2vh, 67px);
  border-radius: 11px;
  background: rgba(218, 225, 235, 0.94);
  box-shadow: var(--shadow-md);
}

.play-screen .progress-cell.is-active {
  background: linear-gradient(180deg, rgba(255, 218, 114, 0.98), rgba(255, 198, 83, 0.98));
}

.play-screen .progress-cell.is-solved {
  background: linear-gradient(180deg, rgba(93, 241, 156, 0.99), rgba(29, 171, 98, 0.98));
  border-color: rgba(17, 110, 69, 0.5);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 12px 24px rgba(18, 128, 76, 0.28);
}

.keypad-shell {
  width: min(368px, 100%);
  margin: 0 auto;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 14px;
  background: rgba(255, 252, 246, 0.92);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-lg);
}

@media (min-width: 700px) and (orientation: portrait) {
  .play-layout {
    width: min(576px, 100%);
    gap: 8px;
  }

  .play-screen .progress-grid {
    gap: 6px;
  }

  .play-screen .progress-cell {
    min-height: clamp(51px, 5.6vh, 70px);
  }

  .keypad-shell {
    width: min(368px, 100%);
  }
}

.keypad-shell .answer-display {
  position: absolute;
  width: 1px;
  height: 1px;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.keypad-shell .question-hint {
  visibility: hidden;
  min-height: 20px;
  margin: 0 0 6px;
  color: var(--text-main);
  font-weight: 800;
  text-align: center;
}

.keypad-shell .answer-display.is-incorrect + .question-hint {
  visibility: visible;
}

.keypad-shell .keypad {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.keypad-shell .keypad-button {
  min-height: clamp(40px, 5.6vh, 51px);
  border-radius: 8px;
  box-shadow: none;
}

@media (max-width: 820px) {
  .play-layout {
    width: min(544px, 100%);
    gap: 8px;
  }

  .play-screen .progress-grid {
    gap: 6px;
  }

  .play-screen .progress-cell {
    min-height: clamp(45px, 6.4vh, 61px);
  }

  .keypad-shell {
    width: min(336px, 100%);
    padding: 8px;
  }
}

@media (max-width: 560px) {
  .play-layout {
    align-content: center;
    gap: 8px;
  }

  .play-screen .progress-grid {
    gap: 5px;
  }

  .play-screen .progress-cell {
    min-height: 48px;
    padding: 6px 3px;
    font-size: 0.75rem;
    border-radius: 10px;
  }

  .keypad-shell {
    padding: 8px;
    border-radius: 14px;
  }

  .keypad-shell .question-hint {
    min-height: 18px;
    margin-bottom: 5px;
    font-size: 0.8rem;
  }

  .keypad-shell .keypad-button {
    min-height: 48px;
  }
}

@media (max-height: 720px) and (min-width: 821px) {
  .play-layout {
    width: min(560px, 100%);
    align-content: start;
    gap: 6px;
  }

  .play-screen .progress-cell {
    min-height: 46px;
  }

  .keypad-shell .keypad-button {
    min-height: 38px;
  }
}
