:root {
  --bg: #0e0f14; --bg2: #151722; --panel: #1b1e2b; --line: #2a2e40;
  --text: #f2f3f7; --muted: #a3a8bd;
  --amber: #ffb020; --orange: #ff7a1a; --accent: #ffa31f; --on-accent: #1a1204;
  --k-me-bg: #2a2410; --k-me-bd: #ffd166;
  --k-amber-bg: #2b2111; --k-amber-bd: #ffa31f;
  --k-hub-bg: #33180f; --k-hub-bd: #ff6a3d;
  --k-ext-bg: #172338; --k-ext-bd: #5aa2ff;
  --k-infra-bg: #11302d; --k-infra-bd: #38d2b4;
  --edge: #8f95ad; --pkt: #ffd166;
  --live: #3ddc97; --built: #4fc3f7; --coming: #c39bff; --planned: #9aa3c0; --hold: #ff8a8a; --target: #ffd166; --dormant: #7b8196;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #fbf8f2; --bg2: #f3eee3; --panel: #ffffff; --line: #e3dccb;
    --text: #1b1a17; --muted: #5d5a50; --accent: #e8870c; --on-accent: #fff;
    --k-me-bg: #fff4cf; --k-me-bd: #c98f00;
    --k-amber-bg: #fff0d6; --k-amber-bd: #e8870c;
    --k-hub-bg: #ffe4da; --k-hub-bd: #d9441c;
    --k-ext-bg: #e4efff; --k-ext-bd: #2f6fd1;
    --k-infra-bg: #d9f5ef; --k-infra-bd: #11866f;
    --edge: #6b6f82; --pkt: #e8870c;
    --live: #0f8f58; --built: #0a76a8; --coming: #7a46d1; --planned: #5d6584; --hold: #c43e3e; --target: #a86f00; --dormant: #6a7087;
    --shadow: 0 8px 22px rgba(60,40,0,.12);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; -webkit-tap-highlight-color: transparent; }
#app { height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; max-width: 100vw; background:
  radial-gradient(900px 500px at 85% -10%, rgba(255,140,30,.14), transparent 60%), radial-gradient(700px 400px at -10% 110%, rgba(255,176,32,.08), transparent 60%), var(--bg); }
button { font: inherit; color: inherit; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: max(10px, env(safe-area-inset-top)) 16px 6px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; letter-spacing: .02em; }
.logo { width: 18px; height: 18px; border-radius: 5px; background: linear-gradient(135deg, var(--amber), var(--orange)); display: inline-block; }
.chap-label { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.stage { position: relative; min-height: 0; overflow: hidden; }
.scene { position: absolute; inset: 0; padding: 4px 16px 8px; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; cursor: pointer; }
.scene.in > * { animation: rise .5s cubic-bezier(.2,.8,.2,1) both; }
.scene.in > .visual { animation-delay: .08s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.ctag { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--accent); font-weight: 700; margin: 6px 0 2px; }
h1 { margin: 0 0 6px; font-size: clamp(25px, 7vw, 42px); line-height: 1.08; font-weight: 800; letter-spacing: -.01em; }
.visual { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.cap { margin: 8px 0 4px; min-height: 4.4em; font-size: clamp(17px, 4.6vw, 24px); line-height: 1.32; color: var(--text); font-weight: 500; }
.cap.swap { animation: capin .45s ease both; }
@keyframes capin { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* title card */
.is-title { justify-content: center; }
.title-card { display: flex; flex-direction: column; gap: 10px; }
.chno { font-size: clamp(64px, 24vw, 150px); font-weight: 900; line-height: .9; background: linear-gradient(135deg, var(--amber), var(--orange)); -webkit-background-clip: text; background-clip: text; color: transparent; letter-spacing: -.04em; }
h1.big { font-size: clamp(34px, 11vw, 64px); margin: 0; }
.serves { margin-top: 14px; border-left: 3px solid var(--accent); padding: 4px 0 4px 14px; }
.serves span { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--accent); font-weight: 700; }
.serves p { margin: 4px 0 0; font-size: clamp(18px, 4.8vw, 26px); line-height: 1.3; }

/* cards */
.cards { width: 100%; display: grid; gap: 8px; grid-template-columns: 1fr; align-content: center; }
.cards.dense { gap: 6px; }
.card { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 12px; padding: 9px 12px; box-shadow: var(--shadow); animation: pop .5s cubic-bezier(.2,.9,.3,1.2) both; }
.dense .card { padding: 6px 10px; }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: none; } }
.ctext { flex: 1; min-width: 0; }
.ct { font-weight: 700; font-size: 15.5px; line-height: 1.2; overflow-wrap: anywhere; }
.cb { color: var(--muted); font-size: 13px; line-height: 1.25; margin-top: 1px; }
.num { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--on-accent); font-weight: 800; font-size: 13px; display: grid; place-items: center; }
.badge { flex: none; font-size: 10.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; padding: 3px 8px; border-radius: 999px; border: 1.5px solid currentColor; }
.b-live { color: var(--live); } .b-built { color: var(--built); } .b-coming { color: var(--coming); } .b-planned { color: var(--planned); }
.b-hold { color: var(--hold); } .b-target { color: var(--target); } .b-dormant { color: var(--dormant); }
.card.st-live { border-left-color: var(--live); } .card.st-built { border-left-color: var(--built); }
.card.st-coming { border-left-color: var(--coming); border-style: dashed; border-left-style: solid; }
.card.st-planned { border-left-color: var(--planned); border-style: dashed; border-left-style: solid; }
.card.st-hold { border-left-color: var(--hold); border-style: dashed; border-left-style: solid; }
.card.st-target { border-left-color: var(--target); } .card.st-dormant { border-left-color: var(--dormant); opacity: .85; }
.card.st-coming .ct, .card.st-planned .ct, .card.st-hold .ct { font-style: normal; }

/* flow diagrams */
svg.flow { width: 100%; height: 100%; max-height: 100%; overflow: visible; }
.node { animation: nodein .55s cubic-bezier(.2,.9,.3,1.2) both; transform-box: view-box; }
@keyframes nodein { from { opacity: 0; transform: scale(.8); } to { opacity: 1; transform: none; } }
.node rect { stroke-width: 1.8; }
.node .nl { font-weight: 700; fill: var(--text); } .node .ns { fill: var(--muted); }
.k-me rect { fill: var(--k-me-bg); stroke: var(--k-me-bd); } .k-amber rect { fill: var(--k-amber-bg); stroke: var(--k-amber-bd); }
.k-hub rect { fill: var(--k-hub-bg); stroke: var(--k-hub-bd); } .k-ext rect { fill: var(--k-ext-bg); stroke: var(--k-ext-bd); }
.k-infra rect { fill: var(--k-infra-bg); stroke: var(--k-infra-bd); }
.node.st-coming rect, .node.st-planned rect, .node.st-hold rect { stroke-dasharray: 5 4; }
.tag rect { stroke: none !important; } .tag text { font-size: 8.5px; font-weight: 800; letter-spacing: .06em; fill: #fff; }
.st-coming .tag rect { fill: var(--coming); } .st-planned .tag rect { fill: var(--planned); } .st-hold .tag rect { fill: var(--hold); }
.edge { fill: none; stroke: var(--edge); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw .6s ease-out both; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.arrow { fill: var(--edge); animation: fadein .3s both; }
.elabel { font-size: 10.5px; fill: var(--muted); paint-order: stroke; stroke: var(--bg); stroke-width: 4px; stroke-linejoin: round; animation: fadein .4s both; }
.pkt { fill: var(--pkt); filter: drop-shadow(0 0 4px var(--pkt)); }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.paused .card, .paused .node, .paused .edge, .paused .arrow, .paused .elabel, .paused .url { animation-play-state: paused !important; }

/* end card */
.urls { width: 100%; display: grid; grid-template-columns: 1fr; gap: 4px; align-content: center; }
.goalbox { grid-column: 1 / -1; padding: 8px 12px; margin-bottom: 4px; border-radius: 12px; background: linear-gradient(135deg, var(--amber), var(--orange)); color: var(--on-accent); font-size: 13px; line-height: 1.3; animation: pop .5s both; }
.goalbox b { text-transform: uppercase; letter-spacing: .08em; font-size: 11px; margin-right: 4px; }
.url { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 6px 10px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; color: var(--text); text-decoration: none; animation: pop .5s both; }
.url b { font-size: 13.5px; white-space: nowrap; } .url span { font-size: 12.5px; color: var(--accent); overflow-wrap: anywhere; text-align: right; } .url i { display: none; font-style: normal; font-size: 11.5px; color: var(--muted); }
a.url:hover, a.url:focus-visible { border-color: var(--accent); outline: none; }
.url.nolink { opacity: .85; border-left-color: var(--planned); }
.url.nolink span { display: none; } .url.nolink i { display: inline; }
.is-end .cap { min-height: 3.2em; font-size: clamp(15px, 4vw, 20px); }
.is-end h1 { font-size: clamp(22px, 6vw, 34px); }

/* controls */
.controls { padding: 6px 12px max(10px, env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 70%, transparent); }
.bar { position: relative; height: 22px; cursor: pointer; touch-action: none; outline: none; }
.bar::before { content: ""; position: absolute; left: 0; right: 0; top: 9px; height: 5px; border-radius: 3px; background: var(--line); }
.fill { position: absolute; left: 0; top: 9px; height: 5px; border-radius: 3px; background: linear-gradient(90deg, var(--amber), var(--orange)); width: 0; }
.marks i { position: absolute; top: 5px; width: 2px; height: 13px; background: var(--muted); opacity: .7; border-radius: 1px; }
.knob { position: absolute; top: 4px; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 3px rgba(255,163,31,.25); left: 0; }
.bar:focus-visible .knob { box-shadow: 0 0 0 4px var(--accent); }
.row { display: flex; align-items: center; gap: 6px; }
.btn { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center; cursor: pointer; padding: 0; flex: none; }
.btn svg { width: 22px; height: 22px; fill: currentColor; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn svg path { fill: none; }
.btn.play { width: 52px; background: linear-gradient(135deg, var(--amber), var(--orange)); color: var(--on-accent); border: 0; }
.btn.play svg path { fill: currentColor; stroke: none; }
.btn.play svg path[d^="M5 12"] { fill: none; stroke: currentColor; }
.btn.on { border-color: var(--accent); color: var(--accent); }
.btn:focus-visible, .url:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.time { flex: 1; text-align: center; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); white-space: nowrap; }

.edge-l, .edge-r { position: absolute; top: 0; bottom: 0; width: 13%; max-width: 90px; background: transparent; border: 0; z-index: 3; padding: 0; cursor: pointer; }
.edge-l { left: 0; } .edge-r { right: 0; }
.flash { position: absolute; left: 50%; top: 45%; width: 76px; height: 76px; margin: -38px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; opacity: 0; pointer-events: none; z-index: 4; }
.flash svg { width: 38px; height: 38px; fill: currentColor; }
.flash.go { animation: flashgo .7s ease-out; }
@keyframes flashgo { 0% { opacity: 0; transform: scale(.7); } 25% { opacity: 1; } 100% { opacity: 0; transform: scale(1.15); } }

/* chapter sheet */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.55); animation: fadein .2s both; }
.sheet-panel { position: relative; width: 100%; max-width: 560px; max-height: 82dvh; overflow: auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 18px 18px 0 0; padding: 10px 12px max(14px, env(safe-area-inset-bottom)); animation: up .28s cubic-bezier(.2,.8,.2,1) both; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 2px 4px 8px; font-size: 17px; }
#chapList { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#chapList button { width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
#chapList .on button { border-color: var(--accent); background: var(--k-amber-bg); }
#chapList .n { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--on-accent); font-weight: 800; display: grid; place-items: center; font-size: 14px; }
#chapList .tt { flex: 1; min-width: 0; display: flex; flex-direction: column; } #chapList small { color: var(--muted); font-size: 12.5px; }
#chapList .d { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* wider screens */
@media (min-width: 700px) and (min-aspect-ratio: 5/4) {
  .cards { grid-template-columns: 1fr 1fr; } .urls { grid-template-columns: 1fr 1fr; } .url i { display: inline; }
  .scene { padding: 8px 24px; max-width: 1000px; }
  .is-title { flex-direction: column; }
  .controls { max-width: 760px; margin: 0 auto; width: 100%; }
}
@media (max-height: 640px) { .cap { min-height: 3.6em; } h1 { font-size: clamp(22px, 6vw, 32px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition: none !important; }
  .edge { stroke-dashoffset: 0; }
}
