:root {
  --viewport-height: 100dvh;
  --bg: #0d0d1c;
  --bg-deep: #090916;
  --surface: rgba(24, 24, 42, 0.94);
  --surface-strong: rgba(31, 31, 52, 0.98);
  --surface-raised: rgba(36, 36, 58, 0.96);
  --surface-soft: rgba(48, 48, 76, 0.7);
  --surface-glass: rgba(36, 36, 58, 0.62);
  --text: #e6e3fa;
  --text-muted: #aba9be;
  --text-soft: rgba(230, 227, 250, 0.78);
  --primary: #ff9f4a;
  --primary-strong: #fd8b00;
  --primary-shadow: rgba(253, 139, 0, 0.28);
  --secondary: #dd8bfb;
  --secondary-deep: #6e208c;
  --shadow-xl: 0 28px 70px rgba(0, 0, 0, 0.46);
  --shadow-lg: 0 18px 40px rgba(0, 0, 0, 0.34);
  --glow-soft: 0 0 0 1px rgba(230, 227, 250, 0.06), 0 14px 36px rgba(0, 0, 0, 0.34);
  --glow-primary: 0 0 0 1px rgba(255, 159, 74, 0.18), 0 18px 40px rgba(253, 139, 0, 0.24);
  --radius-xl: 36px;
  --radius-lg: 28px;
  --radius-md: 22px;
  --radius-sm: 16px;
  --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
  --font-display: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-body: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  position: relative;
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(circle at 20% 12%, rgba(110, 32, 140, 0.18), transparent 24%),
    radial-gradient(circle at 82% 20%, rgba(253, 139, 0, 0.16), transparent 26%),
    radial-gradient(circle at 50% 100%, rgba(110, 32, 140, 0.12), transparent 38%),
    linear-gradient(180deg, #121224 0%, var(--bg) 48%, var(--bg-deep) 100%);
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  opacity: 0.22;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='80' viewBox='0 0 160 80'%3E%3Cg fill='none' stroke='%23e6e3fa' stroke-opacity='0.09' stroke-width='1.1'%3E%3Cpath d='M0 80c0-20 20-40 40-40s40 20 40 40'/%3E%3Cpath d='M40 80c0-20 20-40 40-40s40 20 40 40'/%3E%3Cpath d='M80 80c0-20 20-40 40-40s40 20 40 40'/%3E%3Cpath d='M120 80c0-20 20-40 40-40s40 20 40 40'/%3E%3Cpath d='M20 40C20 20 40 0 60 0s40 20 40 40'/%3E%3Cpath d='M60 40C60 20 80 0 100 0s40 20 40 40'/%3E%3Cpath d='M100 40c0-20 20-40 40-40s40 20 40 40'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 220px 110px;
  mix-blend-mode: screen;
}

body::after {
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 159, 74, 0.08), transparent 34%),
    radial-gradient(circle at 50% 100%, rgba(221, 139, 251, 0.08), transparent 36%);
}

button,
canvas {
  touch-action: manipulation;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--font-display);
}

h1 {
  font-size: clamp(3.2rem, 7vw, 5.5rem);
  line-height: 0.96;
  letter-spacing: -0.05em;
}

h2 {
  font-size: clamp(1.2rem, 2vw, 1.6rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

h3 {
  font-size: 1rem;
}

.app-shell {
  position: relative;
  width: 100%;
  height: 100vh;
  height: var(--viewport-height);
  padding: 0;
  overflow: hidden;
}

.app-shell.is-fullscreen {
  padding: 0;
}

.screen {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: none;
  overflow: hidden;
}

.screen.active {
  display: block;
}

.menu-surface,
.game-surface,
.status-pill,
.overlay-card {
  backdrop-filter: blur(20px);
}

.game-feedback {
  position: absolute;
  z-index: 2;
  right: 12px;
  bottom: 12px;
  left: 12px;
  width: fit-content;
  max-width: calc(100% - 24px);
  margin: 0 auto;
  padding: 8px 14px;
  border: 1px solid rgba(230, 227, 250, 0.12);
  border-radius: 999px;
  background: rgba(18, 18, 30, 0.88);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.32);
  color: var(--text-soft);
  font-size: clamp(0.76rem, 1.4vw, 0.9rem);
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
}

.game-feedback[data-feedback-type="good"] {
  border-color: rgba(255, 209, 102, 0.42);
  color: #fff2c2;
}

.game-feedback[data-feedback-type="bad"] {
  border-color: rgba(221, 139, 251, 0.46);
  color: #f2d9ff;
}

.game-feedback:empty,
.game-feedback.hidden {
  opacity: 0;
}

.menu-surface,
.game-surface {
  position: relative;
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  border-radius: 0;
  box-shadow: none;
}

.menu-surface {
  background:
    linear-gradient(rgba(10, 10, 20, 0.08), rgba(10, 10, 20, 0.18)),
    url("assets/background-snake-dojo.webp") 42% center / cover no-repeat;
}

.game-surface {
  background:
    linear-gradient(180deg, rgba(36, 36, 58, 0.84), rgba(18, 18, 35, 0.96)),
    linear-gradient(120deg, rgba(255, 159, 74, 0.05), transparent 26%),
    linear-gradient(240deg, rgba(221, 139, 251, 0.05), transparent 30%);
}

.menu-surface::before,
.game-surface::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.menu-surface::before {
  background:
    linear-gradient(180deg, rgba(10, 10, 20, 0.08), rgba(10, 10, 20, 0.24)),
    radial-gradient(circle at 50% 0%, rgba(255, 159, 74, 0.12), transparent 24%),
    radial-gradient(circle at 84% 18%, rgba(221, 139, 251, 0.06), transparent 22%);
}

.game-surface::before {
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 159, 74, 0.1), transparent 28%),
    radial-gradient(circle at 84% 18%, rgba(221, 139, 251, 0.08), transparent 24%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 38%);
}

.menu-surface > *,
.game-surface > * {
  position: relative;
  z-index: 1;
}

.menu-surface {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  align-content: center;
  justify-items: center;
  padding: clamp(36px, 5vh, 56px) clamp(22px, 4vw, 52px);
}

.game-surface {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(8px, 1.2vh, 14px);
  padding: clamp(18px, 2.2vh, 28px) clamp(16px, 2vw, 24px);
}

.screen-corner-controls {
  position: absolute;
  top: clamp(16px, 2.4vh, 26px);
  right: clamp(16px, 2.2vw, 24px);
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
}

.site-logo {
  position: absolute;
  top: clamp(14px, 2.2vh, 22px);
  left: clamp(16px, 2.2vw, 24px);
  z-index: 4;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  width: clamp(116px, 16vw, 168px);
  opacity: 0.92;
  filter: brightness(0) invert(1) drop-shadow(0 8px 18px rgba(0, 0, 0, 0.46));
}

.site-logo img {
  display: block;
  width: 100%;
  height: auto;
}

.menu-header {
  width: min(100%, 1040px);
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 8px;
  margin: auto 0 0;
}

.menu-hero {
  width: 100%;
  min-height: clamp(108px, 18vh, 166px);
  justify-content: center;
  align-items: center;
  display: flex;
}

#menu-title {
  display: inline-block;
  line-height: 1.08;
  padding-bottom: 0.12em;
  color: #ffd166;
  background: linear-gradient(180deg, #ffe29a 0%, #ffc15a 52%, #ffb347 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow:
    0 0 10px rgba(255, 180, 80, 0.4),
    0 0 20px rgba(255, 140, 60, 0.3),
    0 16px 40px rgba(0, 0, 0, 0.34);
  transition: text-shadow 220ms ease, filter 220ms ease;
}

.menu-subtitle {
  max-width: min(90%, 620px);
  margin: clamp(-30px, -3.6vh, -16px) 0 0;
  color: rgba(246, 243, 255, 0.9);
  font-size: clamp(1rem, 1.6vw, 1.22rem);
  font-weight: 700;
  line-height: 1.35;
  text-shadow: 0 3px 16px rgba(0, 0, 0, 0.56);
}

.menu-hero:hover #menu-title {
  text-shadow:
    0 0 14px rgba(255, 190, 100, 0.46),
    0 0 26px rgba(255, 150, 70, 0.34),
    0 18px 42px rgba(0, 0, 0, 0.34);
  filter: brightness(1.04);
}

.menu-core {
  width: min(100%, 920px);
  min-height: 0;
  display: grid;
  gap: clamp(24px, 4vh, 34px);
  align-content: center;
  justify-items: center;
  margin: auto 0;
}

.menu-selection-panel {
  width: 100%;
  padding: clamp(20px, 3vw, 30px);
  border-radius: 32px;
  background:
    linear-gradient(180deg, rgba(28, 28, 47, 0.78), rgba(20, 20, 35, 0.84)),
    linear-gradient(135deg, rgba(255, 159, 74, 0.03), transparent 42%);
  box-shadow: 0 0 0 1px rgba(230, 227, 250, 0.07), 0 18px 44px rgba(0, 0, 0, 0.34);
}

.selection-heading {
  display: grid;
  justify-items: center;
  gap: 0;
  margin-bottom: clamp(14px, 2vh, 18px);
  text-align: center;
}

.selection-heading h2 {
  color: var(--text);
}

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

.table-card {
  display: grid;
  gap: 8px;
  justify-items: center;
  align-content: center;
  min-height: 88px;
  padding: 18px 14px;
  border: 0;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(48, 48, 76, 0.96), rgba(31, 31, 52, 0.96)),
    linear-gradient(135deg, rgba(255, 159, 74, 0.02), transparent 60%);
  color: var(--text);
  font: inherit;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(230, 227, 250, 0.05), 0 16px 26px rgba(0, 0, 0, 0.24);
  transition:
    transform 260ms var(--ease-out-expo),
    box-shadow 260ms var(--ease-out-expo),
    background 260ms var(--ease-out-expo);
}

.table-card strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.table-card span {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.table-card:hover,
.table-card:focus-visible,
.primary-button:hover,
.secondary-button:hover,
.icon-button:hover,
.touch-button:hover {
  transform: translateY(-2px);
}

.table-card:hover,
.table-card:focus-visible {
  outline: none;
  background:
    linear-gradient(180deg, rgba(58, 58, 88, 0.98), rgba(37, 37, 60, 0.98)),
    linear-gradient(135deg, rgba(255, 159, 74, 0.04), transparent 62%);
  box-shadow: 0 0 0 1px rgba(230, 227, 250, 0.08), 0 18px 34px rgba(0, 0, 0, 0.32);
}

.table-card.selected {
  background:
    linear-gradient(180deg, rgba(76, 46, 23, 0.98), rgba(48, 30, 16, 0.98)),
    linear-gradient(135deg, rgba(255, 159, 74, 0.22), rgba(253, 139, 0, 0.06));
  box-shadow: var(--glow-primary);
}

.table-card.selected strong,
.table-card.selected span {
  color: #fff2e2;
}

.menu-cta {
  width: 100%;
  display: grid;
  justify-items: center;
}

.menu-meta {
  width: min(100%, 920px);
  margin: 0 auto;
  display: grid;
  justify-items: center;
  gap: 8px;
}

.menu-status-line {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.45;
  text-align: center;
}

.menu-status-line strong {
  color: var(--text-soft);
  font-weight: 700;
}

.site-footer {
  min-height: 32px;
  padding: 6px 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  color: rgba(230, 227, 250, 0.76);
  font-size: 0.86rem;
  line-height: 1.3;
}

.site-footer a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  color: #ffd166;
  font-weight: 700;
  text-decoration: none;
}

.site-footer a:hover,
.site-footer a:focus-visible {
  text-decoration: underline;
  outline: none;
}

.primary-button,
.secondary-button,
.icon-button,
.touch-button {
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 260ms var(--ease-out-expo),
    box-shadow 260ms var(--ease-out-expo),
    background 260ms var(--ease-out-expo),
    opacity 220ms ease;
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 48px;
  padding: 0 18px;
}

.rules-button {
  min-height: 44px;
}

.primary-button {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #341700;
  box-shadow: 0 18px 34px rgba(253, 139, 0, 0.28);
}

.primary-button:hover,
.primary-button:focus-visible {
  outline: none;
  box-shadow: 0 22px 40px rgba(253, 139, 0, 0.34);
}

.menu-cta .primary-button {
  min-height: 64px;
  min-width: min(100%, 310px);
  padding: 0 36px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 1.08rem;
  letter-spacing: -0.02em;
}

.primary-button:disabled {
  background: linear-gradient(135deg, rgba(93, 71, 54, 0.8), rgba(74, 55, 41, 0.8));
  color: rgba(230, 227, 250, 0.5);
  box-shadow: none;
  opacity: 0.88;
  cursor: not-allowed;
  transform: none;
}

.secondary-button,
.icon-button {
  background:
    linear-gradient(180deg, rgba(48, 48, 76, 0.92), rgba(28, 28, 47, 0.92)),
    linear-gradient(135deg, rgba(221, 139, 251, 0.12), transparent 48%);
  color: var(--text-soft);
  box-shadow: 0 0 0 1px rgba(230, 227, 250, 0.06), 0 12px 24px rgba(0, 0, 0, 0.28);
}

.secondary-button:hover,
.secondary-button:focus-visible,
.icon-button:hover,
.icon-button:focus-visible {
  outline: none;
  background:
    linear-gradient(180deg, rgba(58, 58, 88, 0.94), rgba(34, 34, 54, 0.94)),
    linear-gradient(135deg, rgba(221, 139, 251, 0.16), transparent 48%);
}

.small-button {
  min-height: 44px;
  padding: 0 16px;
  font-size: 0.9rem;
}

.fullscreen-toggle {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}

.fullscreen-toggle[aria-pressed="true"] {
  box-shadow: 0 0 0 1px rgba(255, 159, 74, 0.18), 0 16px 32px rgba(253, 139, 0, 0.22);
}

.game-hud {
  display: grid;
  gap: clamp(10px, 1.6vh, 16px);
  padding: clamp(12px, 1.8vh, 20px) clamp(12px, 1.4vw, 16px) 0;
}

.hud-task {
  order: 2;
  width: fit-content;
  max-width: min(94%, 760px);
  margin: 0 auto;
  padding: clamp(8px, 1.3vh, 14px) clamp(24px, 4vw, 48px);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(48, 43, 70, 0.9), rgba(18, 18, 32, 0.74)),
    radial-gradient(circle at 50% 0%, rgba(255, 159, 74, 0.26), transparent 58%);
  box-shadow:
    0 0 0 2px rgba(255, 209, 102, 0.2),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05),
    0 18px 42px rgba(0, 0, 0, 0.34),
    0 0 44px rgba(255, 159, 74, 0.18);
  text-align: center;
  backdrop-filter: blur(18px);
}

.equation-main {
  font-size: clamp(2.6rem, 5.2vw, 4.25rem);
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.05em;
  color: #ffd166;
  background: linear-gradient(180deg, #ffe29a 0%, #ffc15a 52%, #ffb347 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow:
    0 0 10px rgba(255, 180, 80, 0.4),
    0 0 20px rgba(255, 140, 60, 0.3),
    0 16px 40px rgba(0, 0, 0, 0.34);
}

.equation-sub {
  margin-top: 6px;
  min-height: 1em;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.3;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.equation-sub:empty {
  display: none;
}

.hud-inline {
  order: 1;
  width: min(100%, 1040px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
}

.hud-status-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  grid-column: 2;
  justify-self: center;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  grid-column: 3;
  justify-self: end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(38, 38, 62, 0.88);
  box-shadow: 0 0 0 1px rgba(230, 227, 250, 0.08), 0 10px 22px rgba(0, 0, 0, 0.24);
}

.pill-label {
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.status-pill strong {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text);
}

#back-button {
  white-space: nowrap;
}

.game-main {
  min-height: 0;
  display: grid;
}

.board-stage {
  min-height: 0;
  display: grid;
  place-items: start center;
  padding: 0;
}

.board-shell {
  position: relative;
  width: min(100%, 74vh, 84vw, 900px);
  height: auto;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: clamp(12px, 1.6vw, 18px);
  border-radius: 34px;
  background:
    linear-gradient(180deg, rgba(30, 30, 49, 0.98), rgba(16, 16, 28, 0.98)),
    radial-gradient(circle at 50% 0%, rgba(255, 159, 74, 0.06), transparent 38%),
    radial-gradient(circle at 100% 0%, rgba(221, 139, 251, 0.05), transparent 34%);
  box-shadow: 0 0 0 1px rgba(230, 227, 250, 0.08), 0 26px 60px rgba(0, 0, 0, 0.42);
}

.board-shell::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 20%),
    radial-gradient(circle at 50% 100%, rgba(110, 32, 140, 0.1), transparent 34%);
  pointer-events: none;
}

#game-canvas {
  position: relative;
  z-index: 1;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border-radius: 26px;
  background: transparent;
  box-shadow: inset 0 0 0 1px rgba(230, 227, 250, 0.09);
}

.overlay-card {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  width: min(90%, 430px);
  padding: clamp(22px, 3vw, 28px);
  border-radius: 30px;
  background:
    linear-gradient(180deg, rgba(36, 36, 58, 0.82), rgba(18, 18, 30, 0.84)),
    linear-gradient(135deg, rgba(255, 159, 74, 0.08), transparent 46%),
    linear-gradient(220deg, rgba(221, 139, 251, 0.08), transparent 42%);
  box-shadow: 0 0 0 1px rgba(230, 227, 250, 0.08), 0 30px 60px rgba(0, 0, 0, 0.44);
  text-align: center;
}

.rules-modal {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(9, 9, 22, 0.58);
}

.rules-modal.hidden {
  display: none;
}

.rules-card {
  width: min(92%, 460px);
  padding: clamp(22px, 3vw, 30px);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(36, 36, 58, 0.94), rgba(18, 18, 30, 0.96)),
    linear-gradient(135deg, rgba(255, 159, 74, 0.08), transparent 46%);
  box-shadow: 0 0 0 1px rgba(230, 227, 250, 0.08), 0 30px 60px rgba(0, 0, 0, 0.48);
  text-align: center;
}

.rules-card h2 {
  color: var(--text);
}

.rules-card p {
  margin: 12px 0 0;
  color: var(--text-soft);
  line-height: 1.5;
}

.rules-card .primary-button {
  margin-top: 20px;
}

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

.overlay-card h2 {
  color: var(--text);
}

.overlay-card p {
  margin: 10px 0 0;
  color: var(--text-muted);
  line-height: 1.55;
}

.overlay-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 20px;
}

.game-bottom-ui {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.legacy-helper {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.touch-controls {
  display: none;
  grid-template-columns: repeat(3, minmax(60px, 76px));
  grid-template-rows: repeat(2, minmax(48px, 54px));
  gap: 9px;
}

@media (hover: none) and (pointer: coarse) {
  .touch-controls {
    display: grid;
  }
}

.touch-button {
  min-height: 48px;
  padding: 0 10px;
  background:
    linear-gradient(180deg, rgba(58, 58, 88, 0.94), rgba(34, 34, 56, 0.94)),
    linear-gradient(135deg, rgba(255, 159, 74, 0.1), transparent 54%);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  box-shadow: 0 0 0 1px rgba(230, 227, 250, 0.08), 0 12px 24px rgba(0, 0, 0, 0.26);
}

.touch-up {
  grid-column: 2;
  grid-row: 1;
}

.touch-left {
  grid-column: 1;
  grid-row: 2;
}

.touch-right {
  grid-column: 3;
  grid-row: 2;
}

.touch-down {
  grid-column: 2;
  grid-row: 2;
}

.flash-good {
  animation: pulse-good 350ms ease;
}

.flash-bad {
  animation: pulse-bad 420ms ease;
}

.app-shell.is-fullscreen .menu-surface,
.app-shell.is-fullscreen .game-surface {
  width: 100%;
  max-width: none;
  border-radius: 0;
  box-shadow: none;
}

.app-shell.is-fullscreen .menu-surface,
.app-shell.is-fullscreen .game-surface {
  min-height: 100vh;
  min-height: 100dvh;
}

.app-shell.is-fullscreen .menu-surface {
  padding: clamp(24px, 3vh, 32px);
}

.app-shell.is-fullscreen .game-surface {
  padding: clamp(18px, 2vh, 24px);
}

.app-shell.is-fullscreen .board-shell {
  width: min(100%, 79dvh, 88vw, 980px);
}

@keyframes pulse-good {
  0% { transform: scale(1); }
  40% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

@keyframes pulse-bad {
  0% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  100% { transform: translateX(0); }
}

@media (max-width: 1040px) {
  .table-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (max-width: 920px) {
  .menu-surface,
  .game-surface {
    border-radius: 0;
  }

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

  .board-shell {
    width: min(100%, 70vh, 90vw, 760px);
  }
}

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

  .menu-surface,
  .game-surface {
    padding-inline: 14px;
  }

  .site-logo {
    width: 104px;
  }

  .screen-corner-controls {
    top: 12px;
    right: 12px;
  }

  .rules-button {
    padding-inline: 12px;
  }

  .menu-header {
    gap: 10px;
  }

  .menu-hero {
    min-height: clamp(126px, 22vh, 170px);
  }

  .menu-subtitle {
    max-width: 92%;
    margin-top: -6px;
    font-size: 0.98rem;
  }

  .menu-selection-panel {
    padding: 18px 14px;
  }

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

  .table-card {
    min-height: 78px;
    padding: 14px 10px;
  }

  .table-card span {
    font-size: 0.68rem;
  }

  .menu-cta {
    width: 100%;
  }

  .menu-cta .primary-button {
    width: 100%;
    min-width: 0;
  }

  .game-surface {
    gap: 10px;
  }

  .hud-task {
    padding: 8px 22px;
    border-radius: 24px;
  }

  .equation-main {
    font-size: clamp(2.2rem, 9vw, 3rem);
  }

  .hud-inline,
  .hud-status-group,
  .hud-actions {
    width: 100%;
    justify-content: center;
  }

  .hud-inline {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }

  .hud-actions #back-button {
    width: 100%;
  }

  .board-shell {
    width: min(100%, 62vh, 96vw, 620px);
    padding: 10px;
    border-radius: 26px;
  }

  #game-canvas {
    border-radius: 22px;
  }

  .overlay-card {
    width: min(92%, 360px);
  }

  .touch-controls {
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(50px, 54px));
  }
}

@media (max-width: 480px) {
  .menu-surface {
    padding-top: 18px;
    padding-bottom: 12px;
  }

  .menu-core {
    gap: 14px;
  }

  #menu-title {
    font-size: clamp(2.65rem, 13vw, 3.2rem);
  }

  .menu-subtitle {
    font-size: 0.88rem;
  }

  .menu-selection-panel {
    padding: 16px 12px;
    border-radius: 26px;
  }

  .table-card {
    min-height: 68px;
    border-radius: 20px;
  }

  .menu-meta {
    gap: 2px;
  }

  .menu-status-line {
    display: none;
  }

  .site-footer {
    font-size: 0.76rem;
  }
}

@media (max-height: 820px) {
  .menu-surface {
    padding-top: clamp(28px, 4vh, 38px);
    padding-bottom: clamp(22px, 4vh, 32px);
  }

  .menu-core {
    gap: 22px;
  }

  .menu-hero {
    min-height: clamp(88px, 15vh, 128px);
  }

  .menu-selection-panel {
    padding-top: 18px;
    padding-bottom: 18px;
  }

  .menu-status-line {
    display: none;
  }

  .site-footer {
    padding-top: 2px;
    padding-bottom: 2px;
  }

  .game-surface {
    gap: 8px;
    padding-top: 14px;
    padding-bottom: 12px;
  }

  .game-hud {
    gap: 8px;
    padding-top: 10px;
  }

  .hud-task {
    padding: 6px clamp(18px, 3vw, 34px);
  }

  .equation-main {
    font-size: clamp(2rem, 4.6vw, 3rem);
  }

  .board-shell {
    width: min(100%, 66vh, 84vw, 720px);
  }
}

@media (max-height: 820px) and (hover: none) and (pointer: coarse) {
  .board-shell {
    width: min(100%, 58vh, 80vw, 680px);
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (min-width: 760px) {
  .game-surface {
    grid-template-columns: minmax(0, 1fr) minmax(176px, 220px);
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: clamp(10px, 2vw, 22px);
    row-gap: 8px;
  }

  .game-hud {
    grid-column: 1 / -1;
    gap: 8px;
  }

  .hud-task {
    padding-block: 6px;
  }

  .game-main {
    grid-column: 1;
    grid-row: 2;
  }

  .game-bottom-ui {
    grid-column: 2;
    grid-row: 2;
    align-self: center;
    justify-self: stretch;
  }

  .board-stage {
    justify-items: end;
    padding: 0;
  }

  .board-shell {
    width: min(100%, 74dvh, 64vw, 620px);
  }

  .touch-controls {
    width: 100%;
    grid-template-columns: repeat(3, minmax(48px, 1fr));
    grid-template-rows: repeat(2, 54px);
    gap: 10px;
  }

  .touch-button {
    min-height: 54px;
    font-size: 0.8rem;
  }
}

@media (max-height: 700px) {
  .menu-header {
    gap: 4px;
  }

  .menu-hero {
    min-height: auto;
  }

  .menu-subtitle {
    display: none;
  }

  .table-card {
    min-height: 72px;
    padding: 12px 10px;
  }

  .table-card span {
    display: none;
  }

  .equation-main {
    font-size: clamp(1.9rem, 4.8vw, 2.7rem);
  }

  .status-pill {
    min-height: 38px;
  }

  .board-shell {
    width: min(100%, 60vh, 78vw, 620px);
  }

  .touch-controls {
    grid-template-rows: repeat(2, 44px);
  }

  .touch-button {
    min-height: 44px;
    font-size: 0.72rem;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: portrait) and (min-width: 700px) {
  .board-shell {
    width: min(92vw, 62dvh, 720px);
  }

  .touch-controls {
    grid-template-rows: repeat(2, minmax(48px, 54px));
  }
}

@media (max-height: 499px) {
  .screen.active {
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .menu-surface,
  .game-surface {
    height: auto;
    min-height: 100%;
    overflow: visible;
  }

  .menu-surface {
    min-height: 560px;
  }

  .game-surface {
    min-height: 500px;
  }
}
