*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --font-title: "Pirata One", "Cinzel", serif;
  --font-head: "Cinzel", serif;
  --font-body: "Crimson Pro", "Noto Serif JP", "Songti SC", "PMingLiU", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --brass-hi: #e8c98e;
  --brass-mid: #b98d4a;
  --brass-lo: #6b4f26;
  --brass-edge: #5a3f1a;
}

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #05070a;
  font-family: var(--font-body);
  color: #dfe6e2;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
}

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

/* -------------------------------------------------- non-gameplay backdrop */
/* The WebGL canvas never renders anything meaningful until a ward is
   actually running, so it's hidden (opaque black otherwise) on every
   menu/overlay screen and this photo takes its place. */
#bg-backdrop {
  position: fixed; inset: 0; z-index: 0;
  background: url('../assets/menu-backdrop.webp') center 38% / cover no-repeat, #05070a;
  filter: saturate(0.9) brightness(0.82);
}
#bg-backdrop::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 42%, rgba(3,5,4,0.68) 100%);
}
body.playing #bg-backdrop { display: none; }
body:not(.playing) #game { visibility: hidden; }

/* -------------------------------------------------- rotate-to-landscape */
#rotate-hint {
  position: fixed; inset: 0; z-index: 90; display: none;
  align-items: center; justify-content: center;
  background: #05070a; color: #9aa8a0; text-align: center;
  padding: 30px; line-height: 1.6; font-size: 15px;
}
#rotate-hint .btn { margin: 12px 0 6px; }
#rotate-hint .rh-tip { font-size: 12px; opacity: 0.65; }
@media (orientation: portrait) and (max-width: 900px) {
  #rotate-hint { display: flex; }
}
/* CSS forced landscape (in-app browsers like WeChat that refuse orientation.lock) */
body.force-ls #rotate-hint { display: none !important; }
body.force-ls #stage {
  position: fixed; left: 50%; top: 50%; width: 100dvh; height: 100dvw;
  transform: translate(-50%, -50%) rotate(90deg);
}

#game {
  display: block; width: 100%; height: 100%;
  outline: none;
  cursor: crosshair;
  background: #000;
}
body.touch #game { cursor: default; }

#stage::after {
  content: '';
  position: absolute; inset: 0; pointer-events: none; z-index: 5;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,0.55) 100%);
}

/* cheap film-grain finishing pass — animated SVG turbulence noise, no WebGL postprocessing needed */
#stage::before {
  content: '';
  position: absolute; inset: -10%; pointer-events: none; z-index: 6;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.05;
  mix-blend-mode: overlay;
  animation: grain-shift 0.6s steps(4) infinite;
}
@keyframes grain-shift {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-2%, 1%); }
  50% { transform: translate(1%, -2%); }
  75% { transform: translate(-1%, 2%); }
  100% { transform: translate(0, 0); }
}

#screen-flash {
  position: absolute; inset: 0; z-index: 40; pointer-events: none;
  background: #fff; opacity: 0; transition: opacity 0.06s ease-out;
}
#screen-flash.active { opacity: 0.92; transition: opacity 0.02s; }

/* -------------------------------------------------- touch zones */
.touch-zone {
  position: absolute; top: 0; bottom: 0; z-index: 8;
  width: 50%;
}
.touch-zone.left { left: 0; }
.touch-zone.right { right: 0; }
body:not(.touch) .touch-zone { display: none; }

.joy-base, .joy-knob {
  position: fixed; z-index: 30; pointer-events: none;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}
.joy-base { width: 92px; height: 92px; border: 2px solid rgba(190,220,200,0.35); background: rgba(20,30,26,0.25); }
.joy-knob { width: 40px; height: 40px; background: rgba(190,220,200,0.5); }
.hidden { display: none !important; }

/* -------------------------------------------------- HUD */
#hud.hidden { display: none; }
#hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; }

#topbar {
  position: absolute; top: 12px; left: 12px; right: 12px;
  display: flex; gap: 10px; flex-wrap: wrap;
}
#topbar span {
  background: rgba(6,10,8,0.6);
  padding: 6px 12px; border-radius: 8px;
  font-size: 0.82rem; font-weight: 600;
  border: 1px solid rgba(160,200,175,0.15);
  letter-spacing: 0.02em;
}

#battery-wrap {
  position: absolute; top: 12px; right: 12px;
  display: flex; align-items: center; gap: 6px;
  background: rgba(6,10,8,0.6); padding: 6px 10px; border-radius: 8px;
  border: 1px solid rgba(160,200,175,0.15);
}
#battery-bar { width: 84px; height: 10px; background: rgba(255,255,255,0.12); border-radius: 5px; overflow: hidden; }
#battery-fill { height: 100%; width: 100%; background: #8fd9b0; transition: width 0.2s linear; }
#battery-fill.low { background: #d9704f; }

#tip {
  position: absolute; bottom: 120px; left: 50%; transform: translateX(-50%);
  background: rgba(6,10,8,0.72); padding: 10px 18px; border-radius: 10px;
  font-size: 0.86rem; max-width: min(560px, 88vw); text-align: center; line-height: 1.5;
  border: 1px solid rgba(160,200,175,0.18);
  opacity: 0; transition: opacity 0.25s;
}
#tip.show { opacity: 1; }

#reticle {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 5px; height: 5px; border-radius: 50%;
  background: rgba(230,240,235,0.55);
}

#minimap {
  position: absolute; top: 56px; right: 12px;
  border-radius: 10px; border: 1px solid rgba(160,200,175,0.22);
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
}

#touch-buttons {
  position: absolute; bottom: env(safe-area-inset-bottom, 16px); right: 16px;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: auto; z-index: 12;
}
body:not(.touch) #touch-buttons { display: none; }
#touch-buttons button {
  width: 64px; height: 64px; border-radius: 50%;
  background: rgba(20,30,26,0.55); border: 1px solid rgba(190,220,200,0.3);
  color: #dfe6e2; font-size: 0.78rem; font-weight: 700;
}
#touch-buttons button:active { background: rgba(190,220,200,0.3); }

/* -------------------------------------------------- overlays */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: none; align-items: center; justify-content: center;
  background: rgba(3,4,4,0.32);
  backdrop-filter: blur(1.5px);
  padding: 16px;
}
.overlay.show { display: flex; }

/* Institutional plaque: sharp corners, dark bronze-green gradient, a thin
   engraved brass ring border (double-gradient mask trick — no extra asset). */
.panel {
  position: relative;
  background: linear-gradient(160deg, #142019 0%, #0a1310 55%, #060b09 100%);
  border-radius: 3px;
  padding: 28px 32px;
  max-width: 440px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 28px 80px rgba(0,0,0,0.7), inset 0 0 40px rgba(0,0,0,0.35);
}
.panel::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: 3px;
  padding: 1.5px;
  background: linear-gradient(155deg, var(--brass-hi), var(--brass-lo) 30%, var(--brass-mid) 55%, var(--brass-edge) 80%, var(--brass-hi));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: 0.75;
}
.panel.wide { max-width: 620px; }

.logo {
  font-family: var(--font-title);
  font-size: 2rem; font-weight: 400; letter-spacing: 0.03em;
  color: #e4ecdf;
  text-shadow: 0 0 14px rgba(150,200,165,0.45), 0 2px 3px rgba(0,0,0,0.6);
  animation: title-flicker 7s infinite;
}
/* .logo.sm carries localized section titles (Archive/How to Play/etc., in any of
   the 5 supported languages) — Pirata One and Cinzel have no CJK/JA glyphs, so
   route those through the serif body stack instead of a generic system default. */
.logo.sm { font-family: var(--font-body); font-size: 1.5rem; font-weight: 600; letter-spacing: 0.02em; animation: none; text-shadow: none; }
.caught-title { color: #e0574f; }
.sub {
  font-family: var(--font-body); font-size: 0.85rem; letter-spacing: 0.03em;
  opacity: 0.62; margin-top: 6px;
}
.intro { margin: 16px 0; line-height: 1.65; font-size: 1rem; opacity: 0.88; }
.menu-progress { font-family: var(--font-body); font-size: 0.78rem; opacity: 0.55; margin-top: 12px; }

.lang-row { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.lang-label { font-size: 0.78rem; opacity: 0.6; }
.lang-select {
  font-family: var(--font-body); font-size: 0.82rem;
  background: rgba(255,255,255,0.06); color: #dfe6e2;
  border: 1px solid rgba(160,200,175,0.25); border-radius: 6px;
  padding: 5px 8px; cursor: pointer;
}
.lang-select:focus { outline: 1px solid var(--brass-mid); }

@keyframes title-flicker {
  0%, 4%, 6%, 8%, 88%, 100% { opacity: 1; }
  5%, 7% { opacity: 0.55; }
  40% { opacity: 0.85; }
}

.menu-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.btn {
  border-radius: 2px;
  padding: 11px 20px;
  font-family: var(--font-body); font-weight: 600; font-size: 0.92rem;
  letter-spacing: 0.02em;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center;
  transition: filter 0.15s, transform 0.1s;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, var(--brass-hi) 0%, var(--brass-mid) 48%, var(--brass-lo) 100%);
  color: #1b1305;
  border: 1px solid var(--brass-edge);
  text-shadow: 0 1px 0 rgba(255,255,255,0.3);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), inset 0 -2px 4px rgba(0,0,0,0.25), 0 3px 10px rgba(0,0,0,0.45);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost {
  background: linear-gradient(180deg, #263129, #131a15);
  border: 1px solid #445248;
  color: #cfe0d2;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
}
.btn.ghost:hover { filter: brightness(1.25); }

.help-body p { margin: 10px 0; line-height: 1.6; font-size: 0.95rem; }

#recap-canvas {
  display: block; margin: 14px auto; border-radius: 8px;
  border: 1px solid rgba(224,87,79,0.35);
  background: #0a0d0a;
}

.archive-list { max-height: 50vh; overflow-y: auto; margin: 12px 0; display: grid; gap: 8px; }
.lore-entry {
  background: rgba(255,255,255,0.04); border: 1px solid rgba(160,200,175,0.12);
  border-radius: 8px; padding: 10px 12px;
}
.lore-entry b { font-size: 0.86rem; color: #a8d9bb; }
.lore-entry p { font-size: 0.8rem; opacity: 0.75; margin-top: 4px; line-height: 1.5; }
.lore-entry.locked b { color: #6a7570; }
.lore-entry.locked p { opacity: 0.45; }

.submit-row { display: flex; gap: 8px; margin: 14px 0 8px; }
.submit-row input {
  flex: 1; padding: 9px 12px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.16); background: rgba(255,255,255,0.05);
  color: #dfe6e2; font-size: 0.88rem;
}
#submit-status { font-size: 0.8rem; opacity: 0.7; min-height: 1.2em; margin-bottom: 8px; }

.board { display: grid; gap: 6px; margin-bottom: 6px; max-height: 200px; overflow-y: auto; }
.board-row { display: flex; gap: 10px; align-items: center; padding: 6px 10px; background: rgba(255,255,255,0.04); border-radius: 8px; font-size: 0.84rem; }
.board-rank { opacity: 0.6; width: 28px; }
.board-empty { opacity: 0.5; font-size: 0.85rem; padding: 8px 0; }

@media (max-width: 480px) {
  .panel { padding: 20px; }
  .logo { font-size: 1.3rem; }
}

/* -------------------------------------------------- settings gear + panel */
#btn-settings {
  pointer-events: auto; cursor: pointer;
  background: rgba(6,10,8,0.6); border: 1px solid rgba(160,200,175,0.15);
  border-radius: 8px; width: 34px; height: 34px; font-size: 1rem;
  color: #dfe6e2; margin-left: auto;
}
#btn-settings:active { filter: brightness(1.3); }

.settings-body { margin: 16px 0; display: grid; gap: 16px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  font-size: 0.88rem;
}
.setting-row span { flex: 1; line-height: 1.4; }
.setting-row em { display: block; font-style: normal; font-size: 0.74rem; opacity: 0.55; margin-top: 2px; }
.setting-row input[type="range"] {
  width: 130px; accent-color: var(--brass-mid);
}
.setting-row input[type="checkbox"] {
  width: 22px; height: 22px; accent-color: var(--brass-mid); flex: none;
}
.toggle-row { cursor: pointer; }

/* -------------------------------------------------- cutscene card (ward-clear / reveal) */
.cutscene-overlay { z-index: 45; background: rgba(2,3,3,0.88); backdrop-filter: none; }
.cutscene-frame {
  max-width: 640px; width: 100%; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  cursor: pointer;
}
.cutscene-img {
  max-width: 100%; max-height: 56vh; border-radius: 4px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.75);
  border: 1px solid rgba(160,200,175,0.18);
}
.cutscene-img:not([src]), .cutscene-img[src=""] { display: none; }
.cutscene-caption {
  font-family: var(--font-body); font-size: 1.02rem; line-height: 1.7;
  color: #e4ecdf; opacity: 0.92; max-width: 52ch;
}
.cutscene-hint { font-size: 0.76rem; opacity: 0.4; letter-spacing: 0.04em; }

/* -------------------------------------------------- ward 5 confrontation dialogue */
.confront-box {
  position: absolute; left: 50%; bottom: 8%; transform: translateX(-50%) translateY(12px);
  z-index: 22; width: min(560px, 92vw); text-align: center;
  background: rgba(4,6,5,0.78); border: 1px solid rgba(160,200,175,0.2);
  border-radius: 6px; padding: 18px 22px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.confront-box.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; cursor: pointer; }
.confront-speaker { font-family: var(--font-body); font-weight: 600; font-size: 0.82rem; color: #a8d9bb; letter-spacing: 0.05em; margin-bottom: 6px; }
.confront-line { font-size: 1.02rem; line-height: 1.6; color: #e4ecdf; }
.confront-hint { font-size: 0.72rem; opacity: 0.4; margin-top: 10px; }

.ending-text {
  margin-top: 14px; padding-top: 14px; border-top: 1px solid rgba(160,200,175,0.15);
  font-style: italic; opacity: 0.82; line-height: 1.7;
}

@media (max-width: 480px) {
  .setting-row input[type="range"] { width: 100px; }
  .confront-box { bottom: 12%; padding: 14px 16px; }
}
