:root {
  --bg1: #151728;
  --bg2: #20253b;
  --panel: rgba(15, 18, 36, 0.82);
  --panel-strong: rgba(23, 28, 54, 0.95);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f3f6ff;
  --subtext: #c6d0ee;
  --accent: #ff6fb1;
  --accent2: #7be1ff;
  --accent3: #ffe57b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, #2d335e, var(--bg1) 45%), linear-gradient(180deg, var(--bg2), #121523 70%);
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.topbar h1 {
  margin: 0;
  font-size: clamp(1.6rem, 2.7vw, 2.4rem);
  letter-spacing: 0.03em;
}
.subtitle {
  margin: 4px 0 0;
  color: var(--subtext);
}
.status-inline {
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: 999px;
  font-weight: 700;
}

.game-shell {
  display: flex;
  justify-content: center;
}
.canvas-wrap {
  position: relative;
  width: min(960px, 100%);
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 22px 70px rgba(0,0,0,0.45);
}
canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #e8edf6;
}

.hud {
  pointer-events: none;
  position: absolute;
  inset: 0;
}
.hud-panel {
  position: absolute;
  background: rgba(13, 18, 35, 0.78);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--subtext);
  backdrop-filter: blur(10px);
}
.hud-panel.left { left: 16px; top: 16px; max-width: 310px; }
.hud-panel.right { right: 16px; top: 16px; max-width: 250px; text-align: right; color: #fff; }
.hud-title { font-weight: 700; color: #fff; margin-bottom: 4px; }

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(4, 7, 17, 0.72);
  padding: 16px;
  z-index: 20;
}
.overlay.visible { display: grid; }
.panel {
  width: min(1100px, 100%);
  background: var(--panel-strong);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 24px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.52);
}
.intro-panel, .ending-panel {
  max-width: 760px;
  padding: 28px;
}
.intro-panel h2, .ending-panel h2 { margin-top: 0; font-size: 2rem; }
.intro-panel p, .intro-panel li, .ending-panel p { color: var(--subtext); line-height: 1.8; }
.intro-panel ul { padding-left: 1.3rem; }

.dialogue-panel { padding: 20px; }
.dialogue-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.dialogue-head h2 { margin: 0; }
.speaker { color: var(--accent2); margin-top: 4px; font-weight: 700; }
.portrait-row {
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  gap: 16px;
  align-items: stretch;
}
.portrait-card {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 18px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.portrait-label {
  font-size: 0.9rem;
  color: var(--accent3);
  font-weight: 700;
}
.portrait-card img {
  width: 100%;
  height: 360px;
  object-fit: contain;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
}
.npc-placeholder {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 360px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(123,225,255,0.15), rgba(255,111,177,0.15));
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #fff;
  text-align: center;
  padding: 16px;
}

.dialogue-center {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.dialogue-text {
  min-height: 170px;
  padding: 18px;
  border-radius: 18px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  font-size: 1.02rem;
  line-height: 1.95;
  color: #f7f8ff;
  white-space: pre-line;
}
.choices {
  display: grid;
  gap: 10px;
}
.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
button {
  cursor: pointer;
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font: inherit;
}
.primary-btn {
  background: linear-gradient(135deg, var(--accent), #ffa2c8);
  color: #240814;
  font-weight: 800;
}
.choice-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  color: #fff;
  text-align: left;
}
.choice-btn:hover { background: rgba(255,255,255,0.14); }
.secondary-btn {
  background: rgba(123,225,255,0.18);
  color: #dbf9ff;
  border: 1px solid rgba(123,225,255,0.24);
}
.ghost-btn {
  background: rgba(255,255,255,0.08);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.14);
}

.ending-panel {
  text-align: center;
}
.portal {
  width: 190px;
  height: 190px;
  border-radius: 50%;
  margin: 0 auto 18px;
  background:
    radial-gradient(circle at center, rgba(255,255,255,0.98) 0 12%, rgba(255,255,255,0.55) 12% 18%, rgba(123,225,255,0.6) 19% 34%, rgba(255,111,177,0.55) 35% 52%, rgba(255,229,123,0.48) 53% 64%, rgba(255,255,255,0) 65%),
    conic-gradient(from 0deg, #7be1ff, #ff6fb1, #ffe57b, #7be1ff);
  box-shadow: 0 0 24px rgba(123,225,255,0.6), 0 0 52px rgba(255,111,177,0.45);
  animation: spin 5s linear infinite;
}
.ending-sub { font-size: 0.95rem; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

@media (max-width: 940px) {
  .portrait-row {
    grid-template-columns: 1fr;
  }
  .portrait-card img, .npc-placeholder { height: 240px; }
  .hud-panel.left { max-width: 230px; font-size: 0.82rem; }
}
