:root {
  --ink: #07100d;
  --panel: rgba(15, 22, 19, 0.88);
  --panel-2: rgba(27, 37, 32, 0.82);
  --gold: #d6b66d;
  --jade: #77b897;
  --ivory: #f0e7d4;
  --muted: #b8ad97;
  --danger: #d66d6d;
  --border: rgba(214, 182, 109, 0.34);
}

* { box-sizing: border-box; }

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

body {
  color: var(--ivory);
  background:
    radial-gradient(circle at 30% 0%, rgba(119, 184, 151, 0.18), transparent 34%),
    radial-gradient(circle at 90% 20%, rgba(214, 182, 109, 0.10), transparent 28%),
    linear-gradient(180deg, #050a08 0%, #101915 55%, #17231d 100%);
  font-family: Georgia, 'Times New Roman', serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image: repeating-linear-gradient(115deg, transparent 0 18px, rgba(255,255,255,0.13) 19px, transparent 20px);
  animation: rain 18s linear infinite;
}
@keyframes rain { from { transform: translateY(-40px); } to { transform: translateY(40px); } }

.shell {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 26px 0 36px;
  height: calc(100% - 52px);
  display: flex;
  flex-direction: column;
}

.hero, .stage-card, .director-card, .controls {
  border: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(214,182,109,0.08), transparent 30%), var(--panel);
  box-shadow: 0 22px 48px rgba(0,0,0,0.36);
}
.hero { padding: 26px 28px; margin-bottom: 18px; flex-shrink: 0; }
.eyebrow { margin: 0 0 7px; color: var(--gold); text-transform: uppercase; letter-spacing: 0.16em; font-size: 0.76rem; }
h1 { margin: 0; color: var(--gold); font-size: clamp(2.5rem, 7vw, 5.2rem); letter-spacing: 0.08em; text-transform: uppercase; }
.intro { max-width: 820px; color: var(--muted); line-height: 1.55; font-size: 1.16rem; }

/* Game grid - explicit row height so HF iframe doesn't collapse flex children */
.game-grid {
  display: flex;
  gap: 18px;
  height: 540px;
  min-height: 540px;
  margin-bottom: 18px;
}

/* Stage card - left side, flex column */
.stage-card {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

/* Portrait - fixed aspect, flex-shrink 0 */
.portrait {
  position: relative;
  min-height: 300px;
  flex-shrink: 0;
  background: radial-gradient(circle at 50% 26%, rgba(214,182,109,0.16), transparent 30%), linear-gradient(180deg, #0a120f, #101914);
  border-right: 1px solid var(--border);
}
.moon { position: absolute; width: 82px; height: 82px; border-radius: 50%; top: 48px; left: 92px; background: rgba(240,231,212,0.82); box-shadow: 0 0 38px rgba(240,231,212,0.35); }
.sword { position: absolute; width: 8px; height: 300px; top: 118px; left: 132px; background: linear-gradient(180deg, #eee, #777); transform: rotate(18deg); box-shadow: 0 0 16px rgba(214,182,109,0.28); }
.figure { position: absolute; left: 76px; bottom: 54px; width: 112px; height: 150px; display: grid; place-items: center; border: 1px solid var(--border); color: var(--gold); font-size: 4rem; background: rgba(7,16,13,0.74); }

/* Dialogue area - fills remaining space, scrolls internally */
.dialogue {
  padding: 22px;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.speaker { margin: 0 0 12px; color: var(--gold); letter-spacing: 0.1em; text-transform: uppercase; }
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 8px;
}
.message { margin: 0 0 14px; padding: 13px 15px; line-height: 1.48; border: 1px solid rgba(214,182,109,0.18); background: rgba(5,10,8,0.58); }
.message.user { margin-left: 38px; color: var(--gold); background: rgba(214,182,109,0.09); }
.message.assistant { margin-right: 38px; }

/* Director card - right sidebar, fixed width */
.director-card {
  width: 330px;
  flex-shrink: 0;
  padding: 20px;
  height: 100%;
  background-color: var(--panel-2);
}

dl { margin: 0; display: grid; gap: 10px; }
dl div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid rgba(214,182,109,0.13); padding-bottom: 8px; }
dt { color: var(--muted); }
dd { margin: 0; color: var(--ivory); text-align: right; }
.delta { color: var(--jade); margin-left: 6px; }
.delta.negative { color: var(--danger); }

/* Scrollbar styling */
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-track { background: var(--ink); }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

meter { width: 100%; height: 12px; accent-color: var(--gold); }

.paths { margin-top: 16px; display: grid; gap: 8px; }
.path-title { margin: 0 0 2px; color: var(--gold); text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.72rem; }
.paths div { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 10px; color: var(--muted); font-size: 0.92rem; }

.director-note { color: var(--muted); line-height: 1.45; }

.controls { margin-top: 18px; padding: 16px; flex-shrink: 0; }
.approaches { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
button { border: 1px solid var(--border); background: rgba(214,182,109,0.1); color: var(--ivory); padding: 10px 12px; cursor: pointer; font: inherit; }
button:hover { background: rgba(214,182,109,0.22); color: var(--gold); }
form { display: flex; gap: 10px; }
input { flex: 1; min-width: 0; border: 1px solid var(--border); background: rgba(5,10,8,0.82); color: var(--ivory); padding: 12px 14px; font: inherit; }
.status { margin: 10px 0 0; color: var(--muted); }

@media (max-width: 860px) {
  .shell { height: auto; min-height: 100vh; padding-bottom: 40px; }
  .game-grid { flex-direction: column; }
  .portrait { min-height: 230px; border-right: 0; border-bottom: 1px solid var(--border); }
  .sword { height: 180px; }
  .director-card { width: 100%; }
  form { flex-wrap: wrap; }
  #player-input { flex-basis: 100%; }
}