:root {
  color-scheme: dark;
  --ink: #f7efe7;
  --muted: #cfc2b6;
  --panel: rgba(26, 28, 34, 0.86);
  --panel-solid: #1a1c22;
  --line: rgba(255, 255, 255, 0.18);
  --accent: #f2a65a;
  --accent-2: #73c0b0;
  --shadow: rgba(0, 0, 0, 0.42);
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  height: 100vh;
  background: #15171b;
  color: var(--ink);
  overflow: hidden;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
}

button:hover,
button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.novel {
  position: relative;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}

.stage {
  position: absolute;
  inset: 0;
  min-height: 100vh;
  overflow: hidden;
}

.background {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(1.04);
}

.character-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: clamp(22px, 4vh, 56px) 6vw clamp(90px, 16vh, 170px);
  pointer-events: none;
  transform: translateY(clamp(74px, 14vh, 150px));
}

.character-layer--duo {
  gap: clamp(10px, 2.8vw, 34px);
}

.character {
  width: auto;
  height: clamp(380px, 84vh, 780px);
  max-width: min(74vw, 620px);
  object-fit: contain;
  filter: drop-shadow(0 20px 24px var(--shadow));
}

.character--llanovar {
  height: clamp(420px, 91vh, 850px);
  max-width: min(82vw, 720px);
}

.character--kalt {
  height: clamp(390px, 85vh, 790px);
  max-width: min(76vw, 640px);
}

.character--runald {
  height: clamp(340px, 76vh, 700px);
  max-width: min(68vw, 560px);
}

.character-layer--duo .character {
  max-width: min(44vw, 460px);
}

.character-layer--duo .character--llanovar {
  height: clamp(380px, 82vh, 780px);
  max-width: min(48vw, 520px);
}

.character-layer--duo .character--kalt {
  height: clamp(350px, 77vh, 720px);
  max-width: min(43vw, 470px);
}

.character-layer--duo .character--runald {
  height: clamp(305px, 68vh, 640px);
  max-width: min(38vw, 420px);
}

.build-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  max-width: calc(100vw - 24px);
  padding: 6px 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  background: rgba(18, 20, 24, 0.58);
  color: rgba(247, 239, 231, 0.78);
  font-size: 0.72rem;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0;
  box-shadow: 0 10px 26px var(--shadow);
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.hud {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 3;
  margin: 0;
  width: min(1120px, calc(100vw - 32px));
  max-height: min(44vh, 330px);
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 22px 70px var(--shadow);
  backdrop-filter: blur(16px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.chapter {
  min-height: 18px;
  margin: 0 0 2px;
  color: var(--accent-2);
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.title {
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.2;
}

.toolbar {
  display: flex;
  gap: 8px;
}

.toolbar button,
.history-head button {
  width: 38px;
  height: 38px;
  padding: 0;
  font-weight: 700;
}

.dialogue {
  min-height: 96px;
}

.speaker {
  margin: 0 0 8px;
  color: var(--accent);
  font-weight: 700;
}

.text {
  margin: 0;
  max-width: 76ch;
  color: var(--ink);
  font-size: clamp(1rem, 2.4vh, 1.22rem);
  line-height: 1.55;
}

.choices {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.choice {
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  background: rgba(115, 192, 176, 0.14);
}

.next {
  display: block;
  margin: 14px 0 0 auto;
  min-width: 130px;
  padding: 11px 18px;
  background: #e08f47;
  border-color: #ffc37d;
  color: #171717;
  font-weight: 800;
}

.history {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 4;
  width: min(430px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
  box-shadow: 0 24px 80px var(--shadow);
}

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.history h2 {
  margin: 0;
  font-size: 1rem;
}

.history ol {
  margin: 14px 0 0;
  padding-left: 22px;
}

.history li {
  margin-bottom: 12px;
  color: var(--muted);
  line-height: 1.45;
}

@media (max-width: 720px) {
  body {
    height: 100svh;
    overflow: hidden;
  }

  .novel {
    height: 100svh;
    min-height: 100svh;
  }

  .character-layer {
    padding: 4vh 4vw clamp(82px, 16svh, 138px);
    transform: translateY(clamp(58px, 12svh, 110px));
  }

  .character-layer--duo {
    gap: 0;
    padding-left: 1vw;
    padding-right: 1vw;
  }

  .character {
    height: clamp(310px, 76svh, 650px);
    max-width: min(86vw, 430px);
  }

  .character--llanovar {
    height: clamp(350px, 83svh, 720px);
    max-width: min(94vw, 500px);
  }

  .character--kalt {
    height: clamp(325px, 78svh, 670px);
  }

  .character--runald {
    height: clamp(290px, 70svh, 590px);
  }

  .character-layer--duo .character--llanovar {
    height: clamp(300px, 74svh, 610px);
    max-width: 52vw;
  }

  .character-layer--duo .character--kalt {
    height: clamp(280px, 68svh, 560px);
    max-width: 48vw;
  }

  .character-layer--duo .character--runald {
    height: clamp(255px, 61svh, 500px);
    max-width: 42vw;
  }

  .hud {
    width: min(100vw - 20px, 1120px);
    bottom: 10px;
    max-height: min(48svh, 340px);
    padding: 14px;
  }

  .build-badge {
    top: 8px;
    right: 8px;
    font-size: 0.66rem;
  }

  .topbar {
    align-items: center;
  }
}

@media (max-height: 560px) {
  .character-layer {
    padding-bottom: 92px;
    transform: translateY(70px);
  }

  .character {
    height: 78vh;
  }

  .character--llanovar {
    height: 86vh;
  }

  .character--runald {
    height: 70vh;
  }

  .character-layer--duo .character--llanovar {
    height: 76vh;
  }

  .character-layer--duo .character--kalt {
    height: 70vh;
  }

  .character-layer--duo .character--runald {
    height: 62vh;
  }

  .hud {
    bottom: 8px;
    max-height: 46vh;
    padding: 12px;
  }

  .topbar {
    margin-bottom: 8px;
  }

  .dialogue {
    min-height: 68px;
  }

  .text {
    font-size: 1rem;
    line-height: 1.42;
  }

  .next {
    margin-top: 10px;
    padding: 9px 15px;
  }
}
