/* ==========================================================================
   Christiaan's World — 3D city square UI
   Canvas fills the viewport; everything else is HUD layered on top.
   ========================================================================== */

:root {
  --ink: #1f2430;
  --ink-soft: #4a5163;
  --paper: #fffdf6;
  --accent: #ffb02e;
  --accent-deep: #e08900;
  --grass: #69a84f;
  --sky: #7ec0ee;
  --chip-bg: rgba(24, 28, 38, 0.72);
  --chip-fg: #f5f2e8;
  --radius-lg: 18px;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-pixel: 'Press Start 2P', 'Courier New', monospace;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win over display rules below */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-ui);
  background: linear-gradient(#6fb3e8 0%, #a8d4f0 55%, #cfe8d8 100%);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#scene-root {
  position: fixed;
  inset: 0;
}

#scene-root canvas {
  display: block;
  touch-action: none;
}

/* ---------------------------------------------------------------- HUD --- */

.hud {
  position: fixed;
  z-index: 20;
  pointer-events: none;
}

.hud-top {
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: calc(10px + env(safe-area-inset-top)) 14px 0;
}

.hud-chip {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--chip-bg);
  color: var(--chip-fg);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 8px 14px;
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 2px 10px rgba(15, 20, 30, 0.25);
  text-decoration: none;
  white-space: nowrap;
}

.hud-identity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #58d68d;
  box-shadow: 0 0 6px #58d68d;
}

a.hud-link:hover { background: rgba(40, 47, 62, 0.85); }
a.hud-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------- Prompt --- */

.prompt {
  position: fixed;
  z-index: 25;
  left: 50%;
  bottom: calc(120px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--chip-bg);
  color: var(--chip-fg);
  padding: 10px 16px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(15, 20, 30, 0.3);
  animation: prompt-pop 180ms ease-out;
  pointer-events: none;
  max-width: min(92vw, 480px);
}

.prompt-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: 7px;
  background: var(--accent);
  color: #3a2800;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 2px 0 var(--accent-deep);
}

/* Touch devices: no keyboard hint, the interact button is the prompt */
body.touch .prompt-key { display: none; }

@keyframes prompt-pop {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ------------------------------------------------------------- Dialog --- */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 28;
  background: rgba(20, 26, 38, 0.25);
}

.dialog {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 28px));
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 0 rgba(31, 36, 48, 0.28), 0 24px 48px rgba(15, 20, 30, 0.35);
  padding: 26px 22px 16px;
  animation: dialog-in 220ms cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateX(-50%) translateY(26px) scale(0.96); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.dialog-nameplate {
  position: absolute;
  top: -16px;
  left: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--ink);
  color: var(--chip-fg);
  border-radius: 12px;
  padding: 8px 14px;
  box-shadow: 0 3px 0 rgba(31, 36, 48, 0.35);
}

.dialog-year {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.dialog-device {
  font-size: 12px;
  font-weight: 600;
  color: #cfd6e4;
}

.dialog-body h2 {
  margin: 4px 0 8px;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.dialog-body p {
  margin: 0 0 10px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-soft);
}

.dialog-vibe {
  font-style: italic;
  color: #7a6a4d !important;
}

.dialog-vibe::before { content: '“'; }
.dialog-vibe::after { content: '”'; }

.dialog-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.dialog-links:empty { display: none; }

.dialog-links a,
.dialog-links span.chip-static {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  text-decoration: none;
}

.dialog-links a {
  background: var(--ink);
  color: var(--chip-fg);
  transition: transform 120ms ease, background 120ms ease;
}

.dialog-links a:hover { background: #333b4e; transform: translateY(-1px); }
.dialog-links a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.dialog-links span.chip-static {
  background: #ece5d3;
  color: #6b5f45;
}

.dialog-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 15px;
  cursor: pointer;
}

.dialog-close:hover { background: #f0ead9; color: var(--ink); }
.dialog-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.dialog-hint {
  margin-top: 6px;
  text-align: right;
  font-size: 11px;
  color: #a49a83;
}

body.touch .dialog-hint { display: none; }

/* ----------------------------------------------------- Touch controls --- */

.touch-controls { z-index: 22; }

.joystick {
  position: fixed;
  left: 22px;
  bottom: calc(22px + env(safe-area-inset-bottom));
  width: 124px;
  height: 124px;
  border-radius: 50%;
  background: rgba(24, 28, 38, 0.32);
  border: 2px solid rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  touch-action: none;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(245, 242, 232, 0.92);
  box-shadow: 0 3px 10px rgba(15, 20, 30, 0.35);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.interact-btn {
  position: fixed;
  right: 24px;
  bottom: calc(34px + env(safe-area-inset-bottom));
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.5);
  background: rgba(24, 28, 38, 0.45);
  color: rgba(255, 255, 255, 0.65);
  font-family: var(--font-pixel);
  font-size: 20px;
  touch-action: none;
  transition: transform 120ms ease;
}

.interact-btn:active { transform: scale(0.93); }

.interact-btn.is-active {
  background: var(--accent);
  border-color: #fff2d9;
  color: #3a2800;
  box-shadow: 0 0 0 6px rgba(255, 176, 46, 0.3), 0 6px 18px rgba(224, 137, 0, 0.5);
  animation: interact-pulse 1.1s ease-in-out infinite;
}

@keyframes interact-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}

/* ---------------------------------------------------------- Title card --- */

.title-card {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(28, 38, 56, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  overflow-y: auto;
}

.title-card.is-hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 320ms ease;
}

.title-card-inner {
  width: min(480px, 100%);
  margin: auto;
  text-align: center;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 12px 0 rgba(31, 36, 48, 0.3), 0 30px 60px rgba(10, 15, 25, 0.4);
  padding: 30px 26px 24px;
}

.title-mascot {
  display: block;
  width: 140px;
  height: 200px;
  margin: 0 auto 6px;
  overflow: visible;
}

.title-heading {
  margin: 10px 0 6px;
  font-family: var(--font-pixel);
  font-size: clamp(20px, 5.4vw, 30px);
  line-height: 1.35;
  color: var(--ink);
  text-shadow: 3px 3px 0 rgba(255, 176, 46, 0.55);
}

.title-sub {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-deep);
}

.title-desc {
  margin: 0 auto 16px;
  max-width: 40ch;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-soft);
}

.title-controls {
  list-style: none;
  margin: 0 0 20px;
  padding: 12px 14px;
  background: #f4efe0;
  border-radius: 12px;
  font-size: 13px;
  color: var(--ink-soft);
  display: grid;
  gap: 7px;
}

.title-controls kbd {
  display: inline-block;
  min-width: 20px;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--paper);
  border: 1px solid #d8d0ba;
  border-bottom-width: 2px;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 11px;
  color: var(--ink);
}

/* Show the control hints matching the input method */
.title-controls [data-input="touch"] { display: none; }
body.touch .title-controls [data-input="touch"] { display: list-item; }
body.touch .title-controls [data-input="keyboard"] { display: none; }

.title-start {
  display: block;
  width: 100%;
  padding: 15px 20px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #3a2800;
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-deep);
  transition: transform 100ms ease, box-shadow 100ms ease;
}

.title-start:hover { transform: translateY(-1px); box-shadow: 0 5px 0 var(--accent-deep); }
.title-start:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--accent-deep); }
.title-start:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

.title-classic {
  display: inline-block;
  margin-top: 14px;
  font-size: 13px;
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 1px dashed #b6ad97;
}

.title-classic:hover { color: var(--ink); }

/* ------------------------------------------------------------ Responsive --- */

@media (max-width: 560px) {
  .hud-chip { font-size: 12px; padding: 7px 11px; }

  .dialog {
    padding: 24px 16px 12px;
    border-width: 3px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .dialog-body h2 { font-size: 19px; }
  .dialog-body p { font-size: 14px; }

  .prompt { bottom: calc(128px + env(safe-area-inset-bottom)); font-size: 13px; }

  .joystick { width: 108px; height: 108px; left: 16px; }
  .joystick-knob { width: 48px; height: 48px; }
  .interact-btn { width: 68px; height: 68px; right: 18px; }
}

/* ------------------------------------------------------ Reduced motion --- */

@media (prefers-reduced-motion: reduce) {
  .prompt, .dialog, .interact-btn.is-active { animation: none; }
  .title-card.is-hidden { transition: none; }
}
