/* ==========================================================================
   StoryForge — "Night Edition"
   An ink-well & gold-leaf theme: dark manuscript pages, branching paths
   drawn like a table-of-contents tree, gilded accents on every choice.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=Source+Sans+3:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  /* Palette */
  --ink:        #17162a;   /* page background, deep indigo-black */
  --ink-raised: #221f3b;   /* card / header surface */
  --ink-line:   #38345a;   /* hairlines & borders */
  --parchment:  #e9dfc6;   /* primary text, aged paper */
  --parchment-dim: #b7ae95;/* secondary text */
  --gold:       #c9a227;   /* gilded accent — links, choices, focus */
  --gold-bright:#e6c65b;
  --crimson:    #9a2f3e;   /* ribbon-bookmark accent — danger/cancel */
  --crimson-bright:#c04456;

  /* Type */
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Sans 3", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  /* Layout */
  --radius: 6px;
  --shadow: 0 12px 30px rgba(0,0,0,0.45);
  --spine-width: 3px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse 1200px 600px at 50% -10%, rgba(201,162,39,0.07), transparent 60%),
    var(--ink);
  color: var(--parchment);
  font-family: var(--font-body);
  line-height: 1.6;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

::selection { background: var(--gold); color: var(--ink); }

/* ---- Header ---- */
.header {
  background: var(--ink-raised);
  border-bottom: 1px solid var(--ink-line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header .container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.logo {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.02em;
  margin: 0;
  color: var(--parchment);
}

.logo::before {
  content: "✒";
  color: var(--gold);
  margin-right: 0.45rem;
  font-size: 1.1rem;
}

.nav {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.nav button {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: transparent;
  color: var(--parchment-dim);
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.nav button:hover {
  border-color: var(--gold);
  color: var(--gold-bright);
  background: rgba(201,162,39,0.08);
}

.nav button:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ---- Main content ---- */
main#content {
  flex: 1;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 3.5rem;
}

/* ---- Home ---- */
.home {
  max-width: 640px;
  margin: 2rem auto;
  padding: 2.25rem 2.5rem;
  background: var(--ink-raised);
  border: 1px solid var(--ink-line);
  border-left: var(--spine-width) solid var(--gold);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.home p {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--parchment);
  margin: 0;
}

/* ---- Error ---- */
.error {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  background: rgba(154,47,62,0.12);
  border: 1px solid var(--crimson);
  color: var(--crimson-bright);
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  max-width: 640px;
  margin: 1rem auto;
}

/* ---- Story list (grid of catalog cards) ---- */
.storyList {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.1rem;
}

/* .story = catalog card button (list) AND single-story detail card */
button.story {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--ink-raised);
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  color: var(--parchment);
  font-family: var(--font-body);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  overflow: hidden;
}

button.story::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: var(--spine-width);
  background: var(--gold);
  opacity: 0;
  transition: opacity 0.15s ease;
}

button.story:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

button.story:hover::before { opacity: 1; }

button.story h2,
button.story h3 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: var(--parchment);
}

button.story h2 { font-size: 1.4rem; }
button.story h3 { font-size: 1.1rem; }

button.story p {
  margin: 0.3rem 0;
  color: var(--parchment-dim);
  font-size: 0.92rem;
}

/* single-story detail view text (raw text nodes, not wrapped in <p>) */
button.story br + * { margin-top: 0.2rem; }

/* ---- Story reading mode (.storyElement inside #content directly) ---- */
main#content > .storyElement {
  background: var(--ink-raised);
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  padding: 2rem 2.25rem;
  box-shadow: var(--shadow);
}

main#content > .storyElement h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.6rem;
  line-height: 1.4;
  margin: 0 0 1.75rem;
  color: var(--parchment);
}

/* Options rendered as a branching spine of choices */
main#content > .storyElement {
  position: relative;
}

button.option {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-left: 2px solid var(--ink-line);
  padding: 0.65rem 0 0.65rem 1.4rem;
  margin: 0;
  position: relative;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

button.option::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-line);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

button.option:hover { border-left-color: var(--gold); }

button.option:hover::before {
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(201,162,39,0.18);
}

button.option p {
  margin: 0;
  color: var(--parchment);
  font-size: 1rem;
  transition: color 0.15s ease;
}

button.option:hover p { color: var(--gold-bright); }

/* ---- Create-story form ---- */
#storyForm {
  max-width: 720px;
  margin: 0 auto;
  background: var(--ink-raised);
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  padding: 2rem 2.25rem 2.5rem;
  box-shadow: var(--shadow);
}

#storyForm h2 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  margin: 0 0 1.5rem;
  color: var(--parchment);
}

#storyForm h3 {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--parchment-dim);
  margin: 1.1rem 0 0.35rem;
  font-weight: 500;
}

#storyForm input[type="text"],
#storyForm select {
  width: 100%;
  background: var(--ink);
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  color: var(--parchment);
  font-family: var(--font-body);
  font-size: 0.95rem;
}

#storyForm input[type="text"]::placeholder { color: var(--parchment-dim); opacity: 0.7; }

#storyForm input[type="text"]:focus,
#storyForm select:focus {
  border-color: var(--gold);
  outline: none;
}

#storyForm select { cursor: pointer; }

.storyWrapper {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  margin-top: 1.5rem;
}

/* .storyElement reused as a form row inside the builder — higher
   specificity via #storyWrapper overrides the reading-mode card look */
#storyWrapper .storyElement {
  background: var(--ink);
  border: 1px solid var(--ink-line);
  border-left: var(--spine-width) solid var(--gold);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem 1.4rem;
  box-shadow: none;
}

#storyWrapper .storyElement label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--parchment-dim);
  margin: 0.6rem 0 0.3rem;
}

#storyWrapper .storyElement label:first-of-type { margin-top: 0; }

#storyWrapper .storyElement input[type="text"] {
  width: 100%;
  background: var(--ink-raised);
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  padding: 0.55rem 0.75rem;
  color: var(--parchment);
  font-family: var(--font-body);
  font-size: 0.92rem;
}

#storyWrapper .storyElement input[type="text"]:focus {
  border-color: var(--gold);
  outline: none;
}

.selection {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.selectionElement {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  background: var(--ink-raised);
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  padding: 0.55rem 0.6rem;
}

.selectionElement input[type="text"] {
  flex: 1;
  min-width: 0;
  background: var(--ink);
  border: 1px solid var(--ink-line);
  border-radius: 4px;
  padding: 0.45rem 0.6rem;
  color: var(--parchment);
  font-size: 0.88rem;
}

.selectionElement input.display-text { flex: 1.4; }
.selectionElement input.next-element { flex: 1; font-family: var(--font-mono); }

button.remove-selection {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--crimson);
  color: var(--crimson-bright);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

button.remove-selection:hover { background: rgba(154,47,62,0.15); }

.storyActions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.9rem;
  border-top: 1px dashed var(--ink-line);
}

.storyActions button {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 4px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  border: 1px solid var(--ink-line);
  background: var(--ink-raised);
  color: var(--parchment-dim);
  transition: border-color 0.15s ease, color 0.15s ease;
}

.storyActions button.add-selection:hover { border-color: var(--gold); color: var(--gold-bright); }
.storyActions button.move-up:hover,
.storyActions button.move-down:hover { border-color: var(--parchment); color: var(--parchment); }
.storyActions button.delete:hover { border-color: var(--crimson); color: var(--crimson-bright); }

.storyButtonWropper {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--ink-line);
  flex-wrap: wrap;
}

.storyButton {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.65rem 1.3rem;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--ink-line);
  background: transparent;
  color: var(--parchment-dim);
  transition: all 0.15s ease;
}

.storyButtonWropper .storyButton:first-child {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--ink);
  font-weight: 600;
}
.storyButtonWropper .storyButton:first-child:hover { background: var(--gold-bright); }

.storyButtonWropper .storyButton[type="submit"] {
  background: transparent;
  border-color: var(--gold);
  color: var(--gold-bright);
  margin-left: auto;
}
.storyButtonWropper .storyButton[type="submit"]:hover { background: rgba(201,162,39,0.1); }

.storyButtonWropper .storyButton:not(:first-child):not([type="submit"]):hover {
  border-color: var(--crimson);
  color: var(--crimson-bright);
}

/* ---- Footer ---- */
.footer {
  text-align: center;
  padding: 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--parchment-dim);
  border-top: 1px solid var(--ink-line);
  background: var(--ink-raised);
}

/* ---- Motion ---- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
  main#content { padding: 1.5rem 1rem 2.5rem; }
  .home, #storyForm, main#content > .storyElement { padding: 1.5rem; }
  .storyList { grid-template-columns: 1fr; }
  .storyButtonWropper .storyButton[type="submit"] { margin-left: 0; }
}