:root {
  color-scheme: dark;
  --bg: #08142f;
  --panel: rgba(9, 22, 53, 0.86);
  --panel-solid: #10224f;
  --text: #f7fbff;
  --muted: #a9c1db;
  --teal: #18e3d2;
  --yellow: #ffd33d;
  --orange: #ff7a3d;
  --violet: #7258ff;
  --danger: #ff4668;
  --good: #35f28a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-rounded, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  touch-action: none;
}

button {
  border: 0;
  color: var(--text);
  font: 800 0.92rem/1 var(--font, inherit);
  cursor: pointer;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 560px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 18%, rgba(24, 227, 210, 0.2), transparent 24%),
    linear-gradient(180deg, #10245f 0%, #08142f 62%, #050914 100%);
}

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

.screen,
.panel {
  position: absolute;
  inset: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  z-index: 5;
}

.screen {
  display: none;
}

.screen.active,
.screen:not(.hidden).screen-results {
  display: flex;
}

.screen-menu {
  flex-direction: column;
  justify-content: flex-end;
  gap: 16px;
  pointer-events: auto;
}

.brand {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(8, 20, 47, 0.72), rgba(16, 34, 79, 0.58));
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.logo-mark {
  display: grid;
  place-items: center;
  width: 70px;
  height: 70px;
  border-radius: 8px;
  color: #08142f;
  font-weight: 1000;
  font-size: 1.6rem;
  background: linear-gradient(135deg, var(--yellow), var(--teal));
  box-shadow: 0 10px 25px rgba(24, 227, 210, 0.2);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.4rem, 13vw, 4rem);
  letter-spacing: 0;
  line-height: 0.9;
  text-transform: uppercase;
}

h2 {
  font-size: 2rem;
  text-transform: uppercase;
}

.brand p,
#resultMessage {
  margin-top: 8px;
  color: var(--muted);
  font-weight: 650;
  line-height: 1.35;
}

.primary-action {
  width: 100%;
  min-height: 64px;
  border-radius: 8px;
  color: #07112d;
  font-size: 1.35rem;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--yellow), #ff9d2f);
  box-shadow: 0 16px 30px rgba(255, 122, 61, 0.32);
}

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

.menu-grid button,
.result-actions button,
.panel-close,
.icon-button,
.board-button {
  min-height: 48px;
  border-radius: 8px;
  background: rgba(16, 34, 79, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
}

.profile-card,
.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(14px);
}

.profile-card span,
.result-grid span,
.hud-pill span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.profile-card strong,
.result-grid strong,
.hud-pill strong {
  display: block;
  margin-top: 4px;
  font-size: 1.2rem;
}

.hud {
  position: absolute;
  inset: max(10px, env(safe-area-inset-top)) 10px auto;
  z-index: 4;
  display: none;
  grid-template-columns: 1fr 1fr 48px;
  gap: 8px;
  pointer-events: none;
}

.hud.active {
  display: grid;
}

.hud button {
  pointer-events: auto;
}

.hud-pill,
.power-timer,
.mission-toast,
.board-button {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(8, 20, 47, 0.76);
  border: 1px solid rgba(255, 255, 255, 0.13);
  backdrop-filter: blur(12px);
}

.power-timer {
  grid-column: 1 / -1;
  color: #07112d;
  background: linear-gradient(135deg, var(--teal), var(--yellow));
  font-weight: 900;
}

.mission-toast {
  grid-column: 1 / -1;
  color: var(--yellow);
  font-weight: 900;
}

.board-button {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  min-width: 132px;
  color: #07112d;
  background: linear-gradient(135deg, var(--teal), #64ff8a);
}

.panel {
  z-index: 7;
  padding: 16px;
  overflow: auto;
  border-radius: 8px;
  background: rgba(8, 20, 47, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panel.hidden,
.hidden {
  display: none !important;
}

.panel-close {
  position: sticky;
  top: 0;
  float: right;
  width: 44px;
  color: var(--yellow);
  font-size: 1.4rem;
}

.panel h2 {
  margin-bottom: 12px;
}

.panel-list {
  display: grid;
  gap: 10px;
}

.panel-item {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.panel-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  color: #07112d;
  font-weight: 1000;
  background: linear-gradient(135deg, var(--yellow), var(--orange));
}

.panel-item p {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

.screen-results {
  z-index: 6;
  flex-direction: column;
  justify-content: flex-end;
  gap: 14px;
  padding: 16px;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(8, 20, 47, 0.22), rgba(8, 20, 47, 0.94) 42%);
}

.result-grid {
  grid-template-columns: repeat(2, 1fr);
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.result-actions .primary-action {
  grid-column: 1 / -1;
  min-height: 56px;
}

.tutorial {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: max(86px, calc(env(safe-area-inset-bottom) + 86px));
  z-index: 4;
  display: none;
  justify-content: center;
  pointer-events: none;
}

.tutorial.active {
  display: flex;
}

.tutorial span {
  max-width: 340px;
  padding: 10px 14px;
  border-radius: 8px;
  color: #07112d;
  background: rgba(255, 211, 61, 0.94);
  font-weight: 950;
  text-align: center;
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.25);
}

@media (min-width: 720px) {
  .app-shell {
    width: min(430px, 100vw);
    height: min(932px, 100dvh);
    margin: 0 auto;
    border-inline: 1px solid rgba(255, 255, 255, 0.12);
  }

  body {
    background:
      radial-gradient(circle at 50% 15%, rgba(114, 88, 255, 0.22), transparent 24%),
      #030713;
  }
}

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