:root {
  color: #eee9df;
  background: #111719;
  font-family: Inter, "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", sans-serif;
  font-synthesis: none;
  --bg: #111719;
  --surface: #1b2325;
  --surface-2: #222d30;
  --surface-3: #2a3639;
  --line: #3b484b;
  --text: #eee9df;
  --muted: #aab4b3;
  --accent: #e3bc67;
  --accent-ink: #2a2213;
  --teal: #66c2b5;
  --danger: #e58275;
  --focus: #8cd5ff;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); }
button, input, select { font: inherit; }
button, select, input[type="checkbox"], input[type="range"] { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip-link {
  position: fixed;
  z-index: 100;
  top: -4rem;
  left: 1rem;
  padding: 8px 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
}
.skip-link:focus { top: 1rem; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 86px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: #151c1e;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-weight: 900;
  letter-spacing: -0.08em;
}
h1 { margin: 0; font-family: Georgia, "Yu Mincho", serif; font-size: 1.55rem; letter-spacing: 0.01em; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 0.75rem; }
.unofficial {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid #7c6841;
  background: #2b261d;
  color: #e8d29f;
  font-size: 0.72rem;
}
.unofficial strong { color: var(--accent); }

main { min-height: calc(100vh - 136px); }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.toolbar-group { display: flex; align-items: center; gap: 7px; }
.toolbar-files { margin-left: auto; }
.button,
.icon-button,
.button-grid button {
  min-height: 36px;
  border: 1px solid #546164;
  border-radius: 3px;
  background: #273235;
  color: var(--text);
  font-weight: 700;
  font-size: 0.77rem;
}
.button { padding: 8px 12px; }
.button:hover:not(:disabled), .icon-button:hover:not(:disabled), .button-grid button:hover:not(:disabled) { border-color: var(--accent); background: #323d3f; }
.button.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.button.export { border-color: var(--teal); background: #23534e; color: #ecfffb; }
.button.danger { color: #ffc2ba; }
.button.compact { min-height: 32px; padding: 5px 9px; }
.icon-button { width: 39px; padding: 0; font-size: 1.3rem; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

.status {
  min-height: 34px;
  margin: 0;
  padding: 8px 20px;
  border-bottom: 1px solid var(--line);
  background: #141b1d;
  color: var(--muted);
  font-size: 0.76rem;
}
.status[data-kind="error"] { color: #ff9e92; }
.status[data-kind="success"] { color: #8ce1d2; }

.editor-shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 270px;
  min-height: calc(100vh - 205px);
}
.left-panel, .right-panel { background: var(--surface); }
.left-panel { border-right: 1px solid var(--line); }
.right-panel { border-left: 1px solid var(--line); }
.panel-section { padding: 18px; border-bottom: 1px solid var(--line); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.panel-heading h2 { margin: 0; font-size: 0.84rem; letter-spacing: 0.04em; }
.panel-heading span { color: var(--muted); font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 0.68rem; }

.field { display: grid; gap: 6px; color: var(--muted); font-size: 0.7rem; }
select, input[type="number"] {
  width: 100%;
  min-height: 35px;
  border: 1px solid #536064;
  border-radius: 2px;
  background: #151c1e;
  color: var(--text);
  padding: 6px 8px;
}
.custom-canvas { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 6px; margin-top: 10px; }
.custom-canvas .button { grid-column: 1 / -1; }
.inline-field { grid-template-columns: auto 1fr auto; align-items: center; margin-top: 12px; }
.inline-field input { min-width: 0; }
.field-note, .empty-note { margin: 9px 0 0; color: #899493; font-size: 0.67rem; line-height: 1.5; }
.switch-row { display: flex; align-items: center; gap: 9px; color: var(--text); font-size: 0.77rem; }
.switch-row input { position: absolute; opacity: 0; }
.switch { position: relative; width: 40px; height: 22px; border: 1px solid #697376; border-radius: 20px; background: #111719; }
.switch span { position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #83908e; transition: transform 140ms; }
.switch-row input:checked + .switch { border-color: var(--teal); background: #264b47; }
.switch-row input:checked + .switch span { transform: translateX(18px); background: var(--teal); }
.switch-row input:focus-visible + .switch { outline: 3px solid var(--focus); outline-offset: 2px; }

.layers-section { min-height: 250px; }
.layer-list { display: grid; gap: 6px; max-height: 390px; overflow: auto; margin: 0; padding: 0; list-style: none; }
.layer-item {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 45px;
  padding: 5px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
}
.layer-item:hover { border-color: #667477; }
.layer-item.selected { border-color: var(--accent); background: #352f23; }
.layer-item img { width: 36px; height: 32px; object-fit: contain; background: repeating-conic-gradient(#394346 0 25%, #263033 0 50%) 0/10px 10px; }
.layer-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.7rem; }
.layer-item small { color: var(--muted); font-size: 0.62rem; }

.stage { position: relative; min-width: 0; background: #0d1214; }
.stage-heading { display: flex; justify-content: space-between; align-items: center; height: 42px; padding: 0 16px; border-bottom: 1px solid #2c3639; }
.stage-heading h2 { margin: 0; font-size: 0.78rem; }
.stage-heading span { color: #7e8989; font-size: 0.67rem; }
.canvas-scroll { display: grid; place-items: center; height: calc(100vh - 247px); min-height: 480px; overflow: auto; padding: 30px; }
.canvas-wrap {
  position: relative;
  width: min(100%, 1000px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  background:
    linear-gradient(45deg, #30393b 25%, transparent 25%),
    linear-gradient(-45deg, #30393b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #30393b 75%),
    linear-gradient(-45deg, transparent 75%, #30393b 75%),
    #222b2d;
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}
#editor-canvas { display: block; width: 100%; height: auto; touch-action: none; cursor: crosshair; }
.drop-overlay { position: absolute; inset: 0; display: grid; place-items: center; border: 3px dashed var(--accent); background: rgba(17, 23, 25, 0.88); color: var(--accent); font-size: 1.2rem; font-weight: 900; pointer-events: none; }

.selection-name { min-height: 38px; margin: 0 0 16px; padding: 9px; overflow-wrap: anywhere; border: 1px solid #3b474a; background: #141b1d; color: #d8dedc; font-size: 0.72rem; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.slider-field { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-bottom: 16px; color: var(--muted); font-size: 0.72rem; }
.slider-field output { color: var(--accent); font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; }
.slider-field input { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }
.action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin: 20px 0; }
.control-block { margin-top: 20px; }
.control-block h3 { margin: 0 0 9px; color: var(--muted); font-size: 0.69rem; font-weight: 600; }
.button-grid { display: grid; gap: 5px; }
.button-grid button { min-height: 32px; padding: 5px; font-size: 0.66rem; }
.align-grid { grid-template-columns: repeat(3, 1fr); }
.layer-grid { grid-template-columns: repeat(2, 1fr); }
.privacy-note { margin: 18px; padding: 13px; border: 1px solid #315c57; background: #172a28; color: #9fe1d7; }
.privacy-note strong { font-size: 0.75rem; }
.privacy-note p { margin: 5px 0 0; color: #83aaa4; font-size: 0.66rem; line-height: 1.5; }

footer { padding: 18px 24px; border-top: 1px solid var(--line); color: #7f8a89; font-size: 0.68rem; text-align: center; }

@media (max-width: 1050px) {
  .topbar { align-items: flex-start; flex-wrap: wrap; }
  .toolbar-files { width: 100%; margin-left: 0; }
  .editor-shell { grid-template-columns: 220px minmax(0, 1fr); }
  .right-panel { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr auto; border-top: 1px solid var(--line); border-left: 0; }
  .inspector-section fieldset { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
  .action-row, .control-block { margin: 0; }
  .selection-name { max-width: 500px; }
}

@media (max-width: 700px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .unofficial { align-items: flex-start; flex-direction: column; gap: 3px; }
  .toolbar-group { flex-wrap: wrap; }
  .editor-shell { display: flex; flex-direction: column; }
  .left-panel { border-right: 0; }
  .layers-section { min-height: auto; }
  .layer-list { max-height: 200px; }
  .stage { order: -1; }
  .canvas-scroll { height: auto; min-height: 340px; padding: 16px; }
  .right-panel { display: block; }
  .inspector-section fieldset { display: block; }
  .action-row { margin: 20px 0; }
  .control-block { margin-top: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
