:root {
  --gold: #e6b93c;
  --white: #f5f5f5;
  --silver: #bebec8;
  --black: #05050a;
  --panel: rgba(20, 10, 35, 0.92);
  --panel-soft: rgba(35, 20, 55, 0.9);
  --button: #462864;
  --button-hover: #6e4696;
  --danger: #ff6b9a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at top left, #241139 0, #05050a 48%, #020205 100%);
  color: var(--white);
  font-family: Arial, Helvetica, sans-serif;
  overflow-x: hidden;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.app-shell {
  width: min(1280px, 100%);
  position: relative;
}

.reader {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 560px;
  overflow: hidden;
  border: 3px solid rgba(230, 185, 60, 0.8);
  border-radius: 24px;
  background: #05050a;
  box-shadow: var(--shadow);
}

.art-panel {
  position: absolute;
  inset: 0 auto 0 0;
  width: 59.4%;
  background: #111;
  overflow: hidden;
}

.scene-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scale(1.01);
  transition: opacity 220ms ease, transform 520ms ease;
}

.reader.scene-changing .scene-image {
  opacity: 0.35;
  transform: scale(1.04);
}

.missing-image {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--gold);
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    #101020;
  background-size: 70px 70px;
}

.missing-image strong {
  display: block;
  margin-bottom: 8px;
  font-size: clamp(1.4rem, 3vw, 2.4rem);
}

.divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 59.4%;
  width: 4px;
  background: var(--gold);
  box-shadow: 0 0 18px rgba(230, 185, 60, 0.55);
}

.story-panel {
  position: absolute;
  top: 40px;
  right: 28px;
  bottom: 118px;
  width: calc(40.6% - 56px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  border: 3px solid var(--gold);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 0 28px rgba(0, 0, 0, 0.35);
}

.eyebrow {
  margin: 0;
  color: var(--silver);
  font-size: 0.85rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.title {
  margin: 0;
  color: var(--gold);
  font-size: clamp(1.25rem, 2.8vw, 2.35rem);
  line-height: 1.08;
  text-wrap: balance;
}

.story-text {
  overflow: auto;
  padding-right: 4px;
  font-size: clamp(1rem, 1.45vw, 1.48rem);
  line-height: 1.38;
  scrollbar-width: thin;
  scrollbar-color: var(--gold) rgba(255, 255, 255, 0.08);
}

.story-text p {
  margin: 0 0 0.64em;
}

.cover-copy {
  margin-top: auto;
  color: var(--white);
  font-size: clamp(1rem, 1.5vw, 1.4rem);
}

.controls {
  position: absolute;
  left: calc(59.4% + 20px);
  right: 28px;
  bottom: 28px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 14px;
  align-items: center;
}

button,
.icon-button,
.select-jump {
  min-height: 50px;
  border: 3px solid var(--gold);
  border-radius: 14px;
  background: var(--button);
  color: var(--white);
  font: 700 1rem/1 Arial, Helvetica, sans-serif;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, opacity 160ms ease;
  touch-action: manipulation;
}

button:hover,
.icon-button:hover,
.select-jump:hover {
  background: var(--button-hover);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  min-width: 130px;
  color: var(--silver);
  font-size: 0.88rem;
  text-align: center;
}

.progress-track {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), #fff0a6);
  transition: width 240ms ease;
}

.top-actions {
  position: absolute;
  z-index: 5;
  top: 16px;
  right: 18px;
  display: flex;
  gap: 8px;
}

.icon-button {
  min-width: 44px;
  min-height: 40px;
  border-width: 2px;
  border-radius: 12px;
  background: rgba(70, 40, 100, 0.78);
}

.drawer {
  position: absolute;
  z-index: 10;
  right: 18px;
  top: 64px;
  width: min(430px, calc(100% - 36px));
  max-height: calc(100% - 94px);
  display: none;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border: 2px solid var(--gold);
  border-radius: 16px;
  background: rgba(8, 6, 16, 0.96);
  box-shadow: var(--shadow);
}

.drawer.open {
  display: flex;
}

.select-jump {
  width: 100%;
  padding: 0 12px;
  appearance: none;
}

.help-text {
  margin: 0;
  color: var(--silver);
  font-size: 0.95rem;
  line-height: 1.4;
}

.rain-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  opacity: 0.48;
}

.raindrop {
  position: absolute;
  width: 1px;
  height: 18px;
  background: linear-gradient(var(--silver), transparent);
  transform: rotate(14deg);
  animation: rain-fall linear infinite;
}

@keyframes rain-fall {
  from { transform: translate3d(0, -130vh, 0) rotate(14deg); }
  to { transform: translate3d(-90px, 130vh, 0) rotate(14deg); }
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 102px;
  z-index: 6;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  max-width: min(760px, 86%);
  padding: 16px 22px;
  border: 2px solid var(--silver);
  border-radius: 16px;
  background: var(--panel-soft);
  color: var(--white);
  text-align: center;
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.install-note {
  margin: 14px 4px 0;
  color: rgba(245, 245, 245, 0.8);
  font-size: 0.9rem;
  text-align: center;
}

.install-note code {
  color: #fff0a6;
}

@media (max-width: 860px) {
  body {
    display: block;
    padding: 0;
    background: #05050a;
  }

  .app-shell {
    width: 100%;
  }

  .reader {
    min-height: 100svh;
    aspect-ratio: auto;
    border: 0;
    border-radius: 0;
  }

  .art-panel {
    inset: 0 0 auto 0;
    width: 100%;
    height: 58svh;
  }

  .scene-image {
    object-position: center top;
  }

  .divider {
    display: none;
  }

  .story-panel {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 92px;
    width: auto;
    max-height: 46svh;
    padding: 18px;
    border-width: 2px;
    background: linear-gradient(180deg, rgba(20, 10, 35, 0.88), rgba(7, 5, 13, 0.97));
    backdrop-filter: blur(8px);
  }

  .story-text {
    font-size: clamp(1rem, 4.4vw, 1.24rem);
  }

  .controls {
    left: 12px;
    right: 12px;
    bottom: 18px;
    grid-template-columns: 1fr 112px 1fr;
    gap: 8px;
  }

  .status {
    min-width: 0;
    font-size: 0.76rem;
  }

  button,
  .select-jump {
    min-height: 54px;
  }

  .top-actions {
    top: 12px;
    right: 12px;
  }

  .drawer {
    top: 60px;
    right: 12px;
    width: calc(100% - 24px);
  }

  .toast {
    bottom: 156px;
  }

  .install-note {
    display: none;
  }
}

@media (max-width: 420px) {
  .story-panel {
    max-height: 49svh;
    padding: 15px;
  }

  .title {
    font-size: 1.28rem;
  }

  .controls {
    grid-template-columns: 1fr 86px 1fr;
  }

  .status span:first-child {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 520px) and (max-width: 940px) {
  .art-panel {
    width: 55%;
    height: 100%;
  }

  .story-panel {
    left: 56%;
    right: 10px;
    top: 54px;
    bottom: 76px;
    max-height: none;
  }

  .controls {
    left: 56%;
    right: 10px;
    bottom: 10px;
  }
}

@media print {
  body {
    display: block;
    padding: 0;
    background: white;
    color: black;
  }

  .reader,
  .art-panel,
  .story-panel,
  .controls,
  .top-actions,
  .drawer,
  .rain-layer,
  .install-note {
    position: static;
  }

  .reader {
    border: 0;
    box-shadow: none;
    min-height: auto;
    aspect-ratio: auto;
  }

  .art-panel,
  .controls,
  .top-actions,
  .drawer,
  .rain-layer,
  .divider,
  .install-note {
    display: none !important;
  }

  .story-panel {
    width: auto;
    border: 1px solid #333;
    color: black;
    background: white;
    page-break-after: always;
  }

  .title,
  .eyebrow,
  .story-text {
    color: black;
  }
}
