* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif; }
.sr, .skip:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip:focus { position: fixed; top: 8px; left: 8px; z-index: 10; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.bar { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 10px; } .brand h1 { margin: 0; font-size: 18px; letter-spacing: .2px; }
.logo { display: grid; place-items: center; width: 32px; height: 32px; }
.logo-img { width: 32px; height: 32px; display: block; }
.logo-on-light { display: none; }
:root[data-ui="light"] .logo-on-dark { display: none; }
:root[data-ui="light"] .logo-on-light { display: block; }
.controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
.field { display: flex; align-items: center; gap: 6px; color: var(--dim); font-size: 12px; }
select, input[type=search], .btn { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
select { max-width: 260px; }
.btn { cursor: pointer; text-decoration: none; display: inline-block; transition: background var(--dur-fast, 140ms) ease, transform 120ms ease; }
.btn:hover { background: color-mix(in srgb, var(--accent) 20%, var(--surface-2)); }
.btn:active { transform: scale(.97); }
.btn.toggle[aria-pressed=true] { border-color: var(--accent); }
.modes { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.modes button { font: inherit; color: var(--dim); background: transparent; border: 0; padding: 7px 14px; cursor: pointer; }
.modes button[aria-checked=true] { background: var(--accent); color: #0b0e14; font-weight: 700; }
.modes button[disabled] { opacity: .5; cursor: not-allowed; }
.subbar { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; justify-content: space-between; padding: 8px 20px; border-bottom: 1px solid var(--line); min-height: 46px; }
.layers { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.layers:empty { display: none; }
.chip { font: inherit; font-size: 12px; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; cursor: pointer; }
.chip[aria-pressed=true] { background: color-mix(in srgb, var(--accent) 35%, var(--surface-2)); border-color: var(--accent); }
.chip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--c, var(--accent)); }
.search { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cats { display: flex; flex-wrap: wrap; gap: 6px; }
.main { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; padding: 16px 20px 8px; align-items: start; }
@media (min-width: 901px) { .mobile-only { display: none !important; } }
.stage-wrap { min-width: 0; }
.stage-scroller { overflow: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y pinch-zoom; max-width: 100%; }
.stage { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; overflow: visible; touch-action: pan-x pan-y pinch-zoom; }
.stage .hk-svg { display: block; width: 100%; height: auto; max-height: 78vh; margin: 0 auto; }
.stage-toolbar { display: none; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 8px; }
@media (max-width: 900px) { .stage-toolbar { display: flex; } }
.stage-zoom { display: inline-flex; gap: 4px; align-items: center; }
.detail-close { display: none; }
.stage.physical .hk-svg { max-width: 1000px; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.tools-label { color: var(--dim); font-size: 12px; } .spacer { flex: 1; }
.chk { font-size: 12px; color: var(--dim); display: inline-flex; gap: 6px; align-items: center; }
.exp-note, .product { color: var(--dim); font-size: 12.5px; margin: 8px 0 0; }
.product { padding: 10px 12px; border: 1px dashed var(--line); border-radius: 10px; }
.product a { color: var(--accent); font-weight: 700; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; max-height: calc(100vh - 140px); overflow: auto; position: sticky; top: 8px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; } .panel-head h2 { margin: 0; font-size: 15px; } .count { color: var(--dim); font-size: 12px; }
.list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.list li { margin: 0; }
.item { width: 100%; text-align: left; font: inherit; color: var(--text); background: transparent; border: 1px solid transparent; border-left: 4px solid var(--c); border-radius: 8px; padding: 6px 8px; cursor: pointer; display: grid; gap: 3px; }
.item:hover { background: var(--surface-2); }
.item[aria-pressed=true] { background: color-mix(in srgb, var(--c) 18%, var(--surface)); border-color: var(--c); }
.item .act { font-size: 13px; font-weight: 600; display: flex; gap: 8px; align-items: baseline; } .item .rk { color: var(--dim); font-size: 11px; min-width: 22px; text-align: right; font-weight: 700; }
kbd { font: 700 11.5px/1 ui-monospace, 'SF Mono', Menlo, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 3px 6px; color: var(--text); }
kbd.key { border-color: var(--c); } .plus { color: var(--dim); margin: 0 2px; font-size: 11px; }
.item.dim { opacity: .3; }
.detail { margin-top: 8px; } .detail:empty { display: none; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--surface-2); display: grid; gap: 6px; font-size: 12.5px; }
.card h3 { margin: 0; font-size: 15px; } .card p { margin: 0; } .card .meta { color: var(--dim); font-size: 12px; } .card a { color: var(--accent); }
.card ul { margin: 0; padding-left: 16px; }
.off { margin-top: 10px; color: var(--dim); font-size: 12px; } .off:empty { display: none; }
.foot { padding: 12px 20px 28px; color: var(--dim); font-size: 12px; }
.foot a { color: var(--accent); }
.feedback-link { color: var(--accent); font-size: 12px; white-space: nowrap; }
.feedback-link[hidden] { display: none !important; }
.field-set { flex-wrap: wrap; }
.tip { position: fixed; z-index: 20; pointer-events: none; background: #05070b; color: #fff; border: 1px solid #3a4560; border-radius: 8px; padding: 6px 9px; font-size: 12px; max-width: 280px; box-shadow: 0 6px 22px rgba(0,0,0,.4); }

/* ---- SVG states (class toggles only; no re-render) ---- */
.hk-svg .key.is-bound, .hk-svg .row { cursor: pointer; }
.hk-svg .key, .hk-svg .row { outline: none; }
.hk-svg .key-inner, .hk-svg .legend { transform-box: fill-box; transform-origin: center; }
.hk-svg.has-focus [data-cmds]:not(.is-focus) { opacity: .28; transition: opacity var(--dur-med-ms, 280ms) ease; }
.hk-svg [data-cmds] { transition: opacity 200ms ease; }
.hk-svg .key.is-focus .face { stroke: var(--focus); stroke-width: 3; }
.hk-svg .row.is-focus .key-inner { filter: drop-shadow(0 0 4px color-mix(in srgb, var(--focus) 70%, transparent)); }
.hk-svg .key.mod-focus .face { stroke: var(--focus); stroke-width: 2.5; }
.hk-svg .key:focus-visible .face { stroke: var(--focus); stroke-width: 3.5; stroke-dasharray: none; }
.hk-svg .row:focus-visible .key-inner { filter: drop-shadow(0 0 4px var(--focus)) drop-shadow(0 0 2px var(--focus)); }
.hk-svg .hub-mod:focus-visible circle { stroke: var(--focus); stroke-width: 3.5; }
.hk-svg .dim-filter { opacity: .15 !important; }
.hk-svg .hub-mod { cursor: pointer; }
.hk-svg .fx circle { pointer-events: none; }

/* ---- load reveal: CSS keyframes, staggered with --i set from JS ---- */
@keyframes hk-reveal { from { opacity: 0; transform: translateY(10px) scale(.9); } to { opacity: 1; transform: none; } }
.hk-svg.reveal .key-inner, .hk-svg.reveal .legend { animation: hk-reveal calc(var(--dur-slow) * 1ms) var(--ease-emphasized) both; animation-delay: calc(min(var(--i, 0) * var(--stagger), var(--stagger-max)) * 1ms); }
.hk-svg.reveal .legend { --i: 30; }

#print-root { display: none; }
@media print {
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing #print-root { display: block !important; }
  body, html { background: #fff !important; }
  #print-root svg * { animation: none !important; transition: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
html.no-motion *, html.no-motion *::before, html.no-motion *::after { animation: none !important; transition: none !important; }

/* freshness badge: green / amber / red by data age (see src/ui/freshness.js) */
.fresh { font-size: 12px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--dim); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.fresh::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.fresh[data-level=ok] { color: #5fd49a; border-color: color-mix(in srgb, #5fd49a 45%, var(--line)); }
.fresh[data-level=warn] { color: #ffb84d; border-color: color-mix(in srgb, #ffb84d 55%, var(--line)); background: color-mix(in srgb, #ffb84d 10%, transparent); }
.fresh[data-level=bad] { color: #ff6b6b; border-color: color-mix(in srgb, #ff6b6b 60%, var(--line)); background: color-mix(in srgb, #ff6b6b 12%, transparent); font-weight: 600; }
.fresh[data-level=example] { color: var(--dim); }

/* consent + modals */
body { padding-bottom: var(--consent-h, 0); }
.consent-banner { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); padding: 14px 20px; display: grid; gap: 10px; box-shadow: 0 -8px 30px rgba(0,0,0,.25); max-width: 900px; margin: 0 auto; }
.consent-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn.primary { background: color-mix(in srgb, var(--accent) 35%, var(--surface-2)); font-weight: 700; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.modal { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); max-width: 520px; width: calc(100% - 24px); }
.modal.wide { max-width: 640px; }
.modal::backdrop { background: rgba(0,0,0,.45); }
.modal-body { padding: 16px 18px; display: grid; gap: 12px; }
.modal-body h2 { margin: 0; font-size: 18px; }
.modal-body h3 { margin: 8px 0 4px; font-size: 14px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.field.block, .chk.block { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.dim { color: var(--dim); }
.status-banner { margin: 8px 0 0; padding: 8px 12px; border-radius: 8px; background: color-mix(in srgb, #ffb84d 15%, var(--surface)); border: 1px solid color-mix(in srgb, #ffb84d 40%, var(--line)); font-size: 12.5px; }

/* my list panel */
.mylist-panel { margin-top: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.mylist-panel summary { cursor: pointer; padding: 10px 12px; font-weight: 600; }
.mylist-inner { padding: 0 12px 12px; display: grid; gap: 8px; }
.mylist-toolbar, .mylist-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.mylist-rows { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow: auto; display: grid; gap: 2px; }
.mylist-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 4px 6px; border-left: 3px solid var(--c); border-radius: 6px; font-size: 12.5px; }
.mylist-row .act { font-weight: 600; }
.file-btn { cursor: pointer; }
.app-picker { max-height: 240px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.info-only-apps { margin-top: 10px; font-size: 0.92rem; }
.info-only-list { max-height: 200px; overflow: auto; padding: 4px 0; }
.info-only-entry { margin: 8px 0; }
.inherits-note, .forks-info { margin: 0 0 8px; max-width: 72rem; }
.forks-info .linkish { font-size: inherit; vertical-align: baseline; }
.view-toggle { flex-wrap: wrap; }
.badge-fork { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 6px; margin-left: 6px; border-radius: 4px; background: var(--chip); color: var(--accent); vertical-align: middle; }
.indent-fork { padding-left: 1.25rem; }
.indent-combined { padding-left: 2rem; font-style: italic; }
.list.list--dense li { content-visibility: auto; contain-intrinsic-size: auto 2.5rem; }
.app-group { border: 0; margin: 0 0 8px; padding: 0; }
.app-group legend { font-size: 12px; font-weight: 700; }
.app-picker-actions { display: flex; gap: 6px; margin: 6px 0; }
.item .act .cmd-icon, #detail .cmd-icon { display: inline-block; width: 16px; height: 16px; vertical-align: -3px; margin-right: 6px; color: var(--dim); }
.share-dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 0; max-width: 520px; width: calc(100% - 24px); background: var(--surface); color: var(--text); }
.share-dialog::backdrop { background: rgba(0,0,0,.45); }
.export-all-dialog { max-width: 560px; }
.export-fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0; display: grid; gap: 6px; }
.export-fieldset legend { padding: 0 4px; font-size: 13px; font-weight: 600; }
.export-check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 4px 10px; margin-left: 8px; }
.export-preview, .export-summary { font-size: 13px; color: var(--muted); margin: 0; }
.export-warn { color: var(--warn, #c90); font-size: 13px; margin: 0; }
.export-progress-wrap { display: flex; align-items: center; gap: 10px; }
.export-progress-wrap progress { flex: 1; }
.share-form { padding: 16px 18px 18px; display: grid; gap: 10px; }
.share-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.share-head h2 { margin: 0; font-size: 18px; }
.share-intro, .share-help { margin: 0; font-size: 12.5px; color: var(--dim); }
.share-kind label { display: block; margin: 4px 0; font-size: 13px; }
.share-errors { color: #f66; font-size: 12.5px; }
.share-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.share-result { font-size: 12.5px; color: var(--dim); margin: 0; }
.field.block { display: grid; gap: 4px; font-size: 12px; color: var(--dim); }
.field.block input, .field.block textarea, .field.block select { width: 100%; }

/* ---- Mobile / tablet (J23) ---- */
html { overflow-x: clip; }
body { touch-action: manipulation; }

@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; padding: 12px 14px 8px; gap: 12px; }
  .bar { padding: 10px 14px; gap: 8px; }
  .brand { flex: 1; min-width: 0; }
  .brand h1 { font-size: 16px; }
  .controls { width: 100%; flex-direction: column; align-items: stretch; gap: 10px; }
  .controls:not(.is-open) { display: none; }
  .controls.is-open { display: flex; }
  #btn-mobile-menu { margin-left: auto; min-width: 44px; min-height: 44px; }
  .field { flex-wrap: wrap; font-size: 13px; }
  select, input[type=search] { max-width: 100%; width: 100%; font-size: 16px; min-height: 44px; }
  .btn { min-height: 44px; padding: 10px 14px; }
  .modes button { min-height: 44px; padding: 10px 12px; }
  .chip { min-height: 36px; padding: 8px 12px; }
  .subbar { padding: 8px 14px; }
  .panel { position: relative; top: auto; max-height: none; }
  .stage .hk-svg { max-height: 65vh; }
}

@media (max-width: 600px) {
  .panel { display: none; }
  .panel.panel-open { display: block; position: fixed; inset: auto 0 0 0; z-index: 28; max-height: min(72vh, 520px); border-radius: var(--radius) var(--radius) 0 0; box-shadow: 0 -12px 40px rgba(0,0,0,.35); padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  body.cmd-detail-open #detail { position: fixed; left: 0; right: 0; bottom: 0; z-index: 32; margin: 0; padding: 12px 14px max(14px, env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); box-shadow: 0 -10px 36px rgba(0,0,0,.4); max-height: 55vh; overflow: auto; -webkit-overflow-scrolling: touch; }
  body.cmd-detail-open #detail .card { margin: 0; position: relative; padding-top: 36px; }
  .detail-close { display: block; position: absolute; top: 8px; right: 8px; width: 44px; height: 44px; border: 0; border-radius: 8px; background: var(--surface); color: var(--text); font-size: 24px; line-height: 1; cursor: pointer; }
  .consent-banner { left: 0; right: 0; max-width: none; margin: 0; padding: 14px 14px max(14px, env(safe-area-inset-bottom)); border-radius: var(--radius) var(--radius) 0 0; max-height: 70vh; overflow: auto; }
  .consent-actions { flex-direction: column; }
  .consent-actions .btn { width: 100%; }
  #settings-dialog, #consent-dialog, .share-dialog, .export-all-dialog { width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; border-radius: 0; }
  #settings-dialog .modal-body, #consent-dialog .modal-body, .share-form, .export-all-form { max-height: 100vh; overflow: auto; display: flex; flex-direction: column; gap: 12px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  #settings-dialog .modal-actions, #consent-dialog .modal-actions, .share-actions { position: sticky; bottom: 0; background: var(--surface); padding: 10px 0; border-top: 1px solid var(--line); z-index: 2; }
  #pref-app-q { position: sticky; top: 0; z-index: 2; background: var(--surface); }
  #pref-apps.app-picker { max-height: none; flex: 1; min-height: 120px; }
  .app-picker label.chk { min-height: 44px; align-items: center; padding: 6px 4px; }
  .mylist-row { min-height: 44px; }
  .item { min-height: 44px; padding: 10px; }
}

@media (pointer: coarse) {
  .btn, .modes button, .chip, .item, select, input[type=search], input[type=checkbox], .mylist-row, .app-picker label.chk, .consent-actions .btn { min-height: 44px; }
  .btn.sm { min-height: 44px; padding: 8px 12px; }
}

@media (max-width: 900px) and (pointer: coarse) {
  .stage-toolbar .btn { min-width: 44px; }
}
