:root {
  color-scheme: dark;
  --theater-gold: #d7af68;
  --theater-ink: #f3e3c5;
}

.theater-player-body {
  display: grid;
  min-height: 100dvh;
  grid-template-rows: auto 1fr;
  padding: 0;
  background: #070b11;
}

.theater-player-header {
  position: relative;
  z-index: 100;
  display: grid;
  min-height: 58px;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 8px clamp(12px, 2vw, 26px);
  border-bottom: 1px solid rgba(215, 175, 104, 0.2);
  background: linear-gradient(90deg, #111a28, #171321 54%, #101927);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.theater-player-header a,
.theater-player-header button {
  color: #cfbfaa;
  font: 12px/1.2 Georgia, "Noto Serif KR", serif;
}

.theater-player-header a {
  display: inline-flex;
  justify-self: start;
  gap: 8px;
  align-items: center;
  text-decoration: none;
}

.theater-player-header > div { text-align: center; }
.theater-player-header small { display: block; color: #9f8050; font-size: 8px; letter-spacing: 0.16em; }
.theater-player-header strong { display: block; margin-top: 3px; color: var(--theater-ink); font-weight: 500; }

.theater-player-header button {
  min-height: 32px;
  justify-self: end;
  padding: 0 12px;
  border: 1px solid rgba(215, 175, 104, 0.28);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
}

#player-root { min-width: 0; }
#player-root .vn-player-shell { width: min(100%, 96rem); }
#player-root .vn-stage { min-height: calc(100dvh - 58px); }

.player-loading,
.player-error {
  display: grid;
  min-height: calc(100dvh - 58px);
  place-content: center;
  gap: 8px;
  padding: 24px;
  color: var(--theater-ink);
  text-align: center;
}

.player-loading span {
  width: 30px;
  height: 30px;
  margin: 0 auto 12px;
  border: 1px solid rgba(215, 175, 104, 0.25);
  border-top-color: var(--theater-gold);
  border-radius: 50%;
  animation: player-wait 1s linear infinite;
}

.player-loading small,
.player-error p { color: #998e80; }
.player-error[hidden] { display: none; }
.player-error a { color: var(--theater-gold); }

.landscape-prompt {
  position: fixed;
  z-index: 500;
  right: 0;
  bottom: clamp(22px, 7dvh, 64px);
  left: 0;
  display: grid;
  place-items: center;
  padding: 0 18px;
  pointer-events: none;
}

.landscape-prompt[hidden] { display: none; }

.landscape-prompt-card {
  display: grid;
  width: min(100%, 360px);
  justify-items: center;
  padding: 15px 18px 14px;
  border: 1px solid rgba(215, 175, 104, 0.3);
  border-radius: 12px 3px 12px 3px;
  background: linear-gradient(145deg, rgba(31, 27, 42, 0.92), rgba(12, 16, 25, 0.95));
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.42);
  color: var(--theater-ink);
  pointer-events: auto;
  text-align: center;
}

.landscape-phone-icon {
  position: relative;
  display: grid;
  width: 38px;
  height: 24px;
  margin-bottom: 8px;
  place-items: center;
  border: 1px solid rgba(215, 175, 104, 0.74);
  border-radius: 7px;
  box-shadow: 0 0 22px rgba(215, 175, 104, 0.14);
}

.landscape-phone-icon::before {
  position: absolute;
  top: 50%;
  left: -13px;
  width: 9px;
  height: 9px;
  border-top: 1px solid var(--theater-gold);
  border-left: 1px solid var(--theater-gold);
  content: "";
  transform: translateY(-50%) rotate(-45deg);
}

.landscape-phone-icon i {
  position: absolute;
  right: 3px;
  width: 2px;
  height: 5px;
  border-radius: 999px;
  background: rgba(215, 175, 104, 0.7);
}

.landscape-prompt-card > small {
  color: #b99151;
  font-size: 7px;
  letter-spacing: 0.2em;
}

.landscape-prompt-card h2 {
  margin: 5px 0 4px;
  font: 500 16px/1.35 Georgia, "Noto Serif KR", serif;
  word-break: keep-all;
}

.landscape-prompt-card p {
  margin: 0;
  color: #b8ad9f;
  font-size: 9px;
  line-height: 1.5;
}

.landscape-prompt-card button {
  width: 100%;
  min-height: 36px;
  margin-top: 11px;
  border: 1px solid rgba(232, 194, 126, 0.58);
  border-radius: 4px;
  color: #fff0d1;
  background: linear-gradient(135deg, #754126, #5a2930);
  box-shadow: 0 12px 28px rgba(45, 16, 14, 0.35);
  font: 500 11px/1.2 Georgia, "Noto Serif KR", serif;
  cursor: pointer;
}

.landscape-prompt-card button:disabled { opacity: 0.65; }

.landscape-prompt-card > span:last-child {
  margin-top: 7px;
  color: #847b70;
  font-size: 8px;
  line-height: 1.45;
  word-break: keep-all;
}

@media (orientation: portrait) and (max-height: 680px) {
  .landscape-prompt {
    bottom: 14px;
  }

  .landscape-prompt-card {
    padding: 10px 14px;
  }

  .landscape-phone-icon,
  .landscape-prompt-card > small,
  .landscape-prompt-card p,
  .landscape-prompt-card > span:last-child {
    display: none;
  }

  .landscape-prompt-card h2 {
    margin: 0;
    font-size: 14px;
  }

  .landscape-prompt-card button {
    min-height: 32px;
    margin-top: 8px;
  }
}

@keyframes player-wait { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .theater-player-header {
    min-height: 50px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .theater-player-header a span:last-child { display: none; }
  .theater-player-header > div { overflow: hidden; }
  .theater-player-header strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
  .theater-player-header button { min-height: 28px; padding: 0 9px; font-size: 10px; }
  #player-root .vn-stage { min-height: calc(100dvh - 50px); }
}

@media (orientation: portrait) and (max-width: 640px) {
  #player-root .vn-dialogue {
    right: .45rem;
    bottom: .4rem;
    left: .45rem;
    min-height: 64px;
    padding: .88rem .78rem .68rem;
    border-radius: .72rem .14rem .72rem .14rem;
  }

  #player-root .vn-speaker {
    top: -10px;
    left: .65rem;
    min-width: 70px;
    padding: .2rem .55rem;
    font-size: .62rem;
  }

  #player-root .vn-text {
    font-size: .7rem;
    line-height: 1.45;
  }

  #player-root .vn-hint {
    right: .5rem;
    bottom: .2rem;
    font-size: .46rem;
  }

  #player-root .vn-options {
    right: .45rem;
    bottom: 76px;
    width: calc(100% - .9rem);
    gap: .3rem;
  }

  #player-root .vn-options button {
    min-height: 34px;
    padding: .34rem .5rem;
    font-size: .68rem;
  }

  #player-root.is-cinematic-narration .vn-dialogue {
    right: 5%;
    left: 5%;
    padding: 1rem .8rem 1.3rem;
  }

  #player-root.is-cinematic-narration .vn-text {
    width: min(100%, 26ic);
    max-width: 26ic;
    font-size: clamp(.78rem, 3.8vw, .92rem);
    line-height: 1.65;
  }
}

@media (orientation: landscape) and (max-height: 640px) {
  .theater-player-body {
    grid-template-rows: 38px 1fr;
    overflow: hidden;
  }

  .theater-player-header {
    min-height: 38px;
    gap: 7px;
    padding: max(3px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 3px max(10px, env(safe-area-inset-left));
  }

  .theater-player-header a,
  .theater-player-header button {
    font-size: 9px;
  }

  .theater-player-header a span:last-child,
  .theater-player-header small {
    display: none;
  }

  .theater-player-header strong {
    margin: 0;
    overflow: hidden;
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .theater-player-header button {
    min-height: 24px;
    padding: 0 8px;
  }

  .theater-player-body #player-root {
    min-height: calc(100dvh - 38px);
    padding: 0;
  }

  .theater-player-body #player-root.is-landscape .vn-player-shell {
    width: min(calc((100dvh - 38px) * 16 / 9), 100vw);
  }

  #player-root .vn-stage {
    min-height: 0;
  }

  #player-root .vn-topbar {
    gap: .45rem;
    padding: .55rem .7rem;
  }

  #player-root .vn-title {
    padding-right: 2.5rem;
  }

  #player-root .vn-title strong {
    font-size: .72rem;
  }

  #player-root .vn-more {
    top: .4rem;
    right: .4rem;
  }

  #player-root .vn-more summary {
    min-width: 29px;
    min-height: 26px;
    padding: .2rem .4rem;
    font-size: .6rem;
  }

  #player-root .vn-progress {
    top: 48px;
    right: .75rem;
    left: .75rem;
  }

  #player-root .vn-chapter {
    top: 57px;
    left: .78rem;
    font-size: .58rem;
  }

  #player-root .vn-dialogue {
    right: .8rem;
    bottom: .55rem;
    left: .8rem;
    min-height: 78px;
    padding: 1rem 1rem .82rem;
    border-radius: .75rem .15rem .75rem .15rem;
  }

  #player-root .vn-speaker {
    top: -12px;
    left: .8rem;
    min-width: 76px;
    padding: .24rem .65rem;
    font-size: .66rem;
  }

  #player-root .vn-text {
    font-size: .76rem;
    line-height: 1.5;
  }

  #player-root .vn-hint {
    right: .65rem;
    bottom: .28rem;
    font-size: .5rem;
  }

  #player-root .vn-options {
    right: 3%;
    bottom: 92px;
    width: min(540px, 94%);
    gap: .35rem;
  }

  #player-root .vn-options button {
    min-height: 34px;
    padding: .35rem .55rem;
    font-size: .7rem;
  }

  #player-root.is-cinematic-narration .vn-dialogue {
    right: 8%;
    left: 8%;
    padding: 1.2rem 1.5rem 1.5rem;
  }

  #player-root.is-cinematic-narration .vn-text {
    font-size: clamp(.82rem, 2.2vw, 1rem);
    line-height: 1.65;
  }
}

@media (prefers-reduced-motion: reduce) {
  .player-loading span { animation: none; }
}
