:root {
  --bg: #15120f;
  --bg-2: #211c18;
  --panel: #2b241f;
  --panel-2: #352d27;
  --ink: #f5efe7;
  --muted: #c3b4a5;
  --line: #58483f;
  --accent: #dca74a;
  --accent-2: #ffcf75;
  --danger: #f07667;
  --ok: #9bd28f;
  --shadow: rgba(0, 0, 0, 0.35);
  --stage: #0e0d0c;
  --button: #40362f;
  --button-hover: #56483e;
  --focus: #f3bd5b;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); }
body { font-size: 14px; }
button, input, select, textarea { font: inherit; }
button, .file-button {
  border: 1px solid var(--line);
  background: var(--button);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}
button:hover, .file-button:hover { background: var(--button-hover); border-color: var(--accent); }
button:active { transform: translateY(1px); }
button.primary { background: linear-gradient(135deg, #b6762b, #e2aa4f); color: #1e130a; border: 0; font-weight: 700; }
button.active, .tool.active, .tab.active, .bottom-tab.active { background: #76552b; border-color: var(--accent-2); color: white; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #181411;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(243, 189, 91, 0.14); }
input[type="range"] { padding: 0; }
input[type="color"] { height: 38px; padding: 2px; }
textarea { min-height: 90px; resize: vertical; }
label { display: grid; gap: 6px; color: var(--muted); }
.hidden { display: none !important; }

.boot-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(220,167,74,0.12), transparent 30%),
    radial-gradient(circle at 80% 65%, rgba(184,112,58,0.12), transparent 32%),
    linear-gradient(135deg, #16120f, #261e19 60%, #15120f);
}
.boot-card {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 34px;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 28px;
  background: rgba(36, 30, 26, 0.92);
  box-shadow: 0 24px 90px rgba(0,0,0,0.45);
}
.brand-mark, .mini-logo {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 15px;
  background: linear-gradient(135deg, #201713, #dca74a);
  color: #1e130a;
  font-weight: 900;
  letter-spacing: 0.08em;
}
.mini-logo { width: 38px; height: 38px; border-radius: 11px; font-size: 12px; }
.boot-card h1 { margin: 18px 0 6px; font-size: clamp(30px, 5vw, 54px); }
.subtitle { color: var(--muted); margin-bottom: 24px; font-size: 16px; }
.boot-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.boot-language { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--muted); }
.lang-chip { padding: 7px 12px; }
.project-picker { margin-top: 18px; display: grid; gap: 8px; }
.project-picker button { text-align: left; display: flex; justify-content: space-between; gap: 12px; }
.file-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; position: relative; overflow: hidden; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-button.wide { width: 100%; margin-bottom: 10px; }

.project-dialog { border: 1px solid var(--line); border-radius: 22px; background: var(--panel); color: var(--ink); width: min(560px, calc(100vw - 32px)); box-shadow: 0 30px 90px rgba(0,0,0,0.55); }
.project-dialog::backdrop { background: rgba(0,0,0,0.62); }
.project-dialog form { display: grid; gap: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.app { height: 100vh; display: grid; grid-template-rows: 58px 1fr 172px; gap: 8px; padding: 8px; }
.topbar, .bottom-tray, .panel, .canvas-toolbar {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(53,45,39,0.98), rgba(40,34,30,0.98));
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.18);
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 10px; }
.project-title-wrap { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.project-title-wrap small { display: block; color: var(--muted); margin-top: 2px; }
.topbar-controls { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
.topbar-controls select { min-width: 132px; }
.topbar-controls button { white-space: nowrap; }
.workspace { min-height: 0; display: grid; grid-template-columns: 230px minmax(0,1fr) 315px; gap: 8px; }
.panel { padding: 10px; min-height: 0; overflow: auto; }
.panel-title { color: var(--accent-2); font-weight: 800; margin: 4px 0 8px; letter-spacing: 0.03em; text-transform: uppercase; font-size: 12px; }
.tool-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.tool { display: grid; place-items: center; min-height: 42px; font-size: 12px; padding: 7px; }
.brush-card { margin-top: 14px; display: grid; gap: 9px; }
.color-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.checkbox { display: flex; align-items: center; gap: 8px; padding: 4px 0; color: var(--ink); }
.checkbox input { width: auto; }

.stage-wrap { min-width: 0; min-height: 0; display: grid; grid-template-rows: 38px 1fr; gap: 8px; }
.canvas-toolbar { padding: 8px 12px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); }
.stage {
  min-width: 0;
  min-height: 0;
  position: relative;
  border: 1px solid #3c332d;
  border-radius: 18px;
  background:
    linear-gradient(45deg, rgba(255,255,255,0.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,0.035) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.035) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.035) 75%),
    var(--stage);
  background-size: 38px 38px;
  background-position: 0 0, 0 19px, 19px -19px, -19px 0px;
  overflow: hidden;
  box-shadow: inset 0 0 45px rgba(0,0,0,0.35);
  touch-action: none;
}
#viewportCanvas { width: 100%; height: 100%; display: block; cursor: none; }
#brushCursor { position: absolute; width: 12px; height: 12px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.85); box-shadow: 0 0 0 1px rgba(0,0,0,0.8); pointer-events: none; transform: translate(-50%, -50%); display: none; }

.tabs, .bottom-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.tab, .bottom-tab { padding: 7px 5px; font-size: 12px; }
.tab-panel, .bottom-panel { display: none; }
.tab-panel.active, .bottom-panel.active { display: block; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.row-actions.stack { display: grid; }
.layer-list { display: grid; gap: 8px; }
.layer-item {
  display: grid;
  grid-template-columns: 32px 1fr 32px 32px 32px 32px;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.12);
  border-radius: 12px;
  padding: 7px;
}
.layer-item.active { border-color: var(--accent-2); background: rgba(220,167,74,0.12); }
.layer-thumb { width: 30px; height: 30px; border-radius: 8px; background: #f5efe7; border: 1px solid rgba(255,255,255,0.12); object-fit: cover; }
.layer-name { min-width: 0; }
.layer-name input { padding: 5px 6px; font-size: 12px; }
.layer-mini { padding: 5px; font-size: 12px; border-radius: 8px; }
.layer-opacity { grid-column: 2 / 7; }
.layer-opacity input { width: 100%; }
.palette-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(32px, 1fr)); gap: 7px; margin: 10px 0; }
.palette-grid.small { grid-template-columns: repeat(auto-fill, 28px); }
.swatch { height: 32px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.22); cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12); }
.reference-list { display: grid; gap: 8px; margin: 10px 0; }
.reference-item { display: grid; grid-template-columns: 48px 1fr; gap: 8px; align-items: center; border: 1px solid var(--line); background: rgba(0,0,0,0.12); padding: 7px; border-radius: 12px; cursor: pointer; }
.reference-item.active { border-color: var(--accent-2); background: rgba(220,167,74,0.12); }
.reference-item img { width: 48px; height: 42px; object-fit: cover; border-radius: 8px; }
.reference-viewer { min-height: 180px; display: grid; place-items: center; border: 1px dashed var(--line); border-radius: 14px; background: rgba(0,0,0,0.18); overflow: hidden; margin-bottom: 10px; }
.reference-viewer img { max-width: 100%; max-height: 280px; display: none; transform-origin: center; }
.reference-viewer img.has-image { display: block; }

.bottom-tray { min-height: 0; overflow: auto; padding: 8px; }
.bottom-tabs { grid-template-columns: repeat(4, 120px); justify-content: start; }
.frame-strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; }
.frame-card { width: 118px; min-width: 118px; border: 1px solid var(--line); border-radius: 12px; padding: 6px; background: rgba(0,0,0,0.14); cursor: pointer; }
.frame-card.active { border-color: var(--accent-2); background: rgba(220,167,74,0.12); }
.frame-card img { width: 100%; height: 62px; object-fit: contain; background: white; border-radius: 8px; display: block; }
.frame-card span { display: block; color: var(--muted); margin-top: 5px; font-size: 12px; text-align: center; }
.undo-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px; color: var(--muted); }
.undo-item { border: 1px solid var(--line); border-radius: 10px; padding: 7px; background: rgba(0,0,0,0.12); }
.info-line { color: var(--muted); padding: 8px 0; }
#bottomNotes { width: 100%; min-height: 86px; }

@media (max-width: 1080px) {
  .workspace { grid-template-columns: 200px minmax(0,1fr) 260px; }
  .topbar { align-items: stretch; flex-direction: column; height: auto; }
  .app { grid-template-rows: auto 1fr 172px; }
}
@media (max-width: 820px) {
  body { overflow: auto; }
  .app { min-height: 100vh; height: auto; grid-template-rows: auto 70vh auto; }
  .workspace { grid-template-columns: 1fr; }
  .tool-cabinet, .inspector { max-height: 42vh; }
}

/* Phase 2 — comics / manga system */
.phase-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border: 1px solid rgba(246, 193, 97, 0.35);
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  margin-bottom: 0.65rem;
  font-size: 0.78rem;
  color: #f4c46f;
  background: rgba(246, 193, 97, 0.08);
}
.help-note {
  margin-top: 0.75rem;
  padding: 0.65rem;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.09);
  background: rgba(255,255,255,0.045);
  font-size: 0.82rem;
  line-height: 1.4;
  color: rgba(255,255,255,0.75);
}
.template-preview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.template-card {
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 0.6rem;
  background: rgba(255,255,255,0.045);
}
.template-card strong { display: block; margin-bottom: 0.25rem; }
.template-card small { color: rgba(255,255,255,0.62); line-height: 1.35; display: block; }
#tab-comics textarea { min-height: 58px; resize: vertical; }
.tool[data-tool="panel"],
.tool[data-tool="balloon"],
.tool[data-tool="thought"],
.tool[data-tool="caption"],
.tool[data-tool="tone"],
.tool[data-tool="speed"],
.tool[data-tool="focus"] {
  border-color: rgba(246, 193, 97, 0.22);
}

/* Phase 3 — animation timeline / keyframe system */
.tabs { grid-template-columns: repeat(5, 1fr); }
.bottom-tabs { grid-template-columns: repeat(5, 120px); }
.timeline-grid-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0 10px; }
.timeline-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.timeline-ruler { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0; color: var(--muted); font-size: 11px; }
.timeline-tick { min-width: 126px; padding: 2px 6px; border-left: 1px solid var(--line); }
.timeline-track { display: flex; gap: 8px; overflow-x: auto; padding: 3px 0 10px; }
.timeline-cell { min-width: 126px; border: 1px solid var(--line); border-radius: 12px; padding: 7px; background: rgba(0,0,0,0.14); cursor: pointer; display: grid; gap: 5px; }
.timeline-cell.active { border-color: var(--accent-2); background: rgba(220,167,74,0.13); }
.timeline-cell.key { box-shadow: inset 0 0 0 2px rgba(255,207,117,0.16); }
.timeline-cell img { width: 100%; height: 50px; object-fit: contain; background: #fff; border-radius: 8px; }
.timeline-cell .meta { display: flex; justify-content: space-between; gap: 6px; color: var(--muted); font-size: 11px; }
.role-pill { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: rgba(255,207,117,0.14); color: var(--accent-2); border: 1px solid rgba(255,207,117,0.24); font-size: 10px; }
.frame-card.key { box-shadow: inset 0 0 0 2px rgba(255,207,117,0.22); }
.frame-card .frame-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; font-size: 10px; color: var(--muted); }

/* Phase 4 — screenplay, shot list, storyboard, animatic system */
.screenplay-editor { min-height: 190px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.45; }
.scene-card-list { display: grid; gap: 8px; max-height: 220px; overflow: auto; margin-bottom: 10px; }
.scene-card { text-align: left; display: grid; gap: 4px; border: 1px solid var(--line); border-radius: 12px; padding: 9px; background: rgba(255,255,255,0.035); color: var(--text); }
.scene-card.active { border-color: var(--accent-2); background: rgba(220,167,74,0.12); }
.scene-card small, .scene-card em { color: var(--muted); font-style: normal; }
.shot-list { display: grid; gap: 6px; max-height: 240px; overflow: auto; margin-bottom: 10px; }
.shot-row { display: grid; grid-template-columns: 82px minmax(120px,1fr) 78px 62px; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 12px; padding: 6px; background: rgba(0,0,0,0.13); }
.shot-row.active { border-color: var(--accent-2); }
.shot-row input { min-width: 0; }
.shot-select { font-weight: 800; }
.storyboard-panel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; max-height: 170px; overflow: auto; }
.storyboard-tile { display: grid; gap: 4px; text-align: left; border: 1px solid var(--line); border-radius: 12px; padding: 7px; background: rgba(255,255,255,0.035); color: var(--text); }
.storyboard-tile.active { border-color: var(--accent-2); background: rgba(220,167,74,0.12); }
.storyboard-tile img { width: 100%; height: 70px; object-fit: contain; background: #fff; border-radius: 8px; }
.storyboard-tile small { color: var(--muted); }
.animatic-sequencer { display: grid; gap: 6px; max-height: 210px; overflow: auto; }
.animatic-item { display: grid; grid-template-columns: 28px 76px minmax(100px,1fr) 80px 62px; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 12px; padding: 6px; background: rgba(0,0,0,0.13); }
.animatic-item input { min-width: 0; }
.story-bottom-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mirror-note { color: var(--muted); padding: 10px; border: 1px dashed var(--line); border-radius: 12px; }
@media (max-width: 980px) {
  .story-bottom-layout { grid-template-columns: 1fr; }
  .shot-row { grid-template-columns: 1fr; }
  .animatic-item { grid-template-columns: 1fr; }
}

/* Phase 5 — production and resizable workspace */
.app {
  grid-template-rows: 58px 1fr 6px var(--bottom-tray-height, 172px);
}
.workspace {
  grid-template-columns: var(--left-panel-width, 230px) 6px minmax(0, 1fr) 6px var(--right-panel-width, 315px);
}
.resize-handle {
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(0,0,0,0.12));
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03);
}
.resize-handle.vertical { cursor: col-resize; min-height: 0; }
.resize-handle.horizontal { cursor: row-resize; height: 6px; margin: -2px 4px; }
.resize-handle:hover { border-color: var(--accent-2); background: var(--accent); }
.tabs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.bottom-tabs { grid-template-columns: repeat(6, 120px); }
.studio-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.production-dashboard { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 8px 0 12px; }
.production-dashboard.compact { grid-template-columns: repeat(4, minmax(90px, 1fr)); }
.tracker-card { border: 1px solid var(--line); background: rgba(0,0,0,0.14); border-radius: 14px; padding: 9px; }
.tracker-card strong { display: block; color: var(--accent-2); font-size: 18px; }
.tracker-card span { color: var(--muted); font-size: 12px; }
.model-sheet-list, .retake-list, .cut-folder-board { display: grid; gap: 8px; margin: 8px 0 14px; }
.model-card, .retake-card, .cut-card { border: 1px solid var(--line); border-radius: 13px; padding: 8px; background: rgba(0,0,0,0.14); }
.model-card img { width: 100%; max-height: 120px; object-fit: contain; background: #fff; border-radius: 8px; margin-top: 6px; }
.xsheet-table { overflow: auto; border: 1px solid var(--line); border-radius: 13px; margin-bottom: 12px; }
.xsheet-table table { width: 100%; border-collapse: collapse; min-width: 520px; }
.xsheet-table th, .xsheet-table td { border-bottom: 1px solid var(--line); padding: 6px; font-size: 12px; vertical-align: top; }
.xsheet-table input, .xsheet-table select { padding: 5px 6px; font-size: 12px; min-width: 80px; }
.production-bottom-layout { display: grid; grid-template-columns: 1fr 1.2fr; gap: 10px; }
.cut-folder-board { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); max-height: 120px; overflow: auto; }
.cut-card small, .retake-card small, .model-card small { color: var(--muted); display: block; margin-top: 3px; }
.workspace-layout-btn { text-align: left; }
.stage::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 44%);
  opacity: 0.28;
}
body[data-layout="production"] .tab[data-tab="studio"],
body[data-layout="animation"] .tab[data-tab="animation"],
body[data-layout="story"] .tab[data-tab="story"] { outline: 2px solid var(--accent-2); }
@media (max-width: 900px) {
  .app { grid-template-rows: auto auto auto auto; overflow: auto; }
  .workspace { grid-template-columns: 1fr; }
  .resize-handle { display: none; }
  .production-bottom-layout, .studio-grid { grid-template-columns: 1fr; }
}

/* Phase 6 — zen shell, mobile/touch, sprite/vector, print polish */
html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
button, .tab, .bottom-tab { -webkit-tap-highlight-color: transparent; }
.tool { grid-template-columns: 28px 1fr; place-items: center start; text-align: left; gap: 6px; }
.tool-icon {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  background: rgba(255,255,255,0.075);
  color: var(--accent-2);
  font-weight: 900;
}
.tool[data-tool="pixel"], .tool[data-tool="vector"] { border-color: color-mix(in srgb, var(--accent-2) 45%, transparent); }
.zen-overlay {
  position: absolute;
  left: 16px;
  bottom: 14px;
  color: rgba(255,255,255,0.36);
  font-size: 12px;
  letter-spacing: 0.05em;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s ease;
}
.mobile-control-dock {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: none;
  gap: 8px;
  z-index: 6;
  padding: 8px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  backdrop-filter: blur(16px) saturate(1.15);
  box-shadow: 0 20px 42px rgba(0,0,0,0.35);
}
.mobile-control-dock button {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  padding: 0;
  font-size: 18px;
}
body.mobile-controls-on .mobile-control-dock { display: flex; }
.zen-card, .print-check-report {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  margin-bottom: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(0,0,0,0.08));
}
.print-check-report { color: var(--muted); line-height: 1.45; }
body.focus-drawing .tool-cabinet,
body.focus-drawing .inspector,
body.focus-drawing .bottom-tray,
body.focus-drawing #resizeLeftHandle,
body.focus-drawing #resizeRightHandle,
body.focus-drawing #resizeBottomHandle,
body.focus-drawing .canvas-toolbar { display: none; }
body.focus-drawing .app { grid-template-rows: 48px 1fr; padding: 6px; }
body.focus-drawing .workspace { grid-template-columns: 1fr; }
body.focus-drawing .stage-wrap { grid-template-rows: 1fr; }
body.focus-drawing .stage { border-radius: 24px; }
body.focus-drawing .zen-overlay { opacity: 1; }
body.zen-mode .inspector,
body.zen-mode #resizeRightHandle { display: none; }
body.zen-mode .workspace { grid-template-columns: minmax(64px, var(--left-panel-width, 76px)) 6px minmax(0,1fr); }
body.zen-mode .tool-cabinet .brush-card,
body.zen-mode .tool-cabinet .panel-title:not(:first-child) { display: none; }
body.zen-mode .tool-grid { grid-template-columns: 1fr; }
body.zen-mode .tool { grid-template-columns: 1fr; justify-items: center; }
body.zen-mode .tool span:not(.tool-icon) { display: none; }
body.zen-mode .bottom-tray { opacity: 0.76; }
body.zen-mode .zen-overlay { opacity: 1; }
body.ios-shell .topbar,
body.ios-shell .panel,
body.ios-shell .bottom-tray,
body.ios-shell .canvas-toolbar {
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  backdrop-filter: blur(20px) saturate(1.2);
  border-color: rgba(255,255,255,0.13);
}
body.ios-shell button,
body.ios-shell input,
body.ios-shell select,
body.ios-shell textarea { border-radius: 14px; }
body.ios-shell .stage { border-radius: 28px; }
body.ios-shell .topbar { padding-top: max(8px, env(safe-area-inset-top)); }
@media (pointer: coarse), (max-width: 820px) {
  button, .file-button { min-height: 42px; }
  .mobile-control-dock { display: flex; }
  .tool { min-height: 48px; }
  .tabs, .bottom-tabs { overflow-x: auto; display: flex; }
  .tab, .bottom-tab { min-width: 112px; }
  .stage { min-height: 62vh; }
}

/* Phase 7 — menu bar, settings, mode stitching, pro workflow */
.topbar { position: relative; z-index: 20; }
.menu-bar { overflow: visible; gap: 6px; }
.menu { position: relative; }
.menu summary {
  list-style: none;
  border: 1px solid var(--line);
  background: var(--button);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.menu summary::-webkit-details-marker { display: none; }
.menu[open] summary { border-color: var(--accent); background: var(--button-hover); }
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 220px;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(53,45,39,0.99), rgba(28,23,20,0.99));
  box-shadow: 0 18px 50px rgba(0,0,0,0.42);
  z-index: 100;
}
.menu-panel.wide-menu { min-width: 270px; }
.menu-panel button, .menu-panel select { width: 100%; }
.settings-dialog { width: min(820px, calc(100vw - 32px)); }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.settings-grid section { border: 1px solid var(--line); border-radius: 16px; padding: 12px; background: rgba(0,0,0,0.12); }
.diagnostic-report, .desk-mode-summary {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(0,0,0,0.18);
  color: var(--muted);
  padding: 10px;
  white-space: pre-wrap;
  min-height: 48px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}
body[data-desk="paint"] .tool-cabinet { box-shadow: inset 4px 0 0 rgba(220,167,74,0.42), 0 10px 25px rgba(0,0,0,0.18); }
body[data-desk="manga"] .stage { background-color: #17110c; }
body[data-desk="comic"] .stage { background-color: #14171e; }
body[data-desk="newspaper"] .stage { background-color: #2a241b; }
body[data-desk="animation_test"] .stage { background-color: #080c12; }
body[data-desk="storyboard"] .stage { background-color: #111016; }
body[data-desk="sprite"] .stage { image-rendering: pixelated; }
body[data-desk] #activeToolLabel::before { content: attr(data-desk-label) ' · '; color: var(--accent-2); }
body.proofing-shell .stage { outline: 2px dashed rgba(142,197,255,0.28); outline-offset: -8px; }
@media (max-width: 1080px) {
  .menu-panel { left: 0; right: auto; }
  .settings-grid { grid-template-columns: 1fr; }
}


/* Phase 8 — repaired desk switching and clearer OS shell polish */
.desk-mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  min-width: 280px;
  padding: 6px 0 2px;
  border-top: 1px solid rgba(255,255,255,0.12);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.desk-grid-label {
  grid-column: 1 / -1;
  font-size: 10px;
  letter-spacing: .12em;
  opacity: .7;
  text-transform: uppercase;
  padding: 2px 2px 4px;
}
.desk-mode-btn {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  text-align: left;
  border: 1px solid rgba(255,255,255,0.12);
  background: linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0.03));
  color: var(--ink);
  border-radius: 12px;
  padding: 7px 9px;
  cursor: pointer;
}
.desk-mode-btn:hover,
.desk-mode-btn.active {
  border-color: color-mix(in srgb, var(--accent) 72%, white 10%);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.04), 0 8px 24px rgba(0,0,0,0.22);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 22%, transparent), rgba(255,255,255,0.04));
}
.desk-icon {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 9px;
  background: rgba(0,0,0,0.22);
  color: var(--accent-2);
  font-weight: 800;
}
.active-desk-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 999px;
  padding: 3px 10px;
  background: rgba(0,0,0,0.24);
  color: var(--accent-2);
  font-size: 12px;
  white-space: nowrap;
}
body[data-desk="manga"] .stage,
body[data-desk="comic"] .stage,
body[data-desk="newspaper"] .stage {
  background-image: radial-gradient(rgba(255,255,255,0.04) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.03), transparent);
  background-size: 18px 18px, 100% 100%;
}
body[data-desk="animation_test"] .stage,
body[data-desk="rigging"] .stage {
  background-image: linear-gradient(rgba(120,190,255,0.08) 1px, transparent 1px), linear-gradient(90deg, rgba(120,190,255,0.08) 1px, transparent 1px);
  background-size: 32px 32px;
}
body[data-desk="studio"] .stage {
  background-image: linear-gradient(135deg, rgba(255,255,255,0.05), transparent 40%), repeating-linear-gradient(0deg, rgba(255,255,255,0.04) 0 1px, transparent 1px 28px);
}
body[data-desk="web_proof"] .stage {
  background-image: linear-gradient(90deg, rgba(142,197,255,0.07) 0 1px, transparent 1px 80px), linear-gradient(rgba(142,197,255,0.06) 0 1px, transparent 1px 80px);
}
body[data-desk="sprite"] .stage {
  image-rendering: pixelated;
}
@media (max-width: 760px) {
  .desk-mode-grid { grid-template-columns: 1fr; min-width: 230px; }
  .active-desk-pill { max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
}


/* Phase 9 power tools */
.power-grid { display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:10px; }
.power-card { border:1px solid rgba(255,207,117,.18); background:rgba(255,255,255,.035); border-radius:16px; padding:12px; box-shadow:0 8px 20px rgba(0,0,0,.16); }
.power-card .panel-title { margin-top:0; }
.microcopy { color:rgba(245,239,231,.72); font-size:.82rem; line-height:1.35; margin:4px 0 10px; }
.power-summary { background:rgba(0,0,0,.22); border:1px solid rgba(255,255,255,.08); border-radius:14px; padding:12px; line-height:1.45; }
.managed-page-list, .symbol-library-list { display:grid; gap:8px; }
.managed-page-item, .symbol-item { display:grid; grid-template-columns:54px 1fr; gap:10px; align-items:center; background:rgba(0,0,0,.18); border:1px solid rgba(255,255,255,.08); border-radius:12px; padding:8px; }
.managed-page-item img, .symbol-item img { width:54px; height:42px; object-fit:cover; border-radius:8px; background:#f7efe0; }
.managed-page-item small, .symbol-item small { display:block; color:rgba(245,239,231,.62); margin-top:3px; }


/* Phase 10 rebuilt from stable Phase 9: cozy visual polish without layout breakage */
body.phase10-cozy {
  background:
    radial-gradient(circle at 12% 14%, color-mix(in srgb, var(--accent) 11%, transparent), transparent 28%),
    radial-gradient(circle at 84% 88%, rgba(255,255,255,0.035), transparent 34%),
    var(--bg);
}
body.phase10-cozy .topbar,
body.phase10-cozy .bottom-tray,
body.phase10-cozy .panel,
body.phase10-cozy .canvas-toolbar {
  border-radius: 18px;
  box-shadow: 0 18px 44px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.045);
}
body.phase10-cozy .stage {
  border-radius: 22px;
  background:
    linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255,255,255,.035) 1px, transparent 1px),
    radial-gradient(circle at 48% 22%, color-mix(in srgb, var(--accent-2) 12%, transparent), transparent 34%),
    var(--stage);
  background-size: 34px 34px, 34px 34px, auto, auto;
}
.phase-badge.stable-rebuild { background: linear-gradient(135deg, rgba(220,167,74,.20), rgba(255,255,255,.055)); border-color: color-mix(in srgb, var(--accent) 48%, var(--line)); }
.phase10-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.phase10-card {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.055), rgba(0,0,0,.09));
  border-radius: 16px;
  padding: 10px;
  display: grid;
  gap: 8px;
}
.phase10-report { color: var(--muted); font-size: 12px; line-height: 1.45; border: 1px dashed var(--line); border-radius: 12px; padding: 8px; background: rgba(0,0,0,.10); max-height: 160px; overflow: auto; }
.phase10-report div { margin-bottom: 4px; }
@media (min-width: 1200px) { .phase10-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }


/* Phase 10 rebuilt-from-v9 safety polish: compact, cozy, no full-screen UI rewrite. */
.phase10-card .compact-report { margin-top: 8px; }
.phase10-cozy .app-shell { border-radius: 18px; }
.phase10-cozy .topbar { backdrop-filter: blur(18px); }
.phase10-cozy .menu-popover, .phase10-cozy .modal, .phase10-cozy .inspector, .phase10-cozy .tools-panel, .phase10-cozy .bottom-panel {
  border-radius: 18px;
}
.phase10-cozy .phase10-grid { align-items: stretch; }
.phase10-cozy .phase10-card { min-height: 140px; }
.phase10-cozy .phase10-report { max-height: 160px; overflow: auto; }
@media (max-width: 900px) {
  .phase10-grid { grid-template-columns: 1fr; }
  .topbar { gap: 6px; }
  .topbar .menu-button { padding-inline: 10px; }
}


/* Phase 11 alignment and UI safety refinements */
.topbar, .menu-bar, .canvas-toolbar, .bottom-tabs, .tabs { min-width: 0; }
.menu-panel { max-height: min(72vh, 680px); overflow: auto; overscroll-behavior: contain; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start; }
.tab, .bottom-tab, .menu-panel button, .workspace-layout-btn { touch-action: manipulation; }
.workspace { min-width: 0; }
.stage-wrap, .inspector, .tool-cabinet, .bottom-tray { min-width: 0; }
.inspector { overflow: hidden; }
.tab-panel { overflow-wrap: anywhere; }
.phase11-badge { border-color: color-mix(in srgb, var(--accent) 70%, white 15%); background: color-mix(in srgb, var(--panel) 78%, var(--accent) 12%); }
.alignment-report { display: grid; gap: 6px; padding: 10px; border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent); border-radius: 14px; background: color-mix(in srgb, var(--stage) 62%, transparent); }
.align-row { display: grid; grid-template-columns: minmax(110px, 0.8fr) minmax(0, 1.2fr); gap: 8px; align-items: start; padding: 6px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,.08); }
.align-row.ok { background: rgba(105, 190, 120, .10); }
.align-row.warn { background: rgba(240, 160, 70, .13); }
.align-row span { opacity: .86; }
.layout-map-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 8px; margin-top: 8px; }
.layout-map-card { border: 1px solid rgba(255,255,255,.10); border-radius: 14px; padding: 9px; background: rgba(255,255,255,.045); display: grid; gap: 4px; }
.layout-map-card span { font-size: 12px; opacity: .78; }
body[data-layout="manga"] .stage { background-image: linear-gradient(135deg, rgba(255,255,255,.035), transparent 40%), radial-gradient(circle at 20% 20%, rgba(255,230,185,.08), transparent 32%); }
body[data-layout="animation"] .bottom-tray { box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 -22px 70px rgba(87,182,255,.08); }
body[data-layout="production"] .inspector { box-shadow: inset 1px 0 0 rgba(255,255,255,.08), -18px 0 70px rgba(106,209,255,.06); }
@media (max-width: 900px) {
  .topbar { gap: 8px; }
  .project-title-wrap small { display: none; }
  .menu-panel { left: auto; right: 6px; max-width: calc(100vw - 24px); }
  .align-row { grid-template-columns: 1fr; }
}


/* Phase 11 Recovery — full-preservation scroll/panel repair */
html, body { width: 100%; height: 100%; }
body { overflow: hidden; }
.app {
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
  grid-template-rows: auto minmax(0, 1fr) 6px minmax(120px, var(--bottom-tray-height, 172px));
}
.topbar { min-height: 58px; max-width: 100%; overflow: visible; }
.project-title-wrap { min-width: 160px; max-width: 34vw; overflow: hidden; }
.project-title-wrap > div { min-width: 0; overflow: hidden; }
#projectTitle, #projectMeta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-bar { min-width: 0; flex: 1 1 auto; justify-content: flex-end; }
.workspace {
  min-height: 0;
  overflow: hidden;
  grid-template-columns: minmax(150px, var(--left-panel-width, 230px)) 6px minmax(260px, 1fr) 6px minmax(240px, var(--right-panel-width, 315px));
}
.tool-cabinet,
.stage-wrap,
.inspector,
.bottom-tray {
  min-height: 0;
  min-width: 0;
}
.tool-cabinet {
  overflow: auto;
  overscroll-behavior: contain;
}
.inspector {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden !important;
  max-height: 100%;
}
.inspector .tabs {
  position: sticky;
  top: 0;
  z-index: 4;
  background: linear-gradient(180deg, rgba(53,45,39,0.98), rgba(40,34,30,0.94));
  padding-bottom: 8px;
  margin-bottom: 8px;
  max-height: 112px;
  overflow: auto;
  overscroll-behavior: contain;
}
.tab-panel.active {
  display: block;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}
.bottom-tray {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden !important;
  min-height: 120px;
}
.bottom-tabs {
  margin-bottom: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
}
.bottom-panel.active {
  display: block;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}
.stage-wrap { grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
.stage { min-height: 180px; }
.menu-panel {
  z-index: 100;
  max-height: min(72dvh, 680px);
  max-width: min(560px, calc(100vw - 20px));
  overflow: auto;
  overscroll-behavior: contain;
}
.layer-item { min-width: 0; }
.row-actions button { min-width: fit-content; }
textarea, input, select { min-width: 0; }
.preservation-ok { border-color: rgba(120, 220, 150, .35); background: rgba(120, 220, 150, .10); }
.preservation-warn { border-color: rgba(255, 180, 80, .38); background: rgba(255, 180, 80, .12); }
@media (max-width: 1050px) {
  body { overflow: auto; }
  .app { height: auto; max-height: none; min-height: 100dvh; overflow: visible; grid-template-rows: auto auto 6px auto; }
  .topbar { flex-direction: column; align-items: stretch; }
  .project-title-wrap { max-width: none; }
  .workspace { grid-template-columns: 1fr; overflow: visible; }
  .resize-handle { display: none; }
  .tool-cabinet, .inspector, .bottom-tray { max-height: none; overflow: visible !important; }
  .inspector, .bottom-tray { display: block; }
  .inspector .tabs, .tab-panel.active, .bottom-panel.active { max-height: none; height: auto; overflow: visible; }
  .stage { min-height: 60dvh; }
}
@media (max-width: 720px) {
  .menu-bar { justify-content: flex-start; overflow-x: auto; padding-bottom: 6px; }
  .menu-panel { left: 0; right: auto; }
  .canvas-toolbar { flex-wrap: wrap; gap: 6px; }
  .project-title-wrap small { display: block; }
}


/* Phase 12 — commercial studio OS, business paper, dialog, and projection refinement */
.phase12-login-card {
  margin: 18px 0 16px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(255,255,255,.06), rgba(0,0,0,.12));
}
.phase12-logo-lockup { display:flex; gap:12px; align-items:center; margin-bottom:12px; }
.phase12-os-icon, .phase12-os-logo {
  display:grid; place-items:center; width:52px; height:52px; border-radius:18px;
  background: linear-gradient(135deg, #f8dca2, #c97c35 50%, #6d3b20);
  color:#1c120b; font-weight:900; box-shadow: inset 0 1px 0 rgba(255,255,255,.35), 0 12px 28px rgba(0,0,0,.26);
}
.phase12-login-grid { display:grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap:10px; }
.phase12-boot-progress { height: 8px; border-radius:999px; background:rgba(0,0,0,.28); overflow:hidden; margin: 12px 0 8px; }
.phase12-boot-progress span { display:block; height:100%; width:72%; background:linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius:999px; animation: phase12BootPulse 2.8s ease-in-out infinite alternate; }
@keyframes phase12BootPulse { from { width: 48%; opacity: .62; } to { width: 96%; opacity: 1; } }
.phase12-boot-copy { color:var(--muted); font-size:12px; margin:0; }
.phase-badge.commercial { background: linear-gradient(135deg, rgba(255,207,117,.18), rgba(116,166,255,.10)); border-color: rgba(255,207,117,.35); }
.phase12-os-home { display:grid; grid-template-columns: 74px 1fr; gap:14px; align-items:center; padding:12px; border:1px solid var(--line); border-radius:18px; background:rgba(255,255,255,.035); margin-bottom:12px; }
.phase12-os-logo { width:64px; height:64px; text-align:center; }
.phase12-os-logo span { display:block; font-size:18px; letter-spacing:.08em; }
.phase12-os-logo small { font-size:10px; }
.phase12-card-grid { display:grid; grid-template-columns:1fr; gap:12px; }
.phase12-card { border:1px solid var(--line); border-radius:16px; background:linear-gradient(180deg, rgba(255,255,255,.045), rgba(0,0,0,.10)); padding:12px; display:grid; gap:10px; }
.phase12-report, .phase12-dialog-timeline { border:1px dashed var(--line); border-radius:14px; padding:10px; min-height:80px; max-height:220px; overflow:auto; color:var(--muted); background:rgba(0,0,0,.14); line-height:1.45; }
.phase12-report .item, .phase12-dialog-timeline .item { display:grid; gap:3px; padding:8px; border-bottom:1px solid rgba(255,255,255,.07); }
.phase12-report .item:last-child, .phase12-dialog-timeline .item:last-child { border-bottom:0; }
.phase12-dock-preview { display:flex; gap:8px; flex-wrap:wrap; padding:10px; border-radius:18px; background:rgba(255,255,255,.06); border:1px solid rgba(255,255,255,.08); }
.phase12-dock-preview button { width:42px; height:42px; border-radius:14px; padding:0; font-weight:800; }
.phase12-presentation-dialog { width:min(1180px, calc(100vw - 24px)); height:min(760px, calc(100dvh - 24px)); border:1px solid rgba(255,255,255,.16); border-radius:24px; padding:0; background:#08090b; color:#f8fafc; box-shadow:0 30px 110px rgba(0,0,0,.72); }
.phase12-presentation-dialog::backdrop { background:rgba(0,0,0,.76); backdrop-filter: blur(4px); }
.phase12-presentation-shell { height:100%; display:grid; grid-template-rows:auto minmax(0,1fr) auto; margin:0; }
.phase12-presentation-shell header, .phase12-presentation-shell footer { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:12px 16px; background:linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.02)); border-bottom:1px solid rgba(255,255,255,.10); }
.phase12-presentation-shell footer { border-top:1px solid rgba(255,255,255,.10); border-bottom:0; }
.phase12-projection-stage { min-height:0; display:grid; place-items:center; padding:24px; background: radial-gradient(circle at 50% 40%, rgba(220,167,74,.12), transparent 36%), #050607; }
.phase12-projection-card { width:min(920px, 92%); aspect-ratio:16/9; border:1px solid rgba(255,255,255,.14); border-radius:22px; background:linear-gradient(135deg, #15120f, #2a211d); display:grid; place-items:center; text-align:center; padding:28px; box-shadow:0 20px 90px rgba(0,0,0,.5); }
.phase12-projection-card strong { font-size:clamp(28px, 5vw, 64px); }
.phase12-projection-card small { display:block; margin-top:14px; color:#d6c9b7; font-size:clamp(14px, 2vw, 22px); }
body.phase12-commercial-shell .topbar { border-radius:22px; background:linear-gradient(180deg, rgba(45,42,39,.92), rgba(24,22,20,.92)); backdrop-filter: blur(22px); }
body.phase12-commercial-shell .stage { border-radius:24px; box-shadow: inset 0 0 72px rgba(0,0,0,.38), 0 18px 70px rgba(0,0,0,.25); }
@media (min-width: 1200px) { .phase12-card-grid { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 720px) { .phase12-login-grid, .phase12-os-home { grid-template-columns:1fr; } .phase12-presentation-shell header, .phase12-presentation-shell footer { flex-direction:column; align-items:flex-start; } }
