:root {
  color-scheme: dark;
  --ink: #f4ead2;
  --muted: #b7b0a3;
  --panel: rgba(12, 13, 11, 0.78);
  --panel-strong: rgba(8, 9, 8, 0.92);
  --line: rgba(244, 234, 210, 0.24);
  --gold: #d8a84a;
  --cyan: #61d6cf;
  --red: #d95b57;
  --green: #76a869;
  --black: #070807;
}

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

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

body {
  overflow: hidden;
  background: var(--black);
  color: var(--ink);
  font-family: "Noto Serif SC", "Source Han Serif SC", "Microsoft YaHei UI", serif;
}

button {
  min-width: 68px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(15, 16, 13, 0.72);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease, transform 160ms ease;
}

button:hover,
button:focus-visible {
  border-color: var(--gold);
  color: #fff8dc;
  background: rgba(64, 48, 24, 0.7);
  outline: none;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: default;
  color: rgba(244, 234, 210, 0.42);
  border-color: rgba(244, 234, 210, 0.12);
  background: rgba(10, 11, 10, 0.54);
}

.app,
.title-screen,
.game-screen {
  position: relative;
  width: 100%;
  height: 100%;
}

.title-screen {
  display: grid;
  place-items: center;
  overflow: hidden;
  background-image:
    linear-gradient(120deg, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.76)),
    url("assets/bg/archive.webp");
  background-position: center, center;
  background-repeat: no-repeat;
  background-size: cover, 120% auto;
}

.title-screen::before {
  position: absolute;
  inset: 0;
  content: "";
  z-index: 0;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0 1px, transparent 1px 92px),
    radial-gradient(circle at 18% 28%, rgba(216, 168, 74, 0.18), transparent 26%),
    radial-gradient(circle at 84% 66%, rgba(97, 214, 207, 0.12), transparent 28%);
  mix-blend-mode: screen;
}

.title-screen::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 0;
  height: 24%;
  content: "";
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.86));
}

.title-screen > * {
  position: relative;
  z-index: 1;
}

.title-code {
  align-self: end;
  padding: 6px 12px;
  border: 1px solid rgba(216, 168, 74, 0.44);
  border-radius: 999px;
  color: var(--gold);
  font-size: 0.8rem;
}

.title-screen h1 {
  margin: 0;
  font-size: 4.8rem;
  font-weight: 700;
  text-shadow: 0 12px 42px rgba(0, 0, 0, 0.88);
}

.title-actions {
  align-self: start;
  display: flex;
  gap: 14px;
}

.title-actions button {
  min-width: 116px;
  background: rgba(7, 8, 7, 0.86);
}

.game-screen {
  overflow: hidden;
  background: var(--black);
}

.is-hidden {
  display: none !important;
}

.background {
  position: absolute;
  inset: -8%;
  background-position: center;
  background-size: cover;
  filter: saturate(0.92) contrast(1.06);
  transform: scale(1.01);
  transition: background-image 260ms ease, filter 260ms ease;
}

.background::after {
  position: absolute;
  inset: 0;
  content: "";
  background:
    linear-gradient(180deg, rgba(4, 5, 4, 0.18), rgba(4, 5, 4, 0.9)),
    radial-gradient(circle at 50% 42%, transparent 0 34%, rgba(0, 0, 0, 0.52) 76%);
}

.game-screen[data-tone="sediment"] .background {
  filter: saturate(0.6) hue-rotate(22deg) contrast(1.18);
}

.game-screen[data-tone="danger"] .background {
  filter: saturate(1.15) contrast(1.2);
}

.game-screen[data-tone="memory"] .background {
  filter: sepia(0.18) saturate(0.82) brightness(1.06);
}

.scanline {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 3;
  opacity: 0.18;
  background:
    linear-gradient(transparent 50%, rgba(255, 255, 255, 0.04) 50%),
    linear-gradient(90deg, rgba(97, 214, 207, 0.06), rgba(216, 168, 74, 0.04), rgba(217, 91, 87, 0.05));
  background-size: 100% 4px, 100% 100%;
}

.stage {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.portrait {
  position: absolute;
  bottom: 14vh;
  max-height: 64vh;
  max-width: 45vw;
  object-fit: contain;
  opacity: 0;
  filter: drop-shadow(0 24px 54px rgba(0, 0, 0, 0.72));
  transition: opacity 220ms ease, transform 220ms ease;
}

.portrait.is-visible {
  opacity: 0.98;
}

.portrait-left {
  left: 3vw;
  transform: translateX(-18px);
}

.portrait-left.is-visible {
  transform: translateX(0);
}

.portrait-right {
  right: 3vw;
  transform: translateX(18px);
}

.portrait-right.is-visible {
  transform: translateX(0);
}

.entity {
  position: absolute;
  left: 50%;
  bottom: 20vh;
  max-height: 48vh;
  max-width: 36vw;
  object-fit: contain;
  opacity: 0;
  transform: translateX(-50%) scale(0.94);
  filter: drop-shadow(0 0 28px rgba(97, 214, 207, 0.36)) drop-shadow(0 16px 40px rgba(0, 0, 0, 0.86));
  transition: opacity 220ms ease, transform 220ms ease;
}

.entity.is-visible {
  opacity: 0.86;
  transform: translateX(-50%) scale(1);
}

.topbar {
  position: absolute;
  z-index: 5;
  top: 18px;
  left: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.chapter {
  max-width: 52vw;
  padding: 10px 14px;
  border-left: 3px solid var(--gold);
  background: rgba(8, 9, 8, 0.68);
  color: #fff1bd;
  font-size: 0.94rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.controls button {
  min-width: 58px;
  min-height: 34px;
  font-size: 0.86rem;
}

.dialogue {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: 22px;
  width: min(1120px, calc(100% - 36px));
  min-height: 178px;
  padding: 22px 24px 20px;
  border: 1px solid rgba(244, 234, 210, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(26, 25, 20, 0.86), rgba(8, 9, 8, 0.9)),
    linear-gradient(90deg, rgba(216, 168, 74, 0.14), rgba(97, 214, 207, 0.07));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(12px);
  transform: translateX(-50%);
}

.speaker {
  min-height: 28px;
  color: var(--gold);
  font-size: 1.08rem;
  font-weight: 700;
}

.dialogue p {
  min-height: 70px;
  margin: 8px 0 0;
  color: var(--ink);
  font-size: 1.22rem;
  line-height: 1.72;
}

.choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.choices button {
  width: 100%;
  min-height: 46px;
  padding: 8px 12px;
  text-align: left;
  line-height: 1.45;
  background: rgba(17, 18, 15, 0.82);
}

.log-panel {
  position: absolute;
  z-index: 8;
  top: 76px;
  left: 50%;
  width: min(780px, calc(100% - 36px));
  max-height: min(68vh, 620px);
  border: 1px solid rgba(244, 234, 210, 0.24);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.74);
  transform: translateX(-50%);
}

.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(244, 234, 210, 0.16);
  color: var(--gold);
}

.log-head button {
  min-width: 56px;
  min-height: 32px;
}

.log-body {
  max-height: calc(min(68vh, 620px) - 58px);
  overflow: auto;
  padding: 16px;
  line-height: 1.7;
}

.log-body p {
  margin: 0 0 14px;
  color: var(--muted);
}

.log-body strong {
  color: var(--gold);
}

.toast {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: 222px;
  min-width: 120px;
  padding: 8px 12px;
  border: 1px solid rgba(216, 168, 74, 0.5);
  border-radius: 999px;
  background: rgba(8, 9, 8, 0.88);
  color: #fff1bd;
  text-align: center;
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 760px) {
  .title-screen h1 {
    font-size: 3rem;
  }

  .topbar {
    top: 10px;
    left: 10px;
    right: 10px;
    align-items: flex-start;
  }

  .chapter {
    max-width: 44vw;
    font-size: 0.82rem;
  }

  .controls button {
    min-width: 48px;
    min-height: 32px;
    font-size: 0.78rem;
  }

  .meters {
    top: 68px;
    right: 10px;
    width: 176px;
    padding: 9px;
  }

  .meter {
    grid-template-columns: 38px 1fr;
    gap: 7px;
    font-size: 0.74rem;
  }

  .portrait {
    bottom: 27vh;
    max-height: 42vh;
    max-width: 56vw;
  }

  .entity {
    bottom: 28vh;
    max-height: 36vh;
    max-width: 56vw;
  }

  .dialogue {
    width: calc(100% - 20px);
    min-height: 214px;
    bottom: 10px;
    padding: 16px;
  }

  .speaker {
    font-size: 0.96rem;
  }

  .dialogue p {
    min-height: 92px;
    font-size: 1rem;
    line-height: 1.65;
  }

  .choices {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 10px;
  }

  .choices button {
    min-height: 42px;
    font-size: 0.92rem;
  }

  .toast {
    bottom: 236px;
  }
}
