:root {
  --bg-glass: rgba(15, 23, 42, 0.72);
  --bg-glass-strong: rgba(15, 23, 42, 0.9);
  --border-glass: rgba(255, 255, 255, 0.18);
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --accent: #f59e0b;
  --accent-2: #38bdf8;
  --radius: 16px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: #0f172a;
  color: var(--text-main);
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* Top HUD */
#hud-top {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none;
  z-index: 20;
  flex-wrap: wrap;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  pointer-events: auto;
}

.hud-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-glass);
  border-radius: 14px;
  padding: 8px 12px;
  font-size: 0.92rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.world-badge {
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 6px 13px;
}

.world-badge span {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #fde047;
}

.keys-badge {
  font-weight: 700;
  font-size: 1rem;
  color: #fde047;
}

.stones-badge {
  gap: 6px;
}

.stones-empty {
  color: var(--text-muted);
  font-size: 0.84rem;
}

.stone-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 0.8rem;
  font-weight: 600;
}

.stone-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.6);
}

.boost-badge {
  background: rgba(14, 116, 144, 0.85);
  border-color: rgba(103, 232, 249, 0.55);
  font-weight: 600;
}

.hud-btn {
  appearance: none;
  border: 1px solid var(--border-glass);
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  color: var(--text-main);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.hud-btn:hover {
  background: rgba(30, 41, 59, 0.9);
}

.hud-btn:active {
  transform: scale(0.95);
}

.hud-btn.active {
  background: rgba(2, 132, 199, 0.85);
  border-color: #7dd3fc;
}

/* Minimap */
#minimap-wrap {
  position: fixed;
  top: 72px;
  right: 12px;
  background: var(--bg-glass);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-glass);
  border-radius: 14px;
  padding: 6px;
  z-index: 18;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

#minimap-canvas {
  display: block;
  border-radius: 10px;
}

/* Toast & Context Prompt */
#toast-banner {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-glass-strong);
  border: 1px solid rgba(250, 204, 21, 0.5);
  color: #fef9c3;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.95rem;
  z-index: 25;
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  text-align: center;
  max-width: min(90vw, 520px);
}

#interact-prompt {
  position: fixed;
  bottom: 34px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.45);
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  z-index: 24;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
  animation: pulsePop 1.5s infinite ease-in-out;
}

@keyframes pulsePop {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.05); }
}

/* Tablet On-Screen Controls */
#touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 22;
}

.touch-group {
  position: fixed;
  bottom: 20px;
  display: flex;
  gap: 12px;
  pointer-events: auto;
  touch-action: none;
}

.touch-left {
  left: 18px;
  align-items: flex-end;
}

.touch-right {
  right: 18px;
  align-items: flex-end;
}

.touch-fb-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.touch-pad-btn {
  width: 74px;
  height: 74px;
  border-radius: 20px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.touch-pad-btn small {
  font-size: 0.68rem;
  font-weight: 600;
  opacity: 0.88;
}

.touch-pad-btn.pressed,
.touch-pad-btn:active {
  background: rgba(2, 132, 199, 0.85);
  border-color: #7dd3fc;
  transform: scale(0.94);
}

.touch-jump {
  width: 66px;
  height: 66px;
  background: rgba(217, 119, 6, 0.72);
  border-color: rgba(253, 224, 71, 0.55);
}

/* Swipe indicator */
#swipe-indicator {
  position: fixed;
  width: 96px;
  height: 96px;
  margin-left: -48px;
  margin-top: -48px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.55);
  background: rgba(15, 23, 42, 0.25);
  pointer-events: none;
  z-index: 19;
}

#swipe-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 34px;
  margin-left: -17px;
  margin-top: -17px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.85);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.7);
}

/* Overlay Screens / Modals */
.overlay-screen {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.66);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 40;
}

.modal-card {
  width: min(640px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: linear-gradient(160deg, rgba(30, 41, 59, 0.96), rgba(15, 23, 42, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 24px;
  padding: 26px 26px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.start-card h1 {
  margin: 10px 0 8px;
  font-size: clamp(2rem, 5vw, 2.8rem);
  background: linear-gradient(90deg, #fde047, #fb923c, #38bdf8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title-pill {
  display: inline-block;
  background: rgba(250, 204, 21, 0.16);
  border: 1px solid rgba(250, 204, 21, 0.4);
  color: #fde047;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.subtitle {
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0 0 18px;
}

.world-preview-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

button.world-chip {
  color: inherit;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

button.world-chip:hover {
  transform: translateY(-2px);
}

button.world-chip.selected {
  border-color: #facc15;
  box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.45);
  transform: translateY(-2px);
}

.world-chip {
  padding: 10px 8px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 0.92rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.world-chip small {
  font-weight: 500;
  opacity: 0.88;
}

.world-chip.food { background: rgba(217, 119, 6, 0.25); }
.world-chip.lego { background: rgba(239, 68, 68, 0.25); }
.world-chip.water { background: rgba(14, 165, 233, 0.25); }
.world-chip.jungle { background: rgba(34, 197, 94, 0.25); }
.world-chip.autumn { background: rgba(234, 88, 12, 0.28); }
.world-chip.newyork { background: rgba(250, 204, 21, 0.2); }
.world-chip.christmas { background: rgba(220, 38, 38, 0.28); }
.world-chip.space { background: rgba(99, 102, 241, 0.28); }

.controls-box {
  text-align: left;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.88rem;
  line-height: 1.55;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

kbd {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 0.82rem;
  margin: 0 2px;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.primary-btn,
.secondary-btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease;
}

.primary-btn {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  box-shadow: 0 8px 22px rgba(245, 158, 11, 0.35);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.12);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.primary-btn:hover,
.secondary-btn:hover {
  filter: brightness(1.08);
}

.primary-btn:active,
.secondary-btn:active {
  transform: scale(0.96);
}

/* Note Card */
.note-badge {
  display: inline-block;
  background: rgba(251, 191, 36, 0.18);
  color: #fde047;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 700;
}

.note-card h2,
.cafe-card h2,
.victory-card h2 {
  margin: 8px 0 12px;
}

.note-paper {
  background: #fef3c7;
  color: #451a03;
  border: 3px solid #d97706;
  border-radius: 14px;
  padding: 18px 20px;
  font-size: 1.08rem;
  font-weight: 600;
  line-height: 1.5;
  box-shadow: inset 0 0 18px rgba(180, 83, 9, 0.18);
}

.notebook-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  margin-top: 12px;
}

.notebook-item {
  background: #fef3c7;
  color: #451a03;
  border-left: 5px solid #d97706;
  border-radius: 10px;
  padding: 10px 14px;
}

.notebook-item strong {
  display: block;
  margin-bottom: 3px;
}

/* Cafe Card */
.cafe-avatar {
  font-size: 3rem;
  line-height: 1;
}

.cafe-speech {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 12px 16px;
  line-height: 1.5;
  margin: 0 0 12px;
}

.cafe-info-box {
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 12px;
  padding: 10px 14px;
  margin-top: 10px;
  font-size: 0.94rem;
  line-height: 1.45;
}

@media (max-width: 720px) {
  .world-preview-row {
    grid-template-columns: 1fr 1fr;
  }
  .btn-label {
    display: none;
  }
  #minimap-wrap {
    top: 66px;
  }
  #minimap-canvas {
    width: 112px;
    height: 112px;
  }
  .touch-pad-btn {
    width: 66px;
    height: 66px;
  }
  .touch-jump {
    width: 60px;
    height: 60px;
  }
}

/* Door transition fade */
#fade-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease;
  z-index: 60;
}

#fade-overlay.on {
  opacity: 1;
}
