:root {
  --ink: #17171c;
  --muted: #6f6d76;
  --paper: #f6f5f2;
  --panel: #ffffff;
  --line: #dedbe4;
  --violet: #7255eb;
  --blue: #2777d3;
  --green: #1b8f6b;
  --coral: #d95b45;
  --gold: #b88918;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: "DM Sans", sans-serif; color: var(--ink); background: var(--paper); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

.studio-header {
  height: 68px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 24px;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { color: var(--ink); font: 800 22px Manrope, sans-serif; text-decoration: none; white-space: nowrap; }
.brand span { color: var(--violet); }
.studio-nav { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.studio-nav a, .soft-btn, .primary-btn, .tool-btn {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 12px;
  color: #4d4954;
  background: #fff;
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
}

.primary-btn { border-color: #17171c; background: #17171c; color: #fff; box-shadow: 0 8px 22px rgba(23,23,28,.16); }
.primary-btn:disabled, .soft-btn:disabled, .tool-btn:disabled { opacity: .55; cursor: wait; }
.soft-btn:hover, .studio-nav a:hover, .tool-btn:hover { border-color: #bbb3db; background: #f5f2ff; color: #6044ce; }
.primary-btn:hover { background: #303038; }

.studio-main { width: min(1380px, calc(100% - 32px)); margin: 0 auto; padding: 26px 0 42px; }
.page-title { display: flex; align-items: end; justify-content: space-between; gap: 22px; margin-bottom: 20px; }
.page-title p { margin: 0 0 6px; color: var(--violet); font-size: 10px; font-weight: 800; letter-spacing: 1.6px; text-transform: uppercase; }
.page-title h1 { margin: 0; font: 800 34px/1.08 Manrope, sans-serif; letter-spacing: -.8px; }
.page-title .lead { max-width: 560px; color: var(--muted); font-size: 14px; line-height: 1.55; }

.workspace-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 45px rgba(31,28,43,.08);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font: 800 16px Manrope, sans-serif; }
.panel-body { padding: 16px; }
.control-stack { display: grid; gap: 12px; }
.control-stack label { display: grid; gap: 6px; color: #5f5b66; font-size: 12px; font-weight: 800; }
.control-stack input[type=text], .control-stack input[type=number], .control-stack textarea, .control-stack select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  outline: 0;
}
.control-stack textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
.control-stack input:focus, .control-stack textarea:focus, .control-stack select:focus { border-color: #9f91ee; box-shadow: 0 0 0 3px rgba(114,85,235,.14); }
.row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.result-card { overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.result-card.active { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(114,85,235,.14); }
.result-card img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; }
.result-card div { padding: 9px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.empty-note { border: 1px dashed #cac6d2; border-radius: 10px; padding: 24px; color: #77737f; text-align: center; font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%,80px); z-index: 500; background: #17171c; color: #fff; border-radius: 9px; padding: 11px 14px; font-size: 12px; transition: .25s ease; }
.toast.show { transform: translate(-50%,0); }
.spinner { width: 34px; height: 34px; border: 3px solid #dad5ea; border-top-color: var(--violet); border-radius: 50%; animation: spin .85s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.landing { min-height: 100vh; overflow-x: hidden; background: #f4f3ef; }
.landing-hero { min-height: 82vh; position: relative; display: flex; align-items: center; padding: 84px min(7vw, 90px) 110px; overflow: hidden; border-bottom: 1px solid var(--line); }
#landingScene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: #f4f3ef; }
.hero-copy { position: relative; z-index: 2; width: min(760px, 96vw); color: #111116; text-shadow: 0 1px 0 rgba(255,255,255,.28); }
.hero-logo-mark { width: clamp(58px, 8vw, 94px); height: clamp(58px, 8vw, 94px); display: block; margin: 0 0 18px; filter: drop-shadow(0 12px 24px rgba(31,28,43,.16)); }
.hero-copy h1 { margin: 0; font: 800 clamp(58px, 9vw, 128px)/.88 Manrope, sans-serif; letter-spacing: 0; }
.hero-copy h1 span { color: var(--violet); }
.hero-copy p { max-width: 560px; margin: 22px 0 26px; color: #3f3c45; font-size: 18px; line-height: 1.45; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.landing-band { width: min(1180px, calc(100% - 32px)); margin: -54px auto 0; position: relative; z-index: 3; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.landing-band a { min-height: 100px; display: flex; flex-direction: column; justify-content: space-between; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.94); color: var(--ink); text-decoration: none; box-shadow: 0 12px 40px rgba(31,28,43,.08); }
.landing-band b { font: 800 15px Manrope, sans-serif; }
.landing-band span { color: var(--muted); font-size: 12px; line-height: 1.4; }

.auth-main { min-height: calc(100vh - 68px); display: grid; place-items: center; padding: 24px; background: #eeeef2; }
.auth-panel { width: min(520px, 100%); display: grid; gap: 14px; padding: 28px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 18px 48px rgba(31,28,43,.1); }
.auth-panel h1 { margin: 0; font: 800 34px/1.05 Manrope, sans-serif; }
.auth-panel p { margin: 0; color: var(--muted); line-height: 1.5; }
.auth-action { width: 100%; min-height: 44px; margin-top: 6px; }
.setup-note { border: 1px solid #dedbe4; border-radius: 8px; padding: 11px 12px; color: #5f5a66; background: #f6f4fa; font-size: 13px; line-height: 1.45; }
.setup-note.error { border-color: #e7c6cc; color: #9d2f42; background: #fff2f4; }
.subscribe-panel { gap: 16px; }
.plan-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.plan-row span { color: #4d4954; font-weight: 800; }
.plan-row strong { color: var(--violet); font-size: 12px; overflow-wrap: anywhere; text-align: right; }
.inline-form { display: inline-flex; margin: 0; }

.themeboard-canvas {
  min-height: 640px;
  position: relative;
  overflow: hidden;
  background: #e8e4db;
  background-image: linear-gradient(90deg, rgba(255,255,255,.45) 1px, transparent 1px), linear-gradient(rgba(255,255,255,.45) 1px, transparent 1px);
  background-size: 32px 32px;
  border-radius: 0 0 12px 12px;
}
.theme-item { position: absolute; width: 210px; border: 6px solid #fff; border-radius: 6px; box-shadow: 0 12px 28px rgba(36,31,44,.18); user-select: none; touch-action: none; background: #fff; }
.theme-item.selected { outline: 3px solid var(--violet); outline-offset: 3px; }
.theme-item img { display: block; width: 100%; aspect-ratio: 1.15; object-fit: cover; pointer-events: none; }
.theme-hint { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: #6c675d; font-weight: 800; pointer-events: none; }

.drawing-stage {
  min-height: 620px;
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #e9ece8;
  border-radius: 0 0 12px 12px;
}
.stage-hint { color: #6e6a73; font-weight: 800; text-align: center; }
.drawing-stage img { max-width: 96%; max-height: 96%; object-fit: contain; background: #fff; box-shadow: 0 8px 24px rgba(31,28,43,.08); }
.dimension-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: auto; }
.dimension-layer line, .dimension-layer path { stroke: #5f5966; stroke-width: 1.4; fill: none; }
.dimension-layer .dimension-hit { stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: move; }
.dimension-layer .dimension-label { pointer-events: all; cursor: move; }
.dimension-layer circle { fill: #5f5966; stroke: #fff; stroke-width: 1.5; }
.dimension-layer text { fill: #17171c; font: 700 14px "DM Sans", sans-serif; paint-order: stroke; stroke: #fff; stroke-width: 4px; }
.dimension-layer .preview line { stroke: var(--violet); stroke-dasharray: 7 5; }
.dimension-layer .preview circle { fill: var(--violet); }
.dimension-layer .preview text { fill: var(--violet); }
.dimension-mode .drawing-stage { cursor: crosshair; }
.dimension-orientation { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.dimension-orientation .active, .tool-btn.active { border-color: var(--violet); background: #f2efff; color: #6044ce; }
.dimension-scale {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 5;
  display: grid;
  grid-template-columns: 116px 78px auto;
  align-items: end;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 10px 30px rgba(31,28,43,.12);
}
.dimension-scale label { display: grid; gap: 4px; color: #5f5b66; font-size: 10px; font-weight: 800; text-transform: uppercase; }
.dimension-scale input { width: 100%; border: 1px solid var(--line); border-radius: 7px; padding: 7px 8px; outline: 0; }
.dimension-scale span { align-self: center; color: var(--muted); font-size: 11px; font-weight: 700; white-space: nowrap; }
.drawing-results { grid-template-columns: 1fr; }

.sketch-mode-body { height: 100vh; overflow: hidden; background: #f4f3ef; }
.sketch-shell { height: calc(100vh - 68px); display: grid; grid-template-columns: minmax(340px, 1fr) 28px minmax(340px, 1fr); }
.sketch-pane, .gen-pane { position: relative; min-width: 0; overflow: hidden; }
.sketch-pane { background: #fff; display: grid; grid-template-rows: minmax(0, 1fr) auto; padding: 0; }
.sketch-toolbar { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 12; width: max-content; max-width: calc(100% - 116px); display: grid; gap: 7px; padding: 8px; border: 1px solid rgba(255,255,255,.12); border-radius: 6px; background: rgba(42,40,48,.94); box-shadow: 0 10px 28px rgba(31,28,43,.22); }
.sketch-toolbar.saving-brush { background: rgba(50,42,78,.96); box-shadow: inset 0 0 0 2px rgba(157,133,255,.32), 0 10px 28px rgba(31,28,43,.24); }
.sketch-toolbar-main { display: flex; align-items: center; gap: 7px; min-width: 0; flex-wrap: wrap; }
.sketch-list-toggle { position: absolute; top: 14px; left: 14px; z-index: 13; width: 38px; height: 34px; padding: 0; border-radius: 4px; box-shadow: 0 7px 18px rgba(31,28,43,.12); }
.icon-tool { width: 34px; height: 34px; display: grid; place-items: center; padding: 0; }
.icon-tool svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sketch-toolbar .tool-btn, .sketch-toolbar .soft-btn, .brush-field { border-radius: 4px; }
.brush-field { display: flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 8px; border: 1px solid var(--line); color: #5f5b66; font-size: 10px; font-weight: 800; text-transform: uppercase; background: #fff; }
.brush-field input[type=color] { width: 26px; height: 24px; padding: 1px; border: 0; background: transparent; }
.brush-size-field { min-width: 150px; }
.brush-size-field input { width: 92px; accent-color: var(--violet); }
.save-brush-btn { min-height: 28px; padding: 0 10px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.save-brush-btn.active { border-color: var(--violet); background: #eee8ff; color: #6044ce; }
.save-brush-hint { display: none; color: #d7ccff; font-size: 11px; font-weight: 800; white-space: nowrap; }
.sketch-toolbar.saving-brush .save-brush-hint { display: inline; }
.brush-hotbar-row { display: flex; align-items: center; gap: 7px; }
.brush-hotbar { display: grid; grid-template-columns: repeat(10, 28px); gap: 5px; align-items: center; }
.brush-slot { width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid #d8d4e0; border-radius: 3px; background: #fbfafc; padding: 0; }
.brush-slot:hover { border-color: var(--violet); background: #f5f1ff; }
.brush-slot.empty::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #c6c1cc; }
.sketch-toolbar.saving-brush .brush-slot { border-color: #b8a9ee; box-shadow: 0 0 0 2px rgba(114,85,235,.12); }
.slot-brush { width: var(--slot-size); height: var(--slot-size); max-width: 20px; max-height: 20px; min-width: 7px; min-height: 7px; border: 1px solid rgba(23,23,28,.4); border-radius: 50%; background: var(--slot-color); box-shadow: 0 0 0 1px rgba(255,255,255,.9); }
.sketch-canvas-wrap { width: 100%; height: 100%; position: relative; display: grid; place-items: center; overflow: hidden; background: #d7d5dc; }
#sketchCanvas { width: 1024px; height: 1024px; max-width: 100%; max-height: 100%; aspect-ratio: 1 / 1; margin: 0; display: block; background: #fff; border: 1px solid #c9c5d0; border-radius: 2px; box-shadow: 0 10px 34px rgba(31,28,43,.1); touch-action: none; cursor: none; }
.brush-preview { position: absolute; z-index: 8; pointer-events: none; display: none; width: 12px; height: 12px; border: 1px solid var(--brush-color, #17171c); border-radius: 50%; transform: translate(-50%, -50%); box-shadow: 0 0 0 1px rgba(255,255,255,.95), 0 0 0 2px rgba(23,23,28,.25); }
.brush-preview.show { display: block; }
.sketch-prompt { display: flex; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--line); background: #fff; box-shadow: 0 -4px 16px rgba(31,28,43,.05); }
.sketch-prompt input { flex: 1; width: 100%; border: 0; outline: 0; padding: 0 8px; }
.divider-action { display: grid; place-items: center; background: #fff; border-inline: 1px solid var(--line); z-index: 8; overflow: visible; }
#shapeSketch { width: 58px; height: 58px; border-radius: 50%; padding: 0; position: relative; z-index: 9; white-space: normal; text-align: center; line-height: 1.05; }
.gen-pane { display: grid; place-items: center; background: #ece7df; }
.gen-pane img { max-width: min(78%, 760px); max-height: 76%; object-fit: contain; border-radius: 8px; background: #fff; box-shadow: 0 24px 70px rgba(31,28,43,.17); }
.gen-result { cursor: zoom-in; }
.gen-placeholder { color: #67626e; font: 800 18px Manrope, sans-serif; }
.history-toggle { position: absolute; top: 18px; right: 18px; z-index: 6; width: 42px; height: 42px; padding: 0; }
.gen-wait { position: absolute; inset: 0; display: none; place-items: center; background: rgba(20,18,25,.32); z-index: 5; }
.gen-pane.loading .gen-wait { display: grid; }
.history-sidebar { position: fixed; top: 68px; right: 0; bottom: 0; width: 250px; z-index: 30; transform: translateX(100%); transition: .25s ease; background: #fff; border-left: 1px solid var(--line); box-shadow: -16px 0 45px rgba(31,28,43,.13); padding: 14px; overflow: auto; }
.history-sidebar.open { transform: translateX(0); }
.sketch-sidebar { position: fixed; top: 68px; left: 0; bottom: 0; width: 278px; z-index: 30; transform: translateX(-100%); transition: .25s ease; background: #fff; border-right: 1px solid var(--line); box-shadow: 16px 0 45px rgba(31,28,43,.13); padding: 14px; overflow: auto; }
.sketch-sidebar.open { transform: translateX(0); }
.history-list { display: grid; gap: 10px; }
.history-card { position: relative; }
.history-thumb { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 0; overflow: hidden; background: #fff; }
.history-thumb img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.history-sketch-btn { position: absolute; top: 7px; right: 7px; z-index: 2; width: 31px; height: 31px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 4px; background: rgba(255,255,255,.94); color: #3d3945; padding: 0; box-shadow: 0 4px 12px rgba(31,28,43,.14); }
.history-sketch-btn:hover { background: #17171c; color: #fff; }
.history-sketch-btn svg, .lightbox-sketch svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sketch-list { display: grid; gap: 9px; }
.sketch-list-card { position: relative; }
.sketch-thumb { width: 100%; display: grid; grid-template-columns: 58px minmax(0,1fr); align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 7px; background: #fff; text-align: left; }
.sketch-thumb:hover { background: #f7f5fa; }
.sketch-thumb.active { border-color: var(--violet); background: #f2efff; }
.sketch-thumb img { width: 58px; aspect-ratio: 1; object-fit: cover; border-radius: 6px; background: #f0eef3; border: 1px solid var(--line); }
.sketch-thumb span { min-width: 0; display: grid; gap: 3px; }
.sketch-thumb b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.sketch-thumb small { color: var(--muted); font-size: 10px; }
.delete-sketch-btn { position: absolute; top: 6px; right: 6px; z-index: 2; width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid #ead5da; border-radius: 4px; background: rgba(255,255,255,.94); color: #b33d4c; padding: 0; box-shadow: 0 4px 12px rgba(31,28,43,.12); }
.delete-sketch-btn:hover { background: #b33d4c; color: #fff; border-color: #b33d4c; }
.delete-sketch-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.lightbox { position: fixed; inset: 0; z-index: 80; display: none; place-items: center; background: rgba(16,14,20,.78); padding: 36px; }
.lightbox.open { display: grid; }
.lightbox img { max-width: min(92vw, 980px); max-height: 84vh; object-fit: contain; background: #fff; border-radius: 8px; }
.lightbox button { position: absolute; top: 22px; width: 42px; height: 42px; border: 0; border-radius: 4px; background: #fff; font-weight: 800; }
#closeLightbox { right: 24px; }
.lightbox-sketch { right: 74px; display: grid; place-items: center; color: #3d3945; }
.lightbox-sketch:hover { background: #17171c; color: #fff; }

@media (max-width: 960px) {
  .workspace-grid { grid-template-columns: 1fr; height: auto; }
  .studio-header { height: auto; min-height: 68px; align-items: flex-start; padding: 14px; }
  .studio-nav { justify-content: flex-end; }
  .landing-band { grid-template-columns: 1fr 1fr; margin-top: -34px; }
  .sketch-shell { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 42px minmax(0, 1fr); height: calc(100vh - 68px); }
  .divider-action { border-inline: 0; border-block: 1px solid var(--line); }
}

@media (max-aspect-ratio: 4 / 5) {
  .sketch-shell { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 42px minmax(0, 1fr); height: calc(100vh - 68px); }
  .divider-action { border-inline: 0; border-block: 1px solid var(--line); }
}

@media (max-width: 620px) {
  .landing-band { grid-template-columns: 1fr; }
  .hero-copy h1 { font-size: 56px; }
  .studio-main { width: calc(100% - 18px); }
  .page-title { align-items: flex-start; flex-direction: column; }
  .sketch-toolbar { max-width: calc(100% - 72px); }
  .brush-hotbar-row { flex-wrap: wrap; }
  .brush-hotbar { margin-left: 0; grid-template-columns: repeat(5, 28px); }
}
