/* ===========================================================================
 * Halftone Engine - UI
 * ========================================================================= */
:root {
  --bg: #0e0f12;
  --bg-2: #15171c;
  --panel: #181b21;
  --card: #1d2128;
  --card-2: #232831;
  --line: #2b313b;
  --line-2: #363d49;
  --text: #e8ebf0;
  --text-dim: #9aa3b2;
  --text-faint: #69707d;
  --accent: #ff5a3c;        /* marcotte-ink warm orange */
  --accent-2: #ffb627;
  --cyan: #00aeef;
  --good: #36d399;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 30px rgba(0,0,0,.45);
  font-synthesis: none;
}

* { box-sizing: border-box; }
/* the [hidden] attribute must always win over component display rules below */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 70% -10%, #1b1e26 0%, var(--bg) 55%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ---- topbar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(14,15,18,.7);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background:
    radial-gradient(circle at 30% 30%, #fff 1.4px, transparent 2px) 0 0/8px 8px,
    radial-gradient(circle at 30% 30%, #fff 1px, transparent 1.6px) 4px 4px/8px 8px,
    linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 15px; letter-spacing: .2px; }
.brand-text small { color: var(--text-faint); font-size: 11px; }
.ghost-link {
  color: var(--text-dim); text-decoration: none; font-size: 12.5px;
  padding: 6px 12px; border: 1px solid var(--line-2); border-radius: 999px;
  transition: .15s;
}
.ghost-link:hover { color: var(--text); border-color: var(--accent); }

/* ---- layout ---- */
.app {
  display: grid;
  grid-template-columns: 310px minmax(0,1fr) 300px;
  gap: 14px;
  padding: 14px;
  height: calc(100vh - 55px);
  min-height: 0;
}
.panel { min-height: 0; }
.controls, .export { overflow-y: auto; padding-right: 4px; }
.controls::-webkit-scrollbar, .export::-webkit-scrollbar { width: 8px; }
.controls::-webkit-scrollbar-thumb, .export::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; }

/* ---- cards ---- */
.card {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--text-dim); margin: 0; font-weight: 600; }

/* ---- dropzone ---- */
.dropzone {
  border: 1.5px dashed var(--line-2); border-radius: var(--radius-sm);
  padding: 22px 14px; text-align: center; cursor: pointer; transition: .15s;
  color: var(--text-dim);
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: rgba(255,90,60,.06); color: var(--text); }
.dz-icon { width: 26px; height: 26px; margin-bottom: 6px; color: var(--accent); }
.dz-title { margin: 2px 0; font-weight: 600; color: var(--text); font-size: 13px; }
.dz-sub { margin: 2px 0; font-size: 11.5px; color: var(--text-faint); }
.dz-meta { margin: 8px 0 0; font-size: 11.5px; color: var(--good); }

/* ---- controls ---- */
.ctl { display: grid; grid-template-columns: 96px 1fr auto; align-items: center; gap: 8px; margin: 9px 0; }
.ctl > span { color: var(--text-dim); font-size: 12.5px; }
.ctl.slider output { font-variant-numeric: tabular-nums; color: var(--text); min-width: 36px; text-align: right; font-size: 12px; }
.ctl.tiny { grid-template-columns: 40px 1fr auto; margin: 6px 0; }
.angles { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; margin-top: 8px; }

input[type=range] {
  -webkit-appearance: none; appearance: none; height: 4px; border-radius: 3px;
  background: var(--line-2); outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--text); border: 3px solid var(--accent); cursor: pointer; margin-top: -0px;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--text); border: 3px solid var(--accent); cursor: pointer; }

.select {
  width: 100%; background: var(--card-2); color: var(--text);
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 13px; cursor: pointer;
}
.select.sm { padding: 6px 8px; font-size: 12.5px; }
.ctl .select.sm { width: auto; grid-column: 2 / 4; }

.preset-hint { margin: 8px 0 0; font-size: 12px; color: var(--text-faint); min-height: 16px; }

/* segmented control (standard vs reductive dot) */
.seg { display: flex; gap: 4px; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 3px; margin-bottom: 10px; }
.seg-btn { flex: 1; border: none; background: transparent; color: var(--text-dim); font-size: 12.5px; font-weight: 600; padding: 7px 8px; border-radius: 6px; cursor: pointer; transition: .15s; }
.seg-btn:hover { color: var(--text); }
.seg-btn.is-active { background: var(--accent); color: #fff; }

/* switch */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line-2); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(16px); }

/* swatches */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 30px; height: 30px; border-radius: 7px; border: 2px solid transparent; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); }
.swatch.is-active { border-color: var(--accent); }

/* ---- buttons ---- */
.btn {
  border: 1px solid var(--line-2); background: var(--card-2); color: var(--text);
  border-radius: var(--radius-sm); padding: 9px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, var(--accent), #e0431f); border-color: transparent; color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.block { display: block; width: 100%; margin-bottom: 8px; }
.mini-btn {
  border: 1px solid var(--line-2); background: var(--card-2); color: var(--text-dim);
  border-radius: 6px; padding: 3px 9px; font-size: 12px; cursor: pointer; transition: .15s;
}
.mini-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---- stage ---- */
.stage { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; position: relative; }

/* live render status pill (floats over the stage top-right) */
.render-status {
  position: absolute; top: 50px; right: 14px; z-index: 8;
  display: flex; align-items: center; gap: 7px;
  padding: 5px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; letter-spacing: .01em;
  background: rgba(18,20,25,.92); border: 1px solid var(--line-2);
  backdrop-filter: blur(6px); color: var(--text-dim);
  opacity: 0; transform: translateY(-5px); pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
}
.render-status.show { opacity: 1; transform: none; }
.render-status[data-state="rendering"] { color: var(--accent-2); border-color: var(--accent-2); }
.render-status[data-state="done"] { color: var(--good); border-color: color-mix(in srgb, var(--good) 50%, var(--line-2)); }
.rs-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.render-status[data-state="rendering"] .rs-dot { border: 2px solid rgba(255,182,39,.3); border-top-color: var(--accent-2); animation: spin .6s linear infinite; }
.render-status[data-state="done"] .rs-dot { background: var(--good); }
.stage-tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.tab {
  border: none; background: transparent; color: var(--text-dim); font-size: 12.5px; font-weight: 600;
  padding: 9px 14px; cursor: pointer; border-radius: 8px 8px 0 0; position: relative; top: 1px;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); background: var(--panel); box-shadow: inset 0 -2px 0 var(--accent); }

.viewport {
  flex: 1; position: relative; overflow: auto; min-height: 0;
  /* `safe center` keeps the art centred when it fits but pins it to the
     top-left when it's bigger than the viewport, so a zoomed-in image can be
     scrolled/panned to every edge instead of clipping the top & left. */
  display: flex; align-items: safe center; justify-content: safe center;
  background:
    linear-gradient(45deg, #1a1d23 25%, transparent 25%) 0 0/24px 24px,
    linear-gradient(-45deg, #1a1d23 25%, transparent 25%) 0 0/24px 24px,
    linear-gradient(45deg, transparent 75%, #1a1d23 75%) 0 0/24px 24px,
    linear-gradient(-45deg, transparent 75%, #1a1d23 75%) 12px 12px/24px 24px,
    #131519;
  padding: 20px;
  overscroll-behavior: contain;
}
/* grab-to-pan affordance, shown only when the image overflows the viewport */
.viewport.can-pan { cursor: grab; }
.viewport.can-pan.panning { cursor: grabbing; user-select: none; }
/* flex: none so the wrap keeps its full (zoomed) size instead of being shrunk to
   the viewport width by flexbox - otherwise a zoomed image only scrolls vertically */
.canvas-wrap { position: relative; box-shadow: var(--shadow); line-height: 0; flex: 0 0 auto; }
.canvas-wrap canvas { display: block; max-width: none; image-rendering: auto; -webkit-user-drag: none; user-select: none; }

/* compare */
.canvas-wrap.compare { overflow: hidden; }
.compare-top { position: absolute; inset: 0; width: 50%; overflow: hidden; border-right: 2px solid var(--accent); }
.compare-top canvas { position: absolute; top: 0; left: 0; }
.compare-handle { position: absolute; top: 0; bottom: 0; left: 50%; width: 28px; transform: translateX(-50%); cursor: ew-resize; display: flex; align-items: center; justify-content: center; }
.compare-handle span { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); box-shadow: 0 2px 10px rgba(0,0,0,.5); position: relative; }
.compare-handle span::before, .compare-handle span::after { content: ""; position: absolute; top: 50%; width: 0; height: 0; border: 5px solid transparent; }
.compare-handle span::before { left: 4px; border-right-color: #fff; transform: translateY(-50%); }
.compare-handle span::after { right: 4px; border-left-color: #fff; transform: translateY(-50%); }

/* empty */
.empty-state { text-align: center; color: var(--text-dim); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-ico { width: 84px; height: 84px; fill: var(--line-2); }
.empty-state p { margin: 0 0 4px; }

.stage-foot { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; border-top: 1px solid var(--line); background: var(--bg-2); font-size: 12px; color: var(--text-dim); }
.zoom { display: flex; align-items: center; gap: 6px; }
.zoom span { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }

/* ---- export panel ---- */
.specs { margin: 0; display: grid; gap: 8px; }
.specs > div { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
.specs dt { color: var(--text-faint); font-size: 12px; margin: 0; }
.specs dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.export-note { font-size: 12px; color: var(--text-faint); margin: 0 0 12px; }
.about p { font-size: 12.5px; color: var(--text-dim); margin: 0 0 8px; }
.fineprint { color: var(--text-faint) !important; font-size: 11.5px !important; }

.progress { margin-top: 8px; }
.progress .bar { height: 5px; background: var(--accent); border-radius: 3px; width: 0%; transition: width .12s; }
.progress span { font-size: 11.5px; color: var(--text-dim); }

/* busy overlay */
.busy { position: fixed; inset: 0; background: rgba(8,9,11,.6); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; gap: 12px; z-index: 50; color: var(--text); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* responsive */
@media (max-width: 1100px) {
  .app { grid-template-columns: 280px minmax(0,1fr); height: auto; }
  .export { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
}
