:root {
  --bg: #15140f;
  --panel: #1d1b15;
  --panel-raised: #24211a;
  --ink: #ede7d9;
  --ink-dim: #9c9583;
  --line: #37331f;
  --amber: #e8963c;
  --amber-dim: #7a5a2c;
  --teal: #5c9c92;
  --danger: #c96a4f;

  --display: "Space Grotesk", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--display);
  min-height: 100vh;
}

body {
  display: flex;
  flex-direction: column;
  position: relative;
}

/* subtle film-grain texture over everything */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: var(--amber); color: #16140d; }

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 28px clamp(20px, 5vw, 56px) 8px;
  flex-wrap: wrap;
}

.mark {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 1.05rem;
  letter-spacing: 0.14em;
  color: var(--ink);
}
.mark-bracket { color: var(--amber); }

.tagline {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-dim);
  letter-spacing: 0.01em;
}

/* ---------- stage / layout ---------- */

main { flex: 1; display: flex; }

.stage {
  flex: 1;
  padding: 12px clamp(20px, 5vw, 56px) 40px;
  display: flex;
  flex-direction: column;
}

/* ---------- dropzone ---------- */

.dropzone {
  flex: 1;
  min-height: 420px;
  border: 1px dashed var(--line);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s ease, background 0.15s ease;
  background:
    linear-gradient(var(--panel), var(--panel)) padding-box;
}

.dropzone::before,
.dropzone::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border: 1px solid var(--amber-dim);
  opacity: 0.7;
}
.dropzone::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.dropzone::after { bottom: -1px; right: -1px; border-left: none; border-top: none; }

.dropzone.is-drag {
  border-color: var(--amber);
  background: #201c14;
}

.dz-content {
  text-align: center;
  color: var(--ink-dim);
}
.dz-icon { color: var(--amber-dim); margin-bottom: 14px; }
.dz-label {
  margin: 0 0 6px;
  font-size: 1.05rem;
  color: var(--ink);
}
.dz-link {
  color: var(--amber);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.dz-sub {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}

/* ---------- workspace ---------- */

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 28px;
  min-height: 460px;
}

.canvas-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.canvas-frame {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    repeating-conic-gradient(#1a1810 0% 25%, #1d1b14 0% 50%) 50% / 18px 18px;
  border: 1px solid var(--line);
  overflow: hidden;
  min-height: 380px;
}

#imageCanvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.status-line {
  margin: 10px 2px 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--amber);
  letter-spacing: 0.04em;
  text-transform: lowercase;
}

/* crop box — viewfinder */

.crop-box {
  position: absolute;
  border: 1px solid var(--amber);
  box-shadow: 0 0 0 2000px rgba(10, 9, 6, 0.72);
  cursor: move;
}

.thirds {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
  opacity: 0.4;
}
.thirds span:nth-child(1) { grid-column: 1; grid-row: 1 / span 3; border-right: 1px solid var(--amber); }
.thirds span:nth-child(2) { grid-column: 2; grid-row: 1 / span 3; border-right: 1px solid var(--amber); }
.thirds span:nth-child(3) {
  grid-column: 1 / span 3; grid-row: 1;
  border-bottom: 1px solid var(--amber);
  position: relative;
}
.thirds span:nth-child(3)::after,
.thirds span:nth-child(3)::before {
  content: "";
  position: absolute;
  left: 0; right: 0;
  border-bottom: 1px solid var(--amber);
}
.thirds span:nth-child(3)::before { top: 100%; }
.thirds span:nth-child(3)::after { top: 200%; }

.corner {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid var(--ink);
}
.c-tl { top: -1px; left: -1px; border-right: none; border-bottom: none; cursor: nwse-resize; }
.c-tr { top: -1px; right: -1px; border-left: none; border-bottom: none; cursor: nesw-resize; }
.c-bl { bottom: -1px; left: -1px; border-right: none; border-top: none; cursor: nesw-resize; }
.c-br { bottom: -1px; right: -1px; border-left: none; border-top: none; cursor: nwse-resize; }

.edge {
  position: absolute;
}
.e-top, .e-bottom { left: 16px; right: 16px; height: 10px; cursor: ns-resize; }
.e-top { top: -5px; }
.e-bottom { bottom: -5px; }
.e-left, .e-right { top: 16px; bottom: 16px; width: 10px; cursor: ew-resize; }
.e-left { left: -5px; }
.e-right { right: -5px; }

/* ---------- side panel ---------- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding-top: 4px;
}

.panel-title {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin: 0 0 10px;
}

.ratio-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.ratio-btn, .focus-btn {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  padding: 9px 6px;
  cursor: pointer;
  border-radius: 1px;
  transition: all 0.12s ease;
}
.ratio-btn:hover, .focus-btn:hover { border-color: var(--amber-dim); color: var(--ink); }
.ratio-btn.is-active, .focus-btn.is-active {
  border-color: var(--amber);
  color: var(--amber);
  background: #241d10;
}

.focal-toggle {
  display: flex;
  gap: 6px;
}
.focal-toggle .focus-btn { flex: 1; }

.panel-note {
  margin: 10px 0 0;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--ink-dim);
}

.readout-grid {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  row-gap: 8px;
  column-gap: 12px;
  font-family: var(--mono);
  font-size: 0.78rem;
}
.readout-grid dt { color: var(--ink-dim); }
.readout-grid dd { margin: 0; color: var(--ink); text-align: right; }

.panel-group.readout {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 18px 0;
}

.resize-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-dim);
  cursor: pointer;
  margin-bottom: 12px;
}
.resize-toggle input { accent-color: var(--amber); }
.resize-toggle:hover { color: var(--ink); }

.resize-fields {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--ink-dim);
}

#resizeWidth {
  width: 76px;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 7px 8px;
  border-radius: 1px;
}
#resizeWidth:disabled { opacity: 0.4; }
#resizeWidth:focus { outline: none; border-color: var(--amber); }

.resize-x { color: var(--ink-dim); }
.resize-height { color: var(--ink); min-width: 36px; }
.resize-unit { color: var(--ink-dim); }

.btn-primary {
  width: 100%;
  padding: 13px;
  background: var(--amber);
  color: #17140c;
  border: none;
  font-family: var(--display);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  border-radius: 1px;
  margin-bottom: 10px;
  transition: background 0.15s ease;
}
.btn-primary:hover { background: #f0a856; }

.btn-ghost {
  width: 100%;
  padding: 11px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: 0.75rem;
  cursor: pointer;
  border-radius: 1px;
}
.btn-ghost:hover { color: var(--ink); border-color: var(--amber-dim); }

/* ---------- footer ---------- */

.foot {
  padding: 18px clamp(20px, 5vw, 56px) 26px;
  border-top: 1px solid var(--line);
}
.foot p {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-dim);
  letter-spacing: 0.02em;
}

/* ---------- responsive ---------- */

@media (max-width: 820px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .canvas-frame { min-height: 320px; }
  .panel { padding-top: 0; }
}
