:root {
  --bg: #15132b;
  --panel: rgba(24, 22, 52, 0.88);
  --panel-border: rgba(255, 255, 255, 0.14);
  --text: #f3f1ff;
  --muted: #b7b3d9;
  --accent: #ffcc4d;
  --accent-dark: #c48d0a;
  --danger: #ff6b6b;
  --radius: 14px;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

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

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  display: block;
  border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  touch-action: none; /* swipes must not scroll or zoom the page */
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}

/* UI layer: sized by main.js to exactly cover the canvas. */
#ui {
  position: absolute;
  pointer-events: none;
  font-size: calc(var(--ui-scale, 1) * 16px);
}

#ui .screen,
#ui .overlay,
#ui .hud-bar,
#ui button {
  pointer-events: auto;
}

.hidden {
  display: none !important;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1em;
  background: radial-gradient(ellipse at center, rgba(20, 18, 45, 0.55), rgba(12, 10, 28, 0.88));
  text-align: center;
  padding: 1em;
}

.logo {
  font-size: 5em;
  margin: 0;
  letter-spacing: 0.02em;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}

.logo span {
  color: var(--accent);
}

.tagline {
  color: var(--muted);
  margin: 0 0 1em;
  font-size: 1.2em;
}

h2 {
  margin: 0;
  font-size: 2.2em;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.6em;
  min-width: 14em;
}

.menu-buttons.row {
  flex-direction: row;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 1.1em;
  padding: 0.65em 1.4em;
  border-radius: 999px;
  border: 2px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.btn:active {
  transform: translateY(1px) scale(0.98);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #2a1d00;
  box-shadow: 0 4px 0 var(--accent-dark);
}

.btn.primary:hover {
  background: #ffd970;
}

.btn.danger {
  border-color: rgba(255, 107, 107, 0.6);
  color: var(--danger);
}

.btn.small {
  font-size: 0.85em;
  padding: 0.4em 0.9em;
}

/* Level select */
#level-grid {
  display: grid;
  grid-template-columns: repeat(5, 8.5em);
  gap: 0.8em;
  margin: 1em 0;
}

.level-tile {
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2em;
  padding: 0.8em 0.4em;
  border-radius: var(--radius);
  border: 2px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.level-tile:hover:not(:disabled) {
  border-color: var(--accent);
}

.level-tile.done {
  border-color: rgba(120, 230, 150, 0.7);
}

.level-tile.locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.level-number {
  font-size: 1.8em;
  font-weight: 800;
}

.level-name {
  font-size: 0.8em;
  color: var(--muted);
}

.level-score {
  font-size: 0.8em;
  color: var(--accent);
  min-height: 1.2em;
}

/* HUD */
#hud {
  position: absolute;
  inset: 0;
}

.hud-bar {
  position: absolute;
  top: 0.6em;
  left: 0.6em;
  right: 0.6em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  padding: 0.4em 0.6em 0.4em 1em;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
}

.hud-title {
  display: flex;
  gap: 0.6em;
  align-items: baseline;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#hud-level {
  color: var(--muted);
  font-size: 0.85em;
}

#hud-balls {
  display: flex;
  gap: 0.35em;
}

.hud-ball {
  width: 1em;
  height: 1em;
  border-radius: 50%;
  border: 2px solid var(--ball);
  background: transparent;
}

.hud-ball.delivered {
  background: var(--ball);
  box-shadow: 0 0 8px var(--ball);
}

.hud-ball.invalid,
.hud-ball.lost {
  border-color: var(--danger);
  background: repeating-linear-gradient(45deg, var(--danger) 0 2px, transparent 2px 5px);
}

.hud-actions {
  display: flex;
  gap: 0.4em;
}

.hud-hint {
  position: absolute;
  bottom: 0.8em;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.4em 1em;
  border-radius: 999px;
  background: rgba(10, 8, 30, 0.55);
  color: var(--muted);
  font-size: 0.95em;
  white-space: nowrap;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 8, 28, 0.45);
  animation: fade-in 0.25s ease;
}

.card {
  background: var(--panel);
  border: 2px solid rgba(120, 230, 150, 0.6);
  border-radius: 20px;
  padding: 1.6em 2.2em;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  animation: pop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.card.failed {
  border-color: rgba(255, 107, 107, 0.7);
}

.card p {
  margin: 0.6em 0;
  font-size: 1.15em;
}

.muted {
  color: var(--muted);
}

#toast {
  position: absolute;
  top: 4em;
  left: 50%;
  transform: translate(-50%, 1em);
  padding: 0.5em 1.2em;
  border-radius: 999px;
  background: rgba(10, 8, 30, 0.85);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Developer tools */
#dev-panel {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 170px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(8, 8, 20, 0.88);
  border: 1px solid var(--panel-border);
  font-size: 13px;
}

#dev-panel label {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  align-items: center;
}

#dev-panel input {
  width: 80px;
  font: inherit;
  background: #1f1d3d;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 2px 6px;
}

#dev-output {
  position: fixed;
  left: 8px;
  bottom: 8px;
  z-index: 11;
  width: min(560px, calc(100vw - 16px));
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#dev-output textarea {
  height: 260px;
  background: rgba(8, 8, 20, 0.92);
  color: #c8f7ff;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font: 12px ui-monospace, monospace;
  padding: 8px;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes pop {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
}

@media (max-width: 700px) {
  #level-grid {
    grid-template-columns: repeat(5, 6.5em);
  }
  #dev-panel {
    width: 140px;
  }
}

/* Per-level notes */
.notes-panel {
  position: absolute;
  top: 4em;
  right: 0.6em;
  width: 22em;
  max-width: calc(100% - 1.2em);
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  padding: 0.8em;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  pointer-events: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.notes-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5em;
}

.notes-head strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notes-rating {
  display: flex;
  align-items: center;
  gap: 0.3em;
}

.notes-rating button {
  width: 2em;
  height: 2em;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

.notes-rating button.on {
  background: var(--accent);
  color: #2a2000;
  border-color: var(--accent);
}

.notes-rating .muted {
  margin-left: 0.4em;
  font-size: 0.9em;
}

#notes-text {
  width: 100%;
  resize: vertical;
  padding: 0.5em;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font: inherit;
  font-size: 0.95em;
}

#notes-status {
  font-size: 0.8em;
  min-height: 1.1em;
}

.level-tile .level-note {
  position: absolute;
  top: 0.3em;
  right: 0.4em;
  font-size: 0.8em;
  color: var(--accent);
}

/* The HUD bar must not block swipes: ropes near the top of the level stay cuttable. Only its buttons take clicks. */
#ui .hud-bar {
  pointer-events: none;
}
#ui .hud-bar button {
  pointer-events: auto;
}

/* Open top bar: the title, the ball counter and the buttons are separate pills, so the middle of the
   level's top edge (where balls often hang) stays visible. */
#ui .hud-bar {
  background: transparent;
  border: none;
  padding: 0;
}
.hud-title,
#hud-balls,
.hud-actions {
  padding: 0.4em 0.9em;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
}
#hud-balls:empty {
  display: none;
}
