:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0b;
  --panel: #121214;
  --panel-soft: #1a1a1e;
  --surface: #202026;
  --line: #303037;
  --line-strong: #464650;
  --text: #ffffff;
  --muted: #a7a7b4;
  --accent: #18a9c8;
  --accent-dark: #55d4ee;
  --accent-soft: #12323a;
  --blue: #18a9c8;
  --danger: #ff5871;
  --shadow: 0 18px 55px rgba(0, 0, 0, .42);
  font-family: Arial, Helvetica, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f5f3;
  --panel: #ffffff;
  --panel-soft: #f6f8f7;
  --surface: #edf2ef;
  --line: #d9dfdc;
  --line-strong: #b9c5bf;
  --text: #151b17;
  --muted: #657269;
  --accent: #078eae;
  --accent-dark: #056f88;
  --accent-soft: #d8f0f5;
  --blue: #078eae;
  --danger: #d43853;
  --shadow: 0 18px 55px rgba(24, 37, 28, .12);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { height: 100vh; overflow: hidden; background: var(--bg); color: var(--text); font-family: inherit; }
button, input { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.topbar {
  height: 82px;
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: 360px 1fr auto;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(18px);
}

.brand { height: 100%; padding: 0 24px; display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; border-right: 1px solid var(--line); }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 900; box-shadow: none; }
.brand > span:last-child, .tool-title > div { display: grid; gap: 2px; }
.brand strong { font-size: 15px; font-weight: 900; letter-spacing: .1em; }
.brand small, .tool-title small { color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .12em; }
.tool-title { justify-self: center; display: flex; align-items: center; gap: 11px; text-align: center; }
.tool-title strong { font-size: 16px; font-weight: 900; letter-spacing: .06em; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: #20c9b9; box-shadow: 0 0 0 6px rgba(32,201,185,.12); }
.top-actions { padding-right: 18px; display: flex; align-items: center; gap: 10px; }
.privacy { height: 38px; padding: 0 14px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); background: var(--panel-soft); font-size: 8px; font-weight: 800; letter-spacing: .08em; }
.privacy i { width: 7px; height: 7px; border-radius: 50%; background: #1bc6a9; }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-soft); cursor: pointer; }

.app-shell { height: calc(100vh - 82px); display: grid; grid-template-columns: 385px minmax(0, 1fr); }
.sidebar { height: 100%; overflow: auto; padding: 22px 20px 80px; background: var(--panel); border-right: 1px solid var(--line); scrollbar-width: thin; scrollbar-color: var(--accent) transparent; }
.intro { padding: 4px 2px 20px; }
.eyebrow { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .12em; }
.eyebrow b { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent-dark); font-size: 9px; }
.intro h1 { max-width: 330px; margin: 15px 0 8px; font-size: 29px; font-weight: 900; line-height: 1.08; letter-spacing: -.05em; }
.intro p { margin: 0; color: var(--muted); font-size: 13px; font-weight: 650; line-height: 1.6; }
.panel-section { padding: 20px 2px; border-top: 1px solid var(--line); }
.section-heading { margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.section-heading > span { color: var(--accent); font-weight: 900; }
.section-heading h2 { flex: 1; margin: 0; font-size: 14px; font-weight: 900; letter-spacing: .055em; text-transform: uppercase; }
.section-heading output { min-width: 28px; height: 24px; padding: 0 8px; display: grid; place-items: center; border-radius: 8px; color: var(--accent-dark); background: var(--accent-soft); font-size: 9px; font-weight: 800; }

.presets { margin-bottom: 10px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.presets button { height: 34px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-soft); color: var(--muted); font-size: 9px; font-weight: 800; cursor: pointer; }
.presets button.active { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent); }
.size-grid { display: grid; grid-template-columns: 1fr 34px 1fr; align-items: end; gap: 7px; }
.size-grid label { display: grid; gap: 6px; }
.size-grid label > span, .range-label label { color: var(--muted); font-size: 11px; font-weight: 850; }
.input-unit { height: 44px; padding: 0 10px 0 13px; display: flex; align-items: center; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-soft); }
.input-unit:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(10,174,164,.1); }
.input-unit input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 13px; font-weight: 800; }
.input-unit b { color: var(--muted); font-size: 9px; }
.swap { width: 34px; height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-soft); color: var(--accent); font-weight: 900; cursor: pointer; }
.page-meta { margin-top: 9px; display: flex; justify-content: space-between; color: var(--muted); font-size: 8px; }

.drop-zone { min-height: 130px; padding: 16px; display: grid; place-items: center; align-content: center; gap: 6px; border: 1.5px dashed color-mix(in srgb, var(--accent) 55%, var(--line)); border-radius: 15px; background: var(--panel-soft); text-align: center; cursor: pointer; transition: .2s; }
.drop-zone:hover, .drop-zone.drag { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 12px 28px rgba(10,174,164,.1); }
.drop-zone input { display: none; }
.upload-icon { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--panel); color: var(--accent); font-size: 18px; font-weight: 900; box-shadow: 0 8px 18px rgba(10,174,164,.1); }
.drop-zone strong { font-size: 14px; font-weight: 900; }
.drop-zone small { color: var(--muted); font-size: 10px; font-weight: 700; }
.drop-zone em { padding: 4px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-dark); font-size: 7px; font-style: normal; font-weight: 800; }
.file-list { margin-top: 10px; display: grid; gap: 7px; }
.file-item { min-width: 0; padding: 7px; display: grid; grid-template-columns: 38px minmax(0,1fr) 28px; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-soft); cursor: pointer; }
.file-item.active { border-color: var(--accent); background: var(--accent-soft); }
.file-item img { width: 38px; height: 38px; object-fit: contain; border-radius: 8px; background: repeating-conic-gradient(#e6eeee 0 25%,#fff 0 50%) 50%/10px 10px; }
.file-item span { min-width: 0; display: grid; gap: 2px; }
.file-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9px; }
.file-item small { color: var(--muted); font-size: 7px; }
.file-item button { width: 28px; height: 28px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.file-item button:hover { background: rgba(216,73,98,.12); color: var(--danger); }
.text-action { width: 100%; margin-top: 8px; border: 0; background: transparent; color: var(--muted); font-size: 8px; font-weight: 800; cursor: pointer; }
.text-action.danger:not(:disabled) { color: var(--danger); }

.range-label { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.range-label.compact { margin-top: 16px; }
.range-label output { padding: 4px 7px; border-radius: 7px; background: var(--accent-soft); color: var(--accent-dark); font-size: 8px; font-weight: 800; }
.range { width: 100%; height: 4px; margin: 13px 0 5px; appearance: none; border-radius: 999px; background: linear-gradient(90deg, var(--accent) var(--progress, 10%), var(--line) var(--progress, 10%)); outline: 0; }
.range::-webkit-slider-thumb { width: 17px; height: 17px; appearance: none; border: 3px solid var(--panel); border-radius: 50%; background: var(--accent); box-shadow: 0 2px 7px rgba(0,0,0,.2); cursor: pointer; }
.range::-moz-range-thumb { width: 12px; height: 12px; border: 3px solid var(--panel); border-radius: 50%; background: var(--accent); cursor: pointer; }
.range-scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 7px; }
.switch-card { margin-top: 17px; padding: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-soft); cursor: pointer; }
.switch-card > span { display: grid; gap: 3px; }
.switch-card strong { font-size: 9px; }
.switch-card small { color: var(--muted); font-size: 7px; }
.switch-card input { display: none; }
.switch-card i { width: 35px; height: 20px; padding: 3px; border-radius: 99px; background: var(--line-strong); transition: .2s; }
.switch-card i::after { content: ""; width: 14px; height: 14px; display: block; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.2); transition: .2s; }
.switch-card input:checked + i { background: var(--accent); }
.switch-card input:checked + i::after { transform: translateX(15px); }
.primary-action { width: 100%; min-height: 58px; margin-top: 12px; padding: 8px 13px; display: flex; align-items: center; gap: 10px; border: 0; border-radius: 13px; background: var(--accent); color: #fff; text-align: left; cursor: pointer; box-shadow: none; }
.primary-action > span:first-child { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: rgba(255,255,255,.15); }
.primary-action > span:last-child { display: grid; gap: 2px; }
.primary-action strong { font-size: 12px; font-weight: 900; }
.primary-action small { opacity: .75; font-size: 7px; }
button:disabled { opacity: .42; cursor: not-allowed; box-shadow: none; }
.selected-panel { border: 1px solid var(--line); border-radius: 14px; padding: 16px; background: var(--panel-soft); }
.selected-name { overflow: hidden; margin: -4px 0 13px; color: var(--accent-dark); font-size: 9px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.secondary-action { width: 100%; height: 38px; margin-top: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 8px; font-weight: 800; cursor: pointer; }
.secondary-action.danger { color: var(--danger); }

.workspace-area { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0,1fr) auto; }
.workspace-toolbar { min-height: 60px; padding: 9px 20px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.view-tabs { padding: 4px; display: flex; gap: 3px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-soft); }
.view-tabs button { min-width: 82px; height: 30px; padding: 0 11px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 8px; font-weight: 800; cursor: pointer; }
.view-tabs button.active { background: var(--panel); color: var(--accent-dark); box-shadow: 0 3px 10px rgba(17,87,84,.08); }
.toolbar-status { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.toolbar-status span, .toolbar-status b { height: 34px; padding: 0 11px; display: flex; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-soft); color: var(--muted); font-size: 8px; }
.toolbar-status span i { width: 6px; height: 6px; border-radius: 50%; background: #a4b8b6; }
.toolbar-status span.ready i { background: #12c6a7; box-shadow: 0 0 0 4px rgba(18,198,167,.12); }
.quick-download { height: 40px; padding: 0 16px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 900; cursor: pointer; }

.stage { min-height: 0; position: relative; overflow: hidden; display: grid; place-items: center; margin: 16px 20px; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); touch-action: none; }
.stage.checker { background-color: #eef4f4; background-image: linear-gradient(45deg,#dfe9e8 25%,transparent 25%),linear-gradient(-45deg,#dfe9e8 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#dfe9e8 75%),linear-gradient(-45deg,transparent 75%,#dfe9e8 75%); background-size: 22px 22px; background-position: 0 0,0 11px,11px -11px,-11px 0; }
.stage.white { background: #e9eeec; }
.stage.black { background: #1c2021; }
:root[data-theme="light"] .stage.black { background: #dce4e0; }
#workspaceCanvas { display: none; position: absolute; left: 50%; top: 50%; max-width: none; transform-origin: center; box-shadow: 0 15px 45px rgba(5,37,35,.18); cursor: grab; }
#workspaceCanvas.visible { display: block; }
#workspaceCanvas.dragging { cursor: grabbing; }
.empty-state { max-width: 570px; padding: 40px 26px; display: grid; justify-items: center; text-align: center; }
.empty-icon { width: 68px; height: 68px; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 22px; background: color-mix(in srgb, var(--panel) 88%, transparent); color: var(--accent); font-size: 28px; box-shadow: 0 14px 32px rgba(10,174,164,.12); }
.empty-state small { margin-top: 18px; color: var(--accent-dark); font-size: 8px; font-weight: 900; letter-spacing: .15em; }
.empty-state h2 { margin: 9px 0 8px; font-size: clamp(22px,3vw,34px); line-height: 1.1; letter-spacing: -.05em; }
.empty-state p { max-width: 510px; margin: 0; color: var(--muted); font-size: 11px; line-height: 1.7; }
.empty-state button { height: 42px; margin-top: 18px; padding: 0 17px; border: 0; border-radius: 11px; background: var(--text); color: var(--panel); font-size: 9px; font-weight: 800; cursor: pointer; }
.canvas-brand { position: absolute; top: 16px; left: 16px; display: flex; align-items: center; gap: 8px; padding: 8px 11px; border: 1px solid rgba(255,255,255,.55); border-radius: 12px; background: rgba(255,255,255,.85); color: #173533; box-shadow: 0 8px 20px rgba(0,0,0,.08); backdrop-filter: blur(12px); }
.canvas-brand b { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: var(--accent); color: #fff; }
.canvas-brand span { display: grid; gap: 1px; }
.canvas-brand strong { font-size: 8px; letter-spacing: .08em; }
.canvas-brand small { color: #69817f; font-size: 6px; letter-spacing: .11em; }
.zoom-controls { position: absolute; right: 15px; bottom: 15px; display: grid; overflow: hidden; border: 1px solid var(--line); border-radius: 13px; background: var(--panel); box-shadow: 0 10px 25px rgba(0,0,0,.1); }
.zoom-controls button { width: 39px; height: 37px; border: 0; border-bottom: 1px solid var(--line); background: transparent; font-size: 15px; cursor: pointer; }
.zoom-controls button:last-child { border-bottom: 0; }
.zoom-controls button:hover { background: var(--accent-soft); color: var(--accent-dark); }

.export-bar { min-height: 86px; padding: 11px 20px; display: flex; align-items: center; gap: 18px; border-top: 1px solid var(--line); background: var(--panel); }
.export-bar > div:first-child { min-width: 240px; display: flex; align-items: center; gap: 11px; }
.export-number { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent-dark); font-size: 9px; font-weight: 900; }
.export-bar > div:first-child > span:last-child { display: grid; gap: 3px; }
.export-bar small { color: var(--muted); font-size: 7px; font-weight: 750; letter-spacing: .08em; }
.export-bar strong { font-size: 9px; }
.layout-summary { margin-left: auto; display: flex; gap: 8px; }
.layout-summary span { min-width: 92px; padding: 8px 10px; display: grid; gap: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-soft); }
.layout-summary b { font-size: 9px; }
#downloadButton { min-width: 280px; height: 62px; padding: 0 15px; display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; border: 0; border-radius: 14px; background: var(--accent); color: #fff; text-align: left; box-shadow: none; cursor: pointer; }
#downloadButton > span:first-child { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: rgba(255,255,255,.14); font-size: 16px; }
#downloadButton > span:nth-child(2) { display: grid; gap: 2px; }
#downloadButton strong { font-size: 12px; font-weight: 900; }
#downloadButton small { color: rgba(255,255,255,.72); font-size: 7px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 100; max-width: 330px; padding: 12px 15px; border-radius: 11px; background: #102b2a; color: #fff; font-size: 9px; font-weight: 800; opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }

@media (max-width: 1100px) {
  .topbar { grid-template-columns: 330px 1fr auto; }
  .app-shell { grid-template-columns: 330px minmax(0,1fr); }
  .privacy, .tool-title small { display: none; }
  .layout-summary { display: none; }
}

@media (max-width: 760px) {
  body { height: auto; min-height: 100vh; overflow: auto; }
  .topbar { height: auto; min-height: 70px; grid-template-columns: 1fr auto; }
  .brand { padding: 12px 15px; border: 0; }
  .brand-mark { width: 38px; height: 38px; }
  .tool-title { grid-column: 1 / -1; grid-row: 2; width: 100%; padding: 9px 14px; justify-content: flex-start; border-top: 1px solid var(--line); text-align: left; }
  .top-actions { grid-column: 2; grid-row: 1; padding-right: 13px; }
  .app-shell { height: auto; display: flex; flex-direction: column; }
  .workspace-area { order: 1; height: 66vh; min-height: 510px; grid-template-rows: auto minmax(0,1fr) auto; }
  .sidebar { order: 2; height: auto; padding: 20px 16px 40px; overflow: visible; border: 0; }
  .workspace-toolbar { padding: 8px 10px; gap: 7px; overflow-x: auto; }
  .view-tabs button { min-width: 68px; padding: 0 8px; }
  .toolbar-status { display: none; }
  .quick-download { margin-left: auto; white-space: nowrap; }
  .stage { margin: 10px; border-radius: 15px; }
  .canvas-brand { top: 10px; left: 10px; transform: scale(.88); transform-origin: top left; }
  .zoom-controls { right: 10px; bottom: 10px; }
  .export-bar { min-height: 78px; padding: 9px 10px; }
  .export-bar > div:first-child { min-width: 0; flex: 1; }
  #downloadButton { min-width: 190px; height: 56px; }
  .intro h1 { max-width: none; }
}

@media (max-width: 470px) {
  .brand strong { font-size: 11px; }
  .brand small { font-size: 6px; }
  .tool-title strong { font-size: 10px; }
  .workspace-area { height: 62vh; min-height: 480px; }
  .view-tabs button { min-width: 56px; font-size: 7px; }
  .quick-download { padding: 0 10px; font-size: 7px; }
  .export-bar > div:first-child { display: none; }
  #downloadButton { width: 100%; min-width: 0; }
  .empty-state { padding: 32px 18px; }
  .empty-state h2 { font-size: 23px; }
  .empty-state p { font-size: 10px; }
}
