:root {
  color-scheme: light;
  --bg: #e8d3b5;
  --bg-soft: #f1e1c9;
  --panel: #fffaf2;
  --panel-strong: #f7ead7;
  --ink: #34261e;
  --muted: #836b58;
  --line: #c7a984;
  --gold: #966f3f;
  --rose: #c72f46;
  --green: #3d766d;
  --shadow: 0 20px 58px rgba(116, 82, 47, 0.14);
  font-family: Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 22% 0%, rgba(255, 250, 242, 0.55), transparent 34%),
    linear-gradient(145deg, rgba(255, 250, 242, 0.36), rgba(201, 169, 128, 0.18)),
    var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea,
a {
  font: inherit;
}

a {
  color: var(--gold);
  text-decoration: none;
}

.game-shell {
  display: grid;
  place-items: center;
  padding: 28px;
}

.story-frame {
  width: min(920px, 100%);
}

.topbar,
.editor-header,
.editor-toolbar,
.preview-title,
.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font: 700 0.76rem/1.2 system-ui, sans-serif;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.55rem, 3vw, 2.4rem);
}

h2 {
  font-size: 1.05rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.top-actions a,
.top-actions button,
.editor-header a,
.editor-toolbar button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--ink);
  cursor: pointer;
  padding: 8px 12px;
}

.top-actions a:hover,
.top-actions button:hover,
.editor-header a:hover,
.editor-toolbar button:hover {
  border-color: var(--green);
  color: var(--green);
}

.story-card {
  min-height: 62vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.96);
  box-shadow: var(--shadow);
  padding: clamp(20px, 4vw, 46px);
}

.story-card.input-only {
  display: grid;
  align-content: center;
  justify-items: center;
}

.story-card.input-only .memory-form {
  display: grid;
  gap: 18px;
  justify-items: center;
  width: min(520px, 100%);
  margin: 0;
}

.story-card.input-only .memory-field {
  text-align: center;
}

.story-card.input-only .memory-field input {
  justify-self: center;
  width: min(50%, 260px);
  min-width: 180px;
}

.story-card.input-only .input-submit {
  width: min(50%, 260px);
  min-width: 180px;
  text-align: center;
}

.node-text {
  font-size: clamp(1.04rem, 1.8vw, 1.22rem);
  line-height: 1.56;
}

.node-text p {
  margin: 0 0 1.05em;
}

.preserve-block {
  margin: 1.1em 0;
  overflow-x: auto;
  color: var(--ink);
  font: 1rem/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
}

.story-image {
  display: flex;
  justify-content: center;
  margin: 1.35em 0;
}

.story-image img {
  display: block;
  max-width: min(520px, 92%);
  height: auto;
}

.entering {
  animation: fadeIn 220ms ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0.72;
    transform: translateY(6px);
  }
}

.align-center,
.align-right {
  display: block;
}

.align-center {
  text-align: center;
}

.align-right {
  text-align: right;
}

.tone-red {
  color: var(--rose);
}

.tone-small {
  color: var(--muted);
  font-size: 0.86em;
}

.tone-big {
  display: block;
  font-size: 1.35em;
  line-height: 1.35;
}

.memory-form {
  margin: 18px 0;
}

.hidden {
  display: none;
}

.memory-field {
  display: grid;
  gap: 10px;
}

.memory-field div p {
  margin: 0;
}

.memory-field > div {
  font-size: clamp(1.28rem, 3vw, 1.7rem);
  line-height: 1.35;
  color: var(--ink);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdf8;
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 42px;
  padding: 9px 11px;
}

textarea {
  min-height: 62vh;
  resize: vertical;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(55, 111, 101, 0.16);
}

.choices {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}

.choice-button {
  width: 100%;
  min-height: 50px;
  border: 1px solid #c9aa85;
  border-radius: 6px;
  background: linear-gradient(180deg, #fffdf8, #f5e4ce);
  color: var(--ink);
  cursor: pointer;
  padding: 12px 14px;
  text-align: left;
}

.choice-button:hover:not(:disabled),
.choice-button:focus-visible:not(:disabled) {
  border-color: var(--green);
  transform: translateY(-1px);
}

.choice-button:disabled,
.choice-button.missing {
  cursor: not-allowed;
  opacity: 0.48;
}

.choice-button p {
  margin: 0;
}

.secret-choice {
  justify-self: end;
  display: grid;
  place-items: center;
  width: 30px;
  min-height: 22px;
  height: 22px;
  border-color: rgba(199, 47, 70, 0.42);
  background: rgba(255, 253, 248, 0.64);
  padding: 0;
  opacity: 0.72;
}

.secret-choice::after {
  content: "?";
  color: rgba(199, 47, 70, 0.72);
  font: 700 0.82rem/1 system-ui, sans-serif;
}

.secret-choice:hover:not(:disabled),
.secret-choice:focus-visible:not(:disabled) {
  border-color: var(--rose);
  background: rgba(199, 47, 70, 0.14);
  opacity: 1;
}

.innocent-choice {
  justify-self: end;
  width: min(156px, 48%);
  min-height: 46px;
  border-color: rgba(199, 47, 70, 0.42);
  background: rgba(255, 253, 248, 0.72);
  padding: 10px 12px;
  text-align: center;
}

.innocent-choice:hover:not(:disabled),
.innocent-choice:focus-visible:not(:disabled) {
  border-color: var(--rose);
  background: rgba(199, 47, 70, 0.12);
}

.status-line {
  margin-top: 12px;
  color: var(--muted);
  font: 0.82rem/1.3 system-ui, sans-serif;
}

.editor-shell {
  min-height: 100vh;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(230px, 290px) 1fr;
  min-height: 100vh;
}

.node-sidebar {
  border-right: 1px solid var(--line);
  background: rgba(247, 234, 215, 0.94);
  padding: 18px;
}

.editor-header {
  align-items: flex-start;
  margin-bottom: 16px;
}

.node-search {
  margin-bottom: 12px;
}

.new-node-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 12px;
}

.new-node-form input,
.new-node-form button {
  min-height: 38px;
}

.new-node-form button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--ink);
  cursor: pointer;
  padding: 8px 12px;
}

.new-node-form button:hover,
.new-node-form button:focus-visible {
  border-color: var(--green);
  color: var(--green);
}

.node-list {
  display: grid;
  gap: 7px;
  max-height: calc(100vh - 195px);
  overflow: auto;
  padding-right: 4px;
}

.node-item {
  display: grid;
  gap: 3px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  padding: 9px;
  text-align: left;
}

.node-item span {
  color: var(--muted);
  font: 0.78rem/1.2 system-ui, sans-serif;
}

.node-item.active,
.node-item:hover {
  border-color: var(--line);
  background: rgba(255, 247, 236, 0.72);
}

.editor-main {
  padding: 18px;
  min-width: 0;
}

.editor-toolbar {
  margin-bottom: 14px;
}

.save-status {
  min-height: 1.2em;
  margin: -4px 0 14px;
  color: var(--green);
  font: 0.86rem/1.35 system-ui, sans-serif;
}

.editor-toolbar > div:not(.editor-buttons) {
  width: min(420px, 100%);
}

.editor-toolbar .editor-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  width: auto;
}

.editor-toolbar label,
.edit-panel label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font: 0.82rem/1.2 system-ui, sans-serif;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
  gap: 16px;
  margin-top: 16px;
}

.edit-panel,
.preview-panel {
  min-width: 0;
}

.preview-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.96);
  padding: 16px;
}

.preview-title {
  margin-bottom: 12px;
  color: var(--muted);
  font: 0.86rem/1.2 system-ui, sans-serif;
}

.preview-text {
  max-height: 52vh;
  overflow: auto;
  padding-right: 8px;
}

.graph-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.96);
  padding: 16px;
}

.graph-scroller {
  height: 340px;
  overflow: auto;
  border: 1px solid rgba(199, 169, 132, 0.7);
  border-radius: 6px;
  background: #fffdf8;
}

.branch-graph {
  display: block;
}

.graph-edge {
  fill: none;
  stroke: rgba(131, 107, 88, 0.34);
  stroke-width: 2;
}

.graph-edge.active {
  stroke: var(--green);
  stroke-width: 3;
}

.graph-node {
  cursor: pointer;
  outline: none;
}

.graph-node rect {
  fill: #f7ead7;
  stroke: var(--line);
  stroke-width: 1;
}

.graph-node text {
  fill: var(--ink);
  font: 0.74rem/1 system-ui, sans-serif;
  pointer-events: none;
}

.graph-node:hover rect,
.graph-node:focus rect {
  stroke: var(--green);
  stroke-width: 2;
}

.graph-node.active rect {
  fill: #dceee8;
  stroke: var(--green);
  stroke-width: 2;
}

@media (max-width: 760px) {
  .game-shell {
    padding: 16px;
  }

  .topbar,
  .editor-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

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

  .top-actions a,
  .top-actions button {
    flex: 1;
    text-align: center;
  }

  .editor-layout,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .node-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .node-list {
    max-height: 240px;
  }
}
