:root {
  --bg: #f4f3f1;
  --panel: #ffffff;
  --line: #e5e2de;
  --text: #1d1b19;
  --muted: #6c6660;
  --accent: #e4572e;
  --accent-ink: #ffffff;
  --danger: #c4372b;
  --input: #ffffff;
  --stage: #e9e7e4;
  --overlay: rgba(20, 18, 16, .55);
  --shadow: 0 18px 50px rgba(0, 0, 0, .18);
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236c6660' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  color-scheme: light;
  --peek: 172px;   /* resting height of the mobile settings drawer; matches PEEK in sheet.js */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121110;
    --panel: #1a1917;
    --line: #2d2a27;
    --text: #ece9e5;
    --muted: #a19a93;
    --accent: #ff6a3d;
    --danger: #ff6b5e;
    --input: #23211f;
    --stage: #0d0c0b;
    --overlay: rgba(0, 0, 0, .65);
    --shadow: 0 18px 50px rgba(0, 0, 0, .5);
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23a19a93' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121110; --panel: #1a1917; --line: #2d2a27; --text: #ece9e5; --muted: #a19a93;
  --accent: #ff6a3d; --danger: #ff6b5e; --input: #23211f; --stage: #0d0c0b;
  --overlay: rgba(0, 0, 0, .65); --shadow: 0 18px 50px rgba(0, 0, 0, .5);
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23a19a93' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: 100vh; }
aside { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; scrollbar-width: none; }
aside::-webkit-scrollbar { display: none; }   /* still scrolls; the bar is just hidden */
main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* brand */
.brand { padding: 14px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 28px; height: 28px; flex: none; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; flex: 1; }

/* sidebar groups */
.group { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.group h2 { font-size: 13px; font-weight: 600; margin: 0 0 12px; }
.note { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.credit { margin-top: auto; padding: 16px 20px; color: var(--muted); font-size: 12px; }

.row { display: flex; gap: 8px; align-items: flex-end; }
.row > * { flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label, .lbl { font-size: 12.5px; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* inputs */
select, input[type="number"], input[type="text"], input[type="email"], input[type="password"] {
  width: 100%; padding: 8px 10px; background: var(--input);
  border: 1px solid var(--line); border-radius: 6px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
input:disabled { opacity: .5; }
select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  padding-right: 34px; text-overflow: ellipsis;
  background-image: var(--chevron);
  background-repeat: no-repeat; background-position: right 12px center; background-size: 12px;
}
select:hover { border-color: var(--muted); }
select option, select optgroup { background: var(--panel); color: var(--text); }

/* buttons */
.btn {
  padding: 8px 12px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--input); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn.small { padding: 5px 10px; font-size: 13px; flex: none; }
.btn.block { width: 100%; }
.btn.with-icon { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.btn-icon { flex: none; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: inherit; text-decoration: underline; text-underline-offset: 2px; }
.icon-btn { background: none; border: 0; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.icon-btn:hover { color: var(--text); }
.theme-btn { width: 32px; height: 32px; padding: 0; display: grid; place-items: center; border-radius: 6px; flex: none; }
.theme-btn:hover { background: var(--input); }
.theme-btn .i-moon { display: none; }
.theme-btn.is-light .i-sun { display: none; }
.theme-btn.is-light .i-moon { display: block; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--input); padding: 7px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }
.field .seg, .seg.full { display: flex; }
.field .seg button, .seg.full button { flex: 1; }

.slider { margin-bottom: 12px; }
.slider .top { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.slider .top output { color: var(--text); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 4px 0 0; }

.check { display: flex; gap: 8px; align-items: center; margin-top: 10px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.preset-actions { display: flex; gap: 8px; margin-top: 12px; }
.preset-actions .btn { flex: 1; }
.preset-form { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }

.warn { color: var(--accent); font-size: 12.5px; margin-top: 8px; display: none; }
.warn.show { display: block; }

/* stage */
.toolbar {
  display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.toolbar-end { display: flex; gap: 8px; align-items: center; }
.toolbar .info { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.toolbar .info b { color: var(--text); font-weight: 500; }
.cardbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel)); font-size: 13px;
}

.stage {
  position: relative; flex: 1; min-height: 0; overflow: auto; background: var(--stage);
  display: grid; place-items: center; padding: 24px;
}
.stage.zoomed { place-items: start; }

.drop {
  width: min(520px, 100%); padding: 44px 24px; text-align: center; cursor: pointer;
  border: 2px dashed var(--line); border-radius: 12px; background: var(--panel);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.drop img { margin-bottom: 10px; }
.drop:hover, .drop.over { border-color: var(--accent); }
.drop strong { font-size: 16px; }
.drop span { color: var(--muted); }

.frame { position: relative; display: none; touch-action: none; user-select: none; box-shadow: var(--shadow); background: #fff; }
.frame canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.frame.px canvas { image-rendering: pixelated; }
.frame.compare { cursor: ew-resize; }
.split { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--accent); pointer-events: none; }
.split::after {
  content: ""; position: absolute; top: 50%; left: 50%; width: 26px; height: 26px; margin: -13px 0 0 -13px;
  border-radius: 50%; background: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.tag { position: absolute; top: 10px; padding: 2px 8px; border-radius: 4px; font-size: 12px; background: rgba(0,0,0,.6); color: #fff; pointer-events: none; }
.tag.l { left: 10px; } .tag.r { right: 10px; }
.busy { position: absolute; top: 12px; right: 16px; font-size: 12.5px; color: var(--muted); display: none; }
.busy.show { display: block; }

/* modals */
.modal { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; padding: 16px; z-index: 50; outline: none; }
.modal-box {
  width: min(420px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; box-shadow: var(--shadow);
}
.modal-box.wide { width: min(900px, 100%); display: flex; flex-direction: column; gap: 14px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-box.wide .modal-head { margin-bottom: 0; }
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 600; }
.confirm-box { width: min(400px, 100%); }
.confirm-box h3 { margin: 0 0 8px; font-size: 17px; font-weight: 600; }
.confirm-box p { margin: 0 0 20px; color: var(--muted); }
.modal-foot { display: flex; gap: 8px; align-items: center; }
.modal-foot .spacer { flex: 1; }
#authTabs { margin-bottom: 16px; }
.link.center { align-self: center; }
.note.flush, p.flush { margin: 0; }
.auth-reason { margin: -6px 0 14px; color: var(--muted); }
.profile-email { font-weight: 600; margin: 0; word-break: break-all; }
.danger-zone { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.error { color: var(--danger); font-size: 13px; margin: 12px 0 0; min-height: 0; }
.error:empty { display: none; }

.crop-area { height: min(60vh, 560px); background: var(--stage); border-radius: 8px; overflow: hidden; }
.crop-area img { display: block; max-width: 100%; }
.crop-controls { display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: end; }
.crop-controls .field .seg { display: inline-flex; }

/* icon segments keep overflow visible so tooltips can show */
.seg.icons { overflow: visible; }
.seg.icons button { width: 44px; height: 38px; padding: 0; display: grid; place-items: center; }
.seg.icons button:first-child { border-radius: 5px 0 0 5px; }
.seg.icons button:last-child { border-radius: 0 5px 5px 0; }
.seg.icons svg { pointer-events: none; }

/* hover tooltips */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 8px);
  transform: translate(-50%, 4px); white-space: nowrap; pointer-events: none;
  background: var(--text); color: var(--panel); font-size: 12px; font-weight: 500; line-height: 1.3;
  padding: 5px 8px; border-radius: 5px; opacity: 0; transition: opacity .12s, transform .12s; z-index: 5;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }
#cropDialog[data-shape="ellipse"] .cropper-view-box,
#cropDialog[data-shape="ellipse"] .cropper-face { border-radius: 50%; }
#cropDialog[data-shape="rounded"] .cropper-view-box,
#cropDialog[data-shape="rounded"] .cropper-face { border-radius: var(--crop-radius, 0); }
.radius-field { min-width: 240px; flex: 1; }
.radius-row { display: flex; align-items: center; gap: 12px; height: 38px; }
.radius-row input[type="range"] { flex: 1; margin: 0; }
.unit-input { position: relative; width: 104px; flex: none; }
.unit-input input { padding-right: 34px; -moz-appearance: textfield; }
.unit-input input::-webkit-inner-spin-button, .unit-input input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.unit-input span { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; pointer-events: none; }
.cropper-view-box { outline-color: var(--accent); }
.cropper-line, .cropper-point { background-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--panel); padding: 10px 16px; border-radius: 8px; font-size: 13.5px;
  box-shadow: var(--shadow); transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.sheet-handle { display: none; }

@media (max-width: 860px) {
  html, body { overflow: hidden; }
  .app { display: block; height: 100dvh; }
  main { height: calc(100dvh - var(--peek)); }

  /* settings drawer */
  aside {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: var(--peek);
    border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 32px rgba(0, 0, 0, .22); overscroll-behavior: contain;
    transition: height .28s cubic-bezier(.2, .8, .2, 1);
    padding-bottom: env(safe-area-inset-bottom);
  }
  aside.dragging { transition: none; }
  .sheet-grab { position: sticky; top: 0; z-index: 2; background: var(--panel); border-radius: 16px 16px 0 0; touch-action: none; cursor: grab; }
  .sheet-handle { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; }
  .sheet-grab .brand { padding-top: 8px; padding-bottom: 12px; }

  .toolbar { padding: 8px 12px; gap: 8px; }
  .toolbar .info { order: 3; width: 100%; text-align: center; }
  .seg button { padding: 7px 10px; }
  #btnStartOver .btn-label { display: none; }
  #segZoom { display: none; }        /* phones always fit the image to the screen */
  #btnStartOver { padding: 8px 10px; }
  .stage { min-height: 0; padding: 12px; }
  .group, .brand, .credit { padding-left: 16px; padding-right: 16px; }
  .crop-controls { grid-template-columns: minmax(0, 1fr); }
  .cardbar { flex-direction: column; align-items: flex-start; }
}
