:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --header: #0b1524;
  --header-2: #101e31;
  --accent: #1478d4;
  --accent-dark: #0c5fb5;
  --focus: #4bb8ff;
  --panel: #f9fafc;
  --surface: #ffffff;
  --workspace: #2c3440;
  --border: #d8dee8;
  --muted: #667085;
  --text: #1d2939;
  --warning: #a15c00;
  --radius: 5px;
  --space-1: 4px;
  --space-2: 6px;
  --space-3: 8px;
  --space-4: 12px;
  --space-5: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { color: var(--text); background: var(--panel); font-size: 13px; }
button, input, select { font: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 2px;
}

.app-shell { display: grid; grid-template-rows: 76px minmax(0, 1fr) 28px; height: 100%; }
.app-header {
  display: grid; grid-template-columns: minmax(250px, 380px) auto minmax(0, 1fr);
  grid-template-rows: 42px 34px; color: #f5f8ff; background: var(--header);
  border-bottom: 1px solid #020813; min-width: 0;
}
.identity { grid-row: 1 / 2; display: flex; align-items: center; gap: 9px; padding: 7px 16px; }
.identity img { border-radius: 6px; }
.identity div { display: grid; }
.identity strong { font-size: 16px; line-height: 1.2; }
.identity span { color: #91a3ba; font-size: 10px; }
.mode-tabs { grid-column: 1 / 2; grid-row: 2; display: flex; padding-left: 12px; }
.mode-tab { min-width: 156px; padding: 0 22px; color: #cbd5e1; background: transparent; border: 1px solid transparent; border-bottom: 0; cursor: pointer; }
.mode-tab.is-active { color: #135fba; background: var(--panel); border-color: #cbd5e1; box-shadow: inset 0 3px var(--accent); font-weight: 650; }
.toolbar { grid-column: 2 / -1; grid-row: 1 / 3; display: flex; justify-content: flex-end; align-items: center; gap: 12px; padding: 10px 16px; min-width: 0; }
.button-group { display: inline-flex; gap: 2px; }
.button {
  min-height: 34px; padding: 0 12px; border: 1px solid #bcc7d5; border-radius: var(--radius);
  color: #243244; background: #fff; cursor: pointer; white-space: nowrap;
}
.button:hover:not(:disabled) { background: #eef5fc; border-color: #91b7dc; }
.button:active:not(:disabled), .button.is-pressed { background: #dcecff; border-color: var(--accent); }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button-primary { color: #fff; border-color: var(--accent-dark); background: var(--accent); font-weight: 650; box-shadow: 0 1px 0 rgba(0,0,0,.1); }
.button-primary:hover:not(:disabled) { background: var(--accent-dark); }
.button-compact { min-height: 30px; padding: 0 9px; font-size: 12px; }
.full-button { width: 100%; margin-top: 9px; }

.app-main { display: grid; grid-template-columns: minmax(300px, 360px) minmax(480px, 1fr) minmax(290px, 340px); min-width: 0; min-height: 0; }
.tools-panel, .context-panel { overflow: auto; min-width: 0; min-height: 0; background: var(--panel); }
.tools-panel { border-right: 1px solid var(--border); }
.context-panel { border-left: 1px solid var(--border); }
.tool-section, .context-section { padding: 11px 13px 13px; border-bottom: 1px solid var(--border); }
.tool-section h2, .context-section h2, .sprite-strip h2 { margin: 0 0 10px; font-size: 13px; font-weight: 700; }
.form-grid { display: grid; grid-template-columns: minmax(96px, 1fr) minmax(68px, 108px) 24px; gap: 7px 8px; align-items: center; }
.form-grid.wide-fields { grid-template-columns: 90px minmax(140px, 1fr) 1px; }
.form-grid input, .form-grid select, .full-input, #preset-select { min-width: 0; height: 30px; border: 1px solid #c7d0dc; border-radius: 4px; padding: 4px 7px; background: #fff; }
.form-grid input[type="number"] { text-align: right; }
.form-grid input[type="color"] { width: 100%; padding: 2px; }
.form-grid input[type="range"] { padding: 0; border: 0; }
.form-grid output { color: var(--muted); font-size: 11px; }
.check-row { display: flex; gap: 7px; align-items: center; margin-bottom: 9px; color: #344054; }
.stacked-label { display: block; margin-bottom: 5px; font-weight: 600; }
.full-input { width: 100%; }
.hint { margin: 6px 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.code-preview { margin: 7px 0 0; padding: 7px; overflow-wrap: anywhere; border: 1px solid #dce3eb; border-radius: 4px; background: #f2f5f8; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; }
.field-error { min-height: 16px; margin: 5px 0 0; color: #b42318; font-size: 11px; }
.action-row { display: flex; gap: 7px; margin-bottom: 7px; }
.action-row > * { min-width: 0; flex: 1; }
.empty-compact { min-height: 38px; color: var(--muted); line-height: 1.45; }
.data-list { display: grid; grid-template-columns: 1fr auto; gap: 5px 8px; margin: 0; }
.data-list dt { color: var(--muted); }
.data-list dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.workspace-panel { display: grid; grid-template-rows: minmax(240px, 1fr) 30px 126px; min-width: 0; min-height: 0; background: #e7ebf0; }
.viewport { position: relative; overflow: hidden; min-width: 0; min-height: 0; background: var(--workspace); touch-action: none; cursor: crosshair; }
.viewport.is-panning { cursor: grabbing; }
.transform-layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; box-shadow: 0 0 0 1px rgba(255,255,255,.5), 0 8px 30px rgba(0,0,0,.25); image-rendering: pixelated; }
.transform-layer canvas { position: absolute; inset: 0; display: block; image-rendering: pixelated; }
.checkerboard { background-color: #eef1f5; background-image: linear-gradient(45deg, #d8dde5 25%, transparent 25%), linear-gradient(-45deg, #d8dde5 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #d8dde5 75%), linear-gradient(-45deg, transparent 75%, #d8dde5 75%); background-size: 18px 18px; background-position: 0 0, 0 9px, 9px -9px, -9px 0; }
.empty-state { position: absolute; z-index: 3; inset: 0; display: grid; place-content: center; justify-items: center; padding: 24px; color: #e8eef7; text-align: center; }
.empty-state h2 { margin: 12px 0 4px; }
.empty-state p { max-width: 360px; margin: 0 0 16px; color: #aebdce; }
.workspace-summary { display: flex; align-items: center; padding: 0 12px; overflow: auto; border-top: 1px solid #cdd5df; border-bottom: 1px solid #cdd5df; background: #f7f9fb; white-space: nowrap; font-size: 11px; }
.sprite-strip { min-width: 0; min-height: 0; padding: 8px 10px; background: var(--surface); }
.sprite-strip header { display: flex; justify-content: space-between; align-items: center; height: 22px; }
.sprite-strip h2 { margin: 0; }
.strip-controls { display: grid; grid-template-columns: 30px minmax(0, 1fr) 30px; align-items: stretch; height: 82px; }
.strip-controls > button { border: 0; background: transparent; font-size: 26px; cursor: pointer; }
.sprite-track { display: flex; gap: 7px; align-items: center; overflow-x: auto; padding: 5px; scroll-behavior: smooth; }
.sprite-thumb { flex: 0 0 64px; width: 64px; height: 64px; display: grid; place-items: center; padding: 4px; border: 1px solid #cfd7e2; border-radius: 5px; background-color: #eef1f5; cursor: pointer; }
.sprite-thumb.is-selected { border: 2px solid var(--accent); background: #e3f0ff; }
.sprite-thumb canvas { max-width: 54px; max-height: 54px; image-rendering: pixelated; }

.selected-preview { display: grid; place-items: center; width: 100%; height: 128px; margin-top: 10px; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.selected-preview canvas { max-width: calc(100% - 16px); max-height: 112px; image-rendering: pixelated; }
.recommendation { margin-bottom: 8px; padding: 10px; border: 1px solid #a8cdf1; border-radius: var(--radius); background: #edf6ff; }
.recommendation.warning { border-color: #efc26d; background: #fff7e8; }
.recommendation h3 { margin: 0 0 5px; font-size: 12px; }
.recommendation p { margin: 0; color: #566273; font-size: 11px; line-height: 1.45; }
.recommendation .button { margin-top: 8px; }
.summary-grid, #layout-details { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; font-size: 11px; }
.summary-grid strong, #layout-details strong { text-align: right; font-weight: 600; }

.status-bar { display: flex; align-items: center; gap: 8px; padding: 0 10px; color: #d4deea; background: var(--header-2); font-size: 11px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; }
#pointer-status { margin-left: auto; }

body[data-mode="grid-creator"] .atlas-only { display: none !important; }
body[data-mode="atlas-slicer"] .grid-only { display: none !important; }
body[data-mode="atlas-slicer"] .workspace-panel { grid-template-rows: minmax(240px, 1fr) 30px 126px; }
body[data-mode="grid-creator"] .workspace-panel { grid-template-rows: minmax(240px, 1fr) 30px; }

@media (max-width: 1450px) {
  .app-main { grid-template-columns: minmax(280px, 330px) minmax(440px, 1fr) 260px; }
  .toolbar { gap: 6px; padding-right: 8px; }
}
@media (max-width: 1050px) {
  .app-shell { grid-template-rows: auto minmax(0, 1fr) 28px; }
  .app-header { grid-template-columns: 1fr; grid-template-rows: 44px 34px auto; }
  .identity { grid-row: 1; }
  .mode-tabs { grid-row: 2; }
  .toolbar { grid-column: 1; grid-row: 3; justify-content: flex-start; overflow-x: auto; padding: 7px 10px; background: var(--header-2); }
  .app-main { grid-template-columns: minmax(260px, 300px) minmax(360px, 1fr); }
  .context-panel { position: fixed; z-index: 8; right: 0; top: 120px; bottom: 28px; width: 330px; min-width: 330px; box-shadow: -8px 0 24px rgba(10,20,35,.18); transform: translateX(322px); transition: transform .18s ease; }
  .context-panel:hover, .context-panel:focus-within { transform: translateX(0); }
}
@media (max-width: 760px) {
  .app-main { grid-template-columns: 1fr; }
  .tools-panel { position: fixed; z-index: 9; left: 0; top: 120px; bottom: 28px; width: 300px; transform: translateX(calc(-100% + 8px)); box-shadow: 8px 0 24px rgba(10,20,35,.18); transition: transform .18s ease; }
  .tools-panel:hover, .tools-panel:focus-within { transform: translateX(0); }
  .identity span { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
