:root {
  --ink: #17212b;
  --muted: #607080;
  --panel: #ffffff;
  --page: #edf1f3;
  --road: #243343;
  --road-dark: #192531;
  --line: #d8e0e5;
  --accent: #e6a500;
  --accent-dark: #b57d00;
  --safe: #f7f9fa;
  --revealed: #e8eef1;
  --danger: #b6322c;
  --success: #33704a;
  --shadow: 0 18px 45px rgba(23, 33, 43, 0.13);
  --radius: 18px;
  --cell-size: 44px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(230, 165, 0, 0.12), transparent 28rem),
    var(--page);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.5;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.game-shell {
  width: min(1080px, calc(100% - 24px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.game-header {
  margin-bottom: 18px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 2px;
  color: var(--road-dark);
  font-size: clamp(2rem, 6vw, 3.4rem);
  line-height: 1.05;
}

.subtitle {
  margin-bottom: 0;
  color: var(--muted);
  font-size: clamp(1rem, 3vw, 1.2rem);
}

.game-card {
  overflow: hidden;
  padding: clamp(18px, 4vw, 32px);
  border: 1px solid rgba(23, 33, 43, 0.08);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.game-intro {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.game-intro h2 {
  margin-bottom: 6px;
  font-size: clamp(1.25rem, 3vw, 1.65rem);
}

.game-intro p {
  max-width: 700px;
  margin-bottom: 0;
  color: var(--muted);
}

.text-button {
  flex: 0 0 auto;
  padding: 6px 0;
  border: 0;
  border-bottom: 2px solid var(--accent);
  color: var(--road);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}

.text-button:hover,
.text-button:focus-visible {
  color: var(--accent-dark);
}


.rules-panel[hidden],
.completion-panel[hidden] {
  display: none;
}

.rules-panel {
  margin-top: 16px;
  padding: 16px 18px;
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: #fff8e5;
}

.rules-panel p:last-child {
  margin-bottom: 0;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 22px;
}

.control-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.control-group legend {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--safe);
}

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

.segment {
  min-height: 44px;
  padding: 9px 12px;
  border: 0;
  border-right: 1px solid var(--line);
  color: var(--road);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}

.segment:last-child {
  border-right: 0;
}

.segment:hover {
  background: #f0f4f6;
}

.segment.is-active {
  color: #ffffff;
  background: var(--road);
}

.segment:focus-visible,
.mode-button:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.cell:focus-visible,
.back-link:focus-visible {
  outline: 3px solid rgba(230, 165, 0, 0.65);
  outline-offset: 2px;
}

.challenge-strip {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin: 20px 0 12px;
  padding: 12px 16px;
  border-radius: 10px;
  color: #ffffff;
  background: var(--road);
}

.challenge-strip > div:last-child {
  text-align: right;
}

.meta-label {
  display: block;
  color: #c7d0d7;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.dashboard {
  display: grid;
  grid-template-columns: 105px 105px 105px 1fr;
  gap: 10px;
}

.stat {
  min-height: 72px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--safe);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.stat-value {
  display: block;
  margin-top: 3px;
  font-size: 1.45rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.stat-message {
  display: block;
  margin-top: 5px;
  font-weight: 700;
}

.action-row {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 14px;
  margin: 16px 0;
}

.tap-mode {
  display: flex;
  gap: 8px;
}

.mode-button,
.primary-button,
.secondary-button {
  min-height: 46px;
  border-radius: 10px;
  font-weight: 900;
  cursor: pointer;
}

.mode-button {
  padding: 10px 15px;
  border: 1px solid var(--line);
  color: var(--road);
  background: var(--panel);
}

.mode-button.is-active {
  border-color: var(--accent-dark);
  color: var(--road-dark);
  background: #fff3c9;
  box-shadow: inset 0 0 0 1px var(--accent);
}

.primary-button {
  padding: 10px 20px;
  border: 1px solid var(--road-dark);
  color: #ffffff;
  background: var(--road);
}

.primary-button:hover {
  background: var(--road-dark);
}

.secondary-button {
  padding: 9px 18px;
  border: 1px solid var(--road);
  color: var(--road);
  background: #ffffff;
}

.board-frame {
  overflow: auto;
  padding: clamp(10px, 2vw, 18px);
  border-radius: 14px;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.035) 0,
      rgba(255, 255, 255, 0.035) 2px,
      transparent 2px,
      transparent 30px
    ),
    var(--road-dark);
  scrollbar-color: var(--accent) var(--road);
}

.game-board {
  display: grid;
  width: max-content;
  margin: 0 auto;
  gap: 3px;
  touch-action: manipulation;
  user-select: none;
}

.cell {
  position: relative;
  display: grid;
  width: var(--cell-size);
  height: var(--cell-size);
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 7px;
  color: var(--road-dark);
  background:
    linear-gradient(145deg, rgba(255,255,255,0.75), rgba(255,255,255,0)),
    #b8c5cd;
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.65),
    inset -2px -2px 0 rgba(55, 72, 84, 0.22);
  font-size: 1.05rem;
  font-weight: 900;
  cursor: pointer;
}

.cell:hover:not(.is-revealed) {
  filter: brightness(1.08);
}

.cell.is-revealed {
  background: var(--revealed);
  box-shadow: inset 0 0 0 1px rgba(23, 33, 43, 0.08);
  cursor: default;
}

.cell.is-flagged {
  color: var(--danger);
  background: #fff2c5;
}

.cell.is-uee {
  color: #ffffff;
  background: var(--danger);
  box-shadow: none;
}

.cell.is-triggered {
  animation: road-shake 0.35s linear 1;
}

.cell.is-wrong-flag {
  color: var(--danger);
  background: #ffd8d4;
}

.cell[data-number="1"] { color: #1d5e9a; }
.cell[data-number="2"] { color: #31703e; }
.cell[data-number="3"] { color: #a9312d; }
.cell[data-number="4"] { color: #543c91; }
.cell[data-number="5"] { color: #833014; }
.cell[data-number="6"] { color: #006d73; }
.cell[data-number="7"] { color: #202020; }
.cell[data-number="8"] { color: #68717a; }

.uee-symbol {
  display: inline-grid;
  place-items: center;
  line-height: 1;
}

.uee-symbol small {
  display: block;
  margin-top: -2px;
  font-size: 0.45rem;
  letter-spacing: 0.04em;
}

.board-help {
  margin: 10px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 0.85rem;
}

.completion-panel {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  margin-top: 18px;
  padding: 16px 18px;
  border: 1px solid #c8dccc;
  border-radius: 12px;
  background: #eef8f0;
}

.completion-panel.has-uees {
  border-color: #e0c0bd;
  background: #fff0ef;
}

.completion-icon {
  font-size: 2rem;
}

.completion-panel h3 {
  margin-bottom: 2px;
}

.completion-panel p {
  margin-bottom: 0;
  color: var(--muted);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 18px 0 0 8px;
  color: var(--road);
  font-weight: 900;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

@keyframes road-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

@media (max-width: 760px) {
  :root {
    --cell-size: 40px;
  }

  .game-shell {
    width: min(100% - 14px, 1080px);
    padding-top: 14px;
  }

  .game-card {
    padding: 16px 12px 18px;
    border-radius: 14px;
  }

  .game-intro {
    display: block;
  }

  .text-button {
    margin-top: 12px;
  }

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

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

  .stat-wide {
    grid-column: 1 / -1;
  }

  .action-row {
    flex-direction: column;
  }

  .tap-mode {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 520px) {
  :root {
    --cell-size: 36px;
  }

  .challenge-strip {
    display: grid;
  }

  .challenge-strip > div:last-child {
    text-align: left;
  }

  .segment {
    padding-inline: 7px;
    font-size: 0.87rem;
  }

  .mode-button {
    padding-inline: 8px;
    font-size: 0.88rem;
  }

  .completion-panel {
    grid-template-columns: auto 1fr;
  }

  .completion-panel .secondary-button {
    grid-column: 1 / -1;
    width: 100%;
  }
}

@media (max-width: 390px) {
  :root {
    --cell-size: 33px;
  }

  .board-frame {
    padding: 8px;
  }

  .game-board {
    gap: 2px;
  }
}

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