:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #12151b;
  --muted: #646c78;
  --line: #e2e5ea;
  --line-strong: #cbd0d8;
  --ink: #12151b;
  --accent: #16a35a;
  --accent-strong: #0f8a4b;
  --accent-soft: #e6f6ed;
  --soft: #eff1f4;
  --success: #12703e;
  --error: #b42323;
  --warn: #8a5a00;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .05);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(22, 163, 90, .09), transparent 60%),
    radial-gradient(900px 400px at -10% 0%, rgba(59, 130, 246, .06), transparent 60%),
    var(--bg);
  min-height: 100vh;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
code { background: #e9ecf0; padding: 2px 6px; border-radius: 6px; font-size: .92em; }
kbd {
  display: inline-block; min-width: 1.5em; padding: 1px 5px; margin-left: 2px;
  border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px;
  background: #fff; color: var(--muted); font: 600 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center; vertical-align: 1px;
}

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; backdrop-filter: saturate(1.4) blur(10px); background: rgba(243, 244, 246, .78); border-bottom: 1px solid rgba(226, 229, 234, .8); }
.topbar-inner { width: min(1180px, calc(100% - 32px)); margin: 0 auto; height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; letter-spacing: -.01em; }
.brand-mark { width: 22px; height: 22px; color: var(--accent); filter: drop-shadow(0 2px 4px rgba(22, 163, 90, .35)); }
.privacy-pill { display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 12.5px; font-weight: 650; }

/* ---------- Hero / drop zone ---------- */
.shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 44px 0 120px; }
.hero { max-width: 760px; margin-bottom: 26px; }
.eyebrow { margin: 0 0 10px; font-size: 12px; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-strong); }
h1 { margin: 0; font-size: clamp(32px, 5vw, 54px); line-height: 1.04; letter-spacing: -.04em; }
.lede { margin: 16px 0 0; color: var(--muted); font-size: 17px; line-height: 1.55; }
body.loaded .hero { display: none; }

.drop-zone {
  border: 1.5px dashed #b7bec9; border-radius: var(--radius);
  background: rgba(255, 255, 255, .7);
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease, transform .15s ease;
}
.drop-full { min-height: 260px; display: grid; place-items: center; align-content: center; text-align: center; padding: 36px; }
.drop-zone.dragging { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 4px var(--accent-soft); }
.drop-icon { width: 54px; height: 54px; border-radius: 16px; background: var(--accent-soft); color: var(--accent-strong); display: grid; place-items: center; margin-bottom: 14px; }
.drop-zone h2 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.drop-full p { margin: 6px 0 20px; color: var(--muted); }
.drop-compact { display: none; align-items: center; gap: 14px; padding: 10px 12px; }
body.loaded .drop-zone { border-style: solid; border-color: var(--line); background: var(--card); box-shadow: var(--shadow); }
body.loaded .drop-full { display: none; }
body.loaded .drop-compact { display: flex; }
.thumb { width: 48px; height: 48px; border-radius: 10px; border: 1px solid var(--line); background: var(--soft); flex: none; }
.compact-text { display: grid; gap: 2px; min-width: 0; flex: 1; }
.compact-text strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compact-text span { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }

.drop-overlay { position: fixed; inset: 0; z-index: 50; display: none; place-items: center; background: rgba(15, 23, 20, .45); backdrop-filter: blur(2px); pointer-events: none; }
.drop-overlay-inner { display: grid; justify-items: center; gap: 6px; padding: 30px 44px; border-radius: 22px; background: #fff; color: var(--accent-strong); border: 2px dashed var(--accent); font-weight: 700; box-shadow: 0 20px 50px rgba(0, 0, 0, .2); }
.drop-overlay-inner p { margin: 0; color: var(--text); }
body.page-dragging.loaded .drop-overlay { display: grid; }

/* ---------- Buttons ---------- */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 11px; border: 1px solid transparent; min-height: 40px; padding: 0 15px; font-weight: 700; font-size: 14px; transition: background .12s ease, border-color .12s ease, transform .06s ease, box-shadow .12s ease; }
.button:active:not(:disabled) { transform: translateY(1px); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button:focus-visible, .seg:focus-visible, .tone:focus-visible, select:focus-visible { outline: 3px solid rgba(22, 163, 90, .35); outline-offset: 2px; }
.button.primary { background: var(--accent); color: #fff; box-shadow: 0 1px 0 rgba(255, 255, 255, .2) inset, 0 4px 12px rgba(22, 163, 90, .25); }
.button.primary:hover:not(:disabled) { background: var(--accent-strong); }
.button.secondary { background: #fff; border-color: var(--line-strong); color: var(--text); }
.button.secondary:hover:not(:disabled) { border-color: #9aa3af; }
.button.subtle { background: var(--soft); color: var(--text); }
.button.subtle:hover:not(:disabled) { background: #e5e8ec; }
.button.small { min-height: 32px; padding: 0 11px; font-size: 12.5px; border-radius: 9px; }
.button.large { min-height: 50px; font-size: 15px; border-radius: 13px; }

/* ---------- Workspace ---------- */
.workspace { margin-top: 18px; }
.preview-grid, .controls-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.controls-grid { margin-top: 18px; align-items: start; }
.stack { display: grid; gap: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.preview-card { padding: 18px; }
.card-heading { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 14px; min-height: 44px; }
.card h2 { margin: 0; font-size: 17px; letter-spacing: -.015em; display: flex; align-items: center; gap: 10px; }
.card h3 { margin: 0; font-size: 13px; letter-spacing: .01em; }
.card-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.4; overflow-wrap: anywhere; }
.card-heading p[data-kind="warn"] { color: var(--warn); }
.card-heading p[data-kind="error"] { color: var(--error); }
.badge { flex: none; font-size: 11px; font-weight: 750; color: var(--muted); border: 1px solid var(--line); padding: 5px 9px; border-radius: 999px; }
.swatch-wrap { display: flex; align-items: center; gap: 8px; flex: none; }
.swatch-label { font-size: 11px; color: var(--muted); font-weight: 650; }
.swatch { width: 30px; height: 30px; border: 1px solid var(--line-strong); border-radius: 9px; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .8); }

.canvas-frame { position: relative; width: 100%; aspect-ratio: 1; overflow: hidden; border-radius: 14px; border: 1px solid var(--line); display: grid; place-items: center; }
.source-frame { background: #e9ecef; }
.source-frame canvas { width: 100%; height: 100%; cursor: crosshair; display: block; }
.stamp-frame canvas { width: 100%; height: 100%; display: block; touch-action: none; }

/* Stamp preview backgrounds */
.stamp-frame.view-dark { background: #0d0f12; border-color: #0d0f12; }
.stamp-frame.view-ink { background: #fff; }
.stamp-frame.view-skin { background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--skin, #c68a5e) 85%, #fff), var(--skin, #c68a5e) 70%); }
.stamp-frame.view-checker {
  background-color: #fff;
  background-image: linear-gradient(45deg,#e3e6ea 25%,transparent 25%),linear-gradient(-45deg,#e3e6ea 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#e3e6ea 75%),linear-gradient(-45deg,transparent 75%,#e3e6ea 75%);
  background-size: 22px 22px; background-position: 0 0,0 11px,11px -11px,-11px 0;
}
.brush-cursor { position: absolute; left: 0; top: 0; border-radius: 50%; pointer-events: none; border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .55); transform: translate(-50%, -50%); }
.stamp-frame.erasing .brush-cursor { border-style: dashed; }

.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.microcopy { margin: 10px 2px 0; color: var(--muted); font-size: 12px; line-height: 1.45; }

.toggle { display: inline-flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 650; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { width: 34px; height: 20px; border-radius: 999px; background: var(--line-strong); position: relative; transition: background .15s ease; flex: none; }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .15s ease; }
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(14px); }
.toggle input:focus-visible + .toggle-track { outline: 3px solid rgba(22, 163, 90, .35); outline-offset: 2px; }

.skin-tones { display: flex; gap: 6px; }
.tone { width: 24px; height: 24px; border-radius: 50%; background: var(--tone); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line-strong); padding: 0; }
.tone.active { box-shadow: 0 0 0 2px var(--accent); }

/* ---------- Controls ---------- */
.controls-card { padding: 20px; }
.controls-card > h2 { margin-bottom: 16px; }
.step-num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-strong); font-size: 13px; font-weight: 800; }
.field { display: grid; gap: 8px; margin-top: 15px; }
.field > span, .slider-field > span { display: flex; justify-content: space-between; gap: 12px; color: #2f3540; font-size: 13px; font-weight: 650; }
.field small { color: var(--muted); font-size: 11.5px; line-height: 1.4; margin-top: -2px; }
.field-row { display: flex; align-items: center; justify-content: space-between; }
output { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600; }
select, input[type="text"] { width: 100%; min-height: 42px; border: 1px solid var(--line-strong); border-radius: 10px; padding: 0 11px; background: #fff; color: var(--text); outline: none; }
select:focus, input[type="text"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(22, 163, 90, .14); }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 20px; margin: 0; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--fill, 50%), #dfe3e8 var(--fill, 50%));
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: #dfe3e8; }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, .18);
}
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, .18); }
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:disabled { opacity: .4; cursor: not-allowed; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(22, 163, 90, .25); }
.check-field { display: flex; align-items: center; gap: 9px; margin-top: 12px; font-size: 13px; font-weight: 650; }
.check-field input { width: 17px; height: 17px; accent-color: var(--accent); }
.divider { height: 1px; background: var(--line); margin: 20px 0 16px; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: var(--soft); border-radius: 12px; }
.segmented.compact { grid-template-columns: repeat(4, auto); }
.seg { border: 0; background: transparent; border-radius: 9px; min-height: 36px; padding: 0 10px; font-weight: 700; font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.segmented.compact .seg { min-height: 30px; font-size: 12.5px; }
.seg:hover { color: var(--text); }
.seg.active { background: #fff; color: var(--text); box-shadow: 0 1px 4px rgba(15, 23, 42, .12); }
.seg kbd { margin-left: 4px; }
.button-row { display: flex; gap: 9px; margin-top: 15px; flex-wrap: wrap; }
.note { margin: 13px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.note kbd { margin: 0 1px; }

.filename-field { display: flex; align-items: center; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; background: #fff; }
.filename-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(22, 163, 90, .14); }
.filename-field input { border: 0; border-radius: 0; min-width: 0; box-shadow: none !important; }
.filename-field span { padding: 0 12px 0 4px; color: var(--muted); font-size: 13px; }
.export-buttons { display: grid; gap: 10px; margin-top: 15px; }

/* ---------- Help ---------- */
.help { margin-top: 18px; padding: 0; }
.help summary { cursor: pointer; padding: 16px 20px; font-weight: 700; list-style: none; display: flex; align-items: center; justify-content: space-between; }
.help summary::-webkit-details-marker { display: none; }
.help summary::after { content: "+"; font-size: 20px; color: var(--muted); font-weight: 500; }
.help[open] summary::after { content: "–"; }
.help-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; padding: 0 20px 20px; }
.help ul { margin: 8px 0 0; padding-left: 18px; color: #3a414c; font-size: 13px; line-height: 1.6; }

footer { color: var(--muted); font-size: 12px; line-height: 1.5; padding: 18px 3px 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 40;
  width: max-content; max-width: min(640px, calc(100% - 28px));
  padding: 12px 16px 12px 40px; border-radius: 13px;
  background: #171a20; color: #f2f4f7; font-size: 13.5px; line-height: 1.5;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .28); overflow-wrap: anywhere;
  animation: toast-in .2s ease;
}
.toast::before { content: ""; position: absolute; left: 16px; top: 18px; width: 10px; height: 10px; border-radius: 50%; background: #8b95a5; }
.toast[data-kind="success"]::before { background: #3ddc84; }
.toast[data-kind="error"] { background: #fff; color: var(--error); border: 1px solid #f0c4c4; }
.toast[data-kind="error"]::before { background: var(--error); }
.toast[data-kind="warn"]::before { background: #f5b301; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .shell { padding-top: 26px; }
  .preview-grid, .controls-grid, .help-grid { grid-template-columns: 1fr; }
  .privacy-pill { display: none; }
  .segmented.compact { grid-template-columns: repeat(2, 1fr); width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
