:root {
  --ink: #f7f2ff;
  --muted: rgba(247, 242, 255, 0.72);
  --panel: rgba(11, 8, 18, 0.76);
  --panel-strong: rgba(12, 9, 20, 0.92);
  --red: #e11d48;
  --deep-red: #8b0000;
  --violet: #7c3aed;
  --blue: #b9e6ff;
  --line: rgba(255, 255, 255, 0.18);
  --shadow: 0 24px 90px rgba(0, 0, 0, 0.5);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; background: #050407; color: var(--ink); overflow: hidden; }
button { font: inherit; }
.game-root { min-height: 100dvh; min-height: 100svh; overflow: hidden; overscroll-behavior: none; }

.stage {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 100svh;
  overflow: hidden;
  isolation: isolate;
  background: #050407;
  touch-action: manipulation;
}

.bg-layer {
  position: absolute;
  inset: 0;
  background-image: linear-gradient(90deg, rgba(5,4,7,0.72), rgba(5,4,7,0.12) 48%, rgba(5,4,7,0.82)), var(--bg);
  background-size: cover;
  background-position: center;
  filter: saturate(1.16) contrast(1.08);
  transform: scale(1.025);
  z-index: -3;
}

.curse-vignette {
  position: absolute;
  inset: -12%;
  background:
    radial-gradient(circle at 82% 18%, rgba(124, 58, 237, 0.36), transparent 28%),
    radial-gradient(circle at 28% 70%, rgba(225, 29, 72, 0.30), transparent 30%),
    linear-gradient(180deg, rgba(0,0,0,0.18), rgba(0,0,0,0.72));
  mix-blend-mode: screen;
  opacity: 0.78;
  animation: cursePulse 5.8s ease-in-out infinite alternate;
  pointer-events: none;
  z-index: -2;
}

.stage.danger .curse-vignette { opacity: 1; filter: hue-rotate(-22deg) saturate(1.6); }
.stage.cold .curse-vignette { filter: hue-rotate(30deg) saturate(1.25); }

@keyframes cursePulse {
  from { transform: scale(1) rotate(0deg); opacity: 0.55; }
  to { transform: scale(1.05) rotate(1deg); opacity: 0.9; }
}

.topbar {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: max(22px, env(safe-area-inset-left));
  right: max(22px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  z-index: 5;
}

.eyebrow { margin: 0 0 5px; color: var(--blue); letter-spacing: 0.14em; text-transform: uppercase; font-size: 11px; font-weight: 800; text-shadow: 0 0 18px rgba(185,230,255,0.5); }
h1 { margin: 0; font-size: clamp(24px, 4vw, 52px); line-height: 0.95; letter-spacing: -0.06em; text-shadow: 0 8px 30px rgba(0,0,0,0.78); }
.ghost-btn {
  min-height: 44px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(10, 8, 14, 0.56);
  backdrop-filter: blur(16px);
  padding: 10px 14px;
  border-radius: 0;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.ghost-btn:hover, .choice-btn:hover { border-color: rgba(255,255,255,0.42); transform: translateY(-1px); }

.status-panel {
  position: absolute;
  top: 112px;
  left: max(22px, env(safe-area-inset-left));
  width: min(310px, 27vw);
  padding: 16px;
  background: linear-gradient(160deg, rgba(12, 9, 20, 0.88), rgba(25, 11, 24, 0.62));
  border: 1px solid rgba(255,255,255,0.16);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  z-index: 4;
}
.status-panel h2 { margin: 0 0 12px; font-size: 15px; letter-spacing: 0.16em; color: rgba(255,255,255,0.86); }
.meter { margin: 10px 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; }
.meter span { color: var(--muted); font-size: 13px; }
.meter b { font-size: 13px; }
.meter i { grid-column: 1 / -1; height: 8px; background: rgba(255,255,255,0.1); overflow: hidden; border: 1px solid rgba(255,255,255,0.09); }
.meter em { display: block; height: 100%; background: linear-gradient(90deg, var(--violet), var(--blue)); box-shadow: 0 0 16px rgba(124,58,237,0.8); }
.meter.risk em { background: linear-gradient(90deg, #5b0000, var(--red)); box-shadow: 0 0 18px rgba(225,29,72,0.8); }
.trust-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 14px 0; }
.trust-chip { border: 1px solid rgba(255,255,255,0.13); background: rgba(255,255,255,0.055); padding: 8px 9px; display:flex; justify-content:space-between; align-items:center; min-height: 38px; }
.trust-chip span { font-size: 12px; color: var(--muted); }
.trust-chip strong { color: #fff; }
.route-log { border-top: 1px solid rgba(255,255,255,0.12); padding-top: 12px; color: var(--muted); font-size: 12px; }
.route-log span { color: var(--blue); font-weight: 800; }
.route-log ol { margin: 8px 0 0; padding-left: 18px; max-height: 80px; overflow: hidden; }
.route-log li { margin: 3px 0; }

.character-zone {
  position: absolute;
  right: clamp(18px, 7vw, 120px);
  bottom: clamp(200px, 22vh, 250px);
  width: min(38vw, 520px);
  height: min(58vh, 620px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
}
.portrait {
  width: min(100%, 460px);
  height: min(100%, 560px);
  object-fit: cover;
  object-position: center 18%;
  border: 1px solid rgba(255,255,255,0.2);
  box-shadow: 0 30px 100px rgba(0,0,0,0.62), 0 0 80px rgba(124,58,237,0.28);
  clip-path: polygon(8% 0, 100% 0, 92% 100%, 0 100%);
}
.character-card {
  position: absolute;
  right: 0;
  bottom: 18px;
  min-width: 190px;
  padding: 12px 14px;
  background: rgba(8, 6, 12, 0.82);
  border: 1px solid rgba(255,255,255,0.16);
  box-shadow: 0 16px 40px rgba(0,0,0,0.4);
}
.character-card strong { display: block; font-size: 22px; letter-spacing: -0.04em; }
.character-card span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.sigil {
  width: 260px;
  height: 260px;
  border: 1px solid rgba(255,255,255,0.26);
  display:grid;
  place-items:center;
  color: rgba(255,255,255,0.24);
  font-size: 52px;
  letter-spacing: 0.15em;
  background: radial-gradient(circle, rgba(124,58,237,0.2), rgba(225,29,72,0.08), transparent 66%);
  animation: spinSigil 18s linear infinite;
}
@keyframes spinSigil { to { transform: rotate(360deg); } }

.dialogue-panel {
  position: absolute;
  left: max(22px, env(safe-area-inset-left));
  right: max(22px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  min-height: 176px;
  padding: clamp(18px, 2.2vw, 28px);
  background: linear-gradient(145deg, rgba(8, 6, 12, 0.92), rgba(17, 10, 24, 0.78));
  border: 1px solid rgba(255,255,255,0.18);
  border-left: 4px solid var(--red);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  z-index: 6;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(300px, 0.95fr);
  gap: 18px;
  align-items: end;
}
.scene-title { margin: 0 0 8px; color: var(--blue); font-weight: 900; letter-spacing: 0.08em; }
.dialogue-text { margin: 0; font-size: clamp(16px, 1.45vw, 22px); line-height: 1.65; text-shadow: 0 3px 18px rgba(0,0,0,0.65); }
.ending-badge { grid-column: 1 / -1; display: inline-flex; width: fit-content; padding: 6px 10px; background: rgba(225,29,72,0.18); border: 1px solid rgba(225,29,72,0.5); color: #fff; font-size: 12px; font-weight: 900; letter-spacing: 0.1em; }
.choices { display: grid; gap: 10px; }
.choice-btn {
  min-height: 54px;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
  border: 1px solid rgba(255,255,255,0.16);
  background: linear-gradient(135deg, rgba(255,255,255,0.10), rgba(124,58,237,0.12));
  padding: 11px 13px;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
  border-radius: 0;
}
.choice-btn span { display:block; font-weight: 800; line-height: 1.35; }
.choice-btn small { display:block; margin-top: 4px; color: var(--muted); }
.choice-btn:focus-visible, .ghost-btn:focus-visible { outline: 3px solid rgba(185,230,255,0.86); outline-offset: 2px; }
.danger-choice { background: linear-gradient(135deg, rgba(225,29,72,0.22), rgba(139,0,0,0.2)); }

@media (max-width: 980px) {
  .topbar { top: max(12px, env(safe-area-inset-top)); left: 14px; right: 14px; align-items: center; }
  .eyebrow { font-size: 9px; }
  h1 { font-size: clamp(22px, 7vw, 34px); }
  .ghost-btn { padding: 8px 10px; font-size: 13px; }
  .status-panel {
    top: auto;
    left: 14px;
    right: 14px;
    bottom: 214px;
    width: auto;
    display: grid;
    grid-template-columns: 90px 1fr 1fr;
    gap: 8px;
    padding: 10px;
  }
  .status-panel h2, .route-log { display:none; }
  .meter { margin: 0; }
  .trust-grid { margin: 0; grid-template-columns: repeat(4, 1fr); grid-column: 1 / -1; }
  .trust-chip { min-height: 32px; padding: 5px 6px; }
  .trust-chip span { font-size: 11px; }
  .character-zone {
    right: 4px;
    bottom: 286px;
    width: 44vw;
    height: 42vh;
  }
  .portrait { width: 100%; height: 100%; }
  .character-card { right: 8px; bottom: -8px; min-width: 136px; padding: 8px 9px; }
  .character-card strong { font-size: 17px; }
  .character-card span { font-size: 10px; }
  .dialogue-panel {
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    min-height: 194px;
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 13px;
  }
  .scene-title { font-size: 13px; margin-bottom: 4px; }
  .dialogue-text { font-size: 15px; line-height: 1.48; }
  .choices { gap: 7px; }
  .choice-btn { min-height: 46px; padding: 8px 10px; }
  .choice-btn small { display:none; }
}

@media (max-width: 520px) {
  .bg-layer { background-position: center; }
  .status-panel { bottom: 250px; grid-template-columns: 1fr 1fr; }
  .trust-grid { display:none; }
  .character-zone { width: 50vw; height: 34vh; bottom: 318px; opacity: 0.92; }
  .dialogue-panel { min-height: 236px; }
  .dialogue-text { font-size: 14px; }
  .choice-btn span { font-size: 13px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .topbar { top: 8px; }
  h1 { font-size: 24px; }
  .status-panel { top: 66px; bottom: auto; left: 12px; width: 250px; display:block; padding: 10px; }
  .status-panel h2 { display:block; font-size: 12px; margin-bottom: 6px; }
  .trust-grid, .route-log { display:none; }
  .character-zone { right: 20px; bottom: 124px; height: 54vh; width: 30vw; }
  .dialogue-panel { min-height: 116px; grid-template-columns: 1.05fr 1fr; padding: 10px 12px; gap: 10px; }
  .dialogue-text { font-size: 13px; line-height: 1.38; }
  .choice-btn { min-height: 36px; padding: 6px 9px; }
  .choice-btn span { font-size: 12px; }
}
