:root {
  --bg-outer: #0d0c14;
  --bg-screen: #12101e;
  --window-bg: #14172b;
  --window-border: #e4e8ff;
  --window-shadow: #4a548f;
  --text-main: #f4f6ff;
  --text-dim: #9aa4d4;
  --accent-love: #ff5d9e;
  --accent-danger: #9eff4a;
  --accent-blood: #e82c4f;
  --accent-gold: #ffd452;
}

* {
  box-sizing: border-box;
  user-select: none;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at center, #1d1830 0%, #09080f 100%);
  color: var(--text-main);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "MS Gothic", monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.crt-shell {
  width: 100%;
  max-width: 720px;
  padding: 14px;
  background: #222230;
  border: 4px solid #3c3e58;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.75), inset 0 0 12px rgba(0, 0, 0, 0.8);
}

.crt-screen {
  position: relative;
  background: var(--bg-screen);
  border: 3px solid #090910;
  border-radius: 6px;
  overflow: hidden;
  min-height: 540px;
  display: flex;
  flex-direction: column;
}

/* CRTスキャンライン演出 */
.scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 30;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.025) 0px,
    rgba(255, 255, 255, 0.025) 1px,
    rgba(0, 0, 0, 0.14) 2px,
    rgba(0, 0, 0, 0.14) 3px
  );
}

.damage-flash {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 25;
  opacity: 0;
  background: radial-gradient(circle, rgba(232, 44, 79, 0.2) 20%, rgba(200, 10, 40, 0.8) 100%);
  transition: opacity 0.25s ease-out;
}

.damage-flash.active {
  opacity: 1;
}

.crt-screen.shake {
  animation: screen-shake 0.38s linear;
}

@keyframes screen-shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-8px, 4px); }
  40% { transform: translate(8px, -4px); }
  60% { transform: translate(-6px, -3px); }
  80% { transform: translate(6px, 3px); }
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: 14px;
  position: relative;
  z-index: 10;
}

.screen.active {
  display: flex;
}

/* タイトル画面 */
#title-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  background: linear-gradient(180deg, #1b112b 0%, #101324 100%);
}

.title-badge {
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--accent-danger);
  border: 1px solid var(--accent-danger);
  padding: 3px 10px;
}

.game-title {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.title-main {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 3px;
  color: var(--accent-love);
  text-shadow: 3px 3px 0 #3f0e2c, -1px -1px 0 #fff;
}

.title-sub {
  font-size: 16px;
  color: var(--accent-gold);
  letter-spacing: 2px;
}

#title-canvas,
#ending-canvas,
#stage-canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 3px solid var(--window-border);
  box-shadow: 0 0 0 3px var(--window-shadow);
  background: #0b0c15;
}

#title-canvas {
  width: 288px;
  height: 180px;
}

.title-catch {
  margin: 4px 0;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-dim);
}

.player-name-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 2px 0 4px;
}

.player-name-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-gold);
}

.player-name-input {
  user-select: text;
  -webkit-user-select: text;
  width: 150px;
  padding: 5px 10px;
  background: #0d1020;
  color: var(--text-main);
  border: 2px solid var(--window-border);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  outline: none;
}

.player-name-input:focus {
  border-color: var(--accent-love);
  box-shadow: 0 0 0 2px rgba(255, 93, 158, 0.3);
}

.title-actions,
.ending-actions,
.gallery-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.title-footer {
  margin-top: 6px;
  font-size: 11px;
  letter-spacing: 2px;
  color: #6b74a5;
  animation: blink 1.3s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0.25; }
}

/* レトロボタン */
.retro-btn {
  cursor: pointer;
  background: var(--window-bg);
  color: var(--text-main);
  border: 2px solid var(--window-border);
  box-shadow: 0 3px 0 var(--window-shadow);
  padding: 9px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  transition: transform 0.08s ease, background 0.15s ease;
}

.retro-btn:hover {
  background: #23294d;
  border-color: var(--accent-gold);
}

.retro-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--window-shadow);
}

.retro-btn.primary {
  background: #381845;
  border-color: var(--accent-love);
}

.retro-btn.primary:hover {
  background: #522063;
}

.retro-btn.danger {
  border-color: var(--accent-blood);
  color: #ff9eb0;
}

.retro-btn.hard-btn {
  background: #421121;
  border-color: var(--accent-blood);
  color: #ffd6de;
  box-shadow: 0 3px 0 #70162d;
}

.retro-btn.hard-btn:hover {
  background: #61152c;
  border-color: var(--accent-gold);
}

.retro-btn.continue-btn {
  background: #143633;
  border-color: #63f2c7;
  color: #dcfff4;
  box-shadow: 0 3px 0 #0d6650;
}

.retro-btn.continue-btn:hover {
  background: #1d4d48;
  border-color: var(--accent-gold);
}

.retro-btn.another-btn {
  background: #271b47;
  border-color: #b78cff;
  color: #efe5ff;
  box-shadow: 0 3px 0 #4d348a;
}

.retro-btn.another-btn:hover {
  background: #382666;
  border-color: var(--accent-gold);
}

#another-screen {
  gap: 10px;
}

.another-lead {
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
}

.another-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.another-card {
  cursor: pointer;
  text-align: left;
  background: var(--window-bg);
  color: var(--text-main);
  border: 2px solid #7d6bb3;
  padding: 10px 12px;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}

.another-card:hover {
  background: #221d3d;
  border-color: var(--accent-gold);
  transform: translateX(4px);
}

.another-card.locked {
  cursor: not-allowed;
  opacity: 0.62;
  border-color: #4b4e69;
  background: #121321;
}

.another-card.locked:hover {
  transform: none;
  border-color: #6b7094;
  background: #121321;
}

.another-tag.locked-tag {
  border-color: #8c92b5;
  color: #aeb5db;
  background: #1a1d30;
}

.another-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
}

.another-tag {
  font-size: 10px;
  padding: 2px 6px;
  border: 1px solid #b78cff;
  color: #d9c2ff;
  white-space: nowrap;
}

.another-tag.cleared {
  border-color: #63f2c7;
  color: #63f2c7;
  background: #102e29;
}

.another-card-desc {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}

.continue-actions {
  margin-top: -2px;
}

/* TRUE END 今風CGイラスト表示 */
.stage-cg {
  display: none;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 3px solid var(--accent-gold);
  box-shadow: 0 0 24px rgba(255, 160, 200, 0.45), 0 0 0 3px var(--window-shadow);
  animation: cg-fade-in 0.8s ease-out;
}

.stage-cg.active {
  display: block;
}

.ending-cg {
  display: none;
  width: 100%;
  max-width: 460px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 3px solid var(--accent-gold);
  box-shadow: 0 0 26px rgba(255, 120, 175, 0.5), 0 0 0 3px var(--window-shadow);
  animation: cg-fade-in 0.7s ease-out;
}

.ending-cg.active {
  display: block;
}

@keyframes cg-fade-in {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

.sub-actions {
  margin-top: -2px;
}

.mode-hint {
  margin: 0;
  font-size: 11px;
  color: #ff9eb0;
}

/* HUD */
.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--window-bg);
  border: 2px solid var(--window-border);
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mode-badge {
  font-size: 10px;
  font-weight: 900;
  padding: 2px 6px;
  letter-spacing: 1px;
  border: 1px solid currentColor;
}

.mode-badge.easy {
  color: #7be8ff;
  background: #102536;
}

.mode-badge.hard {
  color: #ff5d7a;
  background: #3b0d1a;
}

/* 暴走モード演出 */
.crt-screen.berserk-mode {
  background: #1c0810;
  box-shadow: inset 0 0 40px rgba(232, 44, 79, 0.55);
}

.crt-screen.berserk-mode .hud-bar,
.crt-screen.berserk-mode .dialog-box {
  border-color: #ff4d6d;
  box-shadow: inset 0 0 0 2px #7a1228;
}

.berserk-banner {
  display: none;
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(160, 10, 36, 0.94);
  border: 2px solid #ffd452;
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 2px;
  padding: 4px 14px;
  white-space: nowrap;
  animation: berserk-pulse 0.7s ease-in-out infinite alternate;
}

.crt-screen.berserk-mode .berserk-banner {
  display: block;
}

@keyframes berserk-pulse {
  from { transform: translateX(-50%) scale(1); background: rgba(150, 10, 34, 0.92); }
  to { transform: translateX(-50%) scale(1.04); background: rgba(220, 20, 56, 0.98); }
}

/* 暴走タイマー */
.berserk-timer {
  display: none;
  margin-bottom: 8px;
  padding: 6px 10px;
  background: #2b0b16;
  border: 2px solid #ff4d6d;
}

.berserk-timer.active {
  display: block;
}

.berserk-timer.critical {
  border-color: #ffd452;
  animation: timer-blink 0.35s step-end infinite;
}

@keyframes timer-blink {
  50% { background: #590d22; }
}

.berserk-timer-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 900;
  color: #ffd6de;
  margin-bottom: 4px;
}

.berserk-timer-track {
  width: 100%;
  height: 10px;
  background: #120409;
  border: 1px solid #ff8fa3;
  overflow: hidden;
}

.berserk-timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff2a55, #ffd452);
  transition: width 0.08s linear;
}

.clear-badges {
  display: inline-flex;
  gap: 4px;
  margin-left: 6px;
}

.clear-badge {
  font-size: 10px;
  padding: 1px 5px;
  border: 1px solid currentColor;
}

.clear-badge.easy {
  color: #7be8ff;
  background: #102536;
}

.clear-badge.hard {
  color: #ff758f;
  background: #3b0d1a;
}

.hud-scene {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-gold);
  letter-spacing: 1px;
}

.hud-meters {
  display: flex;
  gap: 14px;
  flex: 1;
  justify-content: center;
  min-width: 240px;
}

.meter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
}

.love-meter .meter-label { color: var(--accent-love); }
.danger-meter .meter-label { color: var(--accent-danger); }

.meter-track {
  width: 90px;
  height: 11px;
  background: #0a0b14;
  border: 1px solid #6b74a5;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  transition: width 0.35s ease;
}

.love-meter .meter-fill {
  background: linear-gradient(90deg, #ff3a7f, #ff85b3);
}

.danger-meter .meter-fill {
  background: linear-gradient(90deg, #7be838, #e82c4f);
}

.meter-val {
  min-width: 24px;
  text-align: right;
}

.hud-controls {
  display: flex;
  gap: 6px;
}

.mini-btn {
  cursor: pointer;
  background: #0d1020;
  color: var(--text-dim);
  border: 1px solid #6b74a5;
  padding: 3px 8px;
  font-size: 11px;
  font-family: inherit;
}

.mini-btn:hover {
  color: var(--text-main);
  border-color: var(--window-border);
}

/* ステージ */
.stage-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
}

#stage-canvas {
  width: 100%;
  max-width: 640px;
  aspect-ratio: 16 / 9;
  height: auto;
}

.location-tag {
  position: absolute;
  top: 8px;
  left: 14px;
  background: rgba(12, 14, 28, 0.85);
  border: 1px solid var(--window-border);
  padding: 3px 8px;
  font-size: 11px;
  color: var(--accent-gold);
}

.status-toast {
  position: absolute;
  top: 8px;
  right: 14px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  background: rgba(12, 14, 28, 0.92);
  border: 1px solid var(--accent-gold);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

.status-toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* 選択肢 */
.choices-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  min-height: 0;
}

.choice-btn {
  cursor: pointer;
  text-align: left;
  background: #1a1f3d;
  color: var(--text-main);
  border: 2px solid #8a95d6;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}

.choice-btn:hover {
  background: #2b224a;
  border-color: var(--accent-gold);
  transform: translateX(4px);
}

.choice-btn::before {
  content: "▶ ";
  color: var(--accent-love);
}

/* テキストウィンドウ */
.dialog-box {
  position: relative;
  min-height: 122px;
  background: var(--window-bg);
  border: 3px solid var(--window-border);
  box-shadow: inset 0 0 0 2px var(--window-shadow);
  padding: 16px 16px 14px;
  cursor: pointer;
}

.speaker-name {
  display: inline-block;
  position: absolute;
  top: -13px;
  left: 12px;
  background: #2d1842;
  border: 2px solid var(--window-border);
  padding: 1px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-love);
}

.speaker-name.narrator {
  color: var(--accent-gold);
  background: #1b2242;
}

.dialog-text {
  font-size: 15px;
  line-height: 1.7;
  min-height: 76px;
  white-space: pre-wrap;
}

.next-indicator {
  position: absolute;
  right: 12px;
  bottom: 8px;
  font-size: 12px;
  color: var(--accent-gold);
  animation: blink 0.8s step-end infinite;
}

.next-indicator.hidden {
  visibility: hidden;
}

/* エンディング画面 */
#ending-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
}

.ending-banner {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 3px;
  padding: 4px 14px;
  border: 2px solid currentColor;
}

.ending-banner.good { color: var(--accent-love); }
.ending-banner.normal { color: var(--accent-gold); }
.ending-banner.bad { color: var(--accent-blood); }

.ending-title {
  margin: 0;
  font-size: 21px;
  color: var(--text-main);
}

#ending-canvas {
  width: 288px;
  height: 162px;
}

.ending-desc {
  max-width: 560px;
  margin: 4px 0;
  font-size: 14px;
  line-height: 1.75;
  background: var(--window-bg);
  border: 2px solid var(--window-border);
  padding: 12px 14px;
  text-align: left;
}

.ending-stats {
  font-size: 12px;
  color: var(--text-dim);
}

/* エンディング図鑑 */
#gallery-screen {
  gap: 12px;
}

.gallery-title {
  margin: 0;
  text-align: center;
  color: var(--accent-gold);
  font-size: 19px;
}

.gallery-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.gallery-item {
  background: var(--window-bg);
  border: 2px solid #596294;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gallery-item.unlocked {
  border-color: var(--window-border);
}

.gallery-item-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
}

.tag-good { color: var(--accent-love); }
.tag-normal { color: var(--accent-gold); }
.tag-bad { color: var(--accent-blood); }

.gallery-item-desc {
  font-size: 12px;
  color: var(--text-dim);
}

@media (max-width: 560px) {
  .title-main { font-size: 24px; }
  .dialog-text { font-size: 14px; }
  .choice-btn { font-size: 13px; }
}
