:root {
  --ink: #0f172a;
  --cream: #f6f0e8;
  --sunset: #ff6b4a;
  --sunset-deep: #e23d2f;
  --sky: #b6d4ff;
  --panel: rgba(15, 23, 42, 0.76);
  --panel-light: rgba(15, 23, 42, 0.6);
  --border: rgba(255, 255, 255, 0.15);
  --shadow: 0 20px 60px rgba(10, 20, 40, 0.45);
  --safe-top: env(safe-area-inset-top);
  --safe-right: env(safe-area-inset-right);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Work Sans", system-ui, sans-serif;
  color: #fff;
  background: #0a0f1d;
  overflow: hidden;
  overflow-x: hidden;
}

#map {
  position: fixed;
  inset: 0;
}

#ui {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  padding: calc(24px + var(--safe-top))
    calc(24px + var(--safe-right))
    calc(24px + var(--safe-bottom))
    calc(24px + var(--safe-left));
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  pointer-events: auto;
  width: 100%;
  flex-wrap: wrap;
}

.brand,
.stats {
  min-width: 0;
}

.brand .title {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-weight: 700;
  font-size: 28px;
  letter-spacing: 0.5px;
}

.brand,
.stats {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.brand .subtitle {
  opacity: 0.75;
  font-size: 14px;
  margin-top: 2px;
}

.stats {
  text-align: right;
  font-size: 14px;
  opacity: 0.9;
}

#progress,
#score {
  white-space: normal;
}

#panel {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(240px, 360px);
  gap: 18px;
  align-items: end;
  pointer-events: auto;
  width: min(720px, 100%);
}

.panel-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.panel-title {
  font-size: 12px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  opacity: 0.7;
  margin-bottom: 12px;
}

#roundList {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

#roundList li {
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid transparent;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: transform 0.2s ease, border 0.2s ease;
}

#roundList li.active {
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateX(6px);
}

#roundList li.complete {
  opacity: 0.55;
  text-decoration: line-through;
}

#targetName {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 8px;
}

#instructions {
  opacity: 0.8;
  font-size: 14px;
  margin-bottom: 12px;
}

#result {
  font-size: 14px;
  min-height: 24px;
  margin-bottom: 12px;
}

.panel-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--sunset);
  color: #1f120c;
  box-shadow: 0 10px 24px rgba(255, 107, 74, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button.secondary {
  background: #f8f6f2;
  color: #1f2937;
  box-shadow: 0 10px 24px rgba(248, 246, 242, 0.2);
}

button.secondary.selected {
  background: var(--sunset);
  color: #1f120c;
  box-shadow: 0 10px 24px rgba(255, 107, 74, 0.35);
}

button.ghost {
  background: transparent;
  color: #f8f6f2;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: none;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(255, 107, 74, 0.45);
}

button.secondary:hover {
  box-shadow: 0 14px 30px rgba(248, 246, 242, 0.35);
}

button.ghost:hover {
  box-shadow: none;
  background: rgba(255, 255, 255, 0.08);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.audio-controls {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 5;
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.audio-btn {
  position: static;
}

.hidden {
  display: none;
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, rgba(16, 36, 72, 0.92), rgba(5, 8, 18, 0.98));
  z-index: 4;
  padding: 24px;
}

.overlay.active {
  display: flex;
}

.overlay-card {
  max-width: 520px;
  width: min(90vw, 520px);
  background: rgba(12, 20, 38, 0.9);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 28px;
  color: #f8f6f2;
  box-shadow: var(--shadow);
  text-align: left;
  animation: fadeUp 0.6s ease;
}

.overlay-card h1 {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 32px;
  margin: 0 0 12px;
}

.score-display {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 40px;
  font-weight: 700;
  margin: 10px 0 18px;
}

.round-summary {
  margin-bottom: 16px;
}

#roundSummary {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

#roundSummary li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 14px;
}

.overlay-card p {
  margin: 0 0 16px;
  line-height: 1.5;
  opacity: 0.9;
}

.overlay-list {
  display: grid;
  gap: 8px;
  font-size: 14px;
  margin-bottom: 18px;
  opacity: 0.85;
}

.token-label {
  display: block;
  font-size: 12px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  margin-bottom: 6px;
  opacity: 0.7;
}

#tokenInput {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  padding: 12px 14px;
  color: #fff;
  font-size: 14px;
  margin-bottom: 16px;
}

.overlay-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.city-actions {
  justify-content: flex-start;
  margin-bottom: 12px;
}

.difficulty-actions {
  justify-content: flex-start;
  margin-bottom: 12px;
}

#overlayStatus {
  margin-top: 12px;
  font-size: 13px;
  opacity: 0.8;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 900px) {
  #ui {
    padding: calc(clamp(10px, 2.5vw, 16px) + var(--safe-top))
      calc(clamp(10px, 2.5vw, 16px) + var(--safe-right))
      calc(clamp(10px, 2.5vw, 16px) + var(--safe-bottom))
      calc(clamp(10px, 2.5vw, 16px) + var(--safe-left));
    overflow-x: hidden;
  }

  #hud {
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    max-width: 100%;
    padding: clamp(8px, 2.2vw, 12px);
    gap: 6px;
    background: var(--panel-light);
    border: 1px solid var(--border);
    border-radius: 14px;
    backdrop-filter: blur(10px);
  }

  .brand .title {
    font-size: clamp(15px, 4vw, 18px);
  }

  .brand .subtitle {
    display: none;
  }

  .stats {
    text-align: left;
    font-size: clamp(11px, 3.2vw, 13px);
    width: 100%;
    display: grid;
    gap: 4px;
  }

  #panel {
    position: absolute;
    left: clamp(10px, 2.5vw, 16px);
    right: clamp(10px, 2.5vw, 16px);
    bottom: calc(12px + var(--safe-bottom));
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: auto;
    max-width: none;
  }

  .panel-block {
    padding: clamp(8px, 2.2vw, 12px);
    width: 100%;
    max-width: 100%;
  }

  #roundBlock {
    display: none;
  }

  #targetName {
    font-size: clamp(17px, 4.6vw, 20px);
  }

  #instructions {
    font-size: clamp(11px, 3.1vw, 13px);
  }

  #result {
    margin-bottom: 6px;
  }

  .panel-actions {
    gap: 6px;
  }

  button {
    padding: clamp(7px, 2.1vw, 10px) clamp(10px, 3.6vw, 14px);
    font-size: clamp(11px, 3.1vw, 13px);
  }

  .audio-controls {
    right: clamp(10px, 2.5vw, 16px);
    bottom: calc(12px + var(--safe-bottom));
    gap: 8px;
  }
}
