:root {
  --bg-1: #efe5d6;
  --bg-2: #f9f3eb;
  --panel: rgba(255, 251, 245, 0.88);
  --panel-strong: rgba(255, 253, 250, 0.96);
  --ink: #171411;
  --muted: #645d57;
  --line: rgba(23, 20, 17, 0.12);
  --line-strong: rgba(23, 20, 17, 0.18);
  --accent: #b56032;
  --accent-soft: rgba(181, 96, 50, 0.14);
  --shadow: 0 16px 42px rgba(45, 35, 24, 0.13);
  --paper: #f4ecdf;
  --frame-edge: rgba(255,255,255,0.56);
  --frame-inner: rgba(255,255,255,0.2);
  --frame-glow: rgba(181, 96, 50, 0.18);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at 10% 8%, rgba(181, 96, 50, 0.12), transparent 26%),
    radial-gradient(circle at 88% 12%, rgba(27, 23, 20, 0.07), transparent 22%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg-1) 100%);
  overflow: hidden auto;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: -20%;
  pointer-events: none;
  z-index: -1;
}

body::before {
  background: radial-gradient(circle at 20% 18%, rgba(255,255,255,0.22), transparent 18%), radial-gradient(circle at 78% 12%, rgba(181,96,50,0.14), transparent 20%);
  opacity: 0.7;
}

body::after {
  background: radial-gradient(circle at 65% 70%, rgba(181,96,50,0.08), transparent 22%);
  opacity: 0.55;
}

body.night-mode {
  --bg-1: #11161c;
  --bg-2: #1a222b;
  --panel: rgba(22, 27, 34, 0.88);
  --panel-strong: rgba(28, 34, 42, 0.96);
  --ink: #eef1f6;
  --muted: #a4acb8;
  --line: rgba(233, 237, 243, 0.12);
  --line-strong: rgba(233, 237, 243, 0.2);
  --accent: #d98b54;
  --accent-soft: rgba(217, 139, 84, 0.16);
  --shadow: 0 22px 52px rgba(3, 6, 10, 0.42);
  --frame-edge: rgba(248, 250, 255, 0.3);
  --frame-inner: rgba(255,255,255,0.12);
  --frame-glow: rgba(120, 168, 255, 0.16);
}

body.night-mode::before {
  background: radial-gradient(circle at 14% 10%, rgba(217,139,84,0.18), transparent 20%), radial-gradient(circle at 84% 14%, rgba(120,168,255,0.14), transparent 22%), radial-gradient(circle at 50% 110%, rgba(88,130,220,0.12), transparent 24%);
  opacity: 1;
}

body.night-mode::after {
  background: radial-gradient(circle at 34% 62%, rgba(255,255,255,0.04), transparent 20%), radial-gradient(circle at 70% 58%, rgba(217,139,84,0.06), transparent 18%);
  opacity: 1;
}

button,
input,
select {
  font: inherit;
}

button {
  border: none;
  cursor: pointer;
}

.app-shell {
  width: min(1480px, calc(100% - 14px));
  margin: 0 auto;
  padding: 8px 0 14px;
  display: grid;
  gap: 10px;
}

.canvas-viewport-wrap:fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 10px;
  overflow: hidden;
  box-sizing: border-box;
  background:
    radial-gradient(circle at 10% 8%, rgba(181, 96, 50, 0.12), transparent 26%),
    radial-gradient(circle at 88% 12%, rgba(27, 23, 20, 0.07), transparent 22%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg-1) 100%);
}

.canvas-viewport-wrap:fullscreen .canvas-shell {
  max-width: 100%;
  max-height: 100%;
}

.canvas-viewport-wrap:fullscreen .canvas-viewport {
  width: 100%;
  height: 100%;
}

body.app-is-fullscreen {
  overflow: hidden;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.panel-subtle {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 253, 249, 0.74);
}


body.night-mode .panel-subtle {
  background: rgba(28, 34, 42, 0.78);
}

body.night-mode .secondary-button {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.12);
  color: var(--ink);
}

body.night-mode .ghost-button {
  background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.12);
  color: var(--muted);
}

body.night-mode .micro-pill,
body.night-mode .value-pill,
body.night-mode .zoom-cluster {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.08);
}

body.night-mode input[type="color"],
body.night-mode select,
body.night-mode .layer-name,
body.night-mode .layer-visibility,
body.night-mode .layer-order-button,
body.night-mode .pan-button {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.12);
  color: var(--ink);
}

body.night-mode .layer-row {
  background: rgba(255,255,255,0.04);
}

body.night-mode .layer-row.active {
  background: rgba(255,255,255,0.08);
  border-color: rgba(217, 139, 84, 0.32);
  box-shadow: inset 0 0 0 1px rgba(217, 139, 84, 0.16), 0 0 14px rgba(120,168,255,0.06);
}

.hero {
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(280px, 1.4fr) minmax(220px, 0.95fr);
  gap: 10px;
  align-items: center;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--accent);
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  letter-spacing: -0.03em;
}

h1 {
  font-size: clamp(2rem, 3.8vw, 3.6rem);
  line-height: 0.94;
}

h2 {
  font-size: clamp(1.08rem, 1.4vw, 1.4rem);
}

.subcopy,
.status-text,
.hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.42;
}

.hero-copy {
  display: grid;
  gap: 4px;
}

.hero-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

#fullscreenButton.active {
  outline: 1px solid var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent-soft);
}

.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(23, 20, 17, 0.07);
  border: 1px solid rgba(23, 20, 17, 0.08);
}

.mode-option {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.mode-option.active {
  color: #fff;
  background: linear-gradient(180deg, #c06b3b 0%, #a95529 100%);
  box-shadow: 0 10px 20px rgba(181, 96, 50, 0.2);
}

body.night-mode .mode-toggle {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.08);
}

body.night-mode .mode-option {
  color: var(--muted);
}

body.night-mode .mode-option.active {
  color: #fff;
  background: linear-gradient(180deg, #d98b54 0%, #b96837 100%);
}

body.night-mode .primary-button,
body.night-mode .tool-button.active {
  box-shadow: 0 14px 34px rgba(217,139,84,0.22), 0 0 18px rgba(120,168,255,0.08);
}

.primary-button,
.secondary-button,
.ghost-button,
.tool-button,
.layer-visibility,
.layer-order-button {
  min-height: 38px;
  border-radius: 12px;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease, border-color 140ms ease, opacity 140ms ease;
}

.primary-button,
.secondary-button,
.ghost-button {
  padding: 0 13px;
}

.primary-button {
  color: #fff;
  background: linear-gradient(180deg, #c06b3b 0%, #a95529 100%);
  box-shadow: 0 12px 24px rgba(181, 96, 50, 0.22);
}

.secondary-button {
  color: var(--ink);
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--line);
}

.ghost-button {
  color: var(--muted);
  background: rgba(255,255,255,0.55);
  border: 1px dashed rgba(23,20,17,0.16);
}

.tool-button {
  min-height: 42px;
  background: rgba(255,255,255,0.84);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0 10px;
  font-weight: 600;
  font-size: 13px;
}

.tool-button.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(180deg, #c06b3b 0%, #a95529 100%);
  box-shadow: 0 10px 20px rgba(181, 96, 50, 0.2);
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.tool-button:hover,
.layer-visibility:hover,
.layer-order-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled,
.tool-button:disabled,
.layer-visibility:disabled,
.layer-order-button:disabled {
  opacity: 0.48;
  cursor: default;
  transform: none;
  box-shadow: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(268px, 306px) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.controls-column {
  display: grid;
  gap: 10px;
}

.controls-panel,
.canvas-panel {
  padding: 12px;
}

.controls-panel {
  display: grid;
  gap: 12px;
}

.compact-panel {
  gap: 10px;
}

.section-header,
.canvas-topbar,
.layer-rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-height: 24px;
}

.layer-rail-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.canvas-topbar {
  margin-bottom: 8px;
}

.canvas-stats {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}


.zoom-cluster {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(23, 20, 17, 0.07);
  border: 1px solid rgba(23, 20, 17, 0.06);
}

.zoom-button,
.zoom-readout {
  min-height: 26px;
  border-radius: 999px;
  border: 1px solid rgba(23, 20, 17, 0.08);
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  padding: 0 9px;
}

.zoom-button {
  min-width: 28px;
  padding: 0;
}

.zoom-readout {
  min-width: 58px;
}

.micro-pill,
.value-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(23, 20, 17, 0.07);
  border: 1px solid rgba(23, 20, 17, 0.06);
  color: var(--ink);
  font-size: 11px;
  font-weight: 600;
}

.tool-grid,
.slider-grid,
.button-grid,
.dual-grid {
  display: grid;
  gap: 6px;
}

.tool-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.compact-grid {
  gap: 6px;
}

.dual-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.control-card {
  display: grid;
  gap: 6px;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.control-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-weight: 600;
  font-size: 14px;
}

input[type="range"],
input[type="color"],
select {
  width: 100%;
}

input[type="range"] {
  accent-color: var(--accent);
}

input[type="color"] {
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: #fff;
  padding: 0;
}

select,
.layer-name {
  min-height: 38px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(255,255,255,0.94);
  padding: 0 10px;
  color: var(--ink);
}

.canvas-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: min(76vh, 820px);
}

.canvas-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 6px;
  align-items: stretch;
  min-height: 0;
  height: 100%;
}

.canvas-main {
  min-width: 0;
  display: grid;
  overflow: hidden;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 4px;
  min-height: 0;
  height: 100%;
}

.canvas-viewport-wrap {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.canvas-shell {
  position: relative;
  min-width: 320px;
  min-height: 240px;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  border-radius: 0;
  border: 1px solid rgba(23, 20, 17, 0.12);
  background: var(--paper);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.88),
    inset 0 -14px 32px rgba(0,0,0,0.08),
    0 0 0 1px rgba(0,0,0,0.06),
    0 18px 40px rgba(33, 25, 18, 0.12),
    0 0 26px var(--frame-glow);
}

.canvas-shell::before,
.canvas-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 7;
}

.canvas-shell::before {
  box-shadow: inset 0 0 0 1px var(--frame-edge), inset 0 0 0 11px rgba(255,255,255,0.02);
}

.canvas-shell::after {
  inset: 10px;
  border: 1px solid var(--frame-inner);
}

.canvas-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border-radius: 0;
  background: transparent;
}

.canvas-viewport.is-zoomed {
  overflow: auto;
}

.canvas-viewport:not(.is-zoomed) {
  scrollbar-width: none;
}

.canvas-viewport:not(.is-zoomed)::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.canvas-viewport.can-pan,
.canvas-viewport.can-pan * {
  cursor: grab;
}

.canvas-viewport.is-panning,
.canvas-viewport.is-panning * {
  cursor: grabbing;
}

.canvas-zoom-wrap {
  position: relative;
  width: max-content;
  height: max-content;
  min-width: 100%;
  min-height: 100%;
  overflow: visible;
}

.canvas-frame {
  position: relative;
  min-height: 0;
  border-radius: 0;
  overflow: hidden;
  border: none;
  background: var(--paper);
  display: block;
  box-shadow: none;
}

body.night-mode .canvas-shell {
  border-color: rgba(245, 248, 255, 0.16);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.06),
    inset 0 -22px 42px rgba(0,0,0,0.22),
    0 0 0 1px rgba(255,255,255,0.03),
    0 24px 58px rgba(0,0,0,0.42),
    0 0 28px rgba(120,168,255,0.14),
    0 0 52px rgba(217,139,84,0.08);
}

body.night-mode .canvas-shell::after {
  border-color: rgba(255,255,255,0.08);
}

.surface {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  z-index: 1;
}

#paperCanvas,
#templateCanvas {
  pointer-events: none;
}

.drawing-layer {
  pointer-events: auto;
}

.reference-bar {
  display: grid;
  gap: 3px;
  padding: 5px 7px 6px;
}

.reference-row {
  display: grid;
  grid-template-columns: minmax(210px, 290px) minmax(170px, 240px) minmax(0, 1fr);
  gap: 4px;
  align-items: center;
}

.reference-inline {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.dock-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.dock-select {
  min-width: 0;
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.ref-opacity-group input[type="range"] {
  min-width: 0;
  flex: 1 1 auto;
  margin: 0;
}

.reference-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.dock-button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 11px;
  border-radius: 9px;
}

.reference-status {
  display: grid;
  gap: 0;
  min-width: 0;
}

.pan-cluster {
  display: inline-grid;
  grid-template-columns: repeat(4, 28px);
  gap: 4px;
  padding: 3px;
  border-radius: 12px;
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--line);
}

.pan-button {
  min-height: 28px;
  width: 28px;
  padding: 0;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  font-size: 11px;
}

body.night-mode .pan-cluster,
body.night-mode .zoom-cluster {
  background: rgba(255,255,255,0.06);
}

body.night-mode .pan-button,
body.night-mode .zoom-button,
body.night-mode .zoom-readout {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.12);
  color: var(--ink);
}

.reference-status .status-text {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  line-height: 1.18;
}

.hint {
  font-size: 10px;
  line-height: 1.1;
}

.layer-rail {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 5px;
  min-height: 0;
  min-width: 0;
  width: 118px;
  max-width: 118px;
  padding: 5px;
  overflow: hidden;
}

.layer-mini-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.tiny-button {
  min-height: 28px;
  min-width: 0;
  padding: 0 4px;
  font-size: 11px;
}

.layer-list {
  display: grid;
  align-content: start;
  gap: 3px;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  padding-right: 1px;
}

.layer-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 16px;
  gap: 3px;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255,255,255,0.7);
  cursor: pointer;
}

.layer-row.active {
  background: rgba(255,255,255,0.96);
  border-color: rgba(181, 96, 50, 0.34);
  box-shadow: inset 0 0 0 1px rgba(181, 96, 50, 0.12);
}

.layer-visibility,
.layer-order-button {
  min-height: 18px;
  width: 18px;
  padding: 0;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  font-size: 9px;
  border-radius: 8px;
}

.layer-visibility.is-hidden {
  opacity: 0.45;
}

.layer-main {
  display: grid;
  gap: 0;
  min-width: 0;
}

.layer-main-top {
  display: block;
  min-width: 0;
}

.layer-name {
  min-width: 0;
  width: 100%;
  font-size: 10px;
  min-height: 20px;
  padding: 0 5px;
  border-radius: 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-name:focus {
  white-space: normal;
}



.layer-opacity-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px;
  align-items: center;
}

.layer-opacity-label {
  font-size: 8px;
  color: var(--muted);
  text-align: right;
}

.layer-opacity {
  width: 100%;
}

.layer-order {
  display: grid;
  gap: 0;
}

.cursor-ring,
.drop-overlay {
  z-index: 8;
}

.cursor-ring {
  position: absolute;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  margin-top: -4px;
  border-radius: 50%;
  border: 1.25px solid rgba(23,20,17,0.72);
  background: transparent;
  pointer-events: none;
  opacity: 0;
  transform: translate3d(-9999px, -9999px, 0);
  transition: opacity 100ms ease;
}

.cursor-ring.visible {
  opacity: 1;
}

.cursor-ring.eraser {
  border-style: dashed;
  background: transparent;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(16, 12, 8, 0.18);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.drop-overlay div {
  padding: 16px 18px;
  border-radius: 16px;
  background: rgba(14, 10, 8, 0.68);
  display: grid;
  gap: 4px;
  text-align: center;
}

.drop-overlay.visible {
  opacity: 1;
}

@media (max-width: 1240px) {
  .reference-row {
    grid-template-columns: minmax(220px, 1fr) minmax(180px, 240px);
  }

  .reference-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .canvas-panel {
    min-height: 0;
  }

  .canvas-shell {
    min-height: 380px;
  }
}

@media (max-width: 980px) {
  .canvas-stage {
    grid-template-columns: minmax(0, 1fr);
  }

  .layer-rail {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: none;
  }

  .layer-list {
    max-height: 220px;
  }
}

@media (max-width: 860px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .hero-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100%, calc(100% - 8px));
    padding-top: 6px;
  }

  .controls-panel,
  .canvas-panel,
  .hero {
    padding: 10px;
    border-radius: 18px;
  }

  .dual-grid {
    grid-template-columns: 1fr;
  }

  .canvas-topbar,
  .section-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .canvas-stats {
    justify-content: flex-start;
  }

  .canvas-shell {
    min-height: 260px;
  }

  .zoom-cluster {
    padding: 2px;
  }

  .hero-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mode-toggle {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .reference-row {
    grid-template-columns: 1fr;
  }

  .reference-inline,
  .reference-actions {
    justify-content: flex-start;
  }
}


.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.brand-link {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  text-decoration: none;
  opacity: 0.72;
  white-space: nowrap;
}

.brand-link:hover {
  color: var(--accent);
  opacity: 1;
}


.pan-cluster.is-hidden {
  display: none;
}
