:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #181b20;
  --panel-2: #20242b;
  --panel-3: #292e37;
  --line: #343a45;
  --text: #f0f2f5;
  --muted: #9aa4b2;
  --accent: #7fd7ff;
  --accent-strong: #39bdf8;
  --danger: #ff7a90;
  --shadow: 0 12px 40px rgba(0, 0, 0, .35);
  --radius: 12px;
  --topbar-h: 58px;
  --statusbar-h: 28px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overscroll-behavior: none; }
body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Noto Sans JP", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}
button, input, select { font: inherit; }
button { color: inherit; }

.app-shell { height: 100dvh; display: grid; grid-template-rows: var(--topbar-h) minmax(0, 1fr); }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 14px 0 16px; border-bottom: 1px solid var(--line); background: rgba(24,27,32,.96);
  backdrop-filter: blur(14px); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand > div { min-width: 0; }
.brand-mark { width: 28px; aspect-ratio: 1; border-radius: 8px; background:
  linear-gradient(90deg, transparent 33%, rgba(0,0,0,.3) 33% 66%, transparent 66%),
  linear-gradient(transparent 33%, rgba(0,0,0,.3) 33% 66%, transparent 66%), var(--accent-strong); }
.brand strong { display: block; font-size: 14px; letter-spacing: .04em; }
.brand span { display: block; font-size: 10px; color: var(--muted); }
.brand .official-link { display: block; margin-top: 1px; max-width: clamp(128px, 28vw, 260px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); opacity: .58; font-size: 9px; line-height: 1.15; text-decoration: none; }
.brand .official-link:hover { opacity: .92; text-decoration: underline; }
.top-actions { display: flex; align-items: center; gap: 6px; }

.button, .icon-button, .tool-button, .text-button {
  border: 0; cursor: pointer; transition: background .14s ease, color .14s ease, border-color .14s ease, transform .08s ease;
}
.button:active, .icon-button:active, .tool-button:active { transform: translateY(1px); }
.button { min-height: 36px; padding: 0 13px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel-2); }
.button:hover { background: var(--panel-3); }
.button.primary { background: var(--accent-strong); color: #04141c; border-color: transparent; font-weight: 700; }
.button.primary:hover { filter: brightness(1.08); }
.button.ghost { background: transparent; }
.button.small { min-height: 31px; padding: 0 10px; font-size: 12px; }
.button:disabled, .tool-button:disabled { opacity: .35; cursor: default; transform: none; }
.icon-button { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); }
.icon-button:hover { background: var(--panel-3); }
.text-button { padding: 3px 5px; background: none; color: var(--muted); font-size: 11px; }
.text-button:hover { color: var(--text); }

.workspace-layout { min-height: 0; display: grid; grid-template-columns: 74px minmax(0, 1fr) 314px; gap: 8px; padding: 8px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.toolbar { padding: 8px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.tool-button { min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border-radius: 9px; background: transparent; border: 1px solid transparent; color: var(--muted); }
.tool-button:hover { background: var(--panel-2); color: var(--text); }
.tool-button.is-active { background: rgba(57,189,248,.16); color: var(--accent); border-color: rgba(127,215,255,.35); }
.tool-icon { font-size: 19px; line-height: 1; font-weight: 700; }
.tool-label { font-size: 10px; }
.toolbar-separator { height: 1px; background: var(--line); margin: 3px 2px; }

.canvas-column { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0,1fr); gap: 8px; }
.canvas-toolbar { min-height: 48px; display: flex; align-items: center; gap: 14px; padding: 6px 10px; overflow-x: auto; white-space: nowrap; }
.control-group { display: flex; align-items: center; gap: 5px; }
.zoom-field { height: 34px; min-width: 92px; display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.zoom-field input { width: 64px; border: 0; outline: 0; text-align: right; color: var(--text); background: transparent; }
.zoom-field span { color: var(--muted); margin-left: 2px; }
.toggle-control, .select-control { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.toggle-control input { accent-color: var(--accent-strong); }
select, input[type="text"], input[type="number"] { color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; outline: none; }
select:focus, input:focus { border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(57,189,248,.12); }
select { min-height: 34px; padding: 0 30px 0 9px; }

.canvas-stage {
  min-height: 0; position: relative; overflow: hidden; border-radius: var(--radius); border: 1px solid var(--line);
  background-color: #111419;
  background-image:
    linear-gradient(45deg, #171b21 25%, transparent 25%),
    linear-gradient(-45deg, #171b21 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #171b21 75%),
    linear-gradient(-45deg, transparent 75%, #171b21 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#editorCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; image-rendering: pixelated; touch-action: none; }
.canvas-hud { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 7px; pointer-events: none; }
.canvas-hud span { padding: 5px 8px; border-radius: 7px; background: rgba(10,12,15,.78); color: #d7dee8; border: 1px solid rgba(255,255,255,.08); font: 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; backdrop-filter: blur(8px); }
.gesture-hint { position: absolute; top: 9px; left: 50%; transform: translateX(-50%); padding: 5px 9px; background: rgba(10,12,15,.72); border: 1px solid rgba(255,255,255,.08); border-radius: 7px; color: var(--muted); font-size: 10px; pointer-events: none; opacity: 0; transition: opacity .2s ease; }
.canvas-stage:hover .gesture-hint { opacity: 1; }

.inspector { min-height: 0; overflow-y: auto; padding: 5px 0; }
.mobile-inspector-tabs { display: none; }
.inspector-section { padding: 12px 13px; border-bottom: 1px solid var(--line); }
.inspector-section:last-child { border-bottom: 0; }
.section-heading { min-height: 25px; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.section-heading h2 { margin: 0; font-size: 12px; color: #dbe1e8; letter-spacing: .03em; }
.full-width { width: 100%; }
.hint { margin: 7px 0 0; color: var(--muted); font-size: 10px; line-height: 1.55; }
.index-badge { padding: 3px 6px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); font: 10px ui-monospace, monospace; }
.current-color-row { display: grid; grid-template-columns: 44px minmax(0,1fr) 37px; gap: 8px; align-items: end; }
.current-color { height: 42px; border-radius: 9px; border: 1px solid rgba(255,255,255,.14); background: #1d2b53; box-shadow: inset 0 0 0 1px rgba(0,0,0,.28); }
.color-editor { display: grid; gap: 4px; }
.color-editor span, .form-grid label > span, dialog label > span { color: var(--muted); font-size: 10px; }
.color-editor input { height: 38px; padding: 0 9px; font-family: ui-monospace, monospace; text-transform: uppercase; }
#nativeColorInput { width: 37px; height: 38px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); padding: 3px; }
.transparency-row { margin-top: 9px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.palette-actions { display: flex; align-items: center; }
.palette-grid { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
.palette-swatch { aspect-ratio: 1; min-width: 0; position: relative; border-radius: 5px; border: 1px solid rgba(255,255,255,.12); cursor: pointer; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); background-size: 10px 10px; background-position: 0 0, 0 5px, 5px -5px, -5px 0; }
.palette-swatch:hover { z-index: 2; transform: scale(1.12); }
.palette-swatch.is-selected { outline: 2px solid var(--accent); outline-offset: 1px; z-index: 3; }
.palette-swatch.is-secondary::before { content: "2"; position: absolute; left: 1px; top: 1px; min-width: 12px; height: 12px; display: grid; place-items: center; border-radius: 4px; background: rgba(0,0,0,.76); color: #fff; font: 8px/1 ui-monospace, monospace; z-index: 2; }
.palette-swatch.is-transparent::after { content: "T"; position: absolute; right: 1px; bottom: 0; padding: 1px 2px; border-radius: 3px; background: rgba(0,0,0,.72); color: #fff; font: 8px/1 ui-monospace, monospace; }
.palette-swatch.is-unused { opacity: .45; }
.nes-master-wrap { margin-top: 13px; padding-top: 11px; border-top: 1px solid var(--line); }
.nes-master-wrap h3 { margin: 0; font-size: 11px; }
.nes-master-grid { grid-template-columns: repeat(8, minmax(0,1fr)); margin-top: 8px; }
.form-grid { display: grid; gap: 9px; }
.form-grid.two-columns { grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-grid label, dialog label { display: grid; gap: 4px; }
.form-grid select, dialog input, dialog select { width: 100%; }
.output-check { margin-top: 10px; }

/* The status text is temporarily hidden, and its former height is reassigned to
   the mobile inspector row rather than to the canvas. */
.statusbar { display: none; }

.dialog-card { width: min(92vw, 420px); padding: 0; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 24px 80px rgba(0,0,0,.65); }
.dialog-card::backdrop { background: rgba(0,0,0,.62); backdrop-filter: blur(4px); }
.dialog-card form { margin: 0; }
.dialog-header, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; }
.dialog-header { border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: 14px; }
.dialog-body { display: grid; gap: 13px; padding: 14px; }
.dialog-actions { justify-content: flex-end; border-top: 1px solid var(--line); }
.anchor-fieldset { border: 1px solid var(--line); border-radius: 10px; }
.anchor-fieldset legend { padding: 0 6px; color: var(--muted); font-size: 10px; }
.anchor-grid { width: 112px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin: 8px auto; }
.anchor-grid button { aspect-ratio: 1; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); }
.anchor-grid button::after { content: ""; display: block; width: 7px; height: 7px; margin: auto; border-radius: 50%; background: var(--muted); }
.anchor-grid button.is-active { border-color: var(--accent); background: rgba(57,189,248,.13); }
.anchor-grid button.is-active::after { background: var(--accent); }
.export-summary { padding: 10px; border-radius: 9px; background: var(--panel-2); color: var(--muted); font-size: 11px; line-height: 1.6; }
.toast-region { position: fixed; right: 14px; bottom: 42px; z-index: 100; display: grid; gap: 8px; pointer-events: none; }
.toast { min-width: 220px; max-width: 340px; padding: 10px 12px; border-radius: 9px; background: #242a32; border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--text); font-size: 12px; animation: toast-in .18s ease-out; }
.toast.is-error { border-color: rgba(255,122,144,.55); }
@keyframes toast-in { from { opacity: 0; transform: translateY(7px); } }

@media (max-width: 980px) {
  :root { --topbar-h: 54px; }
  .workspace-layout { grid-template-columns: 64px minmax(0, 1fr); grid-template-rows: minmax(0,1fr) minmax(234px, calc(38vh + var(--statusbar-h))); }
  .inspector { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr; grid-template-rows: 38px minmax(0,1fr); overflow: hidden; padding: 0; }
  .mobile-inspector-tabs { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); border-bottom: 1px solid var(--line); }
  .mobile-inspector-tabs button { border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 11px; }
  .mobile-inspector-tabs button:last-child { border-right: 0; }
  .mobile-inspector-tabs button.is-active { color: var(--accent); background: rgba(57,189,248,.12); }
  .inspector-section { display: none; border: 0; overflow-y: auto; }
  .inspector-section.is-mobile-active { display: block; }
  .top-actions .button:nth-child(-n+3) { padding: 0 9px; }
}

@media (max-width: 520px) {
  .brand .official-link { display: none; }
}

@media (max-width: 640px) {
  :root { --statusbar-h: 24px; }
  .brand span { display: none; }
  .brand .official-link { font-size: 8px; max-width: min(42vw, 180px); }
  .brand strong { font-size: 13px; }
  .brand-mark { width: 24px; }
  .topbar { padding-left: 10px; }
  .top-actions { gap: 3px; }
  .top-actions .button { min-height: 34px; padding: 0 8px; font-size: 11px; }
  .workspace-layout { padding: 5px; gap: 5px; grid-template-columns: 52px minmax(0,1fr); grid-template-rows: minmax(0,1fr) calc(238px + var(--statusbar-h)); }
  .toolbar { padding: 5px; gap: 3px; }
  .tool-button { min-height: 47px; }
  .tool-label { font-size: 9px; }
  .canvas-toolbar { gap: 8px; padding: 5px 7px; }
  .canvas-toolbar .select-control { display: none; }
  .canvas-hud span:nth-child(2), .canvas-hud span:nth-child(3) { display: none; }
  .gesture-hint { display: none; }
  .statusbar #autosaveMessage { display: none; }
}

/* Layers */
.layer-section { min-height: 210px; }
.layer-count { color: var(--muted); font: 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.layer-actions { display: flex; align-items: center; gap: 5px; }
.primary-layer-actions { margin-bottom: 8px; }
.primary-layer-actions .button { flex: 1; }
.small-icon { width: 31px; height: 31px; min-width: 31px; }
.danger-button:hover { color: var(--danger); border-color: rgba(255,122,144,.45); background: rgba(255,122,144,.08); }
.layer-list { display: grid; gap: 5px; max-height: 278px; overflow-y: auto; padding: 2px; border-radius: 9px; }
.layer-row {
  min-width: 0; display: grid; grid-template-columns: 29px 36px minmax(0,1fr) 29px; gap: 6px; align-items: center;
  padding: 5px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); cursor: pointer;
}
.layer-row:hover { border-color: #4a5361; background: var(--panel-3); }
.layer-row.is-active { border-color: rgba(127,215,255,.66); box-shadow: 0 0 0 2px rgba(57,189,248,.11); }
.layer-row.is-hidden { opacity: .6; }
.layer-row.is-locked .layer-name { color: #aeb6c2; }
.layer-toggle { width: 29px; height: 29px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; }
.layer-toggle:hover { color: var(--text); background: rgba(255,255,255,.06); }
.layer-thumbnail { width: 36px; height: 36px; border: 1px solid rgba(255,255,255,.12); border-radius: 5px; image-rendering: pixelated; background-color: #111419; background-image: linear-gradient(45deg,#252a31 25%,transparent 25%),linear-gradient(-45deg,#252a31 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#252a31 75%),linear-gradient(-45deg,transparent 75%,#252a31 75%); background-size: 8px 8px; background-position: 0 0,0 4px,4px -4px,-4px 0; }
.layer-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-size: 11px; }
.layer-empty-note { padding: 14px 8px; color: var(--muted); text-align: center; font-size: 11px; }
.secondary-layer-actions { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); margin-top: 8px; }
.secondary-layer-actions .button { min-width: 0; padding: 0 5px; font-size: 10px; }
/* Help */
.help-button { flex: 0 0 auto; font-weight: 800; font-size: 15px; }
.help-dialog { width: min(94vw, 760px); max-width: 760px; max-height: min(90dvh, 820px); }
.help-dialog form { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; max-height: min(90dvh, 820px); }
.dialog-subtitle { margin: 3px 0 0; color: var(--muted); font-size: 10px; }
.help-body { min-height: 0; overflow-y: auto; padding: 16px; display: grid; gap: 14px; overscroll-behavior: contain; }
.help-section { padding: 14px; border: 1px solid var(--line); border-radius: 11px; background: rgba(255,255,255,.018); }
.help-section h3 { margin: 0 0 10px; color: #e7ebf0; font-size: 13px; }
.help-step-grid { list-style: none; counter-reset: help-step; display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 8px; margin: 0; padding: 0; }
.help-step-grid li { counter-increment: help-step; min-width: 0; display: grid; gap: 6px; padding: 11px; border-radius: 9px; background: var(--panel-2); color: var(--muted); font-size: 10px; line-height: 1.55; }
.help-step-grid li::before { content: counter(help-step); width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; background: rgba(57,189,248,.16); color: var(--accent); font: 700 11px/1 ui-monospace, monospace; }
.help-step-grid b { color: var(--text); font-size: 11px; }
.help-card-grid, .help-save-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.help-card { min-width: 0; padding: 11px; border-radius: 9px; background: var(--panel-2); }
.help-card strong { color: var(--text); font-size: 11px; }
.help-card p { margin: 6px 0 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.help-device-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.help-device { padding: 11px; border-radius: 9px; background: var(--panel-2); }
.help-device h4 { margin: 0 0 8px; color: var(--text); font-size: 11px; }
.help-device dl { margin: 0; display: grid; gap: 5px; }
.help-device dl div { display: grid; grid-template-columns: minmax(96px, .75fr) 1fr; gap: 8px; align-items: baseline; }
.help-device dt { color: #dce3eb; font-size: 10px; }
.help-device dd { margin: 0; color: var(--muted); font-size: 10px; }
.help-note { margin: 9px 0 0; padding: 9px 10px; border-left: 3px solid var(--accent-strong); border-radius: 0 7px 7px 0; background: rgba(57,189,248,.07); color: var(--muted); font-size: 10px; line-height: 1.6; }
.help-list { margin: 0; padding-left: 18px; color: var(--muted); font-size: 10px; line-height: 1.65; }
.help-list li + li { margin-top: 4px; }
.help-list b { color: #dce3eb; }
.shortcut-grid { display: grid; grid-template-columns: minmax(210px, .85fr) 1fr; gap: 6px 12px; align-items: center; color: var(--muted); font-size: 10px; }
kbd { display: inline-block; min-width: 20px; padding: 3px 5px; border: 1px solid #4a5361; border-bottom-width: 2px; border-radius: 5px; background: var(--panel-2); color: #e8edf3; font: 9px/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; text-align: center; box-shadow: 0 1px 0 rgba(0,0,0,.35); }

@media (max-width: 520px) {
  .brand .official-link { display: none; }
}

@media (max-width: 640px) {
  .help-dialog { width: calc(100vw - 12px); max-height: calc(100dvh - 12px); }
  .help-dialog form { max-height: calc(100dvh - 12px); }
  .help-body { padding: 10px; gap: 9px; }
  .help-section { padding: 11px; }
  .help-step-grid, .help-card-grid, .help-save-grid, .help-device-grid { grid-template-columns: 1fr; }
  .help-step-grid li { grid-template-columns: 24px 82px minmax(0,1fr); align-items: center; gap: 7px; }
  .help-step-grid li::before { grid-row: 1; }
  .help-step-grid b { grid-column: 2; }
  .help-step-grid span { grid-column: 3; }
  .shortcut-grid { grid-template-columns: minmax(160px, .9fr) 1fr; gap: 7px 9px; }
}



/* Advanced drawing, selection and two-color tools */
.tool-button.has-subtools { position: relative; }
.subtool-mark { position: absolute; right: 4px; bottom: 3px; color: var(--muted); font-size: 8px; }
.tool-flyout {
  position: fixed; z-index: 90; min-width: 144px; padding: 5px; display: grid; gap: 3px;
  border: 1px solid var(--line); border-radius: 10px; background: #20242b; box-shadow: 0 16px 48px rgba(0,0,0,.55);
}
.tool-flyout[hidden] { display: none; }
.tool-flyout button { min-height: 38px; display: grid; grid-template-columns: 26px 1fr; align-items: center; gap: 7px; padding: 0 10px; border: 0; border-radius: 7px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.tool-flyout button:hover, .tool-flyout button:focus-visible { background: rgba(57,189,248,.13); outline: none; }
.tool-flyout button span { color: var(--accent); text-align: center; font-size: 17px; }
.button.tiny { min-height: 27px; padding: 0 8px; border-radius: 7px; font-size: 10px; }
.selection-actions {
  flex: 0 0 auto; max-width: min(100%, 430px); display: flex; align-items: center; gap: 4px;
  padding: 3px 5px; border: 1px solid rgba(255,255,255,.1); border-radius: 9px; background: rgba(10,12,15,.5);
  overflow-x: auto; overscroll-behavior: contain; scrollbar-width: thin;
}
.selection-actions > span { flex: 0 0 auto; padding: 0 5px; color: var(--muted); font: 10px/1 ui-monospace, monospace; }
.selection-actions button { flex: 0 0 auto; }
.selection-actions button:disabled { opacity: .35; }
.secondary-color-row { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line); }
.mini-label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; }
.secondary-color-control { display: flex; align-items: center; gap: 8px; }
.secondary-color { width: 42px; height: 32px; border: 1px solid rgba(255,255,255,.14); border-radius: 8px; cursor: pointer; background-size: 10px 10px; }
.selection-actions.is-empty #copySelectionButton,
.selection-actions.is-empty #cutSelectionButton,
.selection-actions.is-empty #clearSelectionButton,
.selection-actions.is-empty #deselectButton { opacity: .35; pointer-events: none; }
@media (max-width: 520px) {
  .brand .official-link { display: none; }
}

@media (max-width: 640px) {
  .canvas-toolbar { flex-wrap: wrap; }
  .selection-actions { order: 20; width: 100%; max-width: none; }
  .selection-actions > span { display: none; }
  .selection-actions .button.tiny { min-height: 25px; padding: 0 7px; font-size: 9px; }
}


/* Animation */
.animation-section { min-height: 290px; }
.animation-playback { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.animation-play-button { min-width: 72px; }
.animation-loop { margin-left: auto; }
.animation-playback .toggle-control { white-space: nowrap; }
.animation-frame-actions { display: flex; align-items: center; gap: 5px; margin-top: 8px; }
.animation-frame-actions .button { flex: 1 1 auto; min-width: 0; }
.animation-frame-settings {
  display: grid; grid-template-columns: minmax(0,.7fr) minmax(0,1.15fr) auto; gap: 7px; align-items: end;
  margin-top: 9px; padding: 8px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2);
}
.animation-frame-settings > label { min-width: 0; display: grid; gap: 4px; }
.animation-frame-settings > label > span:first-child { color: var(--muted); font-size: 9px; }
.animation-frame-settings strong { min-height: 31px; display: flex; align-items: center; padding: 0 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); font: 11px/1 ui-monospace, monospace; }
.duration-field { min-width: 0; height: 31px; display: flex; align-items: center; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); }
.duration-field input { min-width: 0; width: 100%; height: 29px; padding: 0 5px 0 8px; border: 0; background: transparent; text-align: right; box-shadow: none; }
.duration-field b { padding-right: 7px; color: var(--muted); font-size: 9px; font-weight: 500; }
.animation-visibility-actions { display: flex; gap: 4px; }

.animation-bone-tools { margin: 8px 0 10px; padding: 9px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.animation-bone-tools-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.animation-bone-tools-heading strong { font-size: 12px; color: var(--text); }
.animation-bone-tools-heading span { font-size: 10px; color: var(--muted); }
.animation-bone-tools-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 6px; }
.compact-hint { margin-top: 7px; }


.animation-pose-key-toolbar {
  display: grid;
  grid-template-columns: auto auto minmax(0,1fr);
  gap: 6px;
  align-items: end;
  margin-top: 8px;
  padding: 8px;
  border: 1px solid rgba(255,207,90,.18);
  border-radius: 9px;
  background: rgba(255,207,90,.04);
}
.animation-pose-key-toolbar label { min-width: 0; display: grid; gap: 4px; }
.animation-pose-key-toolbar label > span { color: var(--muted); font-size: 9px; }
.animation-frame-select.has-visible-pose-key { color: #ffcf5a; font-weight: 800; }
.animation-frame-select.has-visible-pose-key:not(.is-active) { background: rgba(255,207,90,.08); }
.animation-frame-select.has-visible-pose-key.is-active { color: #1b1400; background: #ffcf5a; }

.animation-onion-controls {
  display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 7px; align-items: end;
  margin-top: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2);
}
.animation-onion-controls > label { min-width: 0; display: grid; gap: 4px; }
.animation-onion-controls > label > span { color: var(--muted); font-size: 9px; }
.animation-matrix-wrap {
  max-width: 100%; max-height: 330px; margin-top: 9px; overflow: auto; border: 1px solid var(--line); border-radius: 9px;
  background: #13161b; overscroll-behavior: contain;
}
.animation-matrix { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.animation-matrix th, .animation-matrix td { height: 34px; min-width: 34px; padding: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: center; background: var(--panel-2); }
.animation-matrix tr:last-child td, .animation-matrix tr:last-child th { border-bottom: 0; }
.animation-matrix th:last-child, .animation-matrix td:last-child { border-right: 0; }
.animation-matrix thead th { position: sticky; top: 0; z-index: 4; background: #252a32; }
.animation-matrix .animation-layer-head,
.animation-matrix .animation-layer-name { position: sticky; left: 0; z-index: 3; width: 116px; min-width: 116px; max-width: 116px; padding: 0 8px; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: #20242b; color: #dce3eb; font-size: 10px; }
.animation-matrix .animation-layer-head { z-index: 6; background: #292e37; color: var(--muted); }
.animation-frame-head { width: 34px; min-width: 34px; }
.animation-frame-select { width: 100%; height: 100%; padding: 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; font: 10px/1 ui-monospace, monospace; }
.animation-frame-select:hover { color: var(--text); background: rgba(255,255,255,.05); }
.animation-frame-select.is-active { color: #04141c; background: var(--accent); font-weight: 800; }
.animation-cell { width: 100%; height: 100%; display: grid; place-items: center; padding: 0; border: 0; background: transparent; color: #59626f; cursor: pointer; font-size: 16px; line-height: 1; }
.animation-cell:hover { background: rgba(255,255,255,.05); color: #8d98a7; }
.animation-cell.is-on { color: var(--accent); }
.animation-cell.is-active-frame { background: rgba(57,189,248,.06); }
.animation-layer-name.is-global-hidden { color: #717b88; text-decoration: line-through; }
.layer-row.is-frame-hidden .layer-name { color: #7e8895; }
.layer-row.is-frame-hidden::after { content: "F OFF"; position: absolute; right: 38px; bottom: 3px; color: #7e8895; font: 7px/1 ui-monospace, monospace; }
.layer-row { position: relative; }
body.is-animation-playing #editorCanvas { cursor: default; }
.animation-cell.has-bone-pose { position: relative; border-color: rgba(255,207,90,.65); color: #ffcf5a; font-weight: 800; }
.animation-cell.has-bone-pose::after { content: ''; position: absolute; right: 3px; top: 3px; width: 4px; height: 4px; border-radius: 50%; background: #ffcf5a; box-shadow: 0 0 6px rgba(255,207,90,.8); }


@media (max-width: 520px) {
  .brand .official-link { display: none; }
}

@media (max-width: 640px) {
  .animation-playback { gap: 4px; }
  .animation-loop { margin-left: 3px; }
  .animation-frame-settings { grid-template-columns: .65fr 1fr; }
  .animation-pose-key-toolbar { grid-template-columns: 1fr 1fr; }
  .animation-pose-key-toolbar label { grid-column: 1 / -1; }
  .animation-onion-controls { grid-template-columns: 1fr; }
  .animation-visibility-actions { grid-column: 1 / -1; }
  .animation-visibility-actions .button { flex: 1; }
  .animation-matrix-wrap { max-height: 315px; }
  .animation-matrix .animation-layer-head,
  .animation-matrix .animation-layer-name { width: 102px; min-width: 102px; max-width: 102px; }
}

/* Mobile animation table: keep one vertical scroller.
   The inspector panel handles vertical scrolling; the matrix only handles horizontal overflow.
   This prevents the bottom-most layer row from becoming trapped below a nested scroll area. */
@media (max-width: 980px) {
  .animation-matrix-wrap {
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
  }
}

/* Mobile animation matrix final fix: the matrix itself owns both-axis scrolling.
   Vertical gestures on the table no longer get swallowed by a horizontal-only scroller,
   so every layer row, including the bottom-most one, remains reachable. */
@media (max-width: 980px) {
  .animation-matrix-wrap {
    max-height: 315px;
    overflow-x: auto;
    overflow-y: auto;
    overscroll-behavior: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    scrollbar-gutter: stable;
  }
}

@media (max-width: 520px) {
  .brand .official-link { display: none; }
}

@media (max-width: 640px) {
  .animation-matrix-wrap {
    max-height: 220px;
  }
}

/* Mobile inspector height fix.
   The animation section previously kept a 290px minimum height inside a shorter
   grid row. Because the inspector clips overflow, the last layer row was cut off.
   Let the active tab shrink to the assigned row and use it as the sole vertical
   scroller; the matrix wrapper remains horizontal-only and grows to full table height. */
@media (max-width: 980px) {
  .inspector-section,
  .inspector-section.is-mobile-active,
  .animation-section {
    min-height: 0;
  }

  .inspector-section.is-mobile-active {
    height: 100%;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }

  .animation-matrix-wrap {
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    overscroll-behavior-y: auto;
    touch-action: pan-x pan-y;
    scrollbar-gutter: auto;
  }
}

/* Brush size */
.control-caption { color: var(--muted); font-size: 11px; }
.brush-size-control { flex: 0 0 auto; }
.brush-size-control .icon-button { width: 30px; height: 34px; }
.brush-size-field {
  height: 34px; min-width: 66px; display: flex; align-items: center;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2);
}
.brush-size-field input {
  width: 42px; min-width: 0; border: 0; outline: 0; text-align: right;
  color: var(--text); background: transparent; box-shadow: none; appearance: textfield;
}
.brush-size-field input::-webkit-inner-spin-button,
.brush-size-field input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.brush-size-field span { margin-left: 2px; padding-right: 6px; color: var(--muted); font-size: 10px; }

/* Animation export options */
.sprite-sheet-layout { margin-top: 10px; display: grid; grid-template-columns: 96px minmax(0,1fr); align-items: center; gap: 8px; }
.sprite-sheet-layout[hidden] { display: none; }
.sprite-sheet-layout > span { color: var(--muted); font-size: 10px; }
.sprite-sheet-layout select { width: 100%; }

@media (max-width: 520px) {
  .brand .official-link { display: none; }
}

@media (max-width: 640px) {
  .control-caption { display: none; }
  .brush-size-control { gap: 3px; }
  .brush-size-control .icon-button { width: 28px; }
  .brush-size-field { min-width: 58px; }
  .brush-size-field input { width: 35px; }
}

/* Bone rig */
.bone-section { min-height: 330px; }
.bone-mode-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.bone-mode-grid .is-active { border-color: var(--accent); color: var(--accent); background: rgba(57,189,248,.12); }
.bone-create-actions, .bone-danger-actions { display: flex; gap: 6px; margin-top: 8px; }
.bone-create-actions .button, .bone-danger-actions .button { flex: 1; }
.bone-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 8px; }
.bone-controls .button:first-child { grid-column: span 1; }
.bone-controls .toggle-control { min-height: 32px; padding: 0 7px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); }
.bone-pose-controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); }
.bone-pose-controls > label:not(.toggle-control) { display: grid; gap: 4px; }
.bone-pose-controls > label:not(.toggle-control) > span { color: var(--muted); font-size: 9px; }
.bone-pose-controls .toggle-control { min-height: 32px; padding: 0 7px; border: 1px solid var(--line); border-radius: 7px; background: rgba(255,255,255,.03); }
.bone-quality-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; align-items: end; margin-top: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); }
.bone-quality-controls > label:not(.toggle-control) { display: grid; gap: 4px; }
.bone-quality-controls > label:not(.toggle-control) > span { color: var(--muted); font-size: 9px; }
.bone-quality-controls .toggle-control { min-height: 32px; padding: 0 7px; border: 1px solid var(--line); border-radius: 7px; background: rgba(255,255,255,.03); }
.bone-link-count { align-self: center; color: var(--muted); font-size: 10px; text-align: right; }
.bone-link-count b { color: var(--text); font-weight: 700; }
.bone-bind-auto-controls { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; align-items: end; margin-top: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); }
.bone-bind-auto-controls > label, .bone-bind-controls > label { display: grid; gap: 4px; }
.bone-bind-auto-controls > label > span, .bone-bind-controls > label > span { color: var(--muted); font-size: 9px; }
.bone-bind-controls { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; align-items: end; margin-top: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); }
.bone-bind-mode { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 6px; margin: 0; padding: 7px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.03); }
.bone-bind-mode legend { padding: 0 4px; color: var(--muted); font-size: 9px; }
.bone-bind-mode label { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; color: var(--text); font-size: 11px; }
.bone-bind-mode input { accent-color: var(--accent-strong); }
.bone-warning { color: #ffbd69; }
.layer-row.has-rig .layer-name::after { content: " ⌁"; color: var(--accent); }
#editorCanvas.is-bone-tool { cursor: crosshair; }
@media (max-width: 520px) {
  .brand .official-link { display: none; }
}

@media (max-width: 640px) {
  .bone-section { min-height: 0; }
  .bone-mode-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bone-mode-grid .button { padding-inline: 5px; font-size: 9px; }
  .bone-pose-controls, .bone-quality-controls, .bone-bind-auto-controls, .bone-bind-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .bone-bind-mode { grid-template-columns: 1fr; }
  .bone-link-count { font-size: 9px; }
}

/* v11.2: make layer rig vs frame pose-key visible */
.bone-context-panel {
  margin: 8px 0 9px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  border: 1px solid rgba(255,207,90,.22);
  border-radius: 10px;
  background: rgba(255,207,90,.055);
}
.bone-context-panel > div {
  min-width: 0;
  display: grid;
  gap: 3px;
  padding: 6px 7px;
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 7px;
  background: rgba(0,0,0,.12);
}
.bone-context-panel span { color: var(--muted); font-size: 9px; }
.bone-context-panel b { color: var(--text); font-size: 11px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bone-context-panel b.has-current-pose-key { color: #ffcf5a; }
.bone-context-panel b.is-rest-pose-key { color: #9ee6ff; }

.bone-context-panel p { grid-column: 1 / -1; margin: 1px 0 0; color: #ffd876; font-size: 10px; line-height: 1.45; }
.bone-scope-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 7px;
  padding: 7px;
  border: 1px solid rgba(57,189,248,.20);
  border-radius: 10px;
  background: rgba(57,189,248,.045);
}
.bone-scope-strip span {
  min-width: 0;
  display: grid;
  gap: 2px;
  padding: 6px;
  border-radius: 7px;
  background: rgba(0,0,0,.14);
}
.bone-scope-strip b { color: var(--muted); font-size: 9px; font-weight: 600; }
.bone-scope-strip strong { color: var(--text); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bone-scope-strip span.is-active { outline: 1px solid rgba(255,207,90,.45); background: rgba(255,207,90,.09); }
.bone-scope-strip span.is-active strong { color: #ffcf5a; }
.animation-cell-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  padding: 7px 8px;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 8px;
  background: rgba(0,0,0,.12);
  color: var(--muted);
  font-size: 10px;
}
.animation-cell-legend span { display: inline-flex; align-items: center; gap: 4px; }
.animation-cell-legend b { color: #ffcf5a; font-size: 12px; }
.animation-bone-state { color: #ffd876; }
.animation-cell { font-size: 12px; letter-spacing: -1px; }
.animation-cell.has-bone-rig:not(.has-pose-key) { color: #9aa5b2; font-weight: 700; }
.animation-cell.has-pose-key { color: #ffcf5a; font-weight: 800; }
.animation-cell.has-pose-key::after { content: ''; position: absolute; right: 3px; top: 3px; width: 4px; height: 4px; border-radius: 50%; background: #ffcf5a; box-shadow: 0 0 6px rgba(255,207,90,.8); }
.animation-bone-tools { border-color: rgba(255,207,90,.22); background: rgba(255,207,90,.045); }

@media (max-width: 520px) {
  .brand .official-link { display: none; }
}

@media (max-width: 640px) {
  .bone-context-panel { grid-template-columns: 1fr; }
  .bone-context-panel p { grid-column: 1; }
  .bone-scope-strip { grid-template-columns: 1fr; }
  .animation-cell-legend { font-size: 9px; }
}

/* v12.3: inspector accordion compaction */
.inspector-accordion {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.025);
  overflow: clip;
}
.inspector-accordion > summary {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  user-select: none;
  background: rgba(255,255,255,.035);
}
.inspector-accordion > summary::-webkit-details-marker { display: none; }
.inspector-accordion > summary::before {
  content: '▸';
  width: 13px;
  color: var(--muted);
  font-size: 10px;
  transition: transform .12s ease;
}
.inspector-accordion[open] > summary::before { transform: rotate(90deg); }
.inspector-accordion[open] { padding-bottom: 8px; }
.inspector-accordion > :not(summary) { margin-left: 8px; margin-right: 8px; }
.inspector-accordion .hint:last-child { margin-bottom: 0; }
.inspector-accordion.compact-help[open] { padding-bottom: 6px; }
.danger-accordion > summary { color: #ff9d9d; }
.animation-frame-toolbar {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}
.animation-frame-block .animation-frame-actions { margin-top: 0; }
.animation-frame-block .animation-frame-settings { margin-top: 0; }
.animation-frame-block .animation-matrix-wrap { margin-top: 8px; }
.animation-frame-block .animation-cell-legend { margin-top: 7px; }
.inspector-accordion .animation-playback,
.inspector-accordion .bone-mode-grid { margin-top: 8px; }
.inspector-accordion .bone-context-panel,
.inspector-accordion .bone-pose-controls,
.inspector-accordion .bone-quality-controls,
.inspector-accordion .bone-bind-auto-controls,
.inspector-accordion .bone-bind-controls,
.inspector-accordion .animation-bone-tools,
.inspector-accordion .animation-onion-controls { margin-top: 8px; margin-bottom: 0; }
.inspector-accordion .bone-create-actions,
.inspector-accordion .bone-controls,
.inspector-accordion .bone-danger-actions { margin-top: 8px; }
@media (max-width: 520px) {
  .brand .official-link { display: none; }
}

@media (max-width: 640px) {
  .inspector-accordion { margin-top: 6px; }
  .inspector-accordion > summary { min-height: 32px; padding-inline: 8px; font-size: 11px; }
  .inspector-accordion > :not(summary) { margin-left: 6px; margin-right: 6px; }
  .animation-frame-actions { gap: 4px; }
  .animation-frame-actions .button { padding-inline: 6px; font-size: 9px; }
  .animation-frame-actions .icon-button { width: 30px; }
}

.bone-template-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 8px 0 0;
}

.bone-template-grid .button {
  min-height: 32px;
}

/* v14.37 weight paint finishing */
.bone-weight-smooth-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.bone-weight-smooth-actions .button {
  min-width: 5.8em;
}
