:root {
  --ui-bg: #f2f2ef;
  --panel: #fbfbf8;
  --ink: #141414;
  --muted: #74746e;
  --line: #d9d9d3;
  --accent: #ff342b;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--ui-bg);
  color: var(--ink);
  font-family: Inter, Manrope, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button, input, select { font: inherit; }
button, select { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app { display: grid; grid-template-columns: minmax(0, 1fr) 360px; min-height: 100svh; }
.workspace { min-width: 0; max-width: 100%; display: flex; flex-direction: column; overflow: hidden; }
.workspace-bar {
  height: 76px;
  padding: 0 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.workspace-bar h1 { margin: 0; font-size: 14px; line-height: 1.1; letter-spacing: -.01em; }
.workspace-bar p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.workspace-actions { display: flex; gap: 8px; align-items: center; }
.icon-button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  background: rgba(255,255,255,.44);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  cursor: pointer;
  text-decoration: none;
}
.icon-button:hover { background: #fff; }
.icon-button.is-active { border-color: #a9a9a2; background: #fff; }
.home-link { width: 38px; justify-content: center; padding: 0; font-size: 15px; }
.edit-icon { width: 9px; height: 9px; border: 1.5px solid currentColor; border-radius: 50%; box-shadow: 6px -5px 0 -2px var(--ui-bg), 6px -5px 0 -1px currentColor; }

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 34px 42px 54px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background-image: radial-gradient(#d1d1cb 0.7px, transparent 0.7px);
  background-size: 14px 14px;
}
.canvas-wrap {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 260px;
}
#artboard {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  max-height: calc(100svh - 164px);
  background: #40001f;
  box-shadow: 0 20px 70px rgba(30,20,24,.15);
  touch-action: none;
  user-select: none;
}
#artboard.is-editing { cursor: crosshair; }
#artboard.is-editing .cell-path { cursor: pointer; }
.editor-handle { cursor: grab; }
.editor-handle:active { cursor: grabbing; }
.handle-ring { fill: rgba(255,255,255,.92); stroke: rgba(0,0,0,.72); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.handle-dot { fill: #111; pointer-events: none; }
.editor-handle.is-selected .handle-ring { fill: #111; stroke: #fff; stroke-width: 2.5; }
.editor-handle.is-selected .handle-dot { fill: #fff; }
.selection-outline { fill: none; stroke: #fff; stroke-width: 3; stroke-dasharray: 9 7; stroke-linecap: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.stage-hint {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  white-space: nowrap;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .01em;
}

.panel {
  min-height: 100svh;
  padding: 28px 24px 20px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.panel-heading { padding: 4px 2px 27px; }
.eyebrow { display: block; margin-bottom: 18px; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .14em; }
.panel-heading h2 { margin: 0; font-size: 35px; line-height: .98; letter-spacing: -.05em; font-weight: 650; }
.panel-heading p { max-width: 285px; margin: 17px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.control-section { padding: 18px 2px; border-top: 1px solid var(--line); }
.control-section h3 { margin: 0 0 15px; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .13em; font-weight: 600; }
.range-control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  margin-top: 14px;
  font-size: 11px;
}
.range-control:first-of-type { margin-top: 0; }
.range-control output { color: var(--muted); font-variant-numeric: tabular-nums; }
.range-control input { grid-column: 1 / -1; width: 100%; margin: 1px 0 0; accent-color: var(--ink); cursor: ew-resize; }
.selected-control { padding-top: 13px; border-top: 1px dashed var(--line); }
.selected-control.is-disabled { opacity: .42; }
.selected-control.is-disabled input { cursor: default; }
.delete-cell {
  width: 100%;
  height: 34px;
  margin-top: 10px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #8b2b2b;
  font-size: 10px;
  cursor: pointer;
}
.delete-cell b { font-size: 13px; font-weight: 400; }
.delete-cell:hover:not(:disabled) { border-color: #bd6262; background: #fff8f8; }
.delete-cell:disabled { opacity: .38; color: var(--muted); cursor: default; }
input[type="range"] { height: 3px; }
.color-control {
  min-height: 39px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border-bottom: 1px solid #e8e8e3;
  font-size: 11px;
}
.color-control:last-child { border-bottom: 0; }
.color-name { position: relative; display: flex; align-items: center; gap: 9px; cursor: pointer; }
.color-control i { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,.14); background: var(--swatch); }
.color-name input[type="color"] { position: absolute; left: 0; width: 18px; height: 22px; opacity: 0; cursor: pointer; }
.color-value {
  width: 88px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  text-align: left;
  text-transform: uppercase;
  box-shadow: inset 0 1px 1px rgba(0,0,0,.025);
}
.color-value:hover { border-color: #b8b8b1; }
.color-value:focus { border-color: var(--ink); background: #fff; color: var(--ink); outline: none; }
.color-value.is-invalid { border-color: #d94141; color: #b42121; }
.select-control select {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font-size: 11px;
  cursor: pointer;
}
.frame-size-row { margin-top: 9px; display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 7px; align-items: center; }
.frame-size-row label { height: 36px; display: grid; grid-template-columns: auto 1fr; align-items: center; border: 1px solid var(--line); border-radius: 8px; background: #fff; overflow: hidden; }
.frame-size-row label span { padding-left: 9px; color: var(--muted); font-size: 9px; }
.frame-size-row input { width: 100%; min-width: 0; height: 34px; padding: 0 8px 0 5px; border: 0; outline: 0; background: transparent; font-size: 10px; font-variant-numeric: tabular-nums; }
.frame-size-row label:focus-within { border-color: var(--ink); }
.frame-size-row i, .frame-size-row em { color: var(--muted); font-size: 9px; font-style: normal; }
.panel-footer { margin-top: auto; padding: 18px 2px 0; border-top: 1px solid var(--line); }
.primary-button {
  width: 100%;
  height: 52px;
  padding: 0 17px;
  border: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  transition: transform .16s ease, background .16s ease;
}
.primary-button:hover { transform: translateY(-1px); background: #000; }
.primary-button b { font-size: 15px; font-weight: 400; }
.export-grid { margin-top: 8px; display: grid; grid-template-columns: 1fr .55fr; gap: 7px; }
.export-grid button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font-size: 10px;
  cursor: pointer;
}
.export-grid button:last-child { grid-column: 1 / -1; }
.export-grid button:hover { border-color: #aaa; }
#toast { min-height: 14px; margin: 8px 0 0; color: var(--muted); font-size: 9px; text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 860px) {
  .app { display: flex; flex-direction: column; }
  .workspace { min-height: 72svh; }
  .workspace-bar { height: 66px; padding: 0 15px; }
  .icon-button:not(.home-link) { width: 38px; padding: 0; justify-content: center; font-size: 0; }
  .stage { min-height: 58svh; padding: 20px 16px 44px; }
  #artboard { max-height: calc(72svh - 124px); }
  .stage-hint { max-width: 85%; white-space: normal; text-align: center; line-height: 1.4; }
  .panel { min-height: auto; border-left: 0; border-top: 1px solid var(--line); }
  .panel-heading h2 { font-size: 31px; }
}

@media (max-width: 460px) {
  .panel { padding: 24px 18px 18px; }
}

@media (prefers-reduced-motion: reduce) { .primary-button { transition: none; } }
