/* Chrono Adventure — watercolor storybook UI chrome.
   Placeholder gradients stand in for backgrounds/portraits until the
   art pass lands; every image tag degrades gracefully on 404. */

:root {
  --ink: #2b2138;
  --paper: #f7ecd9;
  --paper-dark: #e8d9bb;
  --paper-line: #c9b790;
  --accent-warm: #d97f4c;
  --accent-cool: #4c7fd9;
  --accent-1672: #8a5a2b;
  --gold: #c9a227;
  --danger: #a33b3b;
  --good: #3b8a5a;
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--ink);
  color: var(--ink);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
#app { position: relative; width: 100vw; height: 100vh; overflow: hidden; }
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }

/* ---------- buttons ---------- */
.btn {
  background: url('../assets/img/ui_button_plaque.webp') center/100% 100% no-repeat;
  border: none;
  border-radius: 0;
  padding: 0.75em 1.8em;
  font-size: 1rem;
  font-weight: 700;
  color: #3a2a12;
  text-shadow: 0 1px 1px rgba(255,255,255,0.35);
  filter: drop-shadow(0 3px 3px rgba(0,0,0,0.35));
  transition: transform 0.08s ease, filter 0.08s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-2px) scale(1.03); filter: drop-shadow(0 5px 5px rgba(0,0,0,0.4)) brightness(1.04); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); filter: drop-shadow(0 2px 2px rgba(0,0,0,0.3)); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary {
  background-image: url('../assets/img/ui_button_plaque_primary.webp');
  color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}
.btn-sm { padding: 0.5em 1.1em; font-size: 0.85rem; }

/* inline icon assets (replace emoji) */
.ui-icon { height: 1.3em; width: auto; vertical-align: -0.3em; display: inline-block; }
.ui-icon.icon-inline { height: 1.1em; vertical-align: -0.2em; }
.btn-arrow-back .ui-icon, .btn-arrow-next .ui-icon { height: 0.9em; }
.btn-arrow-back { display: inline-flex; align-items: center; gap: 0.35em; flex-direction: row-reverse; }
.btn-arrow-next { display: inline-flex; align-items: center; gap: 0.35em; }

/* ---------- title screen ---------- */
.title-screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  gap: 1.5rem; text-align: center; padding: 4vh 2rem 8vh;
}
/* Two layers split FROM the single agreed-on title_hero illustration
   (see tools/gen_title_layers.py) — far: the full canal/sky/clock scene
   with the sisters inpainted out; near: just the sisters, cut to alpha —
   both the same 1536x1024 canvas, so they stay perfectly aligned and
   together reconstruct the original at rest. Drifting them at slightly
   different speeds sells a parallax panning depth illusion. */
.title-parallax {
  position: absolute; inset: 0; z-index: -1; overflow: hidden;
  background: #10141f;
}
.title-layer {
  position: absolute; inset: -3% -6%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  will-change: transform;
}
.title-layer-far {
  background-image: url('../assets/img/title_bg_far.webp');
  animation: title-pan-far 46s ease-in-out infinite alternate;
}
.title-layer-near {
  background-image: url('../assets/img/title_fg_near.webp');
  animation: title-pan-near 46s ease-in-out infinite alternate;
}
.title-scrim {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(20,15,26,0.18) 0%, rgba(20,15,26,0.08) 45%, rgba(20,15,26,0.62) 100%);
}
@keyframes title-pan-far {
  from { transform: translateX(-1.2%); }
  to { transform: translateX(1.2%); }
}
@keyframes title-pan-near {
  from { transform: translateX(-2.4%); }
  to { transform: translateX(2.4%); }
}
/* Illustrated calligraphy wordmark (a real painted asset, not a font) —
   one image per language since the subtitle line is translated. */
.title-logo {
  position: absolute; top: 6vh; left: 50%; transform: translateX(-50%);
  width: min(80vw, 46rem); height: auto;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,0.55));
}
.title-buttons { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; }
.lang-row { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center; }
.lang-btn {
  background: var(--paper-dark); border: 2px solid var(--ink); border-radius: 8px;
  padding: 0.4em 0.9em; font-weight: 600;
}
.lang-btn.active { background: var(--gold); }

/* ---------- HUD ---------- */
.hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1rem; pointer-events: none;
}
.trunk-btn {
  pointer-events: auto;
  background: var(--paper); border: 2px solid var(--ink);
  border-radius: 50%; width: 3.2rem; height: 3.2rem; box-shadow: 0 3px 0 var(--ink);
  display: flex; align-items: center; justify-content: center;
}
.trunk-btn .ui-icon { height: 1.9rem; vertical-align: 0; }
.hud-stats { display: flex; gap: 0.6rem; pointer-events: auto; }
.hud-stat {
  background: rgba(43,33,56,0.85); color: var(--paper);
  border: 1px solid var(--gold); border-radius: 999px; padding: 0.3em 0.8em;
  font-weight: 600; font-size: 0.9rem;
}

/* ---------- stage / hotspots ---------- */
.stage { position: absolute; inset: 0; overflow: hidden; }
.bg-fallback {
  position: absolute; inset: 0;
  background: linear-gradient(160deg, #4c6a8a 0%, #6d8fae 40%, #d9b98c 100%);
}
.stage.era-past .bg-fallback {
  background: linear-gradient(160deg, #5a3a24 0%, #8a5a2b 45%, #c9a227 100%);
}
.bg-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hotspot-layer { position: absolute; inset: 0; }
.hotspot {
  position: absolute; border-radius: 12px; cursor: pointer;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.15) inset;
  animation: hotspot-pulse 2.4s ease-in-out infinite;
}
.hotspot-hotcoin { box-shadow: 0 0 18px 4px rgba(201,162,39,0.65) inset; animation-duration: 1.4s; }
.hotspot-hotcoin.collected { opacity: 0; pointer-events: none; }
.hotspot-trigger { box-shadow: 0 0 20px 6px rgba(255,255,255,0.35) inset; animation-duration: 1.6s; }
@keyframes hotspot-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.35); }
}
.fx-layer { position: absolute; inset: 0; pointer-events: none; z-index: 15; }

/* ---------- dialogue box ----------
   Ace Attorney composition: the character fills most of the stage, and a
   wide, centered textbox crosses over their lower body near the bottom —
   the box sits ABOVE the portrait in stacking order, not beside it. */
#dialogue-slot { position: absolute; inset: 0; z-index: 25; pointer-events: none; }
.dialogue-wrap {
  position: absolute; inset: 0;
  pointer-events: auto; cursor: pointer;
  animation: portrait-fade-in 0.28s ease-out;
}
@keyframes portrait-fade-in {
  from { transform: translateY(14px); }
  to { transform: none; }
}
.portrait {
  position: absolute; bottom: -2vh; z-index: 1;
  max-height: 88vh;
  filter: drop-shadow(0 10px 14px rgba(0,0,0,0.45));
}
.portrait-left { left: 3vw; }
.portrait-right { right: 3vw; }
.portrait-center { left: 50%; transform: translateX(-50%); }
.dialogue-box {
  position: absolute; z-index: 2; left: 50%; bottom: 1.2rem;
  transform: translateX(-50%);
  width: min(94vw, 68rem);
  background: var(--paper); border: 3px solid var(--ink); border-radius: 16px;
  padding: 1rem 1.4rem; box-shadow: 0 6px 0 rgba(0,0,0,0.3);
  min-height: 6rem;
}
.narrator .dialogue-box { font-style: italic; text-align: center; background: rgba(247,236,217,0.92); }
.dialogue-name { font-weight: 800; color: var(--accent-warm); margin-bottom: 0.2em; }
.dialogue-text { font-size: 1.08rem; line-height: 1.4; white-space: pre-line; }
.tap-indicator { text-align: right; font-size: 0.8rem; opacity: 0.6; margin-top: 0.3em; }
.dialogue-choices { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.6rem; }
.choice-btn { text-align: left; }

/* ---------- toasts ---------- */
.toast-box {
  position: absolute; top: 4.2rem; left: 50%; transform: translateX(-50%); z-index: 30;
  display: flex; flex-direction: column; gap: 0.3rem; align-items: center;
  pointer-events: none;
}
.toast {
  background: rgba(43,33,56,0.92); color: var(--paper); border: 1px solid var(--gold);
  border-radius: 999px; padding: 0.35em 1em; font-weight: 600; font-size: 0.9rem;
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- overlays (puzzle / confrontation / trunk / evidence) ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 40;
  background: rgba(20,15,26,0.72);
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem; overflow-y: auto;
}
.overlay-panel {
  background: var(--paper); border: 3px solid var(--ink); border-radius: 18px;
  max-width: 56rem; width: 100%; max-height: 92vh; overflow-y: auto;
  padding: 1.4rem 1.6rem; box-shadow: 0 10px 0 rgba(0,0,0,0.35);
}
.overlay-title { font-size: 1.3rem; font-weight: 800; margin-bottom: 0.4rem; display: flex; align-items: center; gap: 0.6rem; }
.picarat-badge { font-size: 0.85rem; background: var(--gold); border-radius: 999px; padding: 0.1em 0.7em; }
.overlay-prompt { margin-bottom: 0.8rem; opacity: 0.85; }
.overlay-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; align-items: center; }

/* sequence puzzle */
.seq-pool { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; min-height: 3rem; }
.seq-card {
  background: var(--paper-dark); border: 2px solid var(--ink); border-radius: 10px;
  padding: 0.5em 0.8em; font-size: 0.92rem; max-width: 20rem; cursor: pointer;
}
.seq-card.selected { background: var(--gold); }
.seq-card.placed { cursor: pointer; max-width: none; }
.seq-slots { display: flex; flex-direction: column; gap: 0.4rem; }
.seq-slot {
  display: flex; align-items: center; gap: 0.6rem; min-height: 2.6rem;
  border: 2px dashed var(--paper-line); border-radius: 10px; padding: 0.3rem 0.6rem;
}
.seq-slot.filled { border-style: solid; }
.seq-slot-num { font-weight: 800; color: var(--accent-warm); width: 1.4em; }

/* matching puzzle */
.match-cols { display: flex; gap: 1rem; flex-wrap: wrap; }
.match-col { flex: 1; min-width: 14rem; display: flex; flex-direction: column; gap: 0.5rem; }
.match-item {
  background: var(--paper-dark); border: 2px solid var(--ink); border-radius: 10px;
  padding: 0.5em 0.8em; font-size: 0.9rem; cursor: pointer; position: relative;
}
.match-item.selected { background: var(--accent-cool); color: #fff; }
.match-item.matched { border-color: var(--good); }
.match-badge {
  display: inline-block; background: var(--good); color: #fff; border-radius: 999px;
  width: 1.4em; height: 1.4em; text-align: center; line-height: 1.4em; font-size: 0.75rem;
  margin-right: 0.4em;
}

.hints-panel { margin-top: 0.8rem; display: flex; flex-direction: column; gap: 0.3rem; }
.hint-text { background: rgba(201,162,39,0.18); border-left: 4px solid var(--gold); padding: 0.4em 0.7em; font-size: 0.9rem; }
.puzzle-feedback { font-weight: 700; margin-top: 0.5rem; min-height: 1.4em; }
.puzzle-feedback.correct { color: var(--good); }
.puzzle-feedback.wrong { color: var(--danger); animation: shake 0.3s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* confrontation */
.confrontation-overlay { flex-direction: column; }
.conf-strikes { position: absolute; top: 1rem; right: 1.5rem; font-size: 1.3rem; letter-spacing: 0.2em; z-index: 30; }
.conf-box { border-color: var(--danger); }
.conf-feedback { margin-top: 0.5rem; font-weight: 700; color: var(--danger); }
.conf-actions {
  display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; margin-top: 0.8rem;
}

/* evidence */
.evidence-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: 0.7rem; margin: 0.8rem 0; }
.evidence-card {
  background: var(--paper-dark); border: 2px solid var(--ink); border-radius: 10px;
  padding: 0.6em; text-align: center; cursor: pointer;
}
.evidence-card.static { cursor: default; text-align: left; }
.evidence-card img { height: 4rem; object-fit: contain; margin: 0 auto 0.4em; }
.evidence-name { font-weight: 700; font-size: 0.85rem; }
.evidence-desc { font-size: 0.8rem; opacity: 0.8; margin-top: 0.3em; }

/* trunk */
.tab-row { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.tab-btn.active { background: var(--gold); }
.trunk-content { min-height: 8rem; margin-bottom: 1rem; }
.journal-list { padding-left: 1.2rem; display: flex; flex-direction: column; gap: 0.5rem; }

/* chapter end */
.chapter-end {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 0.8rem; background: linear-gradient(180deg, #201829, #3a2e4d);
  color: var(--paper); text-align: center; padding: 2rem;
}
.chapter-end h2 { font-family: Georgia, serif; font-size: 2rem; }
.chapter-end .cliff { font-style: italic; color: var(--gold); font-size: 1.2rem; }

/* fx */
.fx-splash {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: Georgia, serif; font-weight: 900; font-size: clamp(2.5rem, 10vw, 7rem);
  color: #fff; -webkit-text-stroke: 3px var(--danger); text-shadow: 0 0 30px rgba(0,0,0,0.6);
  background: rgba(0,0,0,0.15); animation: objection-pop 1.4s ease-out forwards;
}
@keyframes objection-pop {
  0% { transform: scale(0.4) rotate(-8deg); opacity: 0; }
  15% { transform: scale(1.15) rotate(2deg); opacity: 1; }
  25% { transform: scale(1) rotate(0deg); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}
.fx-era-flash {
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 60%, rgba(76,127,217,0.9), rgba(201,162,39,0.6) 60%, transparent 100%);
  animation: era-flash 1.9s ease-in-out forwards;
}
@keyframes era-flash {
  0% { opacity: 0; }
  30% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- small screens ---------- */
@media (max-width: 700px) {
  .portrait { max-height: 58vh; }
  .dialogue-wrap { padding: 0 0.6rem 0.8rem; }
  .match-cols { flex-direction: column; }
}
