:root {
  color-scheme: dark;
  --ink: #fff7e8;
  --muted: #d5c7ae;
  --paper: #0f1314;
  --panel: #171c1d;
  --line: rgba(255, 247, 232, 0.18);
  --ember: #ff6f4f;
  --gold: #f5c45b;
  --mint: #6de1a6;
  --blue: #68b7ff;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow-x: hidden;
  overflow-y: auto;
}

body,
button {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(109, 225, 166, 0.72);
  outline-offset: 3px;
}

.game-app {
  display: grid;
  width: 100vw;
  min-height: 100svh;
  align-content: start;
  grid-template-rows: auto;
  overflow: visible;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(109, 225, 166, 0.13), transparent 34rem),
    linear-gradient(225deg, rgba(104, 183, 255, 0.14), transparent 34rem),
    var(--paper);
}

.titlebar {
  z-index: 4;
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 clamp(14px, 4vw, 48px);
  background: rgba(12, 15, 16, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand-link {
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand,
.brand-title,
.game-nav,
.game-hud {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-width: 0;
  font-weight: 900;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  color: #07100d;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.52), transparent 34%),
    linear-gradient(135deg, var(--mint), var(--gold));
  border: 1px solid rgba(255, 247, 232, 0.24);
  border-radius: 8px;
  box-shadow: 0 0 34px rgba(109, 225, 166, 0.22);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.8rem;
}

.brand-title {
  min-width: 0;
  align-items: flex-start;
  flex-direction: column;
  line-height: 1.05;
  white-space: nowrap;
}

.brand-title strong {
  font-size: 1rem;
}

.document-name {
  overflow: hidden;
  max-width: min(44vw, 430px);
  margin-top: 4px;
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  text-overflow: ellipsis;
}

.game-nav {
  gap: 6px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 850;
}

.game-nav a,
.game-nav button {
  display: flex;
  min-height: 34px;
  align-items: center;
  padding: 8px 10px;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  text-decoration: none;
  transition: color 160ms ease, background 160ms ease, border-color 160ms ease;
}

.game-nav a:hover,
.game-nav button:hover {
  color: var(--gold);
  background: rgba(255, 247, 232, 0.07);
  border-color: rgba(255, 247, 232, 0.14);
}

.game-nav button:disabled {
  color: var(--muted);
  background: rgba(255, 247, 232, 0.045);
  border-color: rgba(255, 247, 232, 0.12);
  cursor: not-allowed;
  opacity: 1;
}

.game-nav button:disabled:hover {
  color: var(--muted);
  background: rgba(255, 247, 232, 0.045);
  border-color: rgba(255, 247, 232, 0.12);
}

.game-nav .nav-cta {
  color: var(--ink);
  background: rgba(109, 225, 166, 0.1);
  border-color: rgba(109, 225, 166, 0.22);
}

.game-hud {
  z-index: 3;
  min-height: 74px;
  justify-content: center;
  gap: 10px;
  padding: 10px clamp(14px, 4vw, 48px);
  background: rgba(16, 19, 21, 0.74);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.22);
}

.score-chip,
.round-status {
  display: grid;
  min-width: 112px;
  gap: 2px;
  padding: 10px 14px;
  background: rgba(23, 28, 29, 0.88);
  border: 1px solid rgba(255, 247, 232, 0.15);
  border-radius: 8px;
  text-align: center;
}

.score-chip.current {
  border-color: rgba(109, 225, 166, 0.34);
}

.score-chip span {
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
}

.score-chip strong {
  font-family: "JetBrains Mono", monospace;
  font-size: 1.16rem;
}

.round-status {
  min-width: min(34vw, 260px);
  margin: 0;
  color: var(--gold);
  font-weight: 900;
}

.game-stage-wrap {
  display: flex;
  min-height: 0;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 2vw, 18px);
}

.game-stage {
  position: relative;
  width: min(100%, 1180px);
  height: clamp(320px, 44vw, 520px);
  min-height: 320px;
  overflow: hidden;
  background: #101516;
  border: 1px solid rgba(255, 247, 232, 0.16);
  border-radius: 8px;
  box-shadow: var(--shadow);
  touch-action: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: none;
}

.game-menu {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  gap: 18px;
  padding: 24px;
  background: linear-gradient(180deg, rgba(15, 19, 20, 0.16), rgba(15, 19, 20, 0.48));
  text-align: center;
  user-select: none;
}

.game-menu[hidden] {
  display: none;
}

.game-menu strong {
  color: var(--ink);
  font-size: clamp(2rem, 5vw, 4.8rem);
  font-weight: 950;
}

.menu-meta {
  justify-self: center;
  min-height: 30px;
  padding: 5px 12px;
  color: var(--gold);
  background: rgba(15, 19, 20, 0.54);
  border: 1px solid rgba(255, 247, 232, 0.16);
  border-radius: 999px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.menu-button {
  min-height: 44px;
  justify-self: center;
  padding: 10px 18px;
  color: #07100d;
  background: linear-gradient(135deg, var(--mint), var(--gold));
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.26);
  font-size: 1rem;
  font-weight: 950;
}

.touch-bar {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 3;
  display: none;
}

.touch-bar button {
  min-width: 112px;
  min-height: 52px;
  padding: 0 18px;
  color: #07100d;
  background: linear-gradient(135deg, var(--mint), var(--gold));
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 8px;
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.26);
  font-size: 1rem;
  font-weight: 950;
  touch-action: none;
}

.touch-bar button:active {
  transform: translateY(1px);
}

.touch-hint {
  position: absolute;
  left: 14px;
  bottom: 18px;
  z-index: 3;
  display: none;
  max-width: min(310px, calc(100% - 152px));
  margin: 0;
  padding: 8px 10px;
  color: var(--ink);
  background: rgba(15, 19, 20, 0.72);
  border: 1px solid rgba(255, 247, 232, 0.16);
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 850;
  line-height: 1.25;
  pointer-events: none;
}

@media (pointer: coarse) {
  .touch-bar,
  .touch-hint {
    display: block;
  }
}

@media (max-width: 780px) {
  .game-app {
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .titlebar {
    flex-wrap: wrap;
    gap: 10px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .game-nav {
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .game-nav::-webkit-scrollbar {
    display: none;
  }

  .game-hud {
    flex-wrap: wrap;
  }

  .round-status {
    min-width: 100%;
  }
}

@media (max-width: 520px) {
  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand-title strong {
    font-size: 0.94rem;
  }

  .document-name {
    max-width: 70vw;
  }

  .game-stage-wrap {
    align-items: flex-start;
    padding: 8px;
  }

  .game-stage {
    width: 100%;
    height: min(58svh, 470px);
    min-height: 0;
  }

  .touch-bar {
    right: 10px;
    bottom: 10px;
  }

  .touch-bar button {
    min-width: 96px;
    min-height: 50px;
  }

  .touch-hint {
    left: 10px;
    bottom: 14px;
    max-width: calc(100% - 122px);
    font-size: 0.78rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .game-nav a:hover,
  .game-nav button:hover,
  .menu-button:hover {
    transform: none;
  }
}
