:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #111318;
  color: #f4f1e8;
  --bg: #111318;
  --panel: #191d25;
  --panel-2: #202631;
  --line: #343b48;
  --text: #f4f1e8;
  --muted: #aeb5c1;
  --accent: #ffcc4d;
  --cyan: #54d8c6;
  --red: #ff6b6b;
  --green: #86df6b;
  --blue: #6ba8ff;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size:
    42px 42px,
    42px 42px,
    auto;
}

button {
  font: inherit;
}

main {
  min-width: 0;
}

.topnav,
.status-strip,
.score-panel,
.game-card {
  min-width: 0;
}

.game-info p,
.status-strip span {
  overflow-wrap: anywhere;
}

.app-shell {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 16px 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-weight: 900;
  letter-spacing: 0;
  box-shadow: 5px 5px 0 #000;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.1;
}

.brand small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.topnav {
  display: inline-flex;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  background: rgba(25, 29, 37, 0.84);
}

.nav-button,
.back-button,
.primary-action,
.secondary-action,
.mobile-controls button {
  min-height: 40px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
}

.nav-button {
  min-width: 78px;
  padding: 0 14px;
}

.nav-button.is-active {
  color: #121212;
  background: var(--accent);
  border-color: var(--accent);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.home-heading,
.game-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin: 30px 0 22px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--cyan);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 5.1rem);
  line-height: 0.94;
  letter-spacing: 0;
}

.game-header h1 {
  font-size: clamp(2rem, 5vw, 4rem);
}

.status-strip,
.score-panel {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.status-strip span,
.score-panel div {
  display: grid;
  min-width: 118px;
  min-height: 58px;
  align-content: center;
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: rgba(25, 29, 37, 0.92);
  box-shadow: 5px 5px 0 #000;
}

.score-panel span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.score-panel strong {
  margin-top: 3px;
  font-size: 1.5rem;
}

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

.game-card {
  display: grid;
  grid-template-rows: 146px auto;
  min-height: 342px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.game-art {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #0f131c;
}

.game-art canvas {
  width: 100%;
  height: 100%;
}

.game-info {
  display: grid;
  align-content: space-between;
  gap: 14px;
  padding: 16px;
}

.game-info h2 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0;
}

.game-info p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.game-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.game-meta span {
  padding: 6px 8px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #151922;
  font-size: 0.76rem;
}

.play-card-button {
  width: 100%;
  min-height: 42px;
  border: 0;
  color: #111;
  background: var(--accent);
  font-weight: 900;
  cursor: pointer;
}

.play-card-button:disabled {
  color: var(--muted);
  background: #2d333f;
  cursor: not-allowed;
}

.back-button {
  min-width: 82px;
  padding: 0 14px;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 292px;
  gap: 18px;
  align-items: start;
}

.play-stage {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 420px;
  border: 1px solid var(--line);
  background: #0b0e14;
  box-shadow: var(--shadow);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.canvas-overlay {
  position: absolute;
  inset: auto 18px 18px 18px;
  display: none;
  gap: 5px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(17, 19, 24, 0.9);
}

.canvas-overlay.is-visible {
  display: grid;
}

.canvas-overlay strong {
  font-size: 1.1rem;
}

.canvas-overlay span {
  color: var(--muted);
}

.control-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(25, 29, 37, 0.94);
  box-shadow: var(--shadow);
}

.panel-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-action {
  color: #111;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 900;
}

.secondary-action {
  font-weight: 800;
}

.game-options.is-hidden {
  display: none;
}

.difficulty-panel {
  display: grid;
  gap: 8px;
}

.option-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  background: #151922;
}

.segmented-control button {
  min-width: 0;
  min-height: 38px;
  border: 1px solid transparent;
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 800;
}

.segmented-control button.is-active {
  color: #111;
  border-color: var(--accent);
  background: var(--accent);
}

.stat-list {
  display: grid;
  gap: 8px;
}

.stat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: #151922;
}

.stat-item span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stat-item strong {
  text-align: right;
}

.mobile-controls {
  display: grid;
  gap: 8px;
}

.mobile-controls div {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.mobile-controls button {
  min-width: 0;
  touch-action: none;
  user-select: none;
}

@media (max-width: 980px) {
  .game-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

@media (max-width: 680px) {
  .app-shell {
    width: min(100%, 372px);
    max-width: 372px;
    padding: 10px 9px 32px;
  }

  .topbar,
  .home-heading,
  .game-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topnav,
  .status-strip,
  .score-panel {
    width: 100%;
  }

  .topnav {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .nav-button {
    padding: 0 5px;
    font-size: 0.72rem;
  }

  .status-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav-button,
  .status-strip span,
  .score-panel div {
    flex: 1;
    min-width: 0;
  }

  .status-strip span {
    font-size: 0.9rem;
  }

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

  .play-stage {
    min-height: auto;
  }
}
