/* 深夜醫院：2:47 — 全域樣式。深藍冷色 + 單點紅光，跟隨美術聖經。 */

:root {
  --ink: #c8d6e5;
  --ink-dim: #7d8fa3;
  --bg: #04070d;
  --panel: rgba(7, 14, 24, 0.82);
  --line: rgba(120, 150, 180, 0.22);
  --accent: #8fb7d9;
  --danger: #b03434;
  --focus: #d7ecff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Noto Sans TC', 'Microsoft JhengHei', system-ui, sans-serif;
  line-height: 1.6;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  z-index: 30;
  padding: 0.5rem 1rem;
  background: var(--panel);
  color: var(--focus);
}

.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- screens ---------- */

.screen {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: clamp(1rem, 3vw, 2.5rem);
}

/* Screens with a fixed backdrop (start video, ending CG) must NOT paint their
   own opaque background — <main> sits above z-index:-1 fixed elements. */
.screen--start {
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 0.75rem;
}

/* Reduced-motion start screen has no trailer video behind it. */
.screen--plain {
  background:
    radial-gradient(ellipse at 50% 120%, rgba(28, 52, 82, 0.5), transparent 60%),
    var(--bg);
}

/* Start screen: the trailer loops behind the title. */
.start-bg {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  z-index: -2;
  filter: brightness(0.55) saturate(0.9);
}

.start-bg-shade {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(ellipse at 50% 55%, rgba(2, 5, 9, 0.25), rgba(2, 5, 9, 0.88) 80%);
}

.title--glitch {
  animation: title-jitter 7s steps(1) infinite;
}

@keyframes title-jitter {
  0%, 92%, 100% { transform: none; opacity: 1; }
  93% { transform: translateX(2px) skewX(-2deg); opacity: 0.85; }
  94% { transform: translateX(-3px); opacity: 1; }
  95.5% { transform: translateX(1px) skewX(1.5deg); opacity: 0.9; }
  96% { transform: none; }
}

.eyebrow {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.title {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3.4rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-shadow: 0 0 24px rgba(80, 130, 180, 0.35);
}

.lede {
  max-width: 34rem;
  color: var(--ink);
}

.start-note {
  font-size: 0.85rem;
  color: var(--ink-dim);
}

/* ---------- game scene ---------- */

.scene-backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
}

.scene-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.92);
  transition: opacity 0.5s ease;
}

.app--transitioning .scene-image {
  opacity: 0;
}

.stage--eerie .scene-image {
  animation: breathe 9s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.015); }
}

.screen--game::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(
    180deg,
    rgba(3, 6, 11, 0.72) 0%,
    rgba(3, 6, 11, 0.12) 35%,
    rgba(3, 6, 11, 0.12) 55%,
    rgba(3, 6, 11, 0.85) 100%
  );
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.scene-title {
  margin: 0.1rem 0 0;
  font-size: clamp(1.4rem, 4vw, 2.1rem);
  letter-spacing: 0.12em;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.hud-clock {
  margin: 0;
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.15em;
  color: var(--focus);
  text-shadow: 0 0 14px rgba(160, 200, 240, 0.5);
}

.stage--eerie .hud-clock {
  color: #d9a0a0;
  text-shadow: 0 0 14px rgba(176, 52, 52, 0.55);
}

.hud-loop {
  margin: 0;
  color: var(--ink-dim);
  font-size: 0.9rem;
}

.panel {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  backdrop-filter: blur(6px);
}

.object-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.object-chip {
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(14, 26, 42, 0.85);
  color: var(--ink);
  font-size: 0.95rem;
  cursor: pointer;
}

.object-chip:hover {
  border-color: var(--accent);
}

.object-chip--seen {
  color: var(--ink-dim);
  border-style: dashed;
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.button {
  padding: 0.65rem 1.2rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(16, 30, 48, 0.9);
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
}

.button--primary {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(46, 80, 116, 0.9), rgba(24, 44, 68, 0.9));
  color: #eaf4ff;
}

.button--primary:hover {
  filter: brightness(1.15);
}

.button--ghost {
  background: transparent;
}

.button--small {
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
}

.logbook-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  border-top: 1px dashed var(--line);
  padding-top: 0.9rem;
}

.logbook-form label {
  flex-basis: 100%;
  color: var(--ink);
}

.logbook-input {
  flex: 1 1 12rem;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(8, 16, 26, 0.95);
  color: var(--focus);
  font-size: 1.05rem;
  letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
}

.button--danger {
  border-color: var(--danger);
  background: linear-gradient(180deg, rgba(96, 26, 26, 0.9), rgba(52, 14, 14, 0.9));
  color: #ffdede;
}

.button--danger:hover {
  filter: brightness(1.2);
}

/* ---------- endings ---------- */

.screen--ending {
  justify-content: flex-end;
  align-items: center;
}

.ending-card {
  max-width: 40rem;
  margin-bottom: clamp(1rem, 6vh, 3.5rem);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  background: rgba(4, 8, 14, 0.78);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.4rem 1.8rem;
  backdrop-filter: blur(8px);
}

.screen--stay .ending-card {
  background: rgba(6, 10, 16, 0.82);
}

/* ---------- late-loop escalation: the hospital presses closer ---------- */

body[data-tier]::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
  opacity: 0;
  transition: opacity 2s ease;
}

body[data-tier='2']::before { opacity: 0.45; }
body[data-tier='3']::before { opacity: 0.7; }
body[data-tier='4']::before {
  opacity: 0.85;
  background:
    radial-gradient(ellipse at 50% 50%, transparent 45%, rgba(26, 2, 2, 0.5) 100%),
    radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.6) 100%);
}

body[data-tier='3'] .scene-image,
body[data-tier='4'] .scene-image {
  animation-duration: 6s;
  filter: saturate(0.8) contrast(1.06);
}

/* ---------- transition video ---------- */

.transition-video {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  z-index: 15;
  opacity: 0;
  pointer-events: none;
  background: #000;
}

.transition-video.transition--active {
  opacity: 1;
}

/* Loop reset: a slow blink, like the hospital closing its eyes. */
.loop-flash::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #000;
  animation: blink 0.9s ease-in-out;
  pointer-events: none;
}

@keyframes blink {
  0% { opacity: 0; }
  40% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- dialog & toast ---------- */

.game-dialog {
  border: none;
  border-radius: 14px;
  padding: 0;
  background: transparent;
  max-width: min(34rem, 92vw);
}

.game-dialog::backdrop {
  background: rgba(2, 4, 8, 0.75);
}

.dialog-frame {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem 1.25rem 1.4rem;
  color: var(--ink);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.dialog-header h2 {
  margin: 0.15rem 0 0;
  font-size: 1.3rem;
  letter-spacing: 0.08em;
}

.icon-button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 8px;
  width: 2.1rem;
  height: 2.1rem;
  font-size: 1.1rem;
  cursor: pointer;
}

.dialog-body {
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translate(-50%, 1rem);
  z-index: 25;
  max-width: min(30rem, 90vw);
  padding: 0.7rem 1.1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.toast--visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast[data-kind='error'] {
  border-color: var(--danger);
}

.toast[data-kind='success'] {
  border-color: var(--accent);
}

.no-script {
  padding: 3rem 1.5rem;
  text-align: center;
}

/* ---------- accessibility modes ---------- */

@media (prefers-reduced-motion: reduce) {
  .stage--eerie .scene-image {
    animation: none;
  }
  .loop-flash::after {
    animation: none;
    opacity: 0;
  }
  .scene-image,
  .toast {
    transition: none;
  }
}

@media (forced-colors: active) {
  .panel,
  .dialog-frame,
  .toast,
  .object-chip,
  .button {
    border: 1px solid CanvasText;
    background: Canvas;
    color: CanvasText;
  }
  .scene-image {
    filter: none;
  }
}
