/* ==========================================================================
   QuickFileTools – Image Cropper
   Design System: "The Desk" (tokens.css + components.css)
   ========================================================================== */

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background-color: var(--bg);
  font-family: var(--font-sans);
  line-height: var(--line-height-body, 1.6);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font-family: inherit;
  font-size: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--action);
  text-decoration: underline;
}

:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--action);
  outline-offset: 2px;
}

main {
  max-width: var(--max-content, 1120px);
  margin: 0 auto;
  padding: 0 var(--space-4, 16px) var(--space-12, 48px);
}

/* ---------- Hero ---------- */

.tool-section {
  padding: var(--space-6, 24px) 0 var(--space-4, 16px);
  text-align: left;
}

.hero-copy {
  text-align: left;
}

.hero-copy h1 {
  margin: 0 0 var(--space-2, 8px);
  font-size: var(--font-size-h1);
  font-weight: var(--font-weight-heading);
  line-height: var(--line-height-heading);
  letter-spacing: -0.02em;
  color: var(--ink);
}

.hero-copy p {
  margin: 0 0 var(--space-3, 12px);
  max-width: var(--max-measure, 70ch);
  color: var(--ink-muted);
  font-size: var(--font-size-base);
}

/* ---------- Main Cropper Sheet ---------- */

.cropper-shell {
  background: var(--sheet);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sheet);
  box-shadow: var(--elevation-sheet);
  overflow: hidden;
  margin-top: var(--space-4, 16px);
}

[data-theme="dark"] .cropper-shell {
  border: 1px solid var(--hairline);
  box-shadow: none;
}

/* ---------- Upload View ---------- */

.upload-view {
  padding: var(--space-6, 24px);
  display: flex;
  flex-direction: column;
}

.drop-zone {
  border: 2px dashed var(--rule);
  border-radius: var(--radius-sheet);
  background: var(--paper);
  min-height: 280px;
  padding: var(--space-6, 24px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.drop-zone:hover {
  border-color: var(--action);
}

.drop-zone.dragging,
.drop-zone.is-dragover {
  border-color: var(--action);
  background: var(--marker);
  color: var(--on-marker);
}

.upload-icon {
  width: 56px;
  height: 56px;
  margin-bottom: var(--space-2, 8px);
  display: grid;
  place-items: center;
  color: var(--action);
  border-radius: var(--radius-control);
  background: var(--sheet);
}

.drop-zone.dragging .upload-icon,
.drop-zone.is-dragover .upload-icon {
  color: var(--on-marker);
  background: transparent;
}

.upload-icon svg {
  width: 28px;
  height: 28px;
}

.drop-zone h2 {
  margin: var(--space-1, 4px) 0;
  font-size: var(--font-size-h3);
  font-weight: var(--font-weight-heading);
  color: var(--ink);
}

.drop-zone p {
  margin: 0 0 var(--space-3, 12px);
  color: var(--ink-muted);
  font-size: var(--font-size-sm);
}

.drop-zone small {
  margin-top: var(--space-3, 12px);
  color: var(--ink-muted);
  font-size: var(--font-size-sm);
}

.upload-details {
  margin-top: var(--space-3, 12px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.upload-details span {
  padding: 4px 10px;
  color: var(--ink-muted);
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  background: var(--sheet);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
}

.privacy-note {
  margin-top: var(--space-4, 16px);
  padding: 8px var(--space-3, 12px);
  display: flex;
  align-items: flex-start;
  gap: var(--space-2, 8px);
  border-radius: var(--radius-control);
  background: var(--marker);
  color: var(--on-marker);
  font-size: var(--font-size-sm);
}

.privacy-note span {
  font-size: 1.1rem;
  line-height: 1.2;
}

.privacy-note strong {
  display: block;
  font-weight: var(--font-weight-semibold);
  color: var(--on-marker);
}

.privacy-note p {
  margin: 2px 0 0;
  color: var(--on-marker);
  font-size: 0.8125rem;
}

/* ---------- Editor View ---------- */

.editor-view {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(340px, 0.55fr);
  min-height: 520px;
}

.editor-main {
  min-width: 0;
  padding: var(--space-4, 16px);
  background: var(--paper);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
}

.editor-topbar {
  margin-bottom: var(--space-3, 12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3, 12px);
}

.file-info {
  min-width: 0;
}

.file-info strong {
  max-width: 440px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--ink);
}

.file-info span {
  display: block;
  margin-top: 2px;
  color: var(--ink-muted);
  font-size: 0.8125rem;
}

/* ---------- Canvas Stage & Checkerboard ---------- */

.canvas-stage {
  min-height: 400px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3, 12px);
  overflow: auto;
  border-radius: var(--radius-control);
  border: 1px solid var(--hairline);
  background-color: var(--checker-a);
  background-image:
    linear-gradient(45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-b) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-b) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.canvas-wrap {
  position: relative;
  flex: 0 0 auto;
  touch-action: none;
  user-select: none;
}

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

.crop-box {
  position: absolute;
  border: 2px solid var(--sheet);
  box-shadow: 0 0 0 9999px rgb(0 0 0 / 0.55);
  cursor: move;
  touch-action: none;
}

.crop-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.grid-v,
.grid-h {
  position: absolute;
  background: rgb(255 255 255 / 0.65);
}

.grid-v {
  top: 0;
  bottom: 0;
  width: 1px;
}

.grid-h {
  left: 0;
  right: 0;
  height: 1px;
}

.v1 { left: 33.333%; }
.v2 { left: 66.666%; }
.h1 { top: 33.333%; }
.h2 { top: 66.666%; }

.crop-handle {
  position: absolute;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid var(--sheet);
  border-radius: 50%;
  background: var(--action);
  box-shadow: 0 0 0 1px var(--ink);
  touch-action: none;
}

.crop-handle.nw {
  top: -11px;
  left: -11px;
  cursor: nwse-resize;
}

.crop-handle.ne {
  top: -11px;
  right: -11px;
  cursor: nesw-resize;
}

.crop-handle.sw {
  bottom: -11px;
  left: -11px;
  cursor: nesw-resize;
}

.crop-handle.se {
  right: -11px;
  bottom: -11px;
  cursor: nwse-resize;
}

.editor-help {
  margin: var(--space-2, 8px) 0 0;
  color: var(--ink-muted);
  text-align: center;
  font-size: var(--font-size-sm);
}

/* ---------- Settings Panel ---------- */

.settings-panel {
  padding: var(--space-6, 24px);
  background: var(--sheet);
}

.settings-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3, 12px);
  min-height: 40px;
}

.settings-heading span {
  color: var(--ink-muted);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
}

.settings-heading h2 {
  margin: 2px 0 0;
  font-size: var(--font-size-h3);
  font-weight: var(--font-weight-heading);
  color: var(--ink);
}

.settings-group {
  margin-top: var(--space-4, 16px);
}

.group-title {
  display: block;
  margin-bottom: var(--space-2, 8px);
  color: var(--ink);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
}

.group-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.group-title-row > span {
  color: var(--ink-muted);
  font-size: var(--font-size-sm);
}

/* Ratio Grid */

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

.ratio-btn {
  min-height: 44px;
  padding: 6px 4px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  color: var(--ink);
  background: var(--sheet);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.ratio-btn:hover {
  border-color: var(--action);
  color: var(--action);
}

.ratio-btn.active {
  color: var(--ink);
  border-color: var(--action);
  background: var(--paper);
  font-weight: var(--font-weight-heading);
  box-shadow: 0 1px 2px rgb(24 33 43 / 0.08);
}

/* Dimension Grid */

.dimension-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2, 8px);
}

.dimension-grid label > span {
  display: block;
  margin-bottom: var(--space-1, 4px);
  color: var(--ink);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
}

.dimension-grid input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  background: var(--sheet);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--font-size-base);
}

/* Transform Grid */

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

.transform-grid button {
  min-height: 48px;
  padding: 6px 4px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  color: var(--ink);
  background: var(--sheet);
  font-size: 1.1rem;
  font-weight: var(--font-weight-semibold);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.transform-grid button:hover {
  color: var(--action);
  border-color: var(--action);
}

.transform-grid span {
  display: block;
  font-size: 0.6875rem;
  font-weight: var(--font-weight-regular);
}

/* Toggle */

.toggle-row {
  margin-top: var(--space-4, 16px);
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: var(--space-2, 8px);
  cursor: pointer;
}

.toggle-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.fake-toggle {
  width: 44px;
  height: 26px;
  padding: 2px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--paper);
  transition: background 0.15s ease, border-color 0.15s ease;
  display: block;
}

.fake-toggle::after {
  content: "";
  width: 20px;
  height: 20px;
  display: block;
  border-radius: 50%;
  background: var(--rule);
  transition: transform 0.15s ease, background 0.15s ease;
}

.toggle-row input:checked + .fake-toggle {
  background: var(--action);
  border-color: var(--action);
}

.toggle-row input:checked + .fake-toggle::after {
  transform: translateX(18px);
  background: var(--on-action);
}

.toggle-row input:focus-visible + .fake-toggle {
  outline: 2px solid var(--action);
  outline-offset: 2px;
}

.toggle-row strong {
  display: block;
  color: var(--ink);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
}

.toggle-row small {
  display: block;
  color: var(--ink-muted);
  font-size: 0.8125rem;
}

/* Output Grid (Format + Quality) */

.output-grid {
  margin-top: var(--space-4, 16px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3, 12px);
}

.field {
  display: block;
}

.field > span {
  margin-bottom: var(--space-1, 4px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--ink);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
}

.field select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  background: var(--sheet);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--font-size-base);
}

.field input[type="range"] {
  width: 100%;
  min-height: 24px;
  accent-color: var(--action);
}

/* Buttons */

.crop-main-btn,
.primary-btn,
.btn-primary {
  width: 100%;
  min-height: 44px;
  margin-top: var(--space-4, 16px);
  padding: 10px var(--space-6, 24px);
  border: 1px solid var(--action);
  border-radius: var(--radius-control);
  color: var(--on-action);
  background: var(--action);
  font-family: inherit;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease;
}

.crop-main-btn:hover:not(:disabled),
.primary-btn:hover:not(:disabled),
.btn-primary:hover:not(:disabled) {
  opacity: 0.92;
  color: var(--on-action);
}

.crop-main-btn:disabled,
.primary-btn:disabled,
.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.secondary-btn,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  color: var(--ink);
  background: var(--sheet);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.secondary-btn:hover,
.btn:hover {
  border-color: var(--action);
  color: var(--action);
}

.text-btn {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 4px 8px;
  border: 0;
  color: var(--action);
  background: transparent;
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
}

.text-btn:hover {
  text-decoration: underline;
}

/* Result Box (Highlighter Strip) */

.result-box {
  margin-top: var(--space-4, 16px);
  padding: var(--space-3, 12px) var(--space-4, 16px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3, 12px);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-control);
  background: var(--marker);
  color: var(--on-marker);
}

.result-box strong {
  display: block;
  color: var(--on-marker);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
}

.result-box span {
  display: block;
  margin-top: 2px;
  color: var(--on-marker);
  font-size: 0.8125rem;
}

.download-btn {
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--action);
  border-radius: var(--radius-control);
  color: var(--on-action);
  background: var(--action);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: opacity 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.download-btn:hover {
  opacity: 0.92;
}

/* ---------- Content Sections, FAQ & Related Tools ---------- */

.content-section {
  padding: var(--space-10, 40px) 0;
  border-top: 1px solid var(--hairline);
}

.content-section.alt {
  background: transparent;
}

.content-wrap {
  max-width: var(--max-content, 1120px);
  margin: 0 auto;
  text-align: left;
}

.section-heading > span,
.section-tag {
  display: none;
}

.section-heading h2,
.seo-grid h2 {
  margin: 0 0 var(--space-3, 12px);
  font-size: var(--font-size-h2);
  font-weight: var(--font-weight-heading);
  color: var(--ink);
  line-height: var(--line-height-heading);
}

.steps-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4, 16px);
  margin-top: var(--space-4, 16px);
}

.steps-grid article {
  padding: var(--space-5, 20px);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-control);
  background: var(--sheet);
}

.step-number {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--paper);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  margin-bottom: var(--space-2, 8px);
}

.steps-grid h3 {
  margin: 0 0 var(--space-2, 8px);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: var(--ink);
}

.steps-grid p,
.seo-grid p,
.faq-wrap p {
  color: var(--ink-muted);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-body);
  margin: 0;
}

.seo-grid {
  display: grid;
  grid-template-columns: 1.35fr 0.65fr;
  gap: var(--space-8, 32px);
  align-items: start;
}

.feature-card {
  padding: var(--space-5, 20px);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-control);
  background: var(--sheet);
}

.feature-card h3 {
  margin: 0 0 var(--space-2, 8px);
  color: var(--ink);
  font-size: var(--font-size-base);
}

.feature-card ul {
  margin: var(--space-3, 12px) 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: var(--space-2, 8px);
}

.feature-card li {
  color: var(--ink-muted);
  font-size: var(--font-size-sm);
  display: flex;
  align-items: baseline;
  gap: var(--space-2, 8px);
}

.feature-card li::before {
  content: "✓";
  color: var(--ok);
  font-weight: bold;
  flex-shrink: 0;
}

.faq-wrap {
  max-width: 860px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2, 8px);
  margin-top: var(--space-4, 16px);
}

.faq-wrap details {
  padding: var(--space-3, 12px) var(--space-4, 16px);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-control);
  background: var(--sheet);
}

.faq-wrap summary {
  color: var(--ink);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  min-height: 24px;
}

.faq-wrap details p {
  margin-top: var(--space-2, 8px);
}

/* ---------- Utility / Toast ---------- */

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 1000;
  max-width: calc(100% - 32px);
  padding: 12px 20px;
  color: var(--sheet);
  border-radius: var(--radius-control);
  background: var(--ink);
  font-size: var(--font-size-sm);
  opacity: 0;
  transform: translate(-50%, 14px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .editor-view {
    grid-template-columns: 1fr;
  }

  .editor-main {
    border-right: 0;
    border-bottom: 1px solid var(--hairline);
  }

  .steps-grid {
    grid-template-columns: 1fr;
  }

  .seo-grid {
    grid-template-columns: 1fr;
  }
}

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

  .crop-main-btn {
    position: sticky;
    bottom: 8px;
    z-index: 10;
  }
}

@media (max-width: 390px) {
  .ratio-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .transform-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ---------- Reduced Motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}