@font-face {
  font-family: 'Unbounded Title';
  src: url(fonts/unbounded-title.woff2) format('woff2');
  font-weight: 700;
  font-display: swap;
}

/* Industrial press: warm concrete neutrals, one safety-orange accent, flat solid surfaces. */
:root {
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --r-panel: 12px;
  --r-ctl: 8px;
  --ease: cubic-bezier(.16, 1, .3, 1);
}
:root, [data-theme=light] {
  color-scheme: light;
  --bg: #dcdfde; --surface: #eceeed; --raised: #f8f9f8;
  --ink: #1b1d1c; --muted: #565c59; --rule: #bfc4c2;
  --accent: #ff5a1f; --accent-hover: #e84a10; --on-accent: #1b1d1c; --accent-text: #b83d0b;
  --ok: #1f7a3a; --ok-bg: #d3e6d9;
  --warn-bg: #f7e7a6; --warn-ink: #1b1d1c;
}
[data-theme=dark] {
  color-scheme: dark;
  --bg: #121413; --surface: #1b1d1c; --raised: #242726;
  --ink: #e8eae9; --muted: #9fa5a2; --rule: #363a38;
  --accent: #ff6a2b; --accent-hover: #ff8147; --on-accent: #121413; --accent-text: #ff7a3d;
  --ok: #5cc27a; --ok-bg: #1e2f23;
  --warn-bg: #3a3112; --warn-ink: #f5e7ae;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html {
  background: var(--bg); accent-color: var(--accent); scrollbar-color: var(--rule) var(--bg);
  text-size-adjust: 100%; -webkit-text-size-adjust: 100%;
}
body {
  margin: 0; min-height: 100vh; min-height: 100dvh; font-family: var(--font); line-height: 1.45;
  color: var(--ink); background: var(--bg);
}
button, input { font: inherit; color: inherit; caret-color: var(--accent-text); touch-action: manipulation; }
input { font-size: max(16px, 1em); }
::selection { background: var(--accent); color: var(--on-accent); }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.muted { color: var(--muted); font-size: .9rem; }
.i {
  width: 1.15em; height: 1.15em; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Layout: one column until the result can sit beside the work without squeezing either. */
main {
  width: min(100%, 42rem); margin: 0 auto;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(40px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  display: grid; grid-template-columns: minmax(0, 1fr); gap: clamp(16px, 2.5vw, 24px);
}
header { border-bottom: 3px solid var(--ink); padding-bottom: 16px; min-width: 0; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; container-type: inline-size; }
h1 {
  margin: 0; min-width: 0; font-family: 'Unbounded Title', 'Arial Black', var(--font); font-weight: 700;
  font-size: clamp(1.45rem, 8cqi, 2.8rem); letter-spacing: -.02em; line-height: 1.1;
}
h1 span { color: var(--accent-text); }
.tag { margin: 10px 0 0; max-width: 46ch; color: var(--muted); display: flex; gap: 8px; align-items: flex-start; text-wrap: pretty; }
.tag .i { margin-top: .2em; color: var(--ok); }

.card { padding: clamp(14px, 2.5vw, 24px); border-radius: var(--r-panel); background: var(--surface); border: 1px solid var(--rule); min-width: 0; }
.card.top { position: relative; z-index: 2; container: work / inline-size; }
#out { container: result / inline-size; }

/* Theme pill */
.pill {
  position: relative; flex: none; display: flex; align-items: center; width: 68px; height: 32px; padding: 3px;
  border-radius: 99px; border: 1px solid var(--rule); background: var(--surface); color: var(--muted); cursor: pointer;
}
.pill::before { content: ''; position: absolute; inset: -6px -2px; } /* 44px hit area */
.pill .i { position: relative; z-index: 1; flex: 1; height: 15px; transition: color .15s; }
.pill .knob {
  position: absolute; top: 3px; left: 3px; width: 30px; height: 24px; border-radius: 99px; background: var(--accent);
  transition: transform .2s var(--ease);
}
[data-theme=dark] .pill .knob { transform: translateX(30px); }
[data-theme=light] .pill .sun, [data-theme=dark] .pill .moon { color: var(--on-accent); }

/* Drop zone */
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: clamp(20px, 5vw, 36px) 16px;
  border: 2px dashed var(--muted); border-radius: var(--r-ctl); background: var(--raised);
  cursor: pointer; text-align: center; transition: border-color .15s, background-color .15s;
}
.drop .muted { max-width: 34ch; text-wrap: balance; }
.verb.coarse { display: none; }
.drop > .i { width: 32px; height: 32px; margin-bottom: 4px; color: var(--accent-text); }
.drop.over { border-style: solid; border-color: var(--accent-text); background: var(--surface); }
.drop.over > .i { transform: translateY(-3px); transition: transform .2s var(--ease); }

.chip { display: flex; align-items: center; gap: 12px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--rule); min-width: 0; }
.chip > .i { width: 22px; height: 22px; color: var(--muted); }
.chip .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.chip .size { color: var(--muted); font-size: .85rem; }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; margin: -6px -10px -6px 0; border: 0; border-radius: var(--r-ctl);
  background: transparent; color: var(--muted); cursor: pointer; transition: background-color .15s, color .15s;
}
.icon-btn:disabled { opacity: .5; cursor: not-allowed; }

/* Controls stack until the card is wide enough for the field and the press. */
.controls { display: grid; gap: 16px; margin-top: 20px; }
.ctl { display: grid; gap: 8px; min-width: 0; }
.lbl { font-size: .875rem; font-weight: 600; color: var(--muted); }
.field, .namefield {
  display: flex; align-items: stretch; min-width: 0; height: 48px; border-radius: var(--r-ctl);
  background: var(--raised); border: 1px solid var(--muted); transition: border-color .15s;
}
.field:focus-within, .namefield:focus-within { border-color: var(--accent-text); outline: 2px solid var(--accent-text); outline-offset: 1px; }
.field input {
  flex: 1; min-width: 0; width: 100%; padding: 0 14px; border: 0; outline: none; background: transparent;
  font: 600 max(16px, 1.125rem) var(--mono); font-variant-numeric: tabular-nums;
}
.field input::placeholder { color: var(--muted); font-weight: 400; }
.field input:disabled { color: var(--muted); }

/* KB | MB toggle */
.seg { display: flex; flex: none; padding: 3px; gap: 3px; border-left: 1px solid var(--muted); }
.seg button {
  min-width: 52px; padding: 0 10px; border: 0; border-radius: 5px; background: transparent;
  color: var(--muted); font-weight: 700; cursor: pointer; transition: background-color .15s, color .15s;
}
.seg button[aria-checked=true] { background: var(--accent); color: var(--on-accent); }
.seg button:disabled { cursor: not-allowed; opacity: .6; }
.seg button:focus-visible { outline-offset: 0; }

@media (pointer: coarse) {
  .verb.fine { display: none; }
  .verb.coarse { display: inline; }
  .field, .namefield { height: 52px; }
  .seg button { min-width: 3.5rem; min-height: 44px; }
  .drop:active { border-color: var(--accent-text); }
}
@media (hover: hover) and (pointer: fine) {
  .drop:hover { border-color: var(--accent-text); }
  .icon-btn:hover { background: var(--rule); color: var(--ink); }
  .seg button:hover:not(:disabled):not([aria-checked=true]) { background: var(--surface); color: var(--ink); }
  .go:hover:not(:disabled) { background: var(--accent-hover); }
}

/* Primary action: a press coming down */
.go {
  height: 48px; padding: 0 24px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: var(--r-ctl); background: var(--accent); color: var(--on-accent);
  font-weight: 700; white-space: nowrap; text-decoration: none; cursor: pointer;
  transition: background-color .15s, transform .1s;
}
.go:active:not(:disabled) { transform: translateY(1px); }
@media (pointer: coarse) { .go { height: 52px; } }
.go:disabled { background: var(--rule); color: var(--muted); cursor: not-allowed; }

/* Progress: hazard stripes are the one authored motion moment */
#progress { margin-top: 20px; display: grid; gap: 8px; }
.track { height: 14px; border-radius: 4px; background: var(--raised); border: 1px solid var(--ink); overflow: hidden; }
#bar {
  height: 100%; width: 0;
  background: repeating-linear-gradient(-45deg, var(--accent) 0 8px, var(--ink) 8px 16px);
  background-size: 22.63px 22.63px; animation: haul .8s linear infinite;
}
@keyframes haul { to { background-position: 22.63px 0; } }
#status { font-size: .875rem; color: var(--muted); }

/* Output */
.empty { display: flex; align-items: center; gap: 12px; padding: 12px 0; color: var(--muted); }
.empty .i { width: 24px; height: 24px; }
.res-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-width: 0; }
.res-head > .i { width: 24px; height: 24px; color: var(--muted); }
.res-head .meta { flex: 1; min-width: 0; }
.fname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sizes { font-size: .95rem; color: var(--muted); }
.sizes b { color: var(--ink); }
.saved { color: var(--ok); font-weight: 700; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px;
  font-size: .85rem; font-weight: 700;
}
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.bad { color: var(--warn-ink); background: var(--warn-bg); }

/* Squeeze gauge: outline = original size, orange fill = result, tick = target */
.gauge { position: relative; height: 16px; margin: 20px 0 6px; border: 1px solid var(--ink); border-radius: 4px; background: var(--raised); }
.gauge .fill { display: block; height: 100%; background: var(--accent); }
.gauge .tick { position: absolute; top: -6px; bottom: -6px; width: 3px; margin-left: -1.5px; background: var(--ink); }
.gauge-key { display: flex; justify-content: space-between; gap: 12px; font-size: .8rem; color: var(--muted); }

.warn {
  display: flex; gap: 10px; align-items: flex-start; margin: 16px 0; padding: 12px 14px; border-radius: var(--r-ctl);
  background: var(--warn-bg); color: var(--warn-ink);
}
.warn .i { margin-top: .15em; }
.cmp { display: grid; grid-template-columns: 1fr; gap: 12px; margin: 16px 0; }
.cmp figure { margin: 0; }
.cmp img {
  display: block; width: 100%; max-width: 100%; height: clamp(160px, 46cqi, 240px); object-fit: contain;
  border: 1px solid var(--rule); border-radius: var(--r-ctl); background: var(--raised);
}
.cmp figcaption { margin-top: 6px; font-size: .85rem; color: var(--muted); }
.notes { list-style: none; margin: 16px 0; padding: 0; display: grid; gap: 6px; color: var(--muted); font-size: .9rem; }
.notes li { display: flex; gap: 8px; align-items: flex-start; }
.notes .i { margin-top: .2em; }
.save { display: grid; gap: 12px; margin-top: 20px; }
.save .go { width: 100%; }
.namefield { flex: 1; min-width: 0; width: 100%; align-items: center; gap: 8px; padding: 0 8px 0 12px; }
.namefield > .i { color: var(--muted); }
.namefield input { flex: 1; min-width: 0; width: 100%; border: 0; outline: none; background: transparent; font-weight: 500; font-size: max(16px, 1rem); }
.ext { padding: 4px 8px; border-radius: 6px; color: var(--ink); background: var(--rule); font: 600 .85rem var(--mono); flex: none; }

/* Wide enough for the field and the press to share a row. */
@container work (min-width: 28rem) {
  .controls { grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
  .go { min-width: 11.5rem; }
  .drop { padding-block: clamp(28px, 6cqi, 48px); }
}
/* Previews sit side by side only once each one is readable. */
@container result (min-width: 26rem) {
  .cmp { grid-template-columns: 1fr 1fr; }
  .cmp img { height: clamp(140px, 28cqi, 260px); }
  .save { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .save .go { width: auto; }
}
@container result (max-width: 22rem) {
  .res-head { display: grid; grid-template-columns: auto minmax(0, 1fr); }
  .res-head .badge { grid-column: 1 / -1; justify-self: start; }
}

/* Tablet landscape and laptops: result beside the work. Capped so 4K stays a tool, not a banner. */
@media (min-width: 960px) {
  main {
    width: min(100%, 72rem);
    grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
    align-items: start;
    column-gap: 24px;
    padding-inline: max(28px, env(safe-area-inset-left)) max(28px, env(safe-area-inset-right));
  }
  header { grid-column: 1 / -1; }
}
@media (min-width: 1600px) {
  main { padding-inline: max(48px, env(safe-area-inset-left)) max(48px, env(safe-area-inset-right)); }
}

/* Short landscape phones: keep the press on screen. */
@media (max-height: 520px) {
  main {
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    gap: 12px;
  }
  header { padding-bottom: 10px; }
  .tag { margin-top: 6px; }
  .drop { padding-block: 14px; }
  .card { padding: 14px; }
  .controls { margin-top: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  #bar { animation: none; }
  .pill .knob, .drop.over > .i { transition: none; }
  .drop.over > .i { transform: none; }
}
