:root {
  color-scheme: dark;
  --ink: #f1eee5;
  --muted: #aaa79e;
  --ground: #11110f;
  --surface: #1b1b18;
  --surface-strong: #24231f;
  --line: #3a3932;
  --accent: #d2b46c;
  --accent-strong: #f0cf7e;
  --danger: #d26f64;
  font-family: Avenir Next, Avenir, Helvetica Neue, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body, #app { min-height: 100%; margin: 0; }

body {
  background: var(--ground);
  color: var(--ink);
}

button, select { font: inherit; }

button {
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  cursor: pointer;
}

button:hover { border-color: #706b5d; }

button:focus-visible, select:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.library {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 40px 0 56px;
}

.library-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.library-header h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 5vw, 44px);
  line-height: 1;
  letter-spacing: -0.035em;
}

.library-header p { margin: 0; color: var(--muted); }

.locale-control {
  display: grid;
  gap: 6px;
  min-width: 150px;
  color: var(--muted);
  font-size: 13px;
}

select {
  min-height: 42px;
  padding: 0 34px 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.game-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  padding-top: 28px;
}

.game-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.game-cover {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: block;
  object-fit: cover;
  background: #272720;
}

.game-card-body { padding: 18px; }

.game-card h2 {
  margin: 0;
  font-size: 23px;
  letter-spacing: -0.02em;
}

.game-card p {
  min-height: 3em;
  margin: 9px 0 18px;
  color: var(--muted);
  line-height: 1.5;
}

.game-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.game-controls select { grid-column: 1 / -1; width: 100%; }

.primary, .secondary, .toolbar button, .continue, .choice {
  min-height: 44px;
  padding: 9px 14px;
}

.primary, .continue {
  border-color: #9b844f;
  background: var(--accent);
  color: #17150f;
  font-weight: 700;
}

.primary:hover, .continue:hover { background: var(--accent-strong); }

.primary:disabled, .secondary:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.player {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  background: #171715;
}

.scene-background,
.scene-shade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.scene-background { object-fit: cover; }

.scene-shade {
  background: linear-gradient(180deg, rgba(11, 11, 10, 0.42), rgba(11, 11, 10, 0.06) 45%, rgba(11, 11, 10, 0.82));
}

.toolbar {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 24px;
}

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

.toolbar button {
  min-height: 40px;
  background: rgba(20, 20, 18, 0.92);
}

.scene-meta {
  padding: 9px 12px;
  border: 1px solid rgba(200, 195, 180, 0.25);
  border-radius: 8px;
  background: rgba(20, 20, 18, 0.88);
  text-align: right;
}

.scene-meta strong, .scene-meta span { display: block; }
.scene-meta strong { color: var(--accent-strong); font-size: 13px; }
.scene-meta span { margin-top: 2px; font-size: 14px; }

.stage {
  position: absolute;
  inset: 72px 0 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 20px clamp(16px, 4vw, 54px) 28px;
}

.portraits {
  display: flex;
  justify-content: flex-end;
  align-items: end;
  gap: 12px;
  min-height: 0;
  padding-right: 2%;
}

.portrait {
  width: clamp(118px, 15vw, 210px);
  height: clamp(170px, 25vh, 300px);
  margin-bottom: 10px;
  border: 1px solid rgba(221, 213, 191, 0.45);
  border-radius: 8px;
  object-fit: cover;
  object-position: center top;
  background: #292923;
  opacity: 0.72;
}

.portrait.speaking { opacity: 1; }

.story-box {
  width: min(1100px, 100%);
  max-height: 43vh;
  margin: 0 auto;
  overflow: auto;
  padding: 18px 20px;
  border: 1px solid rgba(221, 213, 191, 0.3);
  border-radius: 10px;
  background: rgba(20, 20, 18, 0.94);
}

.story-box.scene-narration {
  width: min(820px, 88%);
  margin-bottom: 15vh;
  background: rgba(20, 20, 18, 0.9);
}

.speaker {
  margin: 0 0 7px;
  color: var(--accent-strong);
  font-size: 17px;
  font-weight: 700;
}

.story-text {
  min-height: 1.6em;
  margin: 0;
  font-size: clamp(18px, 2vw, 23px);
  line-height: 1.65;
  white-space: pre-wrap;
}

.story-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-top: 16px;
}

.choice {
  text-align: left;
  line-height: 1.4;
  background: #282721;
}

.choice:hover { background: #333128; }

.complete {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  color: var(--muted);
}

.error {
  width: min(680px, calc(100% - 40px));
  margin: 80px auto;
  padding: 20px;
  border: 1px solid var(--danger);
  background: var(--surface);
}

@media (max-width: 720px) {
  .library-header { align-items: start; flex-direction: column; }
  .game-list { grid-template-columns: 1fr; }
  .toolbar { align-items: start; padding: 12px; }
  .toolbar-actions { flex-wrap: wrap; }
  .scene-meta { display: none; }
  .stage { top: 84px; padding: 12px 12px 18px; }
  .portraits { padding-right: 0; }
  .portrait { width: 96px; height: 142px; }
  .story-box { max-height: 54vh; padding: 15px; }
  .story-box.scene-narration { width: 100%; margin-bottom: 18vh; }
  .choices { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
