/* ============================================================
   DESIGN TOKENS
   Palette: warm paper background + graphite ink + a single
   "blueprint pencil" indigo accent — reads like a sketchbook,
   not a SaaS dashboard.
   ============================================================ */
:root{
  --paper: #F1EEE6;
  --paper-raised: #FBF9F4;
  --ink: #2A2822;
  --ink-soft: #6B675C;
  --line: #DCD6C7;
  --accent: #3E5C76;
  --accent-soft: #DCE5EC;
  --accent-ink: #1E2F3D;
  --danger: #A6493B;

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(42,40,34,.06), 0 6px 20px rgba(42,40,34,.05);
}

[data-theme="dark"]{
  --paper: #1B1A17;
  --paper-raised: #232220;
  --ink: #EDEAE0;
  --ink-soft: #A39E90;
  --line: #38362F;
  --accent: #7FA5C4;
  --accent-soft: #253340;
  --accent-ink: #EAF2F8;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
}

*{ box-sizing: border-box; }

html, body{
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  transition: background .2s ease, color .2s ease;
}

body{
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

h1, h2{ font-family: var(--font-display); font-weight: 600; margin: 0; }

button, input, textarea{ font-family: inherit; color: inherit; }

/* ============================================================
   HEADER
   ============================================================ */
.app-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
}

.brand{ display: flex; align-items: center; gap: 14px; }

.brand-mark{
  font-size: 26px;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-radius: var(--radius);
  flex-shrink: 0;
}

.brand-text h1{ font-size: 22px; letter-spacing: -.01em; }
.brand-text p{ margin: 2px 0 0; font-size: 13.5px; color: var(--ink-soft); }

.icon-btn{
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:hover{ border-color: var(--accent); color: var(--accent); }
.icon-btn svg{ width: 18px; height: 18px; }

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

/* ============================================================
   LAYOUT
   ============================================================ */
.layout{
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: 28px;
  padding: 28px clamp(16px, 4vw, 40px);
  align-items: start;
}

@media (max-width: 860px){
  .layout{ grid-template-columns: 1fr; }
}

/* ============================================================
   PANEL (left controls)
   ============================================================ */
.panel{
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: var(--shadow);
}

.field-group{ display: flex; flex-direction: column; gap: 8px; }

.field-label{ font-size: 13.5px; font-weight: 600; }
.optional{ font-weight: 400; color: var(--ink-soft); }

.field-hint{ margin: 0; font-size: 12.5px; color: var(--ink-soft); line-height: 1.5; }

textarea, input[type="text"], input[type="password"]{
  width: 100%;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  resize: vertical;
}
textarea:focus, input:focus{
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.dropzone{
  position: relative;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  min-height: 150px;
  display: grid;
  place-items: center;
  cursor: pointer;
  background: var(--paper);
  overflow: hidden;
}
.dropzone.drag-over{ border-color: var(--accent); background: var(--accent-soft); }

.dropzone-empty{ text-align: center; color: var(--ink-soft); padding: 20px; }
.dropzone-empty svg{ margin-bottom: 6px; }
.dropzone-empty p{ margin: 0; font-size: 13.5px; }
.link-like{ color: var(--accent); text-decoration: underline; }

#previewImg{ width: 100%; height: 100%; max-height: 220px; object-fit: contain; }

.url-row{ display: flex; gap: 8px; }
.url-row input{ flex: 1; min-width: 0; }
.url-row .ghost-btn{ flex-shrink: 0; }

.advanced{ border-top: 1px solid var(--line); padding-top: 14px; }
.advanced summary{
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  list-style: none;
}
.advanced summary::-webkit-details-marker{ display: none; }
.advanced summary::before{ content: "▸ "; color: var(--accent); }
.advanced[open] summary::before{ content: "▾ "; }
.advanced-body{ display: flex; flex-direction: column; gap: 10px; padding-top: 12px; }

.checkbox-row{ display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.checkbox-row input{ width: 16px; height: 16px; }

code{ background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.primary-btn{
  background: var(--accent);
  color: var(--paper-raised);
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}
.primary-btn:disabled{ opacity: .45; cursor: not-allowed; }
.primary-btn:not(:disabled):hover{ background: var(--accent-ink); }

.status-line{ margin: 0; font-size: 13px; min-height: 18px; color: var(--ink-soft); }
.status-line.is-error{ color: var(--danger); }

/* ============================================================
   STAGE (right: step viewer)
   ============================================================ */
.stage{ display: flex; flex-direction: column; gap: 16px; }

.step-tabs{
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.step-tab{
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  border-radius: 999px;
  padding: 8px 14px 8px 8px;
  font-size: 13px;
  cursor: pointer;
}
.step-tab:disabled{ cursor: not-allowed; opacity: .5; }
.step-num{
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--line);
  color: var(--ink);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
}
.step-tab.active{ border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }
.step-tab.active .step-num{ background: var(--accent); color: var(--paper-raised); }

.stage-frame{
  position: relative;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 340px;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.stage-empty{ text-align: center; color: var(--ink-soft); padding: 30px; }
.stage-empty p{ margin: 10px 0 0; font-size: 13.5px; }

#stepCanvas{ width: 100%; height: auto; max-height: 60vh; display: block; }

.stage-float{
  position: absolute;
  top: 14px; right: 14px;
}

.stage-footer{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.step-caption{ margin: 0; font-size: 13.5px; color: var(--ink-soft); }

.ghost-btn{
  border: 1px solid var(--line);
  background: var(--paper-raised);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 13.5px;
  cursor: pointer;
}
.ghost-btn:disabled{ opacity: .4; cursor: not-allowed; }
.ghost-btn:not(:disabled):hover{ border-color: var(--accent); color: var(--accent); }
.ghost-btn.small{ padding: 6px 10px; font-size: 12.5px; }

.app-footer{
  padding: 16px clamp(16px, 4vw, 40px) 26px;
  text-align: center;
}
.app-footer p{ margin: 0; font-size: 12px; color: var(--ink-soft); }

/* ============================================================
   TRACE MODE — screen-as-lightbox
   Maximum brightness/contrast white backdrop, image filling the
   screen, adjustable brightness/contrast/invert so a phone or
   laptop screen can be used as a backlight under paper.
   ============================================================ */
.trace-overlay{
  position: fixed;
  inset: 0;
  z-index: 999;
  background: #ffffff;
  display: flex;
  flex-direction: column;
}

.trace-topbar{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid #e6e6e6;
  flex-wrap: wrap;
}

.trace-controls, .trace-nav{
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.trace-slider-label{ font-size: 12px; color: #444; }

#traceStepLabel{ font-size: 13px; color: #333; min-width: 78px; text-align: center; }

.trace-overlay img{
  flex: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

/* ============================================================
   ACCESSIBILITY
   ============================================================ */
@media (prefers-reduced-motion: reduce){
  *{ transition: none !important; animation: none !important; }
}

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