:root {
  --it-bg: #0f0e12;
  --it-bg-2: #131217;
  --it-panel: #17161c;
  --it-panel-2: #1c1a21;
  --it-line: rgba(255, 255, 255, 0.1);
  --it-line-strong: rgba(251, 191, 36, 0.3);
  --it-ink: #f5f2ea;
  --it-ink-2: #cec9bf;
  --it-muted: #8e8994;
  --it-amber: #fbbf24;
  --it-amber-soft: #fcd34d;
  --it-blue: #60a5fa;
  --it-danger: #fb7185;
  --it-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --it-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

body.image-tools-page {
  overflow-x: hidden;
  background: var(--it-bg);
}

body.image-tools-standalone {
  min-width: 280px;
  margin: 0;
  color: var(--it-ink);
  font-family: var(--it-sans);
}

.image-tools-page .foot { margin-top: 0; }

.image-tools-app,
.image-tools-app * { box-sizing: border-box; }

.image-tools-app {
  width: 100%;
  max-width: none;
  min-height: calc(100vh - 59px);
  color: var(--it-ink);
  background:
    radial-gradient(circle at 76% -4%, rgba(251, 191, 36, 0.08), transparent 31rem),
    var(--it-bg);
  font-family: var(--it-sans);
}

.image-tools-app button,
.image-tools-app input,
.image-tools-app select { font: inherit; }

.image-tools-app button,
.image-tools-app a { -webkit-tap-highlight-color: transparent; }

.image-tools-app a { color: inherit; }

.it-header {
  display: flex;
  min-height: 64px;
  align-items: stretch;
  justify-content: space-between;
  gap: 28px;
  padding: 0 clamp(14px, 2vw, 32px);
  border-bottom: 1px solid var(--it-line);
  background: rgba(15, 14, 18, 0.88);
  backdrop-filter: blur(18px);
}

.it-identity,
.it-wordmark,
.it-wordmark > span:last-child,
.it-local { display: flex; align-items: center; }

.it-identity { gap: 25px; min-width: 0; }
.it-wordmark { gap: 11px; text-decoration: none; }
.it-wordmark > span:last-child { align-items: baseline; gap: 8px; }
.it-wordmark b { font-size: 13px; font-weight: 660; letter-spacing: 0.01em; }
.it-wordmark small { color: var(--it-muted); font: 9px/1 var(--it-mono); letter-spacing: 0.07em; text-transform: uppercase; }

.it-glyph {
  position: relative;
  width: 18px;
  height: 18px;
  border: 1px solid rgba(251, 191, 36, 0.5);
  border-radius: 5px;
  background: rgba(251, 191, 36, 0.08);
  box-shadow: inset 0 0 14px rgba(251, 191, 36, 0.05);
}

.it-glyph::before,
.it-glyph::after {
  content: "";
  position: absolute;
  background: var(--it-amber);
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.55);
}
.it-glyph::before { inset: 4px 8px; }
.it-glyph::after { inset: 8px 4px; }

.it-local { gap: 7px; color: var(--it-muted); font: 9px/1 var(--it-mono); letter-spacing: 0.05em; text-transform: uppercase; white-space: nowrap; }
.it-local i { width: 6px; height: 6px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 8px rgba(74, 222, 128, 0.55); }

#tabs { display: flex; align-items: stretch; }
.it-tab {
  position: relative;
  min-width: 142px;
  padding: 0 21px;
  border: 0;
  color: var(--it-muted);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 580;
}
.it-tab::after { content: ""; position: absolute; right: 20px; bottom: -1px; left: 20px; height: 2px; border-radius: 2px 2px 0 0; background: transparent; }
.it-tab:hover { color: var(--it-ink-2); }
.it-tab[aria-selected="true"] { color: var(--it-ink); }
.it-tab[aria-selected="true"]::after { background: var(--it-amber); box-shadow: 0 0 13px rgba(251, 191, 36, 0.4); }
.it-tab:focus-visible,
.it-btn:focus-visible,
.thumb:focus-visible,
.thumb-remove:focus-visible,
.dropzone:focus-visible,
.add-tile:focus-visible,
.it-field input:focus-visible,
.it-field select:focus-visible { outline: 2px solid var(--it-blue); outline-offset: 2px; }

.it-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  padding: clamp(30px, 4vw, 54px) clamp(14px, 2vw, 32px) clamp(28px, 3vw, 42px);
  border-bottom: 1px solid rgba(251, 191, 36, 0.09);
  transition: padding 180ms ease;
}
.it-intro > div:first-child { max-width: 820px; }
.it-eyebrow { color: var(--it-amber); font: 600 9px/1.2 var(--it-mono); letter-spacing: 0.12em; text-transform: uppercase; }
.it-intro h1 { margin: 9px 0 12px; font-size: clamp(32px, 4.6vw, 57px); font-weight: 300; line-height: 1.03; letter-spacing: -0.045em; }
.it-intro p { max-width: 720px; margin: 0; color: var(--it-muted); font-size: 15px; line-height: 1.65; }
.it-intro-actions { display: flex; flex: none; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }
.image-tools-app:not(.is-empty) .it-intro { padding-top: 18px; padding-bottom: 18px; }
.image-tools-app:not(.is-empty) .it-intro h1 { margin-bottom: 0; font-size: clamp(23px, 2.7vw, 34px); }
.image-tools-app:not(.is-empty) .it-intro p,
.image-tools-app:not(.is-empty) .it-eyebrow { display: none; }

.it-btn {
  display: inline-flex;
  min-height: 39px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 13px;
  border: 1px solid var(--it-line);
  border-radius: 8px;
  color: var(--it-ink-2);
  background: rgba(255, 255, 255, 0.025);
  cursor: pointer;
  font-size: 11px;
  font-weight: 620;
  line-height: 1;
  text-decoration: none;
  transition: border-color 120ms ease, color 120ms ease, background 120ms ease, transform 120ms ease;
}
.it-btn:hover { border-color: rgba(255, 255, 255, 0.2); color: var(--it-ink); background: rgba(255, 255, 255, 0.045); }
.it-btn:active { transform: translateY(1px); }
.it-btn svg { width: 14px; height: 14px; }
.it-btn-primary { border-color: transparent; color: #18130a; background: var(--it-amber); }
.it-btn-primary:hover { border-color: transparent; color: #120f08; background: var(--it-amber-soft); }
.it-btn-quiet { border-color: transparent; background: transparent; color: var(--it-muted); }

.optionsbar {
  display: flex;
  min-height: 66px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 11px clamp(14px, 2vw, 32px);
  border-bottom: 1px solid var(--it-line);
  background: var(--it-bg-2);
}
.optionsbar[hidden] { display: none; }
#toolOptions,
.grp { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.grp-export { flex-wrap: nowrap; }
.it-field { display: grid; gap: 5px; }
.it-field > span { color: var(--it-muted); font: 8px/1 var(--it-mono); letter-spacing: 0.09em; text-transform: uppercase; }
.it-field input,
.it-field select {
  min-width: 76px;
  height: 35px;
  padding: 6px 9px;
  border: 1px solid var(--it-line);
  border-radius: 7px;
  color: var(--it-ink-2);
  background: var(--it-panel);
  font-size: 11px;
}
.it-field input[type="number"] { width: 82px; }
.it-check { display: flex; min-height: 35px; align-items: center; gap: 7px; color: var(--it-ink-2); font-size: 10px; cursor: pointer; }
.it-check input { accent-color: var(--it-amber); }
.it-divider { width: 1px; height: 31px; background: var(--it-line); }
.auto-size { display: grid; min-width: 0; gap: 5px; margin: 0; padding: 0; border: 0; }
.auto-size legend { margin: 0 0 5px; padding: 0; color: var(--it-muted); font: 8px/1 var(--it-mono); letter-spacing: 0.09em; text-transform: uppercase; }
.auto-size-actions { display: inline-flex; align-items: stretch; }
.auto-choice,
.auto-undo {
  min-width: 52px;
  height: 35px;
  margin: 0 0 0 -1px;
  padding: 6px 9px;
  border: 1px solid var(--it-line);
  border-radius: 0;
  color: var(--it-ink-2);
  background: var(--it-panel);
  font: 600 9px/1 var(--it-sans);
}
.auto-choice:first-child { margin-left: 0; border-radius: 7px 0 0 7px; }
.auto-choice:last-of-type { border-radius: 0 7px 7px 0; }
.auto-choice:hover,
.auto-undo:hover { position: relative; z-index: 1; border-color: rgba(251, 191, 36, 0.44); color: var(--it-ink); }
.auto-choice[aria-pressed="true"] { position: relative; z-index: 1; border-color: rgba(251, 191, 36, 0.56); color: var(--it-amber-soft); background: rgba(251, 191, 36, 0.08); }
.auto-choice:disabled,
.auto-undo:disabled { cursor: wait; opacity: 0.52; }
.auto-undo { margin-left: 6px; border-radius: 7px; color: var(--it-muted); background: transparent; }
.auto-undo[hidden] { display: none; }
.auto-size-note { max-width: 290px; color: var(--it-muted); font-size: 9px; line-height: 1.35; }
.auto-size-note[hidden] { display: none; }

.it-body {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  min-width: 0;
  min-height: 560px;
}
.image-tools-app.is-empty .it-body { grid-template-columns: minmax(0, 1fr); }
.image-tools-app.is-empty .workspace { display: none; }

.workspace {
  min-width: 0;
  padding: 15px 11px;
  border-right: 1px solid var(--it-line);
  background: #111015;
}
.ws-head { display: flex; align-items: center; justify-content: space-between; padding: 1px 5px 11px; color: var(--it-muted); font: 8px/1 var(--it-mono); letter-spacing: 0.1em; text-transform: uppercase; }
.ws-head .cnt { color: var(--it-amber); }
.tray { display: grid; gap: 9px; }
.thumb-wrap { position: relative; }
.thumb,
.add-tile {
  width: 100%;
  border: 1px solid var(--it-line);
  border-radius: 8px;
  color: var(--it-muted);
  background: var(--it-panel);
  cursor: pointer;
}
.thumb { display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: center; gap: 9px; min-height: 56px; padding: 6px 27px 6px 6px; text-align: left; }
.thumb:hover,
.add-tile:hover { border-color: rgba(251, 191, 36, 0.28); color: var(--it-ink-2); }
.thumb[aria-pressed="true"] { border-color: rgba(251, 191, 36, 0.48); background: rgba(251, 191, 36, 0.065); box-shadow: inset 2px 0 var(--it-amber); }
.thumb-preview { display: grid; width: 44px; height: 44px; place-items: center; overflow: hidden; border-radius: 5px; background-color: #27242c; background-image: linear-gradient(45deg, #302d35 25%, transparent 25%), linear-gradient(-45deg, #302d35 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #302d35 75%), linear-gradient(-45deg, transparent 75%, #302d35 75%); background-size: 10px 10px; background-position: 0 0, 0 5px, 5px -5px, -5px 0; }
.thumb-preview canvas { max-width: 100%; max-height: 100%; image-rendering: pixelated; }
.thumb-copy { min-width: 0; }
.thumb-name { display: block; overflow: hidden; color: var(--it-ink-2); font-size: 9px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.thumb-meta { display: block; margin-top: 4px; color: var(--it-muted); font: 8px/1 var(--it-mono); }
.thumb-remove { position: absolute; top: 6px; right: 5px; width: 25px; height: 25px; border: 0; border-radius: 5px; color: transparent; background: transparent; cursor: pointer; }
.thumb-remove::before,
.thumb-remove::after { content: ""; position: absolute; top: 12px; left: 8px; width: 10px; height: 1px; background: var(--it-muted); transform: rotate(45deg); }
.thumb-remove::after { transform: rotate(-45deg); }
.thumb-remove:hover { background: rgba(251, 113, 133, 0.11); }
.thumb-remove:hover::before,
.thumb-remove:hover::after { background: var(--it-danger); }
.add-tile { min-height: 39px; border-style: dashed; background: transparent; font: 9px/1 var(--it-mono); }

.stage-host { min-width: 0; padding: clamp(14px, 2vw, 28px); background: linear-gradient(180deg, rgba(255, 255, 255, 0.009), transparent 18rem); }
.empty-stage { display: grid; min-height: 520px; place-items: center; }
.dropzone {
  display: grid;
  width: min(100%, 760px);
  min-height: 310px;
  place-items: center;
  padding: 36px;
  border: 1px dashed rgba(251, 191, 36, 0.28);
  border-radius: 16px;
  color: var(--it-muted);
  background: radial-gradient(circle at 50% 44%, rgba(251, 191, 36, 0.055), transparent 15rem), rgba(255, 255, 255, 0.012);
  cursor: pointer;
  text-align: center;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}
.dropzone:hover,
.dropzone.is-over { border-color: rgba(251, 191, 36, 0.62); background-color: rgba(251, 191, 36, 0.025); transform: translateY(-1px); }
.dropzone-mark { display: grid; width: 54px; height: 54px; margin: 0 auto 18px; place-items: center; border: 1px solid rgba(251, 191, 36, 0.24); border-radius: 14px; color: var(--it-amber); background: rgba(251, 191, 36, 0.06); font: 300 28px/1 var(--it-sans); }
.dropzone strong { display: block; color: var(--it-ink-2); font-size: 16px; font-weight: 570; }
.dropzone span { display: block; margin-top: 8px; font-size: 11px; line-height: 1.6; }
.dropzone em { display: block; margin-top: 21px; color: #706b75; font: normal 8px/1.5 var(--it-mono); letter-spacing: 0.05em; text-transform: uppercase; }

.compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(12px, 1.6vw, 23px); min-width: 0; }
.preview-panel,
.sheet-panel { min-width: 0; overflow: hidden; border: 1px solid var(--it-line); border-radius: 12px; background: var(--it-panel); }
.panel-head { display: flex; min-height: 43px; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 13px; border-bottom: 1px solid var(--it-line); }
.panel-head strong { color: var(--it-ink-2); font-size: 10px; font-weight: 620; }
.panel-head span { color: var(--it-muted); font: 8px/1 var(--it-mono); white-space: nowrap; }
.canvas-well {
  display: grid;
  min-height: 470px;
  place-items: center;
  overflow: auto;
  padding: clamp(13px, 2vw, 27px);
  background-color: #242129;
  background-image: linear-gradient(45deg, #2d2a32 25%, transparent 25%), linear-gradient(-45deg, #2d2a32 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #2d2a32 75%), linear-gradient(-45deg, transparent 75%, #2d2a32 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}
.canvas-well canvas { display: block; max-width: 100%; max-height: 68vh; object-fit: contain; box-shadow: 0 14px 45px rgba(0, 0, 0, 0.34); image-rendering: pixelated; }
.comparison-frame { position: relative; flex: none; min-width: 1px; min-height: 1px; line-height: 0; }
.comparison-frame > .comparison-image { width: 100%; height: 100%; max-width: none; max-height: none; object-fit: fill; }
.comparison-frame > .sampling-grid { position: absolute; z-index: 2; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; pointer-events: none; box-shadow: none; image-rendering: auto; }
.result-inspector { position: absolute; z-index: 3; right: 10px; bottom: 10px; display: flex; max-width: calc(100% - 20px); max-height: min(48%, 240px); align-items: end; justify-content: end; gap: 8px; }
.actual-inset,
.palette-inset { border: 1px solid rgba(251, 191, 36, 0.55); border-radius: 7px; background: rgba(15, 14, 18, 0.94); box-shadow: 0 12px 34px rgba(0, 0, 0, 0.55); }
.actual-inset { display: grid; max-width: 128px; max-height: 128px; overflow: auto; }
.actual-inset > span,
.palette-inset > span { position: sticky; z-index: 1; top: 0; left: 0; width: max-content; padding: 4px 6px; color: var(--it-amber); background: rgba(15, 14, 18, 0.9); font: 8px/1 var(--it-mono); letter-spacing: 0.08em; text-transform: uppercase; }
.actual-inset canvas { width: auto; height: auto; max-width: none; max-height: none; box-shadow: none; image-rendering: pixelated; }
.palette-inset { display: grid; max-width: 218px; max-height: 230px; overflow: hidden; }
.palette-swatches { display: grid; overflow: auto; grid-template-columns: repeat(var(--palette-columns), 15px); gap: 3px; padding: 7px; }
.palette-swatch { width: 15px; height: 15px; padding: 0; border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 3px; background: var(--swatch); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16); cursor: copy; }
.palette-swatch:hover { z-index: 1; border-color: var(--it-ink); transform: scale(1.22); }
.palette-swatch:focus-visible { z-index: 1; outline: 2px solid var(--it-blue); outline-offset: 2px; }
.sheet-panel .canvas-well { min-height: 520px; }
.render-note { margin: 12px 2px 0; color: var(--it-muted); font-size: 10px; line-height: 1.55; }

.toast { position: fixed; z-index: 20; right: 20px; bottom: 20px; max-width: min(360px, calc(100vw - 32px)); padding: 11px 14px; border: 1px solid rgba(251, 191, 36, 0.24); border-radius: 8px; color: var(--it-ink-2); background: rgba(24, 22, 28, 0.96); box-shadow: 0 18px 48px rgba(0, 0, 0, 0.42); font-size: 11px; }
.toast[hidden] { display: none; }

.it-foot { display: flex; min-height: 58px; align-items: center; justify-content: space-between; gap: 20px; padding: 15px clamp(14px, 2vw, 32px); border-top: 1px solid var(--it-line); color: var(--it-muted); background: #0d0c10; font: 8px/1.5 var(--it-mono); letter-spacing: 0.04em; text-transform: uppercase; }
.it-foot a { color: var(--it-ink-2); text-underline-offset: 3px; }
.it-foot a:hover { color: var(--it-amber); }

/* On a roomy screen, Image Tools behaves like a workstation rather than a long page. */
@media (min-width: 861px) and (min-height: 720px) {
  body.image-tools-page:not(.image-tools-standalone) {
    display: grid;
    height: 100dvh;
    min-height: 100dvh;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
  }

  body.image-tools-page:not(.image-tools-standalone) > .nav { grid-row: 1; }
  body.image-tools-page:not(.image-tools-standalone) > .image-tools-app { grid-row: 2; height: 100%; }
  body.image-tools-page:not(.image-tools-standalone) > .foot { display: none; }

  body.image-tools-standalone {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  body.image-tools-standalone .image-tools-app { height: 100dvh; }

  .image-tools-app {
    display: grid;
    min-height: 0;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    overflow: hidden;
  }

  .image-tools-app:not(.is-empty) .it-intro { display: none; }

  .it-body {
    height: auto;
    min-height: 0;
    overflow: hidden;
  }

  .workspace {
    min-height: 0;
    overflow-y: auto;
  }

  .stage-host {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .empty-stage,
  .compare {
    height: 100%;
    min-height: 0;
  }

  .preview-panel,
  .sheet-panel {
    display: grid;
    height: 100%;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .canvas-well,
  .sheet-panel .canvas-well {
    height: auto;
    min-height: 0;
    overflow: hidden;
  }

  .sheet-stage {
    display: grid;
    height: 100%;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .sheet-panel .canvas-well canvas {
    width: auto !important;
    height: auto !important;
    max-width: 100%;
    max-height: 100%;
  }
}

@media (max-width: 980px) {
  .it-header { align-items: center; }
  .it-local { display: none; }
  .it-intro { align-items: start; flex-direction: column; }
  .it-intro-actions { justify-content: flex-start; }
  .optionsbar { align-items: start; flex-direction: column; }
  .grp-export { align-self: stretch; }
  .grp-export .it-btn { flex: 1; }
  .canvas-well { min-height: 390px; }
}

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

@media (max-width: 760px) {
  .it-header { display: block; padding-top: 13px; }
  .it-identity { min-height: 38px; }
  #tabs { height: 48px; margin-top: 3px; overflow-x: auto; }
  .it-tab { flex: 1; min-width: 136px; }
  .it-body { grid-template-columns: 1fr; }
  .workspace { padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--it-line); }
  .tray { display: flex; overflow-x: auto; padding-bottom: 3px; }
  .thumb-wrap { flex: 0 0 150px; }
  .add-tile { flex: 0 0 82px; min-height: 56px; }
  .stage-host { padding: 14px; }
  .it-foot { align-items: start; flex-direction: column; }
}

@media (max-width: 520px) {
  .it-wordmark small { display: none; }
  .it-intro { padding-right: 16px; padding-left: 16px; }
  .it-intro-actions { width: 100%; }
  .it-intro-actions .it-btn { flex: 1; }
  .image-tools-app:not(.is-empty) .it-intro { display: none; }
  #toolOptions { align-items: stretch; display: grid; width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auto-size { grid-column: 1 / -1; }
  .auto-size-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; }
  .auto-choice,
  .auto-undo { width: 100%; min-width: 0; }
  .auto-size-note { max-width: none; }
  .it-field input,
  .it-field select,
  .it-field input[type="number"] { width: 100%; min-width: 0; }
  .it-divider { display: none; }
  .grp-export { display: grid; width: 100%; grid-template-columns: 1fr 1fr; }
  #clearBtn { grid-column: 1 / -1; }
  .dropzone { min-height: 285px; padding: 26px 18px; }
  .empty-stage { min-height: 410px; }
  .canvas-well,
  .sheet-panel .canvas-well { min-height: 310px; padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .image-tools-app *,
  .image-tools-app *::before,
  .image-tools-app *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
