:root {
  color-scheme: light;
  --ink: #17221d;
  --muted: #68726d;
  --paper: #f4f1e9;
  --card: #fffefb;
  --gold: #c69c54;
  --green: #1b806b;
  --green-soft: #d9eee7;
  --line: #d8d8d0;
  --danger: #a5453f;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--paper); color: var(--ink); }
body { min-height: 100dvh; display: flex; flex-direction: column; }
button, input, label { font: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }

.topbar {
  min-height: 68px; padding: max(12px, env(safe-area-inset-top)) clamp(16px, 4vw, 34px) 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--ink); color: white;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 40px; height: 40px; border: 1px solid #d9b879; color: #d9b879; border-radius: 12px; display: grid; place-items: center; font: 700 22px Georgia, serif; }
.brand strong, .brand small { display: block; }
.brand strong { font: 600 18px Georgia, serif; }
.brand small { margin-top: 2px; color: #ccd4cf; font-size: 12px; }
.privacy-pill { border: 1px solid #4a5a52; border-radius: 999px; padding: 7px 10px; font-size: 12px; color: #d9e3dd; }

.workspace { width: min(1220px, 100%); margin: 0 auto; padding: 18px; display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; flex: 1; }
.stage-card, .controls { background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 10px 30px rgba(23,34,29,.07); }
.stage-card { min-height: 620px; position: relative; overflow: hidden; display: grid; place-items: center; }
.empty-state { max-width: 520px; padding: 42px 24px; text-align: center; }
.camera-icon { width: 64px; height: 64px; margin: 0 auto 20px; border-radius: 18px; background: var(--green-soft); color: var(--green); display: grid; place-items: center; font-size: 30px; }
h1 { margin: 0 0 12px; font: 600 clamp(28px, 4vw, 42px)/1.08 Georgia, serif; }
.empty-state p { margin: 0 auto 24px; color: var(--muted); font-size: 17px; line-height: 1.55; }
.upload-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.primary-button, .secondary-button { min-height: 46px; border-radius: 12px; padding: 12px 18px; border: 1px solid transparent; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-weight: 650; }
.primary-button { color: white; background: var(--ink); }
.secondary-button { color: var(--ink); background: white; border-color: #aeb6b1; }
.full { width: 100%; }
button:disabled { cursor: not-allowed; opacity: .45; }

.editor { width: 100%; height: 100%; min-height: 620px; position: relative; background: #d8d7d2; }
.canvas-wrap { width: 100%; height: 100%; min-height: 620px; position: relative; display: grid; place-items: center; overflow: hidden; touch-action: none; cursor: crosshair; }
canvas { position: absolute; max-width: 100%; max-height: 100%; width: auto; height: auto; }
#photoCanvas { z-index: 1; }
#resultCanvas { z-index: 2; pointer-events: none; }
#overlayCanvas { z-index: 3; touch-action: none; }
.touch-marker { position: absolute; z-index: 4; width: 28px; height: 28px; border: 3px solid white; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(27,128,107,.5); transform: translate(-50%,-50%); pointer-events: none; }
.busy-overlay { position: absolute; z-index: 6; inset: 0; background: rgba(23,34,29,.88); color: white; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 30px; }
.busy-overlay[hidden] { display: none; }
.busy-overlay span { color: #d6ddd9; }
.spinner { width: 34px; height: 34px; border: 3px solid #78847e; border-top-color: #dfbd7a; border-radius: 50%; animation: spin .9s linear infinite; }
progress { width: min(300px, 80%); accent-color: var(--gold); }
@keyframes spin { to { transform: rotate(360deg); } }

.controls { padding: 16px; align-self: start; }
.status-panel { display: flex; gap: 12px; align-items: flex-start; padding: 14px; background: var(--green-soft); border-radius: 14px; }
.step-badge { flex: 0 0 auto; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--green); color: white; font-weight: 700; }
.status-panel strong { display: block; margin-top: 2px; }
.status-panel p { margin: 4px 0 0; color: #36564c; font-size: 14px; line-height: 1.4; }
.control-section { padding: 18px 2px; border-bottom: 1px solid #e5e5df; }
.section-heading { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; margin-bottom: 12px; }
h2 { margin: 0; font-size: 16px; }
.section-heading span { color: var(--muted); font-size: 13px; }
.tool-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.tool-button { min-height: 64px; padding: 8px 4px; border: 1px solid var(--line); background: white; color: var(--ink); border-radius: 12px; font-size: 12px; cursor: pointer; }
.tool-button span { display: block; margin-bottom: 3px; font-size: 22px; }
.tool-button.active { border-color: var(--green); background: var(--green-soft); color: #0f604f; box-shadow: inset 0 0 0 1px var(--green); }
.range-label { margin-top: 16px; display: flex; justify-content: space-between; color: #4a5550; font-size: 14px; }
input[type="range"] { width: 100%; margin: 12px 0 2px; accent-color: var(--green); }
.hint, .device-panel p { color: var(--muted); font-size: 13px; line-height: 1.45; margin: 9px 0 0; }
.actions-section { display: grid; gap: 9px; }
.row-actions { display: flex; justify-content: space-between; gap: 10px; }
.text-button { min-height: 42px; padding: 8px 4px; border: 0; background: transparent; color: #3e5e54; text-decoration: underline; cursor: pointer; }
.device-panel { margin-top: 16px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.device-panel strong { font-size: 14px; }
footer { padding: 14px 18px max(14px, env(safe-area-inset-bottom)); text-align: center; color: var(--muted); font-size: 12px; }

@media (max-width: 820px) {
  .privacy-pill { display: none; }
  .workspace { display: block; padding: 0; }
  .stage-card, .controls { border-radius: 0; border-left: 0; border-right: 0; box-shadow: none; }
  .stage-card { min-height: 54vh; }
  .editor, .canvas-wrap { min-height: 54vh; }
  .controls { margin-top: 0; }
  .empty-state { padding: 34px 20px; }
  .tool-button { min-height: 68px; }
}

@media (max-width: 380px) {
  .topbar { padding-inline: 12px; }
  .brand small { display: none; }
  .workspace { padding: 0; }
}
