:root {
  color-scheme: light;
  --ink: #16202a;
  --muted: #52606d;
  --paper: #fffaf2;
  --panel: rgba(255, 250, 242, 0.94);
  --line: rgba(22, 32, 42, 0.16);
  --teal: #147d7e;
  --teal-dark: #0d5558;
  --coral: #d95542;
  --gold: #d49a2f;
  --green: #2f7b4f;
  --blue: #356aa0;
  --shadow: 0 20px 60px rgba(22, 32, 42, 0.24);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family:
    Inter,
    Pretendard,
    "Noto Sans KR",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  color: var(--ink);
  background: #1f2c31;
  letter-spacing: 0;
}

button {
  font: inherit;
}

.game {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(31, 44, 49, 0.88), rgba(31, 44, 49, 0.96)),
    #1f2c31;
}

.stage {
  position: relative;
  width: min(1200px, 100%);
  min-height: min(760px, calc(100vh - 32px));
  overflow: hidden;
  border: 1px solid rgba(255, 250, 242, 0.2);
  border-radius: 8px;
  background: #dfe8e6;
  box-shadow: var(--shadow);
  isolation: isolate;
}

.backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform-origin: center;
  user-select: none;
  pointer-events: none;
  filter: saturate(1.03) contrast(1.02);
}

.game[data-mood="quake"] .backdrop,
.game[data-mood="aftershock"] .backdrop {
  animation: shake 420ms linear infinite;
}

.game[data-mood="quake"] .stage::after,
.game[data-mood="aftershock"] .stage::after,
.game[data-mood="gameover"] .stage::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(72, 55, 43, 0.18);
  pointer-events: none;
  z-index: 2;
}

.game[data-mood="gameover"] .stage::after {
  background: rgba(54, 10, 16, 0.34);
}

.quake-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
}

.game[data-mood="quake"] .quake-layer,
.game[data-mood="aftershock"] .quake-layer {
  opacity: 1;
}

.dust,
.debris {
  position: absolute;
  display: block;
}

.dust {
  width: 160px;
  height: 24px;
  border-radius: 999px;
  background: rgba(224, 214, 190, 0.5);
  filter: blur(4px);
  animation: dustFloat 4s linear infinite;
}

.dust-a {
  top: 19%;
  left: 18%;
}

.dust-b {
  top: 32%;
  right: 16%;
  animation-delay: 1.1s;
}

.dust-c {
  bottom: 31%;
  left: 42%;
  animation-delay: 2.1s;
}

.debris {
  width: 10px;
  height: 18px;
  border-radius: 2px;
  background: #9c6c43;
  animation: debrisFall 2.4s linear infinite;
}

.debris-a {
  top: -20px;
  left: 28%;
}

.debris-b {
  top: -34px;
  left: 51%;
  width: 14px;
  height: 12px;
  background: #c06959;
  animation-delay: 0.7s;
}

.debris-c {
  top: -26px;
  right: 24%;
  height: 14px;
  background: #365f74;
  animation-delay: 1.3s;
}

.character-sprite {
  position: absolute;
  right: clamp(20px, 7vw, 104px);
  bottom: 78px;
  width: min(39vw, 390px);
  min-width: 240px;
  max-height: 78%;
  object-fit: contain;
  z-index: 4;
  filter: drop-shadow(0 24px 32px rgba(22, 32, 42, 0.3));
  transition: transform 220ms ease, opacity 220ms ease;
}

.game[data-mood="quake"] .character-sprite,
.game[data-mood="aftershock"] .character-sprite {
  transform: translateX(-8px) rotate(-1deg);
}

.game[data-mood="ending"] .character-sprite {
  transform: translateY(-8px) scale(1.02);
  filter: drop-shadow(0 24px 36px rgba(151, 58, 86, 0.34));
}

.game[data-mood="gameover"] .character-sprite {
  transform: rotate(-2deg);
  filter: brightness(0.9) drop-shadow(0 24px 32px rgba(22, 32, 42, 0.36));
}

.hud {
  position: relative;
  z-index: 6;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: start;
  padding: 18px;
}

.title-mark {
  width: fit-content;
  max-width: 100%;
  padding: 12px 14px;
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.86);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.episode {
  display: block;
  margin-bottom: 3px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.meters {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: 8px;
}

.meter {
  min-width: 72px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.9);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.meter span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.meter strong {
  display: block;
  margin-top: 2px;
  font-size: 22px;
  line-height: 1;
}

.ghost-button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 250, 242, 0.9);
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.ghost-button:hover {
  border-color: rgba(20, 125, 126, 0.44);
}

.safety-note {
  position: absolute;
  left: 18px;
  top: 118px;
  z-index: 6;
  width: min(320px, calc(100% - 36px));
  padding: 13px 14px;
  border-left: 5px solid var(--teal);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.91);
  box-shadow: 0 12px 28px rgba(22, 32, 42, 0.14);
  color: #23313b;
  font-size: 14px;
  line-height: 1.55;
  backdrop-filter: blur(8px);
}

.dialogue {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  z-index: 7;
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid rgba(22, 32, 42, 0.18);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(22, 32, 42, 0.22);
  backdrop-filter: blur(12px);
}

.game[data-mood="gameover"] .dialogue {
  border-color: rgba(217, 85, 66, 0.58);
  background: rgba(255, 245, 240, 0.96);
}

.speaker-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.speaker,
.phase {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 800;
}

.speaker {
  padding: 0 12px;
  color: #fffaf2;
  background: var(--teal-dark);
}

.phase {
  padding: 0 10px;
  color: #513917;
  background: rgba(212, 154, 47, 0.22);
  border: 1px solid rgba(212, 154, 47, 0.38);
}

.story-text {
  min-height: 72px;
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.65;
  white-space: pre-line;
}

.feedback {
  margin: -2px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  color: #253640;
  background: rgba(20, 125, 126, 0.11);
  border: 1px solid rgba(20, 125, 126, 0.2);
  font-size: 15px;
  line-height: 1.55;
}

.choices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.choice-button {
  min-height: 64px;
  padding: 12px 13px;
  border: 1px solid rgba(22, 32, 42, 0.14);
  border-radius: 8px;
  color: #132027;
  background: #fffdf7;
  text-align: left;
  line-height: 1.35;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(22, 32, 42, 0.08);
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.choice-button:hover,
.choice-button:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(20, 125, 126, 0.46);
  background: #f4fffb;
  outline: none;
}

.choice-button strong {
  display: block;
  margin-bottom: 4px;
  color: var(--teal-dark);
  font-size: 13px;
}

.choice-button.danger strong {
  color: #9b3328;
}

.choice-button.romance strong {
  color: #a84368;
}

.choice-button.final {
  border-color: rgba(53, 106, 160, 0.28);
}

@keyframes shake {
  0% {
    transform: translate(0, 0) rotate(0);
  }
  20% {
    transform: translate(-8px, 4px) rotate(-0.2deg);
  }
  40% {
    transform: translate(7px, -5px) rotate(0.15deg);
  }
  60% {
    transform: translate(-5px, -2px) rotate(0.2deg);
  }
  80% {
    transform: translate(6px, 3px) rotate(-0.15deg);
  }
  100% {
    transform: translate(0, 0) rotate(0);
  }
}

@keyframes debrisFall {
  0% {
    transform: translateY(-20px) rotate(0deg);
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  100% {
    transform: translateY(780px) rotate(240deg);
    opacity: 0;
  }
}

@keyframes dustFloat {
  0% {
    transform: translateX(-20px);
    opacity: 0;
  }
  20%,
  70% {
    opacity: 0.75;
  }
  100% {
    transform: translateX(120px);
    opacity: 0;
  }
}

@media (max-width: 820px) {
  .game {
    padding: 0;
  }

  .stage {
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .hud {
    grid-template-columns: 1fr auto;
    padding: 12px;
  }

  .title-mark {
    padding: 10px 11px;
  }

  h1 {
    font-size: 20px;
  }

  .meters {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
  }

  .meter {
    padding: 8px 9px;
  }

  .safety-note {
    top: 144px;
    left: 12px;
    right: 12px;
    width: auto;
    font-size: 13px;
  }

  .character-sprite {
    right: -10px;
    bottom: 272px;
    width: 250px;
    min-width: 210px;
  }

  .dialogue {
    left: 10px;
    right: 10px;
    bottom: 10px;
    padding: 14px;
    max-height: 54vh;
    overflow: auto;
  }

  .story-text {
    min-height: 0;
    font-size: 16px;
  }

  .choices {
    grid-template-columns: 1fr;
  }

  .choice-button {
    min-height: 54px;
  }
}

@media (max-width: 420px) {
  .meters {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .meter strong {
    font-size: 19px;
  }

  .character-sprite {
    width: 224px;
    bottom: 294px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
