/* ==========================================================================
   PhotoEasy — design language mirrored from enesaydogan.com
   Tokens, typography, and component geometry are kept in sync with the site.
   Light is the default; dark follows the system unless the user picks a theme.
   ========================================================================== */

:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --ink: #16181c;
  --muted: #6b7079;
  --faint: #9aa0a8;
  --line: #e6e5e1;
  --line-soft: #efeeeb;
  --accent: #1f5fd8;
  --live: #12a150;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgba(20, 22, 26, .04), 0 8px 24px -14px rgba(20, 22, 26, .18);
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Editor surfaces. The canvas well is recessed well below the page so a white
     photo still separates from it — the common case in light mode. */
  --canvas-bg: #e7e6e2;
  --checker-a: rgba(20, 22, 26, .05);
  --checker-b: rgba(20, 22, 26, .015);
  --canvas-edge: rgba(20, 22, 26, .22);
  --canvas-halo: rgba(20, 22, 26, .3);

  /* A scrim must darken in both themes, so it cannot derive from --ink. */
  --scrim: rgba(20, 22, 26, .45);
  --shadow-lifted: 0 24px 80px -20px rgba(20, 22, 26, .35);
}

:root[data-theme="dark"] {
  --bg: #0e0f11;
  --surface: #151719;
  --ink: #eceef1;
  --muted: #9098a2;
  --faint: #6a7078;
  --line: #26292e;
  --line-soft: #1e2125;
  --accent: #7aa2f7;
  --live: #3ecf7f;
  --danger: #f07178;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 28px -16px rgba(0, 0, 0, .7);

  --canvas-bg: #111315;
  --checker-a: rgba(236, 238, 241, .022);
  --checker-b: rgba(0, 0, 0, .03);
  --canvas-edge: rgba(236, 238, 241, .18);
  --canvas-halo: rgba(0, 0, 0, .5);
  --scrim: rgba(0, 0, 0, .65);
  --shadow-lifted: 0 24px 80px -20px rgba(0, 0, 0, .8);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f11;
    --surface: #151719;
    --ink: #eceef1;
    --muted: #9098a2;
    --faint: #6a7078;
    --line: #26292e;
    --line-soft: #1e2125;
    --accent: #7aa2f7;
    --live: #3ecf7f;
    --danger: #f07178;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 28px -16px rgba(0, 0, 0, .7);

    --canvas-bg: #111315;
    --checker-a: rgba(236, 238, 241, .022);
    --checker-b: rgba(0, 0, 0, .03);
    --canvas-edge: rgba(236, 238, 241, .18);
    --canvas-halo: rgba(0, 0, 0, .5);
    --scrim: rgba(0, 0, 0, .65);
    --shadow-lifted: 0 24px 80px -20px rgba(0, 0, 0, .8);
  }
}

/* Interaction tints derive from --ink, so they invert with the theme for free. */
:root {
  --tint-1: color-mix(in srgb, var(--ink) 4%, transparent);
  --tint-2: color-mix(in srgb, var(--ink) 7%, transparent);
  --accent-soft: color-mix(in srgb, var(--accent) 9%, transparent);
  --accent-line: color-mix(in srgb, var(--accent) 50%, var(--line));
  --glass: color-mix(in srgb, var(--surface) 90%, transparent);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  background: var(--bg);
  text-size-adjust: 100%;
}

body {
  height: 100%;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv05", "ss01";
  transition: background .25s ease, color .25s ease;
}

::selection {
  background: var(--accent);
  color: #fff;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

button,
input,
select,
textarea {
  font: inherit;
}

input,
select,
textarea {
  accent-color: var(--accent);
}

.mono {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ── buttons ─────────────────────────────────── */
button {
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s, transform .15s;
}

button:hover {
  background: var(--tint-1);
  border-color: var(--muted);
  color: var(--ink);
  transform: translateY(-1px);
}

button:active {
  background: var(--tint-2);
  transform: none;
}

button:disabled {
  background: var(--surface);
  border-color: var(--line-soft);
  color: var(--faint);
  opacity: .5;
  transform: none;
  cursor: not-allowed;
}

button:disabled:hover {
  background: var(--surface);
  border-color: var(--line-soft);
  color: var(--faint);
  transform: none;
}

/* ── icon buttons ────────────────────────────── */
/* Square, label-less, and quiet until hovered — used by the layer panel header
   and each layer card's action bar. */
.icon-btn {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
}

.icon-btn svg {
  width: 15px;
  height: 15px;
}

.icon-btn:hover {
  background: var(--tint-1);
  border-color: var(--line);
  color: var(--ink);
  transform: none;
}

.icon-btn:disabled,
.icon-btn:disabled:hover {
  background: transparent;
  border-color: transparent;
  color: var(--faint);
  opacity: .35;
}

/* State: the control is engaged (locked, masked). */
.icon-btn.is-on {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
}

/* State: the layer is hidden — the icon should read as switched off. */
.icon-btn.is-off {
  color: var(--faint);
}

.icon-btn.is-danger:hover {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  color: var(--danger);
}

/* The primary action in its group (Export) stays tinted so the icon-only bar
   still has one obvious destination. */
.icon-btn.is-accent {
  color: var(--accent);
}

.icon-btn.is-accent:hover {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
}

/* Toolbar icons run slightly larger than the layer panel's. */
.actions .icon-btn {
  width: 30px;
  height: 30px;
  min-height: 30px;
}

.actions .icon-btn svg {
  width: 16px;
  height: 16px;
}

/* ── toolbar ─────────────────────────────────── */
.toolbar {
  position: relative;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 60px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(180%) blur(14px);
}

.editor-brand {
  display: flex;
  align-items: baseline;
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 15px;
  line-height: 1;
  letter-spacing: -.02em;
}

.editor-brand-name {
  font-weight: 600;
  color: var(--ink);
}

.editor-brand-context {
  margin-left: 5px;
  font-weight: 400;
  color: var(--faint);
}

.toolbar-rule {
  flex: 0 0 auto;
  width: 1px;
  height: 22px;
  background: var(--line);
}

.actions {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 7px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.actions::-webkit-scrollbar {
  display: none;
}

/* No padding here: the toolbar is icon buttons now, and a blanket padding
   outranks .icon-btn's own, squeezing the content box until the glyph
   overflows off-centre. The remaining text buttons (zoom) set their own. */
.actions button {
  flex: 0 0 auto;
}

/* Related actions sit tight together; the rules between groups do the
   separating, so the bar reads in chunks rather than as one long run. */
.action-group {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 2px;
}

/* ── import options popover ──────────────────── */
.menu-anchor {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 2px;
}

.caret-btn {
  width: 18px;
}

.caret-btn svg {
  width: 12px;
  height: 12px;
}

/* Fixed, and placed by JS: .actions is a horizontal scroll container, which
   clips (and swallows clicks on) any absolutely positioned child. */
.toolbar-menu {
  position: fixed;
  z-index: 400;
  min-width: 220px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-lifted);
}

.toolbar-menu[hidden] {
  display: none;
}

.menu-check {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 7px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.35;
  cursor: pointer;
}

.menu-check:hover {
  background: var(--tint-1);
  color: var(--ink);
}

.menu-check input {
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  cursor: pointer;
}

/* ── segmented controls (zoom, language) ─────── */
.zoom-controls,
.language-switch {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 2px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
}

.zoom-controls button,
.language-switch button {
  min-height: 28px;
  padding: 0 8px;
  border-color: transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--faint);
}

.zoom-controls button:hover,
.language-switch button:hover {
  background: var(--tint-1);
  border-color: transparent;
  color: var(--ink);
  transform: none;
}

.language-switch button {
  min-width: 34px;
  font: 600 10px/1 var(--mono);
  letter-spacing: .08em;
}

.language-switch button.is-active {
  background: var(--tint-2);
  color: var(--ink);
}

.zoom-controls button {
  font-size: 12px;
}

.zoom-readout {
  min-width: 54px;
  padding: 0 6px;
  text-align: center;
  color: var(--faint);
  font: 500 11.5px/1 var(--mono);
  letter-spacing: .04em;
}

/* ── theme toggle ────────────────────────────── */
.theme {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
}

.theme:hover {
  background: var(--tint-1);
  color: var(--ink);
  border-color: var(--muted);
  transform: none;
}

.theme svg {
  width: 15px;
  height: 15px;
}

.theme .moon {
  display: none;
}

:root[data-theme="dark"] .theme .sun {
  display: none;
}

:root[data-theme="dark"] .theme .moon {
  display: block;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme .sun {
    display: none;
  }

  :root:not([data-theme="light"]) .theme .moon {
    display: block;
  }
}

/* One auto margin on the cluster, so language and theme end up flush right
   rather than trailing the editing actions. */
.toolbar-right {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 10px;
  margin-left: auto;
  padding-left: 4px;
}

.canvas-size {
  flex: 0 0 auto;
  color: var(--faint);
  font: 500 11.5px/1 var(--mono);
  letter-spacing: .05em;
  text-transform: uppercase;
}

/* ── layout ──────────────────────────────────── */
.main {
  display: flex;
  height: calc(100dvh - 60px);
  background: var(--bg);
}

/* ── tool rail ───────────────────────────────── */
.left-tools {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 58px;
  width: 58px;
  gap: 6px;
  padding: 12px 8px;
  border-right: 1px solid var(--line);
  background: var(--bg);
}

.left-tools .tool {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.left-tools .tool svg {
  display: block;
  width: 20px;
  height: 20px;
}

.left-tools .tool:hover {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
  transform: none;
}

.left-tools .tool.active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
  transform: none;
}

/* ── canvas ──────────────────────────────────── */
.canvas-area {
  display: flex;
  flex: 1;
  min-width: 0;
  padding: 18px;
  background: var(--bg);
}

.viewport {
  position: relative;
  display: flex;
  flex: 1;
  min-width: 0;
  align-items: stretch;
  justify-content: stretch;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    repeating-conic-gradient(from 45deg, var(--checker-a) 0 25%, var(--checker-b) 0 50%) 50%/24px 24px,
    var(--canvas-bg);
  cursor: grab;
}

.viewport:active {
  cursor: grabbing;
}

#viewport-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
}

#view {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: transparent;
  touch-action: none;
}

/* ── sidebar ─────────────────────────────────── */
.sidebar,
.layers {
  display: flex;
  flex-direction: column;
  flex: 0 0 320px;
  width: 320px;
  gap: 12px;
  padding: 12px;
  border-left: 1px solid var(--line);
  background: var(--bg);
}

.sidebar-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color .18s ease, box-shadow .18s ease;
}

.sidebar-panel.is-primary {
  border-color: color-mix(in srgb, var(--muted) 45%, var(--line));
  box-shadow: var(--shadow);
}

.tool-props {
  display: flex;
  flex-direction: column;
  height: 32vh;
  gap: 10px;
  padding: 14px;
}

.tool-props-title,
.layers-title {
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: -.01em;
}

.tool-props-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 10px;
  padding-right: 6px;
  overflow: auto;
}

.prop-block {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-soft);
}

.prop-block:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.prop-title {
  color: var(--faint);
  font-size: 11.5px;
}

.prop-help {
  color: var(--faint);
  font-size: 11.5px;
  line-height: 1.5;
}

.prop-note {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.prop-control-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.prop-control-row input[type="range"] {
  flex: 1;
}

.prop-value {
  min-width: 42px;
  text-align: right;
  color: var(--muted);
  font: 500 11.5px/1 var(--mono);
}

/* ── history ─────────────────────────────────── */
.history-panel {
  display: flex;
  flex-direction: column;
  min-height: 170px;
  max-height: 220px;
  gap: 10px;
  padding: 12px;
}

.history-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-soft);
}

.history-meta,
.history-entry-step {
  color: var(--faint);
  font: 500 10.5px/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.history-list {
  display: flex;
  flex-direction: column;
  padding-right: 2px;
  overflow: auto;
}

.history-entry {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 9px 8px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.history-entry:hover {
  background: var(--tint-1);
  border-color: var(--line-soft);
  transform: none;
}

.history-entry.active {
  background: var(--accent-soft);
  border-color: var(--line-soft);
  color: var(--ink);
  box-shadow: inset 2px 0 0 var(--accent);
  cursor: default;
}

.history-entry.future {
  opacity: .5;
}

.history-entry-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-entry-current,
.layer-badge {
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--faint);
  font: 500 9.5px/1.5 var(--mono);
  letter-spacing: .06em;
  text-transform: uppercase;
}

/* ── layers ──────────────────────────────────── */
.layers-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 12px;
  overflow: hidden;
}

/* Title and its actions share one line: the icons made the old stacked button
   grid unnecessary, and the labels no longer have to fit a 3-column grid. */
.layers-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-soft);
}

.layers-header-top {
  display: flex;
  flex: 0 0 auto;
  gap: 4px;
}

#layers-list {
  flex: 1;
  min-height: 0;
  padding-right: 2px;
  list-style: none;
  overflow: auto;
}

#layers-list li {
  margin-bottom: 8px;
}

#layers-list li.dragging {
  opacity: .45;
}

#layers-list li.drop-before .layer-row {
  box-shadow: inset 0 2px 0 var(--accent);
}

#layers-list li.drop-after .layer-row {
  box-shadow: inset 0 -2px 0 var(--accent);
}

/* Three flat rows: identity, settings, actions. */
.layer-row {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: transparent;
  transition: background .18s, border-color .18s;
}

.layer-row:hover {
  background: var(--tint-1);
  border-color: var(--line);
}

.layer-row.active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.layer-thumb {
  width: 56px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--canvas-bg);
  object-fit: cover;
}

/* row 1 — identity */
.layer-head {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.layer-head-text {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.layer-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}

/* row 2 — settings. The blend column is fixed rather than auto so a long mode
   name ("Kaplama") cannot squeeze the opacity slider. */
.layer-op-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 84px;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.layer-opacity-value {
  min-width: 34px;
  text-align: right;
  color: var(--faint);
  font: 500 11.5px/1 var(--mono);
}

/* row 3 — actions */
.layer-actions {
  display: flex;
  align-items: center;
  gap: 3px;
}

.layer-actions-spacer {
  flex: 1;
}

.layer-grip {
  cursor: grab;
}

.layer-grip:active {
  cursor: grabbing;
}

/* ── inputs ──────────────────────────────────── */
.layer-blend,
.tool-props input[type="number"],
.tool-props select,
.layer-name-input,
.cp-hex,
.form-group input[type="number"] {
  width: 100%;
  min-width: 0;
  min-height: 32px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  color: var(--ink);
  font-size: 12px;
}

.layer-blend,
.tool-props select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 28px;
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='12' height='12'><path d='M7 10l5 5 5-5' fill='none' stroke='%236b7079' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  cursor: pointer;
}

:root[data-theme="dark"] .layer-blend,
:root[data-theme="dark"] .tool-props select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='12' height='12'><path d='M7 10l5 5 5-5' fill='none' stroke='%239098a2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .layer-blend,
  :root:not([data-theme="light"]) .tool-props select {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='12' height='12'><path d='M7 10l5 5 5-5' fill='none' stroke='%239098a2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  }
}

.layer-name-input:focus,
.tool-props input:focus,
.tool-props select:focus,
.cp-hex:focus,
.form-group input[type="number"]:focus,
.layer-blend:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.tool-props input[type="color"],
.left-tools input[type="color"] {
  width: 44px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  cursor: pointer;
}

/* ── range input ─────────────────────────────── */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  border: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 3px rgba(20, 22, 26, .25);
  cursor: pointer;
  transition: transform .15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.12);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 3px rgba(20, 22, 26, .25);
  cursor: pointer;
}

input[type="range"]::-moz-range-track {
  height: 3px;
  border-radius: 999px;
  background: var(--line);
}

/* ── color picker ────────────────────────────── */
.color-picker {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 4px 0;
}

.cp-sv {
  width: 100%;
  height: 140px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: crosshair;
  touch-action: none;
}

.cp-hue {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 12px;
  border-radius: 6px;
}

.cp-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cp-hex {
  flex: 1;
  font-family: var(--mono);
}

.cp-swatch {
  flex: 0 0 auto;
  width: 36px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.cp-recent {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cp-recent .sw {
  width: 20px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}

/* ── canvas overlays ─────────────────────────── */
.selection-rect {
  position: absolute;
  z-index: 28;
  border: 1px dashed var(--accent);
  border-radius: 2px;
  background: var(--accent-soft);
  pointer-events: none;
}

.selection-rect.is-adjustable {
  border-style: solid;
  box-shadow: 0 0 0 1px var(--glass);
}

.selection-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 1px solid var(--accent);
  border-radius: 2px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgb(0 0 0 / .18);
}

.handle-nw { left: 0; top: 0; transform: translate(-50%, -50%); }
.handle-n { left: 50%; top: 0; transform: translate(-50%, -50%); }
.handle-ne { right: 0; top: 0; transform: translate(50%, -50%); }
.handle-e { right: 0; top: 50%; transform: translate(50%, -50%); }
.handle-se { right: 0; bottom: 0; transform: translate(50%, 50%); }
.handle-s { left: 50%; bottom: 0; transform: translate(-50%, 50%); }
.handle-sw { left: 0; bottom: 0; transform: translate(-50%, 50%); }
.handle-w { left: 0; top: 50%; transform: translate(-50%, -50%); }

.drop-overlay {
  position: absolute;
  inset: 16px;
  z-index: 45;
  display: none;
  place-items: center;
  padding: 24px;
  border: 1px dashed var(--accent);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.viewport.is-file-drag .drop-overlay {
  display: grid;
}

.canvas-onboarding {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 30;
  display: none;
  flex-direction: column;
  gap: 5px;
  max-width: 360px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: saturate(180%) blur(14px);
}

.canvas-onboarding.visible {
  display: flex;
}

.canvas-onboarding strong {
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -.01em;
}

.canvas-onboarding span {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.canvas-hud {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 16px;
  z-index: 25;
  display: flex;
  flex-direction: column;
  gap: 9px;
  pointer-events: none;
}

.canvas-status-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
}

.status-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: min(420px, 100%);
}

.tool-hint,
.history-label,
.status-toast {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--glass);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
  box-shadow: var(--shadow);
  backdrop-filter: saturate(180%) blur(14px);
}

.tool-hint {
  align-self: flex-start;
  max-width: min(760px, 100%);
}

.status-toast.is-info {
  color: var(--ink);
}

.status-toast.is-warning {
  border-color: color-mix(in srgb, #d99a2b 42%, var(--line));
  color: #b47a15;
}

.status-toast.is-error {
  border-color: color-mix(in srgb, var(--danger) 42%, var(--line));
  color: var(--danger);
}

:root[data-theme="dark"] .status-toast.is-warning {
  color: #f0c36a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .status-toast.is-warning {
    color: #f0c36a;
  }
}

.cursor-preview {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 22;
  display: none;
  border: 1px solid var(--ink);
  border-radius: 999px;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--bg) 70%, transparent);
  pointer-events: none;
}

.cursor-preview.visible {
  display: block;
}

/* ── text editor ─────────────────────────────── */
.text-editor-shell {
  position: fixed;
  z-index: 1400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: saturate(180%) blur(14px);
}

.text-editor-input {
  display: block;
  border: none;
  outline: none;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: var(--ink);
  caret-color: var(--ink);
  white-space: pre-wrap;
}

.text-editor-input::selection {
  background: var(--accent);
  color: #fff;
}

.text-editor-meta {
  color: var(--faint);
  font: 500 10.5px/1 var(--mono);
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* ── modal ───────────────────────────────────── */
.modal {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  display: none;
  width: 100%;
  height: 100%;
  background: var(--scrim);
  backdrop-filter: blur(4px);
}

.modal-content {
  width: 400px;
  max-width: 90%;
  margin: 10% auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-lifted);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.02em;
}

.close-modal {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.close-modal:hover {
  background: var(--tint-1);
  color: var(--ink);
  transform: none;
}

.modal-body {
  padding: 18px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12.5px;
}

.form-group input[type="number"] {
  font-size: 13px;
}

.form-group input[type="checkbox"] {
  margin-right: 8px;
  vertical-align: middle;
}

.form-group label[for="maintain-aspect"] {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}

.btn-primary {
  padding: 0 18px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  border-color: color-mix(in srgb, var(--accent) 88%, var(--ink));
  background: color-mix(in srgb, var(--accent) 88%, var(--ink));
  color: #fff;
}

.btn-secondary {
  padding: 0 18px;
}

/* ── scrollbars ──────────────────────────────── */
.tool-props-content::-webkit-scrollbar,
#layers-list::-webkit-scrollbar,
.history-list::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.tool-props-content::-webkit-scrollbar-thumb,
#layers-list::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--line);
}

.tool-props-content::-webkit-scrollbar-track,
#layers-list::-webkit-scrollbar-track,
.history-list::-webkit-scrollbar-track {
  background: transparent;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* ── responsive ──────────────────────────────── */
@media (max-width: 1100px) {
  .toolbar {
    height: auto;
    min-height: 60px;
    padding: 8px 12px;
  }

  .editor-brand-context,
  .toolbar-rule {
    display: none;
  }

  .actions {
    flex: 1;
  }

  .canvas-size {
    display: none;
  }

  .sidebar,
  .layers {
    flex-basis: 280px;
    width: 280px;
  }

  .canvas-status-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .status-stack {
    align-items: flex-start;
  }
}

@media (max-width: 820px) {
  body,
  html {
    height: auto;
    min-height: 100%;
  }

  .toolbar {
    position: sticky;
    top: 0;
    min-height: 58px;
    gap: 10px;
    padding: 10px;
  }

  .main {
    flex-direction: column;
    height: auto;
    min-height: calc(100dvh - 58px);
    gap: 10px;
    padding: 10px;
  }

  .left-tools {
    order: 2;
    flex: 0 0 auto;
    width: 100%;
    flex-direction: row;
    justify-content: flex-start;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .left-tools::-webkit-scrollbar {
    display: none;
  }

  .canvas-area {
    order: 1;
    min-height: 44dvh;
    padding: 0;
  }

  .viewport {
    min-height: 44dvh;
  }

  .canvas-onboarding {
    top: 16px;
    left: 16px;
    right: 16px;
    max-width: none;
  }

  .canvas-hud {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .tool-hint {
    max-width: none;
  }

  .status-stack {
    width: 100%;
    max-width: none;
  }

  .status-toast {
    width: 100%;
  }

  .sidebar,
  .layers {
    order: 3;
    flex-basis: auto;
    width: 100%;
    gap: 10px;
    padding: 0;
    border-left: 0;
    background: transparent;
  }

  .tool-props,
  .history-panel,
  .layers-panel {
    height: auto;
    min-height: 0;
    max-height: none;
  }

  .tool-props {
    min-height: 190px;
  }
}

@media (pointer: coarse) {
  button,
  input,
  select {
    min-height: 42px;
  }

  .left-tools .tool {
    width: 44px;
    height: 44px;
    min-height: 44px;
  }

  .selection-handle {
    width: 14px;
    height: 14px;
  }

  .viewport {
    overscroll-behavior: contain;
  }
}

@media (max-width: 560px) {
  .toolbar {
    display: flex;
    flex-wrap: wrap;
    padding: 9px 10px;
  }

  /* flex-basis, not width: the `flex: 1` above sets basis 0, so the row would
     shrink to fit instead of wrapping onto its own line. */
  .actions {
    order: 3;
    flex: 1 0 100%;
  }

  .main {
    gap: 8px;
    padding: 8px;
  }

  .left-tools {
    gap: 5px;
    padding: 7px;
  }

  .left-tools .tool {
    width: 38px;
    height: 38px;
    min-height: 38px;
    border-radius: 7px;
  }

  .viewport {
    min-height: 38dvh;
  }

  .tool-props,
  .history-panel,
  .layers-panel {
    padding: 11px;
    border-radius: 12px;
  }

  .layer-head {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .layer-thumb {
    width: 48px;
    height: 36px;
  }
}
