* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 400 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh;
}
a { color: inherit; text-underline-offset: 2px; text-decoration-color: var(--line-2); }
a:hover { text-decoration-color: currentColor; }
svg { flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 600; letter-spacing: -.01em; font-size: 16px; }
.brand svg { width: 26px; height: 26px; }
.brand rect { fill: var(--accent); }
.brand path { stroke: var(--accent-ink); stroke-width: 2.2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.brand circle { fill: var(--accent-ink); }
.local-note { margin: 0; display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 13.5px; }
.local-note svg { width: 17px; height: 17px; fill: none; stroke: var(--ok); stroke-width: 1.7; stroke-linecap: round; }

/* ---------- layout ---------- */
.app {
  flex: 1; display: grid; grid-template-columns: minmax(320px, 380px) 1fr; min-height: 0;
}
.panel {
  padding: 22px 24px 20px; display: flex; flex-direction: column; gap: 12px;
  border-right: 1px solid var(--line); overflow-y: auto; max-height: calc(100vh - 57px); max-height: calc(100dvh - 57px);
  position: sticky; top: 0;
}
.stage {
  position: relative; background: var(--stage); min-height: 480px;
  display: grid; place-items: center; padding: 40px;
  overflow: hidden;
}

/* ---------- intro ---------- */
.intro h1 {
  font: 600 36px/1.08 var(--display); letter-spacing: -.03em; margin: 4px 0 14px;
}
.intro h1 em { font-style: normal; color: var(--accent); }
.lede { margin: 0 0 22px; color: var(--ink-2); font-size: 16px; }
.pickers { display: flex; gap: 8px; flex-wrap: wrap; }
.hint { color: var(--mute); font-size: 13.5px; margin: 12px 0 0; }
.examples { margin-top: 30px; padding-top: 22px; border-top: 1px solid var(--line); }
.examples h2 { font-size: 12px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--mute); margin: 0 0 12px; }
.example-list { display: grid; gap: 8px; }
.example {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 12px; text-align: left;
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; cursor: pointer; transition: border-color .15s, transform .15s;
}
.example:hover { border-color: var(--line-2); }
.example:active { transform: translateY(1px); }
.example b { font-weight: 500; }
.example small { grid-column: 1; color: var(--mute); font-size: 12.5px; }
.example .go { grid-row: 1 / span 2; grid-column: 2; color: var(--mute); font-size: 18px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 500 14.5px/1 var(--sans); color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-2); border-radius: 9px; padding: 11px 16px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s, opacity .15s;
}
.btn:hover { border-color: var(--mute); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary:hover { opacity: .9; }
.btn.small { padding: 7px 10px; font-size: 13px; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn.wide { width: 100%; justify-content: flex-start; padding: 13px 16px; }
.btn.wide small { margin-left: auto; font-weight: 400; font-size: 12.5px; opacity: .7; }
.btn[disabled] { opacity: .45; cursor: default; }
.btn.busy { cursor: progress; opacity: .7; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card-title { font-size: 12px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--mute); margin: 0 0 12px; }

.board-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.board-name { font: 600 20px/1.2 var(--display); margin: 0 0 4px; overflow-wrap: anywhere; }
.board-spec { margin: 0; color: var(--mute); font-size: 13px; font-variant-numeric: tabular-nums; }
.board-file { margin: 2px 0 0; color: var(--mute); font-size: 12px; overflow-wrap: anywhere; }
.board-head .btn { white-space: nowrap; }
.attribution { margin: 12px 0 0; font-size: 13px; color: var(--ink-2); padding: 10px 12px; background: var(--bg); border-radius: 8px; }
.warnings { margin: 12px 0 0; padding: 10px 12px 10px 28px; background: var(--warn-soft); color: var(--warn); border-radius: 8px; font-size: 13px; }
.warnings li + li { margin-top: 3px; }

.files { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.files summary { cursor: pointer; font-size: 13.5px; color: var(--ink-2); list-style: none; display: flex; align-items: center; gap: 6px; }
.files summary::-webkit-details-marker { display: none; }
.files summary::before { content: ''; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform .15s; margin: 0 4px 0 2px; }
.files[open] summary::before { transform: rotate(45deg); }
.filelist { list-style: none; margin: 10px 0 0; padding: 0; font-size: 12.5px; }
.filelist li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1px 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.filelist li:last-child { border-bottom: 0; }
.filelist .fn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 11.5px; color: var(--ink-2); }
.filelist .role { font-weight: 500; text-align: right; white-space: nowrap; }
.filelist .how { grid-column: 1 / -1; color: var(--mute); font-size: 11.5px; }
.filelist li.skipped .role { color: var(--mute); font-weight: 400; }
.filelist-sub { margin: 12px 0 0; font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--mute); }

/* ---------- styles ---------- */
.styles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.style {
  font: inherit; color: inherit; background: transparent; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 8px 9px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 7px;
  transition: border-color .15s, background .15s;
}
.style:hover { border-color: var(--line-2); }
.style[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
.thumb { width: 100%; max-width: 56px; aspect-ratio: 3 / 4; border-radius: 3px; box-shadow: 0 1px 3px rgba(0, 0, 0, .18); }
.style-name { font-size: 12.5px; font-weight: 500; text-align: center; line-height: 1.2; }

/* ---------- fields ---------- */
.fields { display: grid; gap: 10px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: grid; gap: 4px; }
.field span { font-size: 12.5px; color: var(--mute); }
.field input {
  font: 400 15px/1.3 var(--sans); color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
  transition: border-color .15s, background .15s;
}
.field input::placeholder { color: var(--mute); opacity: .75; }
.field input:hover { border-color: var(--line-2); }
.field input:focus { outline: none; border-color: var(--accent); background: var(--surface); }

/* ---------- download ---------- */
.download { display: grid; gap: 8px; }
.fine { margin: 4px 0 0; color: var(--mute); font-size: 12.5px; }

/* ---------- footer ---------- */
.panel-foot { margin-top: auto; padding-top: 18px; font-size: 12.5px; color: var(--mute); }
.panel-foot p { margin: 0 0 6px; }
.engine { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.engine .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--mute); }
.engine[data-engine="loading"] .dot { animation: pulse 1.2s ease-in-out infinite; background: var(--warn); }
.engine[data-engine="ready"] .dot { background: var(--ok); }
.engine[data-engine="error"] .dot { background: var(--err); }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- stage: drop target ---------- */
.drop {
  width: min(520px, 100%); aspect-ratio: 3 / 4; max-height: calc(100vh - 160px); max-height: calc(100dvh - 160px);
  border: 1.5px dashed var(--line-2); border-radius: 6px; display: grid; place-items: center; text-align: center;
  cursor: pointer; transition: border-color .2s, background .2s; background: color-mix(in srgb, var(--surface) 40%, transparent);
}
.drop:hover, .drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 50%, transparent); }
.drop-art { width: 76px; height: 76px; fill: none; stroke: var(--mute); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 8px; }
.drop-art circle { fill: var(--mute); stroke: none; }
.drop-title { font: 600 24px/1.2 var(--display); margin: 0 0 4px; }
.drop-sub { margin: 0; color: var(--mute); font-size: 14px; }
.dropcover {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; pointer-events: none;
  background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(3px);
  border: 3px solid var(--accent);
}
.dropcover p { font: 600 30px/1 var(--display); margin: 0; }

/* ---------- stage: status + error ---------- */
.status, .error { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; z-index: 3; }
.status { pointer-events: none; }
.status-card, .error-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 24px; box-shadow: var(--shadow);
}
.status-title { font: 600 19px/1.2 var(--display); margin: 0 0 14px; }
.bar { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; position: relative; }
.bar i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); border-radius: 2px; transition: width .25s; }
.bar.indet i { width: 30%; animation: slide 1.3s ease-in-out infinite; }
@keyframes slide { from { left: -30%; } to { left: 100%; } }
.status-detail { margin: 12px 0 0; color: var(--mute); font-size: 13px; min-height: 1.5em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.error-card { width: min(520px, 100%); max-height: 100%; overflow: auto; }
.error-title { font: 600 20px/1.2 var(--display); margin: 0 0 8px; color: var(--err); }
.error-text { margin: 0 0 12px; color: var(--ink-2); }
.error-actions { margin-top: 16px; }
.error-detail { margin-top: 14px; font-size: 12.5px; color: var(--mute); }
.error-detail pre { white-space: pre-wrap; font-size: 11px; max-height: 200px; overflow: auto; background: var(--bg); padding: 8px; border-radius: 6px; }

/* ---------- stage: poster ---------- */
.poster { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; height: 100%; justify-content: center; }
.frame {
  position: relative; flex: none; aspect-ratio: var(--ar, 800 / 1100);
  height: min(calc(100vh - 150px), 1300px); height: min(calc(100dvh - 150px), 1300px); max-width: 100%;
  box-shadow: var(--poster-shadow); background: var(--line);
}
.frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; transition: opacity .35s; }
.frame iframe.pending { opacity: 0; pointer-events: none; }
.frame.busy::after {
  content: ''; position: absolute; top: 12px; right: 12px; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35); border-top-color: rgba(255, 255, 255, .9); animation: spin .8s linear infinite;
  mix-blend-mode: difference;
}
@keyframes spin { to { transform: rotate(360deg); } }
.poster-note { font-size: 12.5px; color: var(--mute); text-align: center; min-height: 1.5em; }
.poster-note.warn { color: var(--warn); }

/* ---------- state switches ---------- */
body[data-state="parsing"] .drop, body[data-state="error"] .drop { visibility: hidden; }
body:not([data-state="empty"]) .drop { display: none; }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .top { padding: 12px 16px; }
  .local-note span { font-size: 12.5px; }
  .app { display: flex; flex-direction: column; flex: none; }
  .panel { position: static; max-height: none; border-right: 0; padding: 20px 16px; overflow: visible; }
  .stage { padding: 20px 16px; min-height: 0; order: -1; }
  body[data-state="empty"] .stage { display: none; }
  .poster { height: auto; }
  .frame { height: auto; width: min(100%, 560px); }
  .status, .error { position: static; padding: 0; }
  body[data-state="parsing"] .stage, body[data-state="error"] .stage { display: grid; min-height: 260px; }
  .intro h1 { font-size: 32px; }
}
@media (max-width: 480px) {
  .local-note span { max-width: 170px; line-height: 1.3; }
  .brand span { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
