:root {
  color-scheme: dark;
  --bg: #121513;
  --surface: #1a201d;
  --surface-raised: #222a26;
  --paper: #f3f0e8;
  --text: #f7f4ed;
  --muted: #9aa49e;
  --ink: #18201c;
  --mint: #82e5d0;
  --coral: #ef714d;
  --sun: #f3d75f;
  --lime: #d6ff55;
  --focus: #f3d75f;
  --danger: #ff8066;
  --radius-sm: 12px;
  --radius-md: 22px;
  --radius-lg: 34px;
  --space-1: 0.5rem;
  --space-2: 0.75rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;
  --space-6: 3rem;
  --shadow: 0 30px 80px rgb(0 0 0 / 0.22);
  --fast: 150ms;
  --slow: 420ms;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); min-width: 320px; }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }

.app-shell { width: min(100%, 1600px); margin: 0 auto; padding: 0 clamp(1.25rem, 4vw, 4.25rem) 4rem; }
.topbar { min-height: 88px; display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; }
.wordmark { color: var(--text); text-decoration: none; display: inline-flex; align-items: center; gap: 0.8rem; font-size: clamp(1.6rem, 3vw, 2.15rem); font-weight: 720; letter-spacing: -0.05em; }
.yo-mark { position: relative; width: 52px; height: 42px; border-radius: 22px 10px 10px 22px; background: var(--sun); color: var(--ink); display: inline-grid; place-items: center; flex: 0 0 auto; font-size: 1rem; font-weight: 800; letter-spacing: -0.04em; line-height: 1; }
.yo-mark::after { content: ""; position: absolute; right: -10px; top: 10px; width: 0; height: 0; border-top: 11px solid transparent; border-bottom: 11px solid transparent; border-left: 13px solid var(--sun); }
.project-kicker, .eyebrow { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.12em; }
.mode-button { justify-self: end; min-height: 44px; border: 0; border-radius: 999px; background: var(--surface); color: var(--muted); padding: 0.65rem 1rem; cursor: pointer; }
.mode-button[aria-pressed="true"] { background: var(--paper); color: var(--ink); }

.intro { padding: clamp(2rem, 5vw, 4.5rem) 0 clamp(2.25rem, 4vw, 3.75rem); }
.intro h1 { margin: 0 0 1rem; max-width: none; white-space: nowrap; font: 500 clamp(3rem, 6.1vw, 5.75rem)/0.94 Georgia, "Times New Roman", serif; letter-spacing: -0.055em; }
.intro-copy { max-width: 670px; margin: 0; color: var(--muted); font-size: clamp(1rem, 1.4vw, 1.15rem); line-height: 1.55; }

.story-example { margin: 2rem 0 1.5rem; display: grid; grid-template-columns: minmax(150px, 0.35fr) minmax(0, 1.7fr); gap: 2rem; align-items: baseline; }
.story-example p { color: var(--coral); font-size: 0.72rem; letter-spacing: 0.13em; }
.story-example strong { max-width: 980px; font: 500 clamp(1.4rem, 2.5vw, 2.3rem)/1.2 Georgia, serif; }

.graph-workspace { border-radius: 38px; background: #181d1a; padding: clamp(1.25rem, 3vw, 2.5rem); box-shadow: var(--shadow); }
.graph-heading { display: flex; align-items: end; justify-content: space-between; gap: 2rem; }
.graph-heading h2 { margin: 0.45rem 0 0; font: 500 clamp(1.65rem, 3vw, 2.8rem)/1 Georgia, serif; }
.unwind-button { min-height: 48px; border: 0; border-radius: 999px; background: var(--lime); color: var(--ink); padding: 0 1.25rem; font-weight: 700; cursor: pointer; white-space: nowrap; }
.unwind-button[aria-pressed="true"] { background: var(--paper); }
.graph-canvas { position: relative; isolation: isolate; height: 480px; margin-top: 1.15rem; overflow: hidden; border-radius: 28px; background-color: #101311; background-image: radial-gradient(circle at center, rgb(255 255 255 / 0.055) 1px, transparent 1.5px); background-size: 28px 28px; }
.graph-canvas::after { content: "KNOWLEDGE GRAPH"; position: absolute; left: 1rem; bottom: 1rem; color: #657069; font-size: 0.64rem; letter-spacing: 0.14em; }
.graph-canvas.story-mode::after { content: "STORY LINE"; }
.graph-lines { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.graph-lines line { stroke: #7f9288; stroke-linecap: round; opacity: 0.82; }
.graph-lines line[data-weight="1"] { stroke-width: 2; opacity: 0.35; }
.graph-lines line[data-weight="2"] { stroke-width: 4; opacity: 0.48; }
.graph-lines line[data-weight="3"] { stroke-width: 7; opacity: 0.65; }
.graph-lines line[data-weight="4"] { stroke: var(--mint); stroke-width: 10; opacity: 0.78; }
.graph-lines .yo-tether { stroke: var(--sun); stroke-width: 2; stroke-dasharray: 5 7; opacity: 0.9; }
.story-thread { fill: none; stroke: var(--mint); stroke-width: 7; stroke-linecap: round; opacity: 0; transition: opacity 250ms var(--ease); }
.story-mode .graph-lines line { opacity: 0.42; }
.story-mode .story-thread { opacity: 0.8; transition-delay: 300ms; }
.graph-node { position: absolute; left: 0; top: 0; border: 0; background: transparent; color: var(--text); display: grid; justify-items: center; gap: 0.25rem; cursor: pointer; transform: translate(-50%, -50%); transition: left 850ms var(--ease), top 850ms var(--ease), transform var(--fast); z-index: 2; }
.graph-node:hover { transform: translate(-50%, -50%) scale(1.07); }
.graph-node .node-orb { width: 58px; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; background: #344039; border: 2px solid #6d7a73; color: var(--text); font-weight: 760; box-shadow: 0 10px 30px rgb(0 0 0 / 0.24); transition: box-shadow var(--fast), border-color var(--fast), background var(--fast); }
.graph-node.character .node-orb { width: 82px; font: 600 1.55rem Georgia, serif; background: var(--coral); color: var(--ink); border: 0; }
.graph-node.echo .node-orb { background: var(--mint); }
.graph-node.location .node-orb { width: 66px; border-radius: 24px 24px 50% 50%; background: #456356; }
.graph-node.idea .node-orb { width: 50px; background: var(--sun); border: 0; }
.graph-node.scene .node-orb { width: 62px; background: var(--paper); color: var(--ink); border: 0; }
.graph-node strong { font-size: 0.88rem; }
.graph-node small { color: var(--muted); font-size: 0.7rem; white-space: nowrap; }
.graph-node.active .node-orb { box-shadow: 0 0 0 9px rgb(214 255 85 / 0.16), 0 12px 40px rgb(0 0 0 / 0.3); border-color: var(--lime); }
.yo-floater { position: absolute; width: min(320px, calc(100% - 2rem)); left: 0; top: 0; z-index: 3; border-radius: 24px; background: var(--paper); color: var(--ink); padding: 1rem; box-shadow: 0 28px 70px rgb(0 0 0 / 0.4); transition: left 420ms var(--ease), top 420ms var(--ease), transform 360ms var(--ease); }
.yo-floater.context-change { transform: scale(1.035); }
.yo-floater-head { display: flex; align-items: center; gap: 0.65rem; }
.yo-floater-head p { margin: 0; font-weight: 750; }
.yo-thread { max-height: 126px; overflow: auto; margin: 0.75rem 0; padding-right: 0.25rem; }
.yo-thread p { margin: 0 0 0.6rem; line-height: 1.4; }
.yo-thread .user-comment { margin-left: 1.6rem; padding: 0.55rem 0.7rem; border-radius: 12px; background: #e1ded5; font-size: 0.84rem; }
.yo-thread .yo-reply { color: #4d5650; font-size: 0.9rem; }
.graph-legend { min-height: 50px; display: flex; align-items: center; flex-wrap: wrap; gap: 1.2rem; color: var(--muted); font-size: 0.72rem; }
.graph-legend span { display: flex; align-items: center; gap: 0.4rem; }
.graph-legend i { width: 10px; aspect-ratio: 1; border-radius: 50%; display: inline-block; }
.legend-character { background: var(--coral); }
.legend-location { background: #456356; }
.legend-idea { background: var(--sun); }

.character-quest { margin: clamp(7rem, 12vw, 12rem) 0 clamp(5rem, 9vw, 9rem); display: grid; grid-template-columns: 0.25fr 0.75fr 1.4fr; gap: clamp(1.5rem, 4vw, 4rem); align-items: center; }
.quest-number { align-self: start; color: var(--lime); font-size: 0.75rem; letter-spacing: 0.12em; }
.character-intro h2 { margin: 0.35rem 0 0.7rem; font: 500 clamp(2.2rem, 4vw, 4rem)/0.98 Georgia, serif; }
.character-intro > p:last-child { color: var(--muted); line-height: 1.55; }
.character-sheet { position: relative; display: grid; grid-template-columns: 150px 1fr; gap: 1.4rem; align-items: center; min-height: 310px; border-radius: 32px; background: var(--paper); color: var(--ink); padding: clamp(1.2rem, 2.5vw, 2rem); transform: rotate(-0.7deg); }
.character-portrait { width: 140px; aspect-ratio: 3 / 4; border-radius: 70px 70px 32px 32px; background: var(--coral); display: grid; place-items: center; font: 600 4rem Georgia, serif; }
.character-facts { display: grid; gap: 1rem; }
.character-facts div { display: grid; gap: 0.22rem; border-bottom: 1px solid #d2d0c8; padding-bottom: 0.8rem; }
.character-facts small { color: #737a75; font-size: 0.66rem; letter-spacing: 0.1em; }
.character-facts strong { font: 500 1.08rem/1.2 Georgia, serif; }
.character-action { position: absolute; right: 1.2rem; bottom: -3.4rem; color: var(--text); }

.scene-knowledge { background: var(--surface); border-radius: var(--radius-lg); padding: clamp(1.25rem, 2.5vw, 2rem); }
.scene-knowledge button { width: 100%; min-height: 62px; border: 0; border-bottom: 1px solid #333b37; background: transparent; display: flex; justify-content: space-between; align-items: center; cursor: pointer; text-align: left; }
.scene-knowledge button span { color: var(--muted); font-size: 0.78rem; }

.world-map { position: relative; height: 350px; margin: 1rem 0 1.5rem; }
.journey-line { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.journey-track, .journey-progress { fill: none; stroke-linecap: round; stroke-width: 10; }
.journey-track { stroke: #48534e; }
.journey-progress { stroke: var(--mint); filter: drop-shadow(0 0 12px rgb(130 229 208 / 0.18)); }
.quest { position: absolute; left: var(--x); top: var(--y); width: clamp(72px, 8vw, 112px); aspect-ratio: 1; border: 2px solid #65716b; border-radius: 50%; background: var(--surface-raised); display: grid; place-content: center; gap: 0.1rem; text-align: center; cursor: pointer; transform: translate(-50%, -50%); transition: transform var(--fast), border-color var(--fast), background var(--fast); }
.quest:hover { transform: translate(-50%, -50%) scale(1.06); }
.quest span, .quest small { font-size: 0.66rem; color: var(--muted); }
.quest strong { font-size: clamp(0.75rem, 1.2vw, 1rem); }
.quest.complete { border: 0; color: var(--ink); }
.quest-one { background: var(--sun); }
.quest-two { background: var(--coral); }
.quest.active { width: clamp(96px, 10vw, 142px); border: 0; background: var(--mint); color: var(--ink); box-shadow: 0 0 0 14px rgb(130 229 208 / 0.08); }
.quest.active span, .quest.active small, .quest.complete span, .quest.complete small { color: rgb(24 32 28 / 0.7); }
.yo-signal { position: absolute; left: 56%; top: 22%; width: 56px; aspect-ratio: 1; border-radius: 50%; background: var(--paper); color: var(--ink); display: grid; place-items: center; font-weight: 750; font-size: 1.15rem; box-shadow: var(--shadow); }

.workspace { display: block; max-width: 1180px; margin: 0 auto; }
.scene-stage, .companion { min-width: 0; }
.scene-stage { background: var(--surface); border-radius: var(--radius-lg); padding: clamp(1rem, 2vw, 1.6rem); }
.stage-toolbar { display: flex; justify-content: space-between; gap: 1rem; color: var(--muted); font-size: 0.72rem; letter-spacing: 0.08em; padding-bottom: 1rem; }
.stage-media { min-height: 420px; position: relative; overflow: hidden; border-radius: 24px; background: var(--paper); color: var(--ink); isolation: isolate; }
.stage-sun { position: absolute; right: 13%; top: 12%; width: min(25vw, 190px); aspect-ratio: 1; border-radius: 50%; background: var(--coral); transition: transform var(--slow) var(--ease), background var(--slow); }
.stage-land { position: absolute; left: -5%; bottom: -12%; width: 110%; height: 60%; border-radius: 50% 50% 0 0; transform-origin: bottom; transition: transform var(--slow) var(--ease); }
.stage-land-one { background: #759383; transform: rotate(-4deg); }
.stage-land-two { bottom: -30%; left: 30%; background: #263a31; transform: rotate(8deg); }
.stage-media p { position: absolute; left: 2rem; bottom: 1.5rem; width: min(70%, 560px); margin: 0; color: var(--paper); font: 500 clamp(1.25rem, 2.5vw, 2.15rem)/1.1 Georgia, serif; z-index: 2; }
.stage-media.is-loading .stage-sun { animation: pulse 1.2s ease-in-out infinite alternate; }
.stage-media.is-loading .stage-land-one { transform: rotate(-4deg) translateX(3%); }
.stage-actions { display: flex; align-items: center; gap: 0.75rem; padding-top: 1rem; }
.primary-action, .quiet-action { min-height: 48px; border: 0; border-radius: 999px; padding: 0 1.2rem; cursor: pointer; transition: transform var(--fast), opacity var(--fast); }
.primary-action { background: var(--lime); color: var(--ink); font-weight: 700; }
.quiet-action { background: transparent; color: var(--muted); }
.primary-action:hover, .quiet-action:hover { transform: translateY(-1px); }
.primary-action:disabled { opacity: 0.55; cursor: wait; transform: none; }

.companion { background: var(--paper); color: var(--ink); border-radius: var(--radius-lg); padding: clamp(1.25rem, 2.5vw, 2rem); display: flex; flex-direction: column; }
.yo-heading { display: flex; align-items: center; gap: 0.9rem; }
.yo-avatar { width: 48px; height: 38px; font-size: 0.92rem; }
.yo-heading p { margin: 0 0 0.15rem; font-weight: 700; }
.yo-heading div span { color: #6d756f; font-size: 0.85rem; }
.yo-message { font: 500 clamp(1.35rem, 2.3vw, 2.15rem)/1.16 Georgia, serif; letter-spacing: -0.025em; }
.memory-thread { border-top: 1px solid #d5d2c9; padding-top: 1rem; }
.memory-thread > p { color: #747b76; font-size: 0.7rem; letter-spacing: 0.12em; }
.memory-thread button { width: 100%; min-height: 48px; border: 0; border-bottom: 1px solid #d5d2c9; background: transparent; color: var(--ink); display: flex; justify-content: space-between; align-items: center; text-align: left; cursor: pointer; }
.memory-thread button span { color: #717972; font-size: 0.78rem; }
.yo-form { margin-top: auto; padding-top: 1.5rem; }
.yo-form label { display: block; margin-bottom: 0.55rem; font-size: 0.8rem; color: #606761; }
.yo-input-row { display: flex; gap: 0.5rem; }
.yo-input-row input { min-width: 0; flex: 1; min-height: 48px; border: 1px solid #c5c3ba; border-radius: 14px; background: #fffdf8; color: var(--ink); padding: 0 0.8rem; }
.yo-input-row button { min-width: 56px; border: 0; border-radius: 14px; background: var(--ink); cursor: pointer; }

.production-record { margin-top: clamp(4rem, 8vw, 8rem); border-top: 1px solid #333b37; padding: 2rem 0; display: grid; grid-template-columns: minmax(210px, 0.7fr) 2fr; gap: 2.5rem; align-items: center; }
.production-record p { margin: 0 0 0.45rem; }
.production-record dl { margin: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.production-record dl div { min-width: 0; }
.production-record dt { color: var(--muted); font-size: 0.72rem; margin-bottom: 0.35rem; }
.production-record dd { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.85rem; }
.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 150%); background: var(--paper); color: var(--ink); border-radius: 999px; padding: 0.85rem 1.2rem; box-shadow: var(--shadow); transition: transform var(--slow) var(--ease); z-index: 10; }
.toast.show { transform: translate(-50%, 0); }

@keyframes pulse { from { transform: scale(0.96); } to { transform: scale(1.04); } }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .world-map { height: 310px; }
  .production-record { grid-template-columns: 1fr; }
  .production-record dl { grid-template-columns: repeat(2, 1fr); }
  .graph-canvas { height: 520px; }
  .character-quest { grid-template-columns: 1fr 1.5fr; }
  .quest-number { grid-column: 1 / -1; }
  .character-sheet { grid-template-columns: 110px 1fr; }
  .character-portrait { width: 105px; }
}

@media (max-width: 560px) {
  .app-shell { padding-inline: 1rem; }
  .mode-button { font-size: 0.75rem; }
  .intro h1 { font-size: 3.3rem; }
  .intro h1 { white-space: normal; }
  .world-map { height: 280px; margin-left: 0.5rem; }
  .quest { width: 66px; }
  .quest.active { width: 86px; }
  .quest small { display: none; }
  .yo-signal { left: 62%; top: 18%; width: 44px; }
  .stage-media { min-height: 310px; }
  .stage-actions { align-items: stretch; flex-direction: column; }
  .primary-action, .quiet-action { width: 100%; }
  .production-record dl { grid-template-columns: 1fr; }
  .story-example { grid-template-columns: 1fr; gap: 0.25rem; }
  .graph-heading { align-items: start; flex-direction: column; }
  .graph-canvas { height: 610px; overflow: visible; margin-bottom: 13rem; }
  .graph-node strong { font-size: 0.7rem; }
  .graph-node small { display: none; }
  .graph-node.character .node-orb { width: 58px; }
  .graph-node .node-orb, .graph-node.location .node-orb, .graph-node.scene .node-orb { width: 46px; }
  .yo-floater { width: calc(100% - 2rem); }
  .character-quest { grid-template-columns: 1fr; }
  .character-sheet { grid-template-columns: 82px 1fr; min-height: 280px; }
  .character-portrait { width: 76px; font-size: 2.4rem; }
  .character-action { position: static; grid-column: 1 / -1; color: var(--ink); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition-duration: 0.01ms !important; }
}
