:root {
  color-scheme: dark;
  --bg: #16171a;
  --panel: #202226;
  --border: #34373d;
  --text: #e8e9ec;
  --muted: #9a9ea8;
  --accent: #4c8dff;
  --accent-text: #fff;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #eceef1;
    --panel: #fff;
    --border: #d3d6dc;
    --text: #1c1e22;
    --muted: #666b75;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, sans-serif;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Toolbar */

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.bar h1 {
  margin: 0 6px 0 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.controls {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.controls:disabled { opacity: 0.5; }

.controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.spacer { flex: 1; }

select,
input[type="number"] {
  height: 30px;
  padding: 0 8px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}

input[type="number"] { width: 76px; }
input[type="range"] { width: 100px; accent-color: var(--accent); }
#qualityOut { min-width: 2ch; color: var(--text); font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}

.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.ghost { background: transparent; }
.controls:disabled .btn { cursor: default; }

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

/* Stage */

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: hidden;
}

.stage.dragover { outline: 2px dashed var(--accent); outline-offset: -10px; }

.empty {
  margin: 0;
  padding: 40px 32px;
  color: var(--muted);
  text-align: center;
  border: 2px dashed var(--border);
  border-radius: 12px;
}

.frame {
  position: relative;
  cursor: crosshair;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  /* checkerboard so transparent areas are visible */
  background: repeating-conic-gradient(#8a8a8a 0 25%, #b4b4b4 0 50%) 0 0 / 16px 16px;
}

.frame img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.shade {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.hole,
.crop {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--w);
  height: var(--h);
}

.hole { box-shadow: 0 0 0 100vmax rgb(0 0 0 / 0.6); }

.crop {
  cursor: move;
  outline: 1px solid #fff;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.5) inset;
}

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

/* rule-of-thirds guides */
.crop::before,
.crop::after {
  content: "";
  position: absolute;
  pointer-events: none;
  border: 0 solid rgb(255 255 255 / 0.35);
}

.crop::before { inset: 0 33.333%; border-width: 0 1px; }
.crop::after { inset: 33.333% 0; border-width: 1px 0; }

.handle {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px;
  background: #fff;
  border: 1px solid rgb(0 0 0 / 0.6);
  border-radius: 2px;
}

/* larger hit area than the visible square */
.handle::after { content: ""; position: absolute; inset: -8px; }

.handle[data-dir="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.handle[data-dir="n"]  { left: 50%; top: 0; cursor: ns-resize; }
.handle[data-dir="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.handle[data-dir="e"]  { left: 100%; top: 50%; cursor: ew-resize; }
.handle[data-dir="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.handle[data-dir="s"]  { left: 50%; top: 100%; cursor: ns-resize; }
.handle[data-dir="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
.handle[data-dir="w"]  { left: 0; top: 50%; cursor: ew-resize; }

/* Status bar */

.status {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  min-height: 32px;
  padding: 6px 16px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
