/* ── CHUNGKING EXPRESS — DESIGN TOKENS ── */
:root {
  --bg-deep:     #050408;
  --bg-panel:    #08050e;
  --bg-surface:  #0d0914;
  --teal:        #00e8b8;
  --teal-dim:    rgba(0, 232, 184, 0.18);
  --teal-glow:   rgba(0, 232, 184, 0.06);
  --magenta:     #e8005a;
  --magenta-dim: rgba(232, 0, 90, 0.2);
  --amber:       #e0940a;
  --amber-dim:   rgba(224, 148, 10, 0.15);
  --gold:        #b8862a;
  --text:        #e0d8cc;
  --text-bright: #f5f0eb;
  --text-dim:    #a09080;
  --text-faint:  #504840;
  --border:      rgba(0, 232, 184, 0.12);
  --border-warm: rgba(224, 148, 10, 0.12);
  --font-serif:  'Playfair Display', 'Noto Serif HK', Georgia, serif;
  --font-zh:     'Noto Serif HK', 'PingFang HK', serif;
  --font-mono:   'Courier Prime', 'Courier New', monospace;

  /* Film grain — SVG noise data URI */
  --grain: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
}

/* ── BASE ── */
body {
  font-family: var(--font-zh);
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
  touch-action: none;
  color: var(--text);
  background: var(--bg-deep);
}

/* ── GAME CONTAINER ── */
#game-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-deep);
}

/* ── FILM GRAIN OVERLAY (decorative, pointer-events: none) ── */
#game-container::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image: var(--grain);
  background-size: 180px 180px;
  opacity: 0.028;
  pointer-events: none;
  z-index: 999;
  mix-blend-mode: overlay;
}

/* ── GAME VIEW (70%) ── */
#game-view {
  position: relative;
  flex: 0 0 70%;
  background: var(--bg-deep);
  overflow: hidden;
}

/* Thin top rule in teal */
#game-view::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--teal) 40%, var(--teal) 60%, transparent 100%);
  opacity: 0.22;
  z-index: 30;
}

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

/* Touch zones — bottom half of game view, 50/50 split */
#zone-joystick,
#zone-camera {
  position: absolute;
  top: 50%;
  height: 50%;
  width: 50%;
  touch-action: none;
  pointer-events: all;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}
#zone-joystick { left: 0;  }
#zone-camera   { right: 0; }

/* UI layer */
#ui-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

/* ── INFO PANEL (15%) ── */
#info-panel {
  flex: 0 0 15%;
  background: var(--bg-panel);
  border-top: 1px solid rgba(0, 232, 184, 0.08);
  display: flex;
  align-items: center;
  padding: 0 14px;
  position: relative;
  overflow: hidden;
  transition: flex-basis 0.2s ease;
}

/* Expand panel when dialogue is active so choices are never clipped */
#info-panel.dialogue-active {
  flex: 0 0 26%;
  overflow-y: auto;
  align-items: flex-start;
  padding-top: 10px;
  padding-bottom: 10px;
}

/* Horizontal rule with glow */
#info-panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--teal) 30%,
    var(--amber) 70%,
    transparent 100%
  );
  opacity: 0.18;
}

/* Grain on panel */
#info-panel::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: var(--grain);
  background-size: 150px 150px;
  opacity: 0.04;
  pointer-events: none;
}

/* ── BUTTON BAR (15%) ── */
#button-bar {
  flex: 0 0 15%;
  background: var(--bg-deep);
  border-top: 1px solid rgba(0, 232, 184, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 4px;
  position: relative;
}

/* ── OVERLAYS — stop above the button bar so it stays visible ── */
#journal-overlay,
#minigame-overlay,
#map-overlay,
#manual-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 15dvh;   /* exact height of #button-bar */
  z-index: 100;
  background: var(--bg-deep);
}

/* Button bar floats above overlays */
#button-bar {
  position: relative;
  z-index: 110;
}

/* ── TITLE SCREEN ── */
#title-screen {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--bg-deep);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: opacity 0.7s ease;
}

#title-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* Rain canvas */
#title-rain {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* Film grain */
#title-grain {
  position: absolute;
  inset: 0;
  background-image: var(--grain);
  background-size: 180px 180px;
  opacity: 0.035;
  pointer-events: none;
}

/* Neon vertical bar accents */
#title-deco-left,
#title-deco-right {
  position: absolute;
  top: 15%;
  width: 1px;
  height: 60%;
  background: linear-gradient(to bottom, transparent, var(--teal), var(--magenta), transparent);
  opacity: 0.18;
}
#title-deco-left  { left: 10%; }
#title-deco-right { right: 10%; }

#title-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 0 24px;
  text-align: center;
  animation: title-rise 0.9s cubic-bezier(0.16,1,0.3,1) both;
}

@keyframes title-rise {
  from { opacity: 0; transform: translateY(28px); }
  to   { opacity: 1; transform: translateY(0); }
}

#title-zh {
  font-family: var(--font-zh);
  font-size: 3rem;
  font-weight: 900;
  color: var(--text-bright);
  letter-spacing: 0.12em;
  line-height: 1.1;
  text-shadow: 0 0 40px rgba(0,232,184,0.2);
  margin-bottom: 10px;
}

#title-en {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--teal);
  letter-spacing: 0.30em;
  text-shadow: 0 0 16px rgba(0,232,184,0.5);
  margin-bottom: 18px;
}

#title-rule {
  width: min(280px, 70vw);
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--teal), var(--magenta), transparent);
  opacity: 0.5;
  margin-bottom: 18px;
}

#title-tagline {
  font-family: var(--font-zh);
  font-size: 0.78rem;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  margin-bottom: 10px;
}

#title-stats {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: #706050;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 32px;
}

#btn-start {
  font-family: var(--font-zh);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--teal);
  border: 1.5px solid rgba(0,232,184,0.35);
  background: rgba(0,232,184,0.06);
  padding: 14px 32px;
  letter-spacing: 0.04em;
  cursor: pointer;
  pointer-events: all;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}

#btn-start.ready {
  border-color: rgba(0,232,184,0.6);
  box-shadow: 0 0 20px rgba(0,232,184,0.15);
}

#btn-start:active {
  background: rgba(0,232,184,0.14);
  border-color: var(--teal);
  box-shadow: 0 0 30px rgba(0,232,184,0.3);
}

#btn-start-sep { opacity: 0.4; }
#btn-start-en  { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.12em; }

#title-loading {
  margin-top: 16px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-dim);
  letter-spacing: 0.12em;
  animation: pulse-dim 1.4s ease-in-out infinite;
}

@keyframes pulse-dim {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 1; }
}

#title-footer {
  position: absolute;
  bottom: 52px;
  font-family: var(--font-mono);
  font-size: 0.59rem;
  color: #b0a090;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  pointer-events: none;
}

#btn-legal {
  position: absolute;
  bottom: 14px;
  right: 18px;
  font-family: var(--font-mono);
  font-size: 0.77rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  cursor: pointer;
  pointer-events: all;
  padding: 7px 16px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
#btn-legal:active {
  color: var(--teal);
  border-color: var(--border);
  background: rgba(0,232,184,0.06);
}

#title-legal {
  position: absolute;
  bottom: 36px;
  left: 16px;
  right: 16px;
  padding: 10px 14px 12px;
  border: 1px solid rgba(255,255,255,0.05);
  background: rgba(2,1,6,0.88);
  font-family: var(--font-mono);
  font-size: 0.63rem;
  color: #a09080;
  line-height: 1.8;
  text-align: left;
  letter-spacing: 0.02em;
  pointer-events: none;
}

#title-legal strong {
  color: #b0a090;
  font-weight: 700;
}

/* ── ERROR SCREEN ── */
#error-screen {
  position: fixed;
  inset: 0;
  z-index: 600;
  background: var(--bg-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#error-content {
  max-width: 340px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#error-icon {
  font-size: 2.5rem;
  color: var(--magenta);
}

#error-title {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-bright);
}

#error-body {
  font-family: var(--font-zh);
  font-size: 0.76rem;
  color: var(--text-dim);
  line-height: 1.6;
}

#error-checks {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: #887868;
  text-align: left;
  line-height: 1.9;
  align-self: stretch;
  padding: 10px 14px;
  border-left: 2px solid var(--border);
}

#btn-reload {
  border: 1px solid var(--border);
  color: var(--teal);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  padding: 10px 24px;
  background: rgba(0,232,184,0.06);
  cursor: pointer;
  pointer-events: all;
}

#error-detail {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: #706050;
  padding: 6px 10px;
  border: 1px solid #1a1816;
  background: rgba(255,255,255,0.01);
  max-width: 100%;
  word-break: break-all;
  text-align: left;
  min-height: 28px;
}

/* ── TOAST ── */
#toast {
  position: fixed;
  bottom: calc(15dvh + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: rgba(8, 6, 15, 0.92);
  border: 1px solid var(--border);
  color: var(--teal);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  padding: 9px 20px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

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

#toast.toast-error {
  border-color: rgba(232,0,90,0.4);
  color: var(--magenta);
}

/* ── SCANLINES over game view ── */
#game-view::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 3px,
    rgba(0, 0, 0, 0.04) 3px,
    rgba(0, 0, 0, 0.04) 4px
  );
  pointer-events: none;
  z-index: 15;
  mix-blend-mode: multiply;
}

/* ── DISTRICT TRANSITION CARD ── */
#district-transition {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: #020106;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

#district-transition.dt-show {
  opacity: 1;
  pointer-events: all;
}

#dt-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  text-align: center;
  padding: 0 28px;
  animation: dt-rise 0.5s cubic-bezier(0.16,1,0.3,1) both;
  animation-play-state: paused;
}

#district-transition.dt-show #dt-inner {
  animation-play-state: running;
}

@keyframes dt-rise {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

#dt-label {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  font-weight: 700;
  color: rgba(0, 232, 184, 0.4);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  margin-bottom: 14px;
}

#dt-name-zh {
  font-family: var(--font-zh);
  font-size: 3.2rem;
  font-weight: 900;
  color: var(--text-bright);
  letter-spacing: 0.08em;
  line-height: 1;
  text-shadow: 0 0 40px rgba(0,232,184,0.15);
  margin-bottom: 12px;
}

#dt-rule {
  width: min(200px, 55vw);
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--teal), var(--magenta), transparent);
  opacity: 0.55;
  margin-bottom: 12px;
}

#dt-name-en {
  font-family: var(--font-mono);
  font-size: 0.77rem;
  font-weight: 700;
  color: var(--teal);
  letter-spacing: 0.28em;
  text-shadow: 0 0 14px rgba(0,232,184,0.5);
  margin-bottom: 8px;
}

#dt-theme {
  font-family: var(--font-zh);
  font-size: 0.72rem;
  font-style: italic;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

/* Landscape blocker */
@media (orientation: landscape) {
  #rotate-prompt { display: flex !important; }
}

#rotate-prompt {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-deep);
  color: var(--teal);
  font-size: 1rem;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  padding: 24px;
  font-family: var(--font-serif);
}

#rotate-prompt .rotate-icon { font-size: 2.5rem; }
