/* Motion Library. Studio shell layout, reel brand (white, ink, one blue). Spacing 4 8 12 16 24 32 48 64; type 16 20 24 32 40. */
:root {
  --bg: #F6F7FA; --surface: #FFFFFF; --ink: #0B0B0F; --mute: #5A6273; --line: #E3E8F2;
  --blue: #1D5BFF; --blue-ink: #FFFFFF; --soft: #EEF2FB; --focus: #1D5BFF;
  --yes: #0F7A3A; --check: #8A5A00; --no: #B42318;
  --rail: 72px; --panel: 288px; --r: 16px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0E0F13; --surface: #17191F; --ink: #F2F4F8; --mute: #A3AABA; --line: #2A2E38; --soft: #1E2330; --focus: #7FA2FF; --yes: #4ADE80; --check: #F5B942; --no: #FF8A80; }
}
* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font: 400 16px/1.5 Inter, system-ui, sans-serif; color: var(--ink); background: var(--bg); }
a { color: inherit; }
b, h1, h2, h3, th { font-weight: 700; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
.skip { position: absolute; left: -9999px; top: 8px; z-index: 50; padding: 8px 16px; background: var(--surface); }
.skip:focus { left: 8px; }
code, pre { font-family: ui-monospace, Menlo, monospace; }

/* rail */
.rail { position: fixed; inset: 0 auto 0 0; width: var(--rail); display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 0; background: var(--surface); border-right: 1px solid var(--line); z-index: 10; }
.rail a { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 64px; padding: 8px 0; border-radius: 12px; text-decoration: none; font-size: 12px; color: var(--mute); }
.rail a span { font-size: 12px; }
.rail a[aria-current] { color: var(--ink); background: var(--soft); }
.rail a:hover { color: var(--ink); }
.rail svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rail .mark { width: 40px; height: 40px; padding: 0; margin-bottom: 16px; justify-content: center; background: var(--blue); color: var(--blue-ink); font-weight: 700; font-size: 20px; border-radius: 12px; }

/* shell */
.shell { margin-left: var(--rail); padding: 16px 24px 32px; min-height: 100vh; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 16px; }
.top h1 { font-size: 24px; line-height: 1.2; letter-spacing: -0.02em; }
.top .sub { color: var(--mute); }
.count { color: var(--mute); white-space: nowrap; }

.work { display: grid; grid-template-columns: var(--panel) 1fr; gap: 16px; align-items: start; }
.controls { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 12px; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.lbl { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--mute); }
input[type=search] { width: 100%; min-height: 44px; padding: 8px 12px; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.cats { display: flex; flex-direction: column; gap: 4px; }
.cats button { display: flex; justify-content: space-between; align-items: center; min-height: 44px; padding: 8px 12px; font: inherit; color: var(--ink); background: none; border: 0; border-radius: 12px; cursor: pointer; text-align: left; }
.cats button span { color: var(--mute); font-size: 14px; }
.cats button:hover { background: var(--soft); }
.cats button[aria-pressed=true] { background: var(--ink); color: var(--surface); }
.cats button[aria-pressed=true] span { color: inherit; opacity: .7; }
.tip { padding: 16px; border-radius: 12px; background: var(--soft); display: flex; flex-direction: column; gap: 8px; }
.motion-toggle { display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; color: var(--mute); }
.motion-toggle input { width: 20px; height: 20px; accent-color: var(--blue); }

/* canvas */
.canvas { min-width: 0; outline: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.tile .open { display: flex; flex-direction: column; gap: 8px; width: 100%; padding: 8px 8px 16px; font: inherit; color: inherit; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; transition: transform .2s cubic-bezier(.16,1,.3,1), box-shadow .2s; }
.tile .open:hover { transform: translateY(-4px); box-shadow: 0 16px 32px rgba(16,24,40,.12); }
.frame { position: relative; width: 100%; aspect-ratio: 9 / 16; overflow: hidden; border-radius: 12px; background: #fff; --k: .2; }
.frame iframe { position: absolute; left: 0; top: 0; width: 1080px; height: 1920px; border: 0; transform: scale(var(--k)); transform-origin: 0 0; pointer-events: none; }
.cap { display: flex; align-items: baseline; gap: 8px; padding: 0 4px; }
.id { font-weight: 700; color: var(--blue); font-variant-numeric: tabular-nums; }
@media (prefers-color-scheme: dark) { .id { color: #7FA2FF; } }
.use { padding: 0 4px; font-size: 14px; color: var(--mute); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.empty { padding: 48px 24px; text-align: center; color: var(--mute); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--r); }

/* pages */
.page { max-width: 880px; padding: 32px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); display: flex; flex-direction: column; gap: 16px; }
.page h2 { font-size: 32px; line-height: 1.2; letter-spacing: -0.02em; }
.page h3 { font-size: 20px; margin-top: 16px; }
.page p, .page li { max-width: 68ch; }
.steps, .rules { padding-left: 24px; display: flex; flex-direction: column; gap: 8px; }
.ranges { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.ranges div { padding: 12px 16px; border-radius: 12px; background: var(--soft); display: flex; flex-direction: column; }
.ranges span { color: var(--mute); }
.lede { color: var(--mute); }
.note { font-size: 14px; color: var(--mute); }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
thead th { position: sticky; top: 0; background: var(--surface); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--mute); }
tbody th a { text-decoration: none; }
tbody th a:hover { text-decoration: underline; }
.v { display: inline-block; padding: 4px 8px; border-radius: 8px; font-weight: 700; font-size: 12px; text-transform: uppercase; border: 1px solid currentColor; }
.v-yes { color: var(--yes); } .v-check { color: var(--check); } .v-no { color: var(--no); }

/* detail */
dialog { width: min(1080px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 24px; background: var(--surface); color: var(--ink); box-shadow: 0 32px 64px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(11,11,15,.55); }
dialog[open] { animation: rise .32s cubic-bezier(.16,1,.3,1); }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.98); } }
.d-wrap { display: grid; grid-template-columns: minmax(240px, 360px) 1fr; gap: 24px; padding: 24px; }
.d-stage .frame { border: 1px solid var(--line); }
.d-info { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.d-head { display: flex; justify-content: space-between; align-items: center; }
.d-info h2 { font-size: 32px; line-height: 1.1; letter-spacing: -0.02em; }
.x { width: 44px; height: 44px; font-size: 24px; line-height: 1; border: 1px solid var(--line); border-radius: 12px; background: none; color: inherit; cursor: pointer; }
.say { display: flex; flex-direction: column; gap: 4px; padding: 12px 16px; border-left: 4px solid var(--blue); background: var(--soft); border-radius: 0 12px 12px 0; }
.say span { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--mute); }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 14px; }
.meta dt { color: var(--mute); }
.d-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.d-actions button, .tabs button { min-height: 44px; padding: 8px 16px; font: inherit; color: var(--ink); background: none; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.d-actions .primary { background: var(--blue); color: var(--blue-ink); border-color: var(--blue); font-weight: 700; }
.tabs { display: flex; gap: 4px; margin-top: 8px; }
.tabs [aria-selected=true] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.tabs .copy { margin-left: auto; }
pre { max-height: 300px; overflow: auto; padding: 16px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); padding: 12px 24px; border-radius: 12px; background: var(--ink); color: var(--surface); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* tablet */
@media (max-width: 1024px) {
  .work { grid-template-columns: minmax(0, 1fr); }
  .work > * { min-width: 0; }
  .controls { position: static; }
  .cats { flex-direction: row; flex-wrap: wrap; }
  .cats button { gap: 8px; }
  .tip { display: none; }
}
/* phone: rail becomes bottom tabs */
@media (max-width: 767px) {
  .rail { inset: auto 0 0 0; width: auto; height: 64px; flex-direction: row; justify-content: space-around; padding: 0 8px; border-right: 0; border-top: 1px solid var(--line); }
  .rail .mark { display: none; }
  .shell { margin-left: 0; padding: 16px 16px 96px; }
  .top { padding: 16px; }
  .top .sub { display: none; }
  .controls { padding: 16px; }
  .cats { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px 4px; }
  .cats button { flex: none; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .use { display: none; }
  .d-wrap { grid-template-columns: 1fr; padding: 16px; }
  .d-stage { max-width: 240px; margin: 0 auto; width: 100%; }
  .page { padding: 24px 16px; }
}
@media (prefers-reduced-motion: reduce) { *, ::before, ::after { transition: none !important; animation: none !important; } }
dialog { margin: auto; }
.id { white-space: nowrap; }
@media (max-width: 767px) { .cap { flex-direction: column; gap: 0; } }
/* inspector fixes: close pinned to the dialog corner, dialog body scrolls, phone sheet shows the action */
dialog { overflow: hidden; }
.d-wrap { max-height: calc(100vh - 32px); overflow: auto; }
.x { position: absolute; top: 16px; right: 16px; z-index: 2; background: var(--surface); }
.d-head { padding-right: 56px; min-height: 44px; }
@media (max-width: 767px) {
  .top .sub { display: block; font-size: 14px; }
  .top { flex-wrap: wrap; }
  .controls { gap: 8px; }
  #cat-lbl, .controls > .lbl:first-child { position: absolute; left: -9999px; }
  .cats { -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); }
  .cats button { border: 1px solid var(--line); }
  .d-wrap { grid-template-columns: 112px 1fr; gap: 16px; padding: 16px; max-height: calc(100vh - 32px); }
  .d-stage { max-width: none; margin: 0; }
  .d-info { display: contents; }
  .d-head, .d-info h2 { grid-column: 2; }
  .d-stage { grid-row: 1 / span 2; grid-column: 1; }
  .d-info > :not(.d-head):not(h2) { grid-column: 1 / -1; }
  .d-info h2 { font-size: 24px; }
  .d-actions { position: sticky; bottom: -16px; z-index: 1; margin: 0 -16px; padding: 12px 16px; background: var(--surface); border-top: 1px solid var(--line); order: 0; }
}
[hidden] { display: none !important; }
.d-wrap > *, .d-info > * { min-width: 0; }
.meta dd, .d-info p { overflow-wrap: anywhere; }
html.locked { overflow: hidden; }
.d-wrap { overscroll-behavior: contain; }
.seg { display: flex; gap: 4px; }
.tabs [aria-pressed=true] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.empty { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.empty button { min-height: 44px; padding: 8px 16px; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.why { margin-top: 8px; font-size: 14px; color: var(--mute); min-width: 200px; }
#lic td:first-child { min-width: 220px; }
dialog .toast { position: absolute; bottom: 16px; }
@media (max-width: 767px) { html { scroll-padding-bottom: 88px; } }
