:root {
  --bg: #0b0f14;
  --panel: #1a2430;
  --panel-light: #243244;
  --cyan: #3fe0ff;
  --violet: #b98bff;
  --orange: #ff9a3c;
  --red: #ff4d5e;
  --text: #e6f1f8;
  --text-dim: #8ea3b8;
  --focus: #3fe0ff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app, .app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 12px);
}

button {
  font-family: inherit;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Loading */
.screen-loading {
  align-items: center;
  justify-content: center;
  gap: 24px;
}
.loading-logo {
  font-size: 1.4rem;
  letter-spacing: 0.35em;
  color: var(--cyan);
  font-weight: 600;
}
.loading-bar {
  width: 160px;
  height: 4px;
  background: var(--panel);
  border-radius: 2px;
  overflow: hidden;
}
.loading-bar-fill {
  height: 100%;
  width: 40%;
  background: var(--cyan);
  animation: loading-sweep 1.1s ease-in-out infinite;
}
@keyframes loading-sweep {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

/* Menu */
.screen-menu {
  align-items: center;
  justify-content: center;
  gap: 48px;
  text-align: center;
}
.menu-logo h1 {
  margin: 0;
  font-size: 2.4rem;
  letter-spacing: 0.3em;
  color: var(--cyan);
  text-shadow: 0 0 24px rgba(63,224,255,0.35);
}
.tagline {
  margin: 8px 0 0;
  color: var(--text-dim);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}
.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(320px, 82vw);
}

.btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--panel-light);
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 1rem;
  min-height: 44px;
  min-width: 44px;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--cyan);
  color: #062028;
  border-color: var(--cyan);
  font-weight: 700;
}
.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: var(--red);
}
.btn-icon {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--panel-light);
  border-radius: 10px;
  width: 48px;
  height: 48px;
  min-width: 44px;
  min-height: 44px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Panel screens (mission select / settings / stats) */
.screen-panel { gap: 16px; }
.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
}
.panel-header h2 { margin: 0; font-size: 1.2rem; letter-spacing: 0.05em; }

.mission-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  overflow-y: auto;
}
.mission-card {
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 12px;
  padding: 14px;
  text-align: left;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 44px;
}
.mission-card[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}
.mission-card .mission-name { font-weight: 600; }
.mission-card .mission-stars { color: var(--panel-light); letter-spacing: 2px; font-size: 0.9rem; }
.mission-card .mission-stars .lit { color: var(--orange); }

.settings-list { display: flex; flex-direction: column; gap: 14px; }
.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 10px;
  padding: 12px 16px;
  min-height: 44px;
}
.settings-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--cyan);
}

.stats-list {
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 10px;
  padding: 12px 16px;
  margin: 0;
  overflow-y: auto;
}
.stats-list div.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--panel-light);
}
.stats-list div.stat-row:last-child { border-bottom: none; }
.stats-list dt { color: var(--text-dim); }
.stats-list dd { margin: 0; font-weight: 600; }

/* Playing screen */
.screen-playing {
  padding-left: 8px;
  padding-right: 8px;
  gap: 8px;
}
.hud-top {
  display: flex;
  align-items: center;
  gap: 10px;
}
.hud-mission {
  flex: 1;
  min-width: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-stats { display: flex; gap: 8px; }
.hud-chip {
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.hud-package.collected { color: var(--violet); border-color: var(--violet); }

.board-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
#board-canvas {
  touch-action: none;
  border-radius: 4px;
}

.planning-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(11,15,20,0.85);
  border: 1px solid var(--cyan);
  color: var(--cyan);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.8rem;
  white-space: nowrap;
  pointer-events: none;
}
.planning-banner.danger {
  border-color: var(--red);
  color: var(--red);
}

.hud-bottom {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding-bottom: 4px;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(6,8,11,0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  animation: overlay-in 0.2s ease;
}
@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.overlay-card {
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 14px;
  padding: 28px 24px;
  width: min(320px, 84vw);
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}
.overlay-card h2 { margin: 0 0 6px; }
.stars {
  font-size: 1.6rem;
  color: var(--panel-light);
  letter-spacing: 6px;
  margin: 6px 0;
}
.stars .lit { color: var(--orange); }

@media (prefers-reduced-motion: reduce) {
  .loading-bar-fill { animation: none; }
  .overlay { animation: none; }
}

@media (min-width: 640px) {
  .app { align-items: center; }
  .screen { max-width: 480px; left: 50%; transform: translateX(-50%); }
}
