:root {
  color: #2f261b;
  background: #f6ead1;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 18px;
  line-height: 1.6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(rgba(246, 234, 209, 0.86), rgba(246, 234, 209, 0.94)),
    url("../public/images/parchment-texture.svg");
}

button {
  font: inherit;
}

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 48px;
}

.site-nav {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 14px;
}

.hero {
  min-height: 280px;
  display: flex;
  align-items: center;
  border-bottom: 4px solid #7e4428;
  background:
    linear-gradient(90deg, rgba(45, 35, 23, 0.9), rgba(45, 35, 23, 0.56)),
    url("../public/images/medieval-village.svg") center / cover;
  color: #fff8e6;
  padding: 34px;
  border-radius: 8px;
}

.hero-content {
  max-width: 720px;
}

.title-row,
.top-bar,
.section-heading,
.primary-button,
.home-button,
.secondary-button {
  display: flex;
  align-items: center;
  gap: 10px;
}

.title-row p {
  margin: 0;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.88rem;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(2.15rem, 6vw, 4.2rem);
  line-height: 1;
  margin-bottom: 16px;
}

h2 {
  font-size: clamp(1.45rem, 4vw, 2.1rem);
  line-height: 1.16;
}

h3 {
  font-size: 1.18rem;
  line-height: 1.25;
  margin-bottom: 8px;
}

.hero-copy {
  font-size: 1.28rem;
  max-width: 520px;
  margin-bottom: 0;
}

.section {
  padding: 36px 0 0;
}

.access-section {
  padding-top: 22px;
}

.access-panel,
.locked-library {
  background: #fff9eb;
  border: 2px solid #d3b47d;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(79, 50, 26, 0.1);
}

.access-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.access-panel h2 {
  margin-bottom: 6px;
}

.access-panel p {
  color: #624326;
  margin-bottom: 0;
}

.access-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.access-form {
  display: grid;
  gap: 10px;
  align-content: start;
  background: #fffdf6;
  border: 2px solid #eadbb6;
  border-radius: 8px;
  padding: 14px;
}

.access-form label {
  display: grid;
  gap: 6px;
  color: #624326;
  font-weight: 900;
}

.access-form input {
  min-height: 48px;
  border: 2px solid #d3b47d;
  border-radius: 8px;
  background: #fffdf6;
  color: #2f261b;
  font: inherit;
  padding: 8px 10px;
}

.locked-library {
  min-height: 220px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 28px;
}

.locked-library h3 {
  font-size: 1.35rem;
}

.locked-library p {
  max-width: 420px;
  margin: 0;
  color: #624326;
  font-weight: 750;
}

.section-heading {
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  margin-bottom: 20px;
}

.section-heading p {
  max-width: 520px;
  margin-bottom: 4px;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}

.game-card {
  background: #fff9eb;
  border: 2px solid #d3b47d;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 360px;
  box-shadow: 0 10px 24px rgba(79, 50, 26, 0.12);
}

.game-card img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: #d8c49a;
}

.placeholder-card {
  min-height: 220px;
  background: #f8edd4;
}

.game-card-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  flex: 1;
}

.game-card h3,
.game-card p,
.game-info h1,
.scene-panel h2 {
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: auto;
}

.primary-button,
.secondary-button,
.home-button,
.choice-list button {
  border: 0;
  border-radius: 8px;
  min-height: 48px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  justify-content: center;
  background: #7e4428;
  color: #fff8e6;
  padding: 12px 16px;
}

.secondary-button {
  background: #e7d3a8;
  color: #5a3b22;
  padding: 12px 16px;
  justify-content: center;
}

.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.86;
}

.top-bar {
  justify-content: flex-end;
  margin-bottom: 18px;
}

.home-button {
  background: #fff9eb;
  color: #3c2c1d;
  border: 2px solid #d3b47d;
  padding: 10px 14px;
}

.home-button {
  background: #7e4428;
  color: #fff8e6;
  justify-content: center;
}

.game-page {
  min-height: 100svh;
}

.game-page .page-shell {
  width: min(1280px, calc(100% - 24px));
  min-height: 100svh;
  padding: 12px 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.game-page .top-bar {
  margin-bottom: 10px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
  min-height: 0;
}

.game-page .game-layout {
  height: calc(100svh - 82px);
}

.game-info,
.scene-panel {
  background: #fff9eb;
  border: 2px solid #d3b47d;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(79, 50, 26, 0.1);
}

.game-info {
  padding: 16px;
  position: sticky;
  top: 12px;
}

.game-page .game-info,
.game-page .scene-panel {
  min-height: 0;
  overflow: auto;
}

.game-info h1 {
  font-size: clamp(1.35rem, 2vw, 1.85rem);
  line-height: 1.15;
  margin-bottom: 10px;
}

.game-info p {
  font-size: 0.95rem;
  line-height: 1.45;
  margin-bottom: 10px;
}

.game-info img {
  width: 100%;
  border-radius: 6px;
  aspect-ratio: 16 / 8;
  object-fit: cover;
  margin-bottom: 10px;
}

.path-count {
  display: inline-block;
  margin-bottom: 14px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #e4f0de;
  color: #27513b;
  font-weight: 800;
  font-size: 0.9rem;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-list span {
  background: #efe0bb;
  border: 1px solid #caa969;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.82rem;
  font-weight: 700;
}

.terms-panel {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 2px solid #eadbb6;
}

.terms-panel h2 {
  font-size: 1rem;
  margin-bottom: 6px;
}

.terms-panel p {
  font-size: 0.92rem;
  margin-bottom: 10px;
}

.term-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.term-list span {
  background: #fff3d8;
  border: 1px solid #d3b47d;
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 0.82rem;
  font-weight: 800;
}

.scene-panel {
  padding: clamp(16px, 2vw, 22px);
}

.game-page .scene-panel {
  display: flex;
  flex-direction: column;
}

.scene-panel h2 {
  font-size: clamp(1.45rem, 2.6vw, 2rem);
  line-height: 1.18;
  margin-bottom: 12px;
}

.complete-popup {
  background: #dcebd6;
  border: 3px solid #2f6f5e;
  border-radius: 8px;
  color: #24573a;
  margin-bottom: 18px;
  padding: 16px;
  box-shadow: 0 10px 22px rgba(47, 111, 94, 0.16);
}

.complete-popup h2 {
  font-size: 1.6rem;
  margin-bottom: 6px;
}

.complete-popup p {
  font-weight: 800;
  margin-bottom: 0;
}

.scene-copy p {
  max-width: 76ch;
}

.path-focus {
  padding: 12px 14px;
  border-left: 5px solid #2f6f5e;
  background: #eef5ed;
  font-weight: 700;
}

.ending-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 10px;
  background: #efe0bb;
  color: #4c341f;
  font-size: 0.82rem;
  text-transform: uppercase;
  font-weight: 900;
  margin-bottom: 8px;
}

.ending-pill.good {
  background: #dcebd6;
  color: #24573a;
}

.ending-pill.neutral {
  background: #e6e0d4;
  color: #4b4439;
}

.ending-pill.bad {
  background: #f0d0c3;
  color: #74321e;
}

.choice-list {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.choice-list button {
  text-align: left;
  background: #f2dfb7;
  color: #2f261b;
  border: 2px solid #b9874c;
  padding: 14px 16px;
  display: grid;
  gap: 3px;
}

.choice-list button:hover,
.choice-list button:focus-visible,
.primary-button:hover,
.primary-button:focus-visible,
.home-button:hover,
.home-button:focus-visible {
  outline: 3px solid #2f6f5e;
  outline-offset: 2px;
}

.choice-list small {
  font-weight: 600;
  color: #65482c;
}

.glossary-term {
  border-bottom: 2px dotted #7e4428;
  font-weight: 800;
  cursor: help;
}

.glossary-tooltip {
  position: fixed;
  z-index: 20;
  width: min(280px, 80vw);
  background: #2f261b;
  color: #fff8e6;
  padding: 10px 12px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 10px 22px rgba(47, 38, 27, 0.24);
}

.glossary-tooltip[hidden] {
  display: none;
}

.ending-box {
  margin-top: 20px;
  padding: 18px;
  background: #f7edda;
  border: 2px solid #d3b47d;
  border-radius: 8px;
}

.ending-box li + li {
  margin-top: 8px;
}

.key-term-review {
  padding: 12px 14px;
  background: #fff3d8;
  border: 1px solid #d3b47d;
  border-radius: 8px;
  font-weight: 700;
}

.editor-layout {
  display: grid;
  gap: 18px;
}

.editor-heading {
  background: #fff9eb;
  border: 2px solid #d3b47d;
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 10px 24px rgba(79, 50, 26, 0.1);
}

.editor-heading p:first-child {
  margin-bottom: 6px;
  color: #624326;
  font-weight: 900;
  text-transform: uppercase;
  font-size: 0.86rem;
}

.editor-heading h1 {
  font-size: clamp(2rem, 5vw, 3.4rem);
}

.editor-toolbar,
.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}

.editor-toolbar {
  background: #fff9eb;
  border: 2px solid #d3b47d;
  border-radius: 8px;
  padding: 16px;
}

.editor-toolbar label {
  display: grid;
  gap: 6px;
  min-width: min(100%, 320px);
  color: #624326;
  font-weight: 900;
}

.editor-toolbar select,
.story-select select,
.field-grid input,
.field-grid select,
.field-grid textarea {
  min-height: 48px;
  border: 2px solid #d3b47d;
  border-radius: 8px;
  background: #fffdf6;
  color: #2f261b;
  font: inherit;
  padding: 8px 10px;
}

.field-grid textarea {
  min-height: 110px;
  resize: vertical;
}

.builder-form {
  display: grid;
  gap: 18px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field-grid label {
  display: grid;
  gap: 6px;
  color: #624326;
  font-weight: 900;
}

.field-grid small {
  color: #6b5136;
  font-weight: 650;
}

.wide-field {
  grid-column: 1 / -1;
}

.check-field {
  align-content: center;
  grid-template-columns: auto 1fr;
  gap: 10px;
  color: #3d2c1d;
  font-weight: 750;
}

.check-field input {
  width: 20px;
  height: 20px;
  min-height: 0;
  margin-top: 4px;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.editor-single-grid {
  display: block;
}

.editor-panel {
  background: #fff9eb;
  border: 2px solid #d3b47d;
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 10px 24px rgba(79, 50, 26, 0.1);
}

.full-width {
  width: 100%;
  margin-top: 8px;
}

.scene-select-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(220px, 0.7fr) auto auto;
  gap: 12px;
  align-items: end;
}

.scene-select-row label {
  display: grid;
  gap: 6px;
  color: #624326;
  font-weight: 900;
}

.scene-select-row select,
.scene-select-row input {
  min-height: 48px;
  border: 2px solid #d3b47d;
  border-radius: 8px;
  background: #fffdf6;
  color: #2f261b;
  font: inherit;
  padding: 8px 10px;
}

.image-picker {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 14px;
  align-items: center;
  border: 2px solid #eadbb6;
  border-radius: 8px;
  background: #fffdf6;
  padding: 12px;
}

.image-picker img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 6px;
  background: #d8c49a;
}

.image-picker p {
  color: #624326;
  font-weight: 900;
  margin-bottom: 8px;
}

.image-picker small {
  display: block;
  color: #6b5136;
  font-weight: 650;
  margin-top: 8px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.compact-heading {
  align-items: center;
  margin-bottom: 12px;
}

.choice-builder {
  margin-top: 20px;
  border-top: 2px solid #eadbb6;
  padding-top: 16px;
}

.choice-editor {
  border: 2px solid #eadbb6;
  border-radius: 8px;
  background: #fffdf6;
  padding: 14px;
}

.choice-editor + .choice-editor {
  margin-top: 12px;
}

.empty-note {
  background: #f7edda;
  border: 2px dashed #d3b47d;
  border-radius: 8px;
  margin: 0;
  padding: 14px;
  font-weight: 750;
}

.action-panel {
  position: sticky;
  bottom: 0;
  z-index: 5;
}

.panel-heading p {
  max-width: 430px;
  margin-bottom: 10px;
  color: #624326;
  font-size: 0.94rem;
}

.editor-panel textarea[data-editor-json] {
  width: 100%;
  min-height: 640px;
  resize: vertical;
  border: 2px solid #b9874c;
  border-radius: 8px;
  background: #fffdf6;
  color: #2f261b;
  font: 0.9rem/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    monospace;
  padding: 14px;
  tab-size: 2;
}

.import-hub {
  border-color: #a86d3a;
  background: #fff8e8;
}

.import-heading {
  align-items: center;
}

.eyebrow {
  color: #624326;
  font-size: 0.82rem;
  font-weight: 900;
  letter-spacing: 0;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.drop-zone {
  display: grid;
  gap: 6px;
  border: 2px dashed #b9874c;
  border-radius: 8px;
  background: #fffdf6;
  color: #3d2c1d;
  margin-top: 16px;
  padding: 20px;
  text-align: center;
}

.drop-zone strong {
  color: #624326;
  font-size: 1.05rem;
}

.drop-zone span {
  color: #6b5136;
  font-weight: 700;
}

.drop-zone.is-dragging {
  background: #f4e1bd;
  border-color: #6b5136;
}

.paste-box,
.story-select {
  display: grid;
  gap: 8px;
  color: #624326;
  font-weight: 900;
}

.paste-box {
  margin-top: 14px;
}

.import-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}

.import-summary {
  background: #efe1c1;
  border: 2px solid #d3b47d;
  border-radius: 8px;
  color: #3d2c1d;
  flex: 1 1 320px;
  font-weight: 850;
  margin: 0;
  padding: 10px 12px;
}

.quick-start-panel {
  display: grid;
  gap: 14px;
}

.editor-actions {
  margin-top: 14px;
}

.editor-help {
  position: sticky;
  top: 16px;
}

.editor-help h3 {
  margin-top: 18px;
}

.editor-help ul {
  padding-left: 20px;
  margin-bottom: 0;
}

.editor-help li + li {
  margin-top: 6px;
}

.editor-message,
.editor-error {
  border-radius: 8px;
  padding: 12px 14px;
  font-weight: 800;
  margin: 0;
}

.editor-message {
  background: #dcebd6;
  border: 2px solid #90b982;
  color: #24573a;
}

.editor-error {
  background: #f0d0c3;
  border: 2px solid #c77861;
  color: #74321e;
}

.custom-list .tag-list {
  margin-top: 10px;
}

.danger-button {
  border-color: #a34a2b;
  color: #74321e;
}

.danger-button:hover,
.danger-button:focus-visible {
  background: #f0d0c3;
  color: #74321e;
}

.removed-list {
  display: grid;
  gap: 14px;
}

.removed-story-list {
  display: grid;
  gap: 10px;
}

.removed-story-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  background: #fffdf6;
  border: 2px solid #eadbb6;
  border-radius: 8px;
  padding: 12px;
}

.removed-story-row span {
  color: #3d2c1d;
  font-weight: 850;
}

.paste-box textarea,
.deep-import-panel textarea {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  border: 2px solid #b9874c;
  border-radius: 8px;
  background: #fffdf6;
  color: #2f261b;
  font: 0.9rem/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    monospace;
  margin-top: 12px;
  padding: 12px;
}

.admin-panel {
  display: grid;
  gap: 14px;
}

.admin-key-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.admin-key-row label {
  display: grid;
  gap: 6px;
  color: #624326;
  font-weight: 900;
}

.admin-key-row input {
  min-height: 48px;
  border: 2px solid #d3b47d;
  border-radius: 8px;
  background: #fffdf6;
  color: #2f261b;
  font: inherit;
  padding: 8px 10px;
}

.status-pill {
  align-self: start;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 900;
  margin: 0;
  padding: 6px 10px;
  white-space: nowrap;
}

.status-pill.good {
  background: #dcebd6;
  color: #24573a;
}

.status-pill.neutral {
  background: #e6e0d4;
  color: #4b4439;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 820px) {
  .page-shell {
    width: min(100% - 20px, 760px);
    padding-top: 10px;
  }

  .hero {
    min-height: 280px;
    padding: 28px 20px;
  }

  .section-heading,
  .game-layout,
  .editor-grid,
  .panel-heading {
    display: block;
  }

  .game-info,
  .editor-help {
    position: static;
    margin-bottom: 16px;
  }

  .game-page {
    overflow: visible;
  }

  .game-page .page-shell {
    min-height: 0;
    display: block;
  }

  .game-page .game-layout {
    height: auto;
  }

  .game-page .game-info,
  .game-page .scene-panel {
    overflow: visible;
  }

  .editor-panel textarea[data-editor-json] {
    min-height: 520px;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .scene-select-row,
  .image-picker,
  .admin-key-row,
  .removed-story-row,
  .access-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  :root {
    font-size: 17px;
  }

  .top-bar {
    justify-content: stretch;
  }

  .top-bar .home-button {
    width: 100%;
  }

  .scene-panel,
  .game-info {
    padding: 14px;
  }
}
