:root {
  --ink-900: #14212f;
  --ink-800: #1d3040;
  --ink-700: #274456;
  --parchment: #f6ebcf;
  --parchment-strong: #fff7e5;
  --paper: rgba(246, 237, 214, 0.88);
  --paper-soft: rgba(255, 248, 230, 0.94);
  --panel: rgba(14, 28, 42, 0.86);
  --panel-strong: rgba(11, 22, 33, 0.95);
  --line: rgba(244, 208, 133, 0.26);
  --line-strong: rgba(244, 208, 133, 0.48);
  --jade: #26b8b0;
  --jade-soft: #8de6dc;
  --vermillion: #d35341;
  --gold: #e9c26e;
  --success: #3fa86f;
  --warning: #d9b34f;
  --incorrect: #6a7586;
  --danger: #d95b53;
  --shadow-lg: 0 28px 60px rgba(5, 11, 20, 0.38);
  --shadow-md: 0 18px 34px rgba(5, 11, 20, 0.28);
  --radius: 18px;
  --radius-sm: 12px;
  --cell-size: clamp(31px, 5vw, 50px);
  --app-height: 100svh;
  font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--parchment);
  background: #0d1824;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: var(--app-height);
  color: var(--parchment);
  background:
    radial-gradient(circle at top, rgba(44, 90, 109, 0.32), transparent 30%),
    linear-gradient(180deg, #0f1b28 0%, #122234 52%, #0a131f 100%);
}

button {
  font: inherit;
}

a {
  color: inherit;
}

.screen {
  position: relative;
  min-height: var(--app-height);
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: clamp(10px, 2vw, 22px);
  overflow: hidden;
  isolation: isolate;
}

.screen::before,
.screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.menu-screen::before {
  background:
    linear-gradient(180deg, rgba(8, 16, 25, 0.12), rgba(8, 16, 25, 0.5)),
    url("assets/control-room-menu-bg-v2.webp") center / cover no-repeat;
  z-index: -2;
}

.menu-screen::after {
  background:
    radial-gradient(circle at top, rgba(255, 244, 214, 0.24), transparent 32%),
    linear-gradient(180deg, rgba(9, 19, 29, 0.08), rgba(9, 19, 29, 0.32));
  z-index: -1;
}

.game-screen::before {
  background:
    linear-gradient(180deg, rgba(18, 31, 45, 0.18), rgba(18, 31, 45, 0.3)),
    url("assets/control-room-gameplay-bg-v2.webp") center / cover no-repeat;
  z-index: -2;
}

.game-screen::after {
  background:
    radial-gradient(circle at center, rgba(255, 241, 209, 0.22), transparent 42%),
    linear-gradient(180deg, rgba(29, 47, 64, 0.06), rgba(29, 47, 64, 0.18));
  z-index: -1;
}

.app-shell {
  min-height: var(--app-height);
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.brand-header {
  min-height: 62px;
  display: flex;
  align-items: flex-start;
}

.site-logo {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 248, 230, 0.98), rgba(241, 227, 194, 0.94));
  box-shadow:
    inset 0 0 0 1px rgba(190, 144, 61, 0.18),
    0 12px 30px rgba(7, 12, 19, 0.22);
}

.site-logo img {
  width: clamp(88px, 13vw, 144px);
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.28));
}

.control-room-shell {
  position: relative;
}

.menu-shell,
.game-shell {
  align-self: center;
  justify-self: center;
  width: min(1120px, 100%);
}

.menu-shell {
  display: grid;
  gap: 12px;
}

.mission-panel,
.briefing-module,
.briefing-panel,
.hud-panel,
.board-panel,
.dock-panel,
.result-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.mission-panel {
  padding: clamp(18px, 3vw, 30px);
  text-align: center;
  background:
    linear-gradient(180deg, rgba(12, 24, 35, 0.82), rgba(12, 24, 35, 0.64)),
    radial-gradient(circle at top, rgba(247, 231, 189, 0.08), transparent 46%);
  backdrop-filter: blur(5px);
}

.control-room-tag,
.panel-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.75rem;
  font-weight: 900;
}

.control-room-tag {
  color: var(--gold);
}

.mission-panel h1 {
  margin: 0;
  color: var(--parchment-strong);
  font-size: clamp(3rem, 7vw, 5.1rem);
  line-height: 0.92;
  text-shadow: 0 10px 26px rgba(7, 12, 19, 0.34);
}

.compact-hero {
  width: min(520px, 100%);
  justify-self: center;
  padding: 14px 20px 12px;
  border-radius: 22px;
}

.compact-hero .control-room-tag {
  margin-bottom: 6px;
}

.compact-hero h1 {
  font-size: clamp(3rem, 6.2vw, 4.6rem);
}

.menu-main {
  width: min(860px, 100%);
  justify-self: center;
  display: grid;
  gap: 10px;
}

.level-sections {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 14px;
}

.symmetric-level-sections {
  width: 100%;
}

.briefing-module,
.briefing-panel {
  background:
    linear-gradient(180deg, rgba(11, 23, 34, 0.9), rgba(15, 31, 45, 0.8)),
    linear-gradient(180deg, rgba(244, 208, 133, 0.05), transparent);
  backdrop-filter: blur(7px);
}

.briefing-module {
  padding: 16px;
}

.level-card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.level-card h2,
.briefing-panel h2,
.board-heading h2,
.result-panel h2 {
  margin: 4px 0 0;
}

.level-card h2 {
  color: var(--parchment-strong);
  font-size: 1.45rem;
}

.panel-kicker {
  color: rgba(246, 237, 214, 0.56);
}

.operation-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  color: var(--ink-900);
  background: linear-gradient(180deg, var(--gold), #f6dca1);
  box-shadow:
    inset 0 -4px 10px rgba(156, 102, 18, 0.18),
    0 10px 18px rgba(6, 13, 22, 0.22);
  font-size: 1.6rem;
  font-weight: 900;
}

.level-buttons {
  display: grid;
  gap: 10px;
}

.level-button,
.primary-button,
.ghost-button,
.small-button,
.icon-button,
.pad-key,
.digit-cell {
  border: 0;
  cursor: pointer;
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

.level-button {
  display: grid;
  grid-template-columns: 14px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 0 14px;
  border: 1px solid rgba(233, 194, 110, 0.18);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(250, 241, 218, 0.98), rgba(241, 226, 192, 0.96));
  color: var(--ink-900);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.38),
    0 8px 18px rgba(4, 10, 18, 0.18);
  text-align: left;
}

.level-button:hover,
.level-button.is-current {
  transform: translateY(-1px);
  border-color: rgba(38, 184, 176, 0.52);
  box-shadow:
    inset 0 0 0 1px rgba(141, 230, 220, 0.34),
    0 18px 24px rgba(9, 16, 24, 0.18);
}

.level-button.is-current {
  background:
    linear-gradient(180deg, rgba(244, 249, 244, 0.98), rgba(228, 244, 239, 0.98));
}

.level-label {
  font-weight: 900;
}

.difficulty-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(16, 27, 39, 0.05);
}

.difficulty-dot.easy {
  background: var(--success);
}

.difficulty-dot.medium {
  background: var(--warning);
}

.difficulty-dot.hard {
  background: var(--danger);
}

.briefing-panel {
  padding: 14px 16px;
  display: grid;
  gap: 12px;
}

.briefing-dropdown {
  padding: 0;
  overflow: hidden;
}

.full-width {
  width: 100%;
}

.help-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 12px 18px 9px;
  cursor: pointer;
  color: var(--parchment-strong);
  font-size: 1.05rem;
  font-weight: 900;
}

.help-summary::-webkit-details-marker {
  display: none;
}

.help-summary-icon {
  font-size: 1rem;
  transition: transform 140ms ease;
}

.briefing-dropdown[open] .help-summary-icon {
  transform: rotate(180deg);
}

.briefing-dropdown .briefing-copy,
.briefing-dropdown .legend-panel {
  padding-left: 18px;
  padding-right: 18px;
}

.briefing-dropdown .briefing-copy {
  padding-top: 0;
  padding-bottom: 6px;
}

.briefing-dropdown .legend-panel {
  padding-bottom: 18px;
}

.briefing-copy ol {
  display: grid;
  gap: 7px;
  margin: 2px 0 0;
  padding-left: 22px;
  color: rgba(246, 237, 214, 0.9);
  font-size: 0.98rem;
  line-height: 1.4;
}

.legend-panel {
  padding-top: 2px;
  border-top: 1px solid rgba(233, 194, 110, 0.16);
}

.legend,
.dock-legend {
  display: grid;
  gap: 10px;
  color: rgba(246, 237, 214, 0.9);
  font-size: 0.93rem;
  font-weight: 800;
}

.legend span,
.dock-legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.swatch.correct {
  background: var(--success);
}

.swatch.misplaced {
  background: var(--warning);
}

.swatch.incorrect {
  background: var(--incorrect);
}

.game-screen {
  place-items: center;
}

.game-shell {
  display: grid;
  gap: 12px;
  min-height: min(760px, calc(var(--app-height) - 24px));
  align-content: start;
}

.hud-panel {
  display: grid;
  grid-template-columns: 52px 1fr 64px;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: linear-gradient(180deg, rgba(11, 22, 33, 0.92), rgba(16, 31, 45, 0.86));
}

.game-title {
  text-align: center;
  display: grid;
  gap: 4px;
}

.game-title p,
.game-title strong {
  margin: 0;
}

.game-title strong {
  color: var(--parchment-strong);
  font-size: clamp(1rem, 2.2vw, 1.18rem);
  font-weight: 900;
}

.icon-button,
.small-button {
  min-height: 46px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(249, 238, 213, 0.96), rgba(231, 215, 178, 0.96));
  color: var(--ink-900);
  font-weight: 900;
  box-shadow:
    inset 0 0 0 1px rgba(233, 194, 110, 0.3),
    0 8px 16px rgba(5, 11, 20, 0.24);
}

.hud-button {
  border: 1px solid rgba(233, 194, 110, 0.18);
}

.icon-button {
  font-size: 1.35rem;
}

.small-button {
  font-size: 0.92rem;
}

.hud-spacer {
  min-height: 46px;
}

.stats-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.status-pill {
  min-height: 38px;
  padding: 8px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 999px;
  background: rgba(11, 22, 33, 0.84);
  color: rgba(246, 237, 214, 0.88);
  box-shadow: inset 0 0 0 1px rgba(233, 194, 110, 0.18);
  font-size: 0.94rem;
}

.status-pill strong {
  color: var(--parchment-strong);
}

.playfield-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 308px);
  gap: 14px;
  min-height: 0;
  align-items: stretch;
}

.board-panel {
  display: grid;
  background:
    linear-gradient(180deg, rgba(11, 22, 33, 0.42), rgba(11, 22, 33, 0.3));
}

.board-frame {
  padding: 16px;
  display: grid;
  gap: 10px;
  min-height: 0;
  border-radius: inherit;
  background:
    linear-gradient(180deg, rgba(223, 207, 170, 0.94), rgba(204, 184, 142, 0.9));
  color: var(--ink-900);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.42),
    inset 0 0 0 6px rgba(13, 23, 35, 0.08);
}

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

.board-heading h2 {
  color: var(--ink-800);
  font-size: clamp(1.55rem, 2.8vw, 2rem);
}

.board-wrap {
  overflow: auto;
  padding: 6px 4px;
  display: grid;
  place-items: center;
  min-height: 0;
}

.board {
  --board-cell-size: var(--cell-size);
  --board-gap: clamp(4px, 1vw, 8px);
  display: grid;
  gap: var(--board-gap);
  width: max-content;
  min-width: 100%;
  justify-content: center;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--board-cell-size));
  gap: var(--board-gap);
  justify-content: center;
  align-items: center;
}

.board.cols-8 {
  --cols: 8;
}

.board.cols-11 {
  --cols: 11;
  --board-cell-size: clamp(29px, 3.4vw, 44px);
  --board-gap: clamp(3px, 0.7vw, 6px);
}

.board.cols-12 {
  --cols: 12;
  --board-cell-size: clamp(27px, 3.1vw, 40px);
  --board-gap: clamp(3px, 0.6vw, 6px);
}

.digit-cell,
.operator-cell {
  width: var(--board-cell-size);
  height: clamp(40px, 6.2vw, 54px);
  display: grid;
  place-items: center;
  border-radius: 14px;
  font-size: clamp(1.1rem, 3.2vw, 1.8rem);
  font-weight: 900;
}

.digit-cell {
  border: 2px solid rgba(32, 58, 73, 0.18);
  background: rgba(255, 250, 239, 0.92);
  color: var(--ink-900);
  box-shadow: inset 0 -4px 10px rgba(132, 112, 68, 0.05);
}

.operator-cell {
  color: var(--ink-800);
  font-size: clamp(1.3rem, 3vw, 2rem);
}

.digit-cell.filled {
  border-color: rgba(38, 184, 176, 0.48);
  background: #fffdf8;
}

.digit-cell.selected {
  border-color: var(--jade);
  background: #f3fffd;
  box-shadow: 0 0 0 4px rgba(38, 184, 176, 0.18);
}

.digit-cell.correct,
.digit-cell.misplaced,
.digit-cell.incorrect {
  color: white;
  border-color: transparent;
}

.digit-cell.correct {
  background: var(--success);
}

.digit-cell.misplaced {
  background: var(--warning);
  color: var(--ink-900);
}

.digit-cell.incorrect {
  background: var(--incorrect);
}

.digit-cell.invalid {
  border-color: var(--danger);
  background: rgba(217, 91, 83, 0.16);
}

.message-line {
  min-height: 26px;
  text-align: center;
  color: var(--ink-700);
  font-size: clamp(0.86rem, 2vw, 0.98rem);
  font-weight: 800;
}

.message-line.error {
  color: var(--danger);
}

.message-line.success {
  color: #2e7d57;
}

.control-dock,
.result-panel {
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(11, 22, 33, 0.94), rgba(16, 31, 45, 0.9)),
    radial-gradient(circle at top, rgba(246, 227, 172, 0.05), transparent 36%);
}

.control-dock {
  display: grid;
  gap: 12px;
  align-content: start;
}

.dock-header {
  display: grid;
  gap: 4px;
}

.dock-header strong {
  color: var(--parchment-strong);
  font-size: 1.05rem;
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(48px, 1fr));
  gap: 8px;
  width: 100%;
}

.pad-key {
  min-height: clamp(48px, 7vw, 58px);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(250, 241, 218, 0.98), rgba(234, 218, 182, 0.98));
  color: var(--ink-900);
  font-size: clamp(1.12rem, 3vw, 1.55rem);
  font-weight: 900;
  box-shadow:
    inset 0 0 0 1px rgba(233, 194, 110, 0.24),
    0 8px 16px rgba(4, 10, 18, 0.2);
}

.pad-key:hover,
.icon-button:hover,
.small-button:hover,
.primary-button:hover,
.ghost-button:hover,
.level-button:hover {
  transform: translateY(-1px);
}

.delete-key {
  grid-column: span 1;
  background: linear-gradient(180deg, #f6c1b7, #e98772);
  color: #591a12;
  font-size: 0.92rem;
}

.enter-key {
  grid-column: span 2;
  background: linear-gradient(180deg, #3fd2c7, #1faaa2);
  color: #f7fffd;
}

.result-panel {
  display: grid;
  gap: 8px;
  align-content: center;
  text-align: center;
}

.result-panel h2,
.result-panel p {
  margin: 0;
}

.result-panel h2 {
  color: var(--parchment-strong);
}

.result-panel p {
  color: rgba(246, 237, 214, 0.9);
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button {
  min-height: 46px;
  padding: 0 18px;
  border-radius: 14px;
  font-weight: 900;
}

.primary-button {
  background: linear-gradient(180deg, #3cd2c6, #1ba49d);
  color: white;
}

.ghost-button {
  background: rgba(247, 237, 212, 0.96);
  color: var(--ink-900);
  box-shadow: inset 0 0 0 1px rgba(233, 194, 110, 0.24);
}

.site-footer {
  flex-shrink: 0;
  min-height: 32px;
  padding: 8px 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  color: rgba(246, 237, 214, 0.88);
  font-size: 0.9rem;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.25);
}

.site-footer a {
  font-weight: 800;
}

@media (max-width: 960px) {
  .playfield-grid {
    grid-template-columns: 1fr;
  }

  .menu-main {
    width: min(720px, 100%);
  }

  .control-dock,
  .result-panel {
    width: min(100%, 720px);
    justify-self: center;
  }

  .number-pad {
    grid-template-columns: repeat(4, minmax(48px, 1fr));
  }

  .delete-key {
    grid-column: span 2;
  }

  .enter-key {
    grid-column: span 4;
  }
}

@media (max-width: 760px) {
  .level-sections {
    grid-template-columns: 1fr;
  }

  .brand-header {
    min-height: 58px;
  }

  .mission-panel {
    padding: 18px 14px;
  }

  .compact-hero {
    width: 100%;
    padding: 14px 16px 12px;
  }
}

@media (max-width: 640px) {
  .screen {
    padding: 8px;
  }

  .hud-panel {
    grid-template-columns: 44px 1fr 48px;
    padding: 8px;
  }

  .board-frame,
  .control-dock,
  .result-panel,
  .briefing-module,
  .briefing-panel {
    padding: 12px;
  }

  .site-footer {
    flex-wrap: wrap;
  }
}

@media (max-height: 820px) and (min-width: 961px) {
  .game-screen {
    padding: 9px;
  }

  .game-shell {
    gap: 8px;
  }

  .hud-panel {
    padding: 8px 10px;
  }

  .status-pill {
    min-height: 34px;
    padding: 6px 12px;
  }

  .board-frame,
  .control-dock,
  .result-panel {
    padding: 12px;
    gap: 8px;
  }

  .message-line {
    min-height: 22px;
  }
}

@media (max-width: 520px) {
  :root {
    --cell-size: clamp(27px, 7.4vw, 36px);
  }

  .mission-panel h1 {
    font-size: clamp(2.5rem, 16vw, 4rem);
  }

  .number-pad {
    gap: 6px;
  }

  .digit-cell,
  .operator-cell {
    height: 40px;
    border-radius: 10px;
  }

  .board,
  .board-row {
    gap: 3px;
  }
}

@media (min-width: 768px) and (orientation: landscape) {
  .game-shell {
    min-height: min(790px, calc(var(--app-height) - 18px));
  }
}

@media (min-width: 1080px) and (orientation: landscape) {
  .game-shell {
    width: min(1180px, 100%);
  }
}

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