:root {
  --bg: #08111f;
  --panel: #101c32;
  --panel-2: #162543;
  --text: #edf3ff;
  --muted: #9db0d1;
  --accent: #6fb0ff;
  --accent-2: #8e7dff;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: Inter, Arial, Helvetica, sans-serif;
  background: radial-gradient(circle at top, #15294c 0%, var(--bg) 55%);
  color: var(--text);
}

body {
  overscroll-behavior: none;
  touch-action: manipulation;
}

.app {
  width: 100vw;
  height: 100dvh;
  padding: calc(8px + var(--safe-top)) 8px calc(8px + var(--safe-bottom));
  display: grid;
  place-items: center;
}

.panel,
.game-shell {
  width: min(100%, 1100px);
  height: 100%;
  min-height: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.menu-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  padding: 10px;
  overflow: hidden;
}

.menu-header {
  display: grid;
  gap: 8px;
}

.compact-hero h1 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1.02;
  letter-spacing: -0.04em;
  display: flex;
  align-items: center;
  gap: 12px;
}

.home-link {
  display: inline-block;
  margin: 0;
  font-size: 0.6em;
  line-height: 1;
  text-decoration: none;
  font-weight: 600;
  color: inherit;
}

.compact-hero .subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.25;
}

.preset-row,
.utility-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

button,
select {
  width: 100%;
  border: 0;
  outline: none;
  border-radius: 12px;
  font: inherit;
}

button {
  cursor: pointer;
  color: var(--text);
  background: var(--panel-2);
  padding: 10px 10px;
  transition: transform 0.16s ease, background 0.16s ease, opacity 0.16s ease;
}

button:active {
  transform: scale(0.99);
}

.preset-btn {
  border: 1px solid rgba(255,255,255,0.08);
  padding: 8px 8px;
  font-size: 0.88rem;
}

.play-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 700;
  padding: 12px 14px;
  font-size: 1rem;
}

.menu-config {
  min-height: 0;
  display: flex;
  align-items: stretch;
}

.compact-grid {
  width: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-content: stretch;
}

.field {
  display: flex;
  flex-direction: column;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 16px;
  overflow: hidden;
}

.compact-field {
  padding: 8px;
  gap: 6px;
  min-height: 0;
}

.compact-field label {
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.1;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  min-height: 0;
}

.visible-segmented {
  display: grid;
}

.segmented-btn {
  padding: 8px 6px;
  font-size: 0.72rem;
  line-height: 1.1;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(8, 22, 48, 0.95);
  min-height: 34px;
}

.segmented-btn.active {
  background: linear-gradient(135deg, rgba(111,176,255,0.95), rgba(142,125,255,0.9));
  color: white;
  font-weight: 700;
}

.menu-actions {
  display: grid;
  gap: 8px;
}

.compact-utility button {
  padding: 9px 8px;
  font-size: 0.86rem;
}

.summary-toggle {
  display: block;
  padding: 9px 10px;
  font-size: 0.88rem;
}

.build-card {
  background: linear-gradient(180deg, rgba(111,176,255,0.12), rgba(142,125,255,0.07));
  border: 1px solid rgba(111,176,255,0.22);
  border-radius: 14px;
  padding: 10px;
  overflow: hidden;
}

.build-card.collapsed {
  display: none;
}

.build-card h2 {
  margin: 0 0 8px;
  font-size: 0.92rem;
}

.build-list {
  display: grid;
  gap: 5px;
  font-size: 0.84rem;
}

.build-list div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
}

.build-list span:last-child {
  color: var(--text);
  font-weight: 600;
  text-align: right;
}

.game-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  padding: 10px;
  min-height: 0;
}

.hud {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 18px;
  padding: 10px 12px;
}

.hud-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, auto));
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  align-items: center;
}

.hud strong {
  color: var(--text);
}

.hud-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.status-pill {
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  white-space: nowrap;
}

.back-btn {
  width: auto;
  padding: 10px 14px;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(6,16,32,0.8), rgba(6,12,22,0.95));
  border: 1px solid rgba(255,255,255,0.06);
  touch-action: none;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(2, 8, 18, 0.45);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.overlay.visible {
  opacity: 1;
}

.overlay-card {
  text-align: center;
  padding: 18px 20px;
  border-radius: 20px;
  background: rgba(10, 22, 42, 0.9);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: var(--shadow);
  max-width: min(90%, 420px);
}

.overlay-card h3 {
  margin: 0 0 8px;
  font-size: clamp(1.25rem, 3vw, 1.6rem);
}

.overlay-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.95rem;
}

.touch-bar {
  display: flex;
  justify-content: center;
}

.touch-note {
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

[hidden] {
  display: none !important;
}

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

  .hud-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    font-size: 0.84rem;
    gap: 8px;
  }

  .hud-actions {
    justify-content: space-between;
  }
}

@media (max-width: 420px) {
  .compact-hero h1 {
    font-size: 1.28rem;
    gap: 8px;
  }

  .home-link {
    font-size: 0.56em;
  }

  .compact-hero .subtitle {
    font-size: 0.8rem;
  }

  .compact-grid {
    gap: 6px;
  }

  .compact-field {
    padding: 7px;
  }

  .segmented-btn {
    min-height: 32px;
    font-size: 0.68rem;
  }

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