/* ===== ImageForge - tool page styles (STEP 2) ===== */
/* Used together with style.css. Reuses its color variables. */
:root { color-scheme: dark; }

[hidden] { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; white-space: nowrap;
}

.tool-page { padding: 32px 0 8px; }
.back-link { display: inline-block; margin-bottom: 14px; color: var(--text-dim); font-size: 14px; }
.back-link:hover { color: var(--text); }
.tool-head { margin-bottom: 24px; }
.tool-head h1 { font-size: clamp(26px, 4vw, 36px); font-weight: 800; letter-spacing: -0.02em; }
.tool-head p { margin-top: 8px; max-width: 720px; color: var(--text-dim); }

/* ===== Notices ===== */
.notice {
  margin-bottom: 16px; padding: 12px 16px; border-radius: 12px; font-size: 14px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-dim);
}
.notice.error { border-color: #ef4444; background: rgba(239, 68, 68, 0.12); color: #fecaca; }
.notice.warn { border-color: #f59e0b; background: rgba(245, 158, 11, 0.1); color: #fde68a; }

/* ===== Drop zone ===== */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 56px 20px; text-align: center; cursor: pointer;
  background: var(--surface); border: 2px dashed var(--border); border-radius: var(--radius);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone svg { width: 40px; height: 40px; color: var(--accent-2); }
.dz-title { font-size: 18px; font-weight: 700; }
.dz-hint { color: var(--text-dim); font-size: 14px; max-width: 520px; }

/* ===== Layout ===== */
.workspace { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; align-items: start; }
.stack { display: grid; gap: 20px; min-width: 0; }
.panel {
  min-width: 0; padding: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.panel h2 { margin-bottom: 14px; font-size: 15px; font-weight: 700; }

/* ===== Form controls ===== */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > label, .field > .label { color: var(--text-dim); font-size: 13px; font-weight: 600; }
.field-hint { color: var(--text-dim); font-size: 12.5px; }
.row { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 16px; }
.row > * { flex: 1; min-width: 0; }
.row .field { margin-bottom: 0; }

input[type="number"], select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; font-size: 15px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
}
textarea { resize: vertical; min-height: 76px; line-height: 1.4; }
input[type="number"]:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="color"] {
  width: 100%; height: 40px; padding: 3px; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px;
}
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; font-size: 14px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.field .check { margin-bottom: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; font-size: 15px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #7c3aed; border-color: #7c3aed; }
.btn-block { display: flex; width: 100%; }
.btn + .btn { margin-top: 10px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 12px; font-size: 13px; font-weight: 600;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 999px;
}
.chip:hover { border-color: var(--accent); color: var(--accent-2); }

/* ===== Previews ===== */
.preview-box {
  display: flex; align-items: center; justify-content: center; min-height: 140px; padding: 12px; overflow: auto;
  background: repeating-conic-gradient(#1a2240 0 25%, #141b33 0 50%) 0 0 / 20px 20px;
  border: 1px solid var(--border); border-radius: 12px;
}
.preview-box img, .preview-box canvas { display: block; max-width: 100%; max-height: 560px; width: auto; height: auto; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.compare h2 { margin-bottom: 10px; }

.stats { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 16px 0 0; font-size: 14px; }
.stats dt { color: var(--text-dim); }
.stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.stats .good { color: #86efac; }
.stats .bad { color: #fca5a5; }

/* ===== Responsive ===== */
@media (min-width: 901px) {
  /* keeps the preview visible while the settings panel is scrolled */
  .preview-panel { position: sticky; top: calc(var(--header-h) + 16px); }
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .preview-panel { order: -1; }
  .mobile-first { order: -1; }
}
@media (max-width: 720px) {
  .tool-page { padding-top: 22px; }
  .dropzone { padding: 40px 16px; }
  .compare { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
}

/* ===== STEP 3 additions ===== */
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip:disabled { opacity: 0.5; cursor: not-allowed; }
.field-inline { display: flex; align-items: center; gap: 10px; }
.field-inline > * { flex: 1; min-width: 0; }
.pair-label { display: inline-block; padding: 6px 14px; margin-bottom: 16px; font-weight: 700; background: var(--accent-soft); color: var(--accent-2); border: 1px solid var(--border); border-radius: 999px; }
.stats .col-end { text-align: right; }

/* color extractor */
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.swatch { overflow: hidden; background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; }
.swatch-color { height: 72px; border-bottom: 1px solid var(--border); }
.swatch-info { display: grid; gap: 2px; padding: 10px 12px 6px; font-size: 13px; color: var(--text-dim); }
.swatch-info strong { color: var(--text); font-size: 15px; letter-spacing: 0.02em; }
.swatch-actions { display: flex; gap: 6px; padding: 6px 12px 12px; }
.swatch-actions .chip { flex: 1; border-radius: 8px; }
.palette-actions { margin-top: 14px; }
.pick-canvas { display: block; max-width: 100%; max-height: 520px; width: auto; height: auto; cursor: crosshair; touch-action: none; }
.picked-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 14px; }
.picked-swatch { width: 54px; height: 54px; flex: none; border: 1px solid var(--border); border-radius: 12px; background: repeating-conic-gradient(#1a2240 0 25%, #141b33 0 50%) 0 0 / 12px 12px; }
.picked-text { display: grid; gap: 2px; min-width: 0; font-size: 14px; color: var(--text-dim); }
.picked-text strong { color: var(--text); font-size: 16px; }
.hover-chip { display: inline-flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13px; color: var(--text-dim); }
.hover-chip i { display: inline-block; width: 18px; height: 18px; border: 1px solid var(--border); border-radius: 5px; }

/* cropper */
.crop-wrap { display: flex; justify-content: center; padding: 12px; background: repeating-conic-gradient(#1a2240 0 25%, #141b33 0 50%) 0 0 / 20px 20px; border: 1px solid var(--border); border-radius: 12px; }
.crop-stage { position: relative; display: inline-block; max-width: 100%; line-height: 0; overflow: hidden; user-select: none; -webkit-user-select: none; }
.crop-stage img { display: block; max-width: 100%; max-height: 68vh; width: auto; height: auto; pointer-events: none; }
.crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55); cursor: move; touch-action: none; outline-offset: 2px; }
.crop-box:focus-visible { outline: 2px solid var(--accent-2); }
.crop-handle { position: absolute; width: 14px; height: 14px; background: var(--accent); border: 2px solid #fff; border-radius: 4px; }
.crop-handle::before { content: ""; position: absolute; inset: -6px; }
.crop-handle[data-h="nw"] { left: -9px; top: -9px; cursor: nwse-resize; }
.crop-handle[data-h="ne"] { right: -9px; top: -9px; cursor: nesw-resize; }
.crop-handle[data-h="sw"] { left: -9px; bottom: -9px; cursor: nesw-resize; }
.crop-handle[data-h="se"] { right: -9px; bottom: -9px; cursor: nwse-resize; }
.crop-handle[data-h="n"] { left: calc(50% - 7px); top: -9px; cursor: ns-resize; }
.crop-handle[data-h="s"] { left: calc(50% - 7px); bottom: -9px; cursor: ns-resize; }
.crop-handle[data-h="w"] { top: calc(50% - 7px); left: -9px; cursor: ew-resize; }
.crop-handle[data-h="e"] { top: calc(50% - 7px); right: -9px; cursor: ew-resize; }
.num-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.num-grid .field { margin-bottom: 0; }

/* ===== STEP 4: loading, favorite toggle, related tools, spacing helpers ===== */
a.chip { display: inline-block; }
.loader {
  position: fixed; top: calc(var(--header-h) + 12px); left: 50%; transform: translateX(-50%); z-index: 90;
  display: inline-flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px);
  padding: 10px 18px; font-size: 14px;
  background: var(--surface-2); border: 1px solid var(--accent); border-radius: 999px; box-shadow: var(--shadow);
}
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent-2); border-radius: 50%; animation: ck-spin .8s linear infinite; }
@keyframes ck-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.fav-toggle {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 14px; padding: 7px 14px;
  font-size: 14px; font-weight: 600; color: var(--text-dim);
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
}
.fav-toggle svg { width: 18px; height: 18px; }
.fav-toggle:hover { border-color: #fbbf24; color: var(--text); }
.fav-toggle.active { color: #fbbf24; border-color: #fbbf24; }
.fav-toggle.active svg { fill: currentColor; }

.related { margin-top: 36px; }
.related h2 { margin-bottom: 12px; font-size: 16px; font-weight: 700; }

.mt-0 { margin-top: 0; }
.mt-10 { margin-top: 10px; }
.mt-12 { margin-top: 12px; }

/* ===== framing control (drag / zoom) ===== */
canvas.framer { cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
canvas.framer.dragging { cursor: grabbing; }
canvas.framer:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.hint { font-size: 13px; color: var(--text-dim); margin: -4px 0 10px; line-height: 1.6; }

/* ===== mosaic tool ===== */
.mosaic-stage { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #000; line-height: 0; }
.mosaic-stage canvas { display: block; width: 100%; height: auto; cursor: crosshair; touch-action: none; user-select: none; -webkit-user-select: none; }
.mosaic-stage canvas:focus-visible { outline: 2px solid var(--accent-2); outline-offset: -2px; }
.mosaic-count { font-size: 14px; color: var(--text-dim); margin: 14px 0 8px; }
.btn-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 16px; }
.btn-row .btn + .btn { margin-top: 0; }
.btn-row .btn { padding-left: 6px; padding-right: 6px; font-size: 14px; white-space: nowrap; }

/* ===== video ratio tool ===== */
.video-src { position: absolute; width: 2px; height: 2px; opacity: 0; pointer-events: none; left: 0; top: 0; }
.video-stage { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #000; line-height: 0; display: flex; justify-content: center; }
/* tall ratios (9:16) would otherwise fill the whole screen: cap the height, keep the aspect */
.video-stage canvas { display: block; width: auto; height: auto; max-width: 100%; max-height: 65vh; }
.video-stage.locked canvas { pointer-events: none; cursor: default; }
.player { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.player .btn { width: auto; margin: 0; padding: 8px 14px; flex: none; }
.player input[type="range"] { flex: 1; min-width: 0; }
.player .time { font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.progress { margin-top: 14px; }
.progress progress { width: 100%; height: 10px; accent-color: var(--accent); }
.progress p { font-size: 13px; color: var(--text-dim); margin-top: 6px; }
.result-video { width: 100%; max-height: 480px; border-radius: 12px; background: #000; display: block; }

fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.plain[disabled] { opacity: .6; }
