/* ===========================================================
   MyFreeImageTool — Apple Preview-inspired stylesheet
   =========================================================== */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-display: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;

  --bg: #ffffff;
  --bg-elevated: #f4f4f4;
  --bg-card: #ffffff;
  --bg-subtle: #fafafa;
  --text: #171a20;
  --text-secondary: #393c41;
  --text-muted: #5c5e62;
  --border: rgba(23, 26, 32, 0.10);
  --border-strong: rgba(23, 26, 32, 0.18);
  --accent: #e82127;
  --accent-hover: #c8161c;
  --accent-soft: rgba(232, 33, 39, 0.08);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 1px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.08), 0 8px 16px rgba(0, 0, 0, 0.04);
  --nav-bg: rgba(255, 255, 255, 0.85);

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --container: 1120px;
}

:root[data-theme="dark"] {
  --bg: #15171c;
  --bg-elevated: #20232a;
  --bg-card: #20232a;
  --bg-subtle: #0e0f12;
  --text: #f4f4f4;
  --text-secondary: #c3c5c8;
  --text-muted: #8e9196;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --accent: #ff4b50;
  --accent-hover: #ff6166;
  --accent-soft: rgba(255, 75, 80, 0.16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.6);
  --nav-bg: rgba(21, 23, 28, 0.82);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171c;
    --bg-elevated: #20232a;
    --bg-card: #20232a;
    --bg-subtle: #0e0f12;
    --text: #f4f4f4;
    --text-secondary: #c3c5c8;
    --text-muted: #8e9196;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --accent: #ff4b50;
    --accent-hover: #ff6166;
    --accent-soft: rgba(255, 75, 80, 0.16);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.6);
    --nav-bg: rgba(21, 23, 28, 0.82);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.25s ease, color 0.25s ease;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
img, svg, canvas { display: block; max-width: 100%; }
.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 24px; }

/* ----------------------------- Nav ----------------------------- */
.nav {
  position: sticky; top: 0; z-index: 50;
  background: #171a20;
}
.nav-inner { position: relative; display: flex; align-items: center; justify-content: center; height: 56px; }
.brand { position: absolute; left: 0; top: 50%; transform: translateY(-50%); display: flex; align-items: center; gap: 8px; color: #fff; }
.brand-mark { width: 24px; height: 24px; color: #fff; }
.brand-text { font-weight: 700; font-size: 16px; letter-spacing: 0.02em; }
.nav-links { display: flex; align-items: center; gap: 30px; }
.nav-links a { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: #fff; transition: opacity 0.15s ease; }
.nav-links a:hover { opacity: 0.6; }
.theme-toggle {
  background: transparent; border: none; padding: 6px; border-radius: 4px;
  color: #fff; display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s ease;
}
.theme-toggle:hover { opacity: 0.6; }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; }
}

/* ----------------------------- Hero ----------------------------- */
.hero {
  padding: 128px 0 104px; text-align: center;
  background: #171a20; color: #fff;
}
.eyebrow { display: inline-block; font-size: 12px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: rgba(255,255,255,0.6); margin: 0 0 18px; }
.hero-title {
  font-size: clamp(44px, 7vw, 76px); line-height: 1.04; font-weight: 700; letter-spacing: -0.03em;
  margin: 0 0 18px; color: #fff;
}
.hero-accent { color: var(--accent); -webkit-text-fill-color: var(--accent); }
.hero-sub { font-size: clamp(17px, 2vw, 20px); color: rgba(255,255,255,0.7); max-width: 600px; margin: 0 auto 36px; }
.hero-cta { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-bottom: 44px; }
.hero-trust { display: flex; gap: 28px; justify-content: center; flex-wrap: wrap; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: rgba(255,255,255,0.5); }
.trust-item { display: inline-flex; align-items: center; gap: 6px; }
.trust-item svg { width: 16px; height: 16px; }
.hero .eyebrow { color: var(--accent); }

/* ----------------------------- Buttons ----------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 30px; border-radius: 4px;
  font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  border: 1px solid transparent; transition: opacity 0.15s ease, background-color 0.15s ease, color 0.15s ease; cursor: pointer;
}
/* In-flow buttons adapt to theme: dark fill on light bg, light fill on dark bg */
.btn-primary { background: var(--text); color: var(--bg); }
.btn-primary:hover { opacity: 0.82; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--text); color: var(--bg); }
/* Fixed variants for always-dark sections (hero / dark panels) */
.btn-light { background: #fff; color: #171a20; }
.btn-light:hover { opacity: 0.85; }
.btn-outline-light { background: transparent; color: #fff; border-color: rgba(255,255,255,0.55); }
.btn-outline-light:hover { background: #fff; color: #171a20; border-color: #fff; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ----------------------------- Tools grid ----------------------------- */
.tools { padding: 96px 0 0; }
.section-label { text-align: center; font-size: 12px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); margin: 0 0 12px; }
.section-title { font-size: clamp(30px, 4.5vw, 46px); font-weight: 700; letter-spacing: -0.02em; margin: 0 0 8px; text-align: center; }
.section-sub { text-align: center; color: var(--text-muted); margin: 0; font-size: 16px; }

/* Flush tile grid — edge to edge, 3px gaps, alternating bg, no borders/shadows */
.tile-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; background: var(--border); margin-top: 56px; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start;
  background: var(--bg); color: var(--text);
  padding: 44px 32px; min-height: 230px;
  transition: background-color 0.18s ease, color 0.18s ease;
}
.tile:nth-child(even) { background: var(--bg-elevated); }
.tile:hover { background: var(--text); color: var(--bg); }
.tile-icon { width: 30px; height: 30px; margin-bottom: 22px; color: var(--accent); }
.tile-icon svg { width: 30px; height: 30px; }
.tile h3 { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 8px; }
.tile p { margin: 0 0 20px; font-size: 14px; color: var(--text-secondary); }
.tile:hover p { color: rgba(255,255,255,0.7); }
.tile-cta { margin-top: auto; font-size: 12px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }

/* ----------------------------- Feature panels ----------------------------- */
.feature { min-height: 78vh; display: flex; align-items: flex-end; padding: 64px; }
.feature-inner { max-width: 540px; }
.feature-dark { background: #171a20; color: #fff; }
.feature-light { background: #f4f4f4; color: #171a20; }
.feature h2 { font-size: clamp(32px, 5vw, 56px); font-weight: 700; letter-spacing: -0.03em; line-height: 1.05; margin: 0 0 14px; }
.feature p { font-size: 17px; margin: 0 0 24px; max-width: 440px; }
.feature-dark p { color: rgba(255,255,255,0.7); }
.feature-light p { color: var(--text-secondary); }
.feature-cta { display: inline-block; font-size: 13px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: inherit; padding-bottom: 4px; border-bottom: 2px solid currentColor; transition: opacity 0.15s ease; }
.feature-cta:hover { opacity: 0.6; }
@media (max-width: 700px) { .feature { min-height: 60vh; padding: 40px 24px; } }

/* ----------------------------- FAQ ----------------------------- */
.faq { padding: 80px 0; }
.faq .container { max-width: 760px; }
.faq-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 4px 20px; margin-bottom: 10px; transition: border-color 0.15s ease; }
.faq-item[open] { border-color: var(--border-strong); }
.faq-item summary { cursor: pointer; padding: 16px 0; font-weight: 500; font-size: 16px; list-style: none; display: flex; align-items: center; justify-content: space-between; }
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: "+"; font-size: 22px; font-weight: 300; color: var(--text-muted); transition: transform 0.2s ease; }
.faq-item[open] summary::after { content: "−"; }
.faq-item p { margin: 0 0 16px; color: var(--text-secondary); font-size: 15px; line-height: 1.55; }

/* ----------------------------- Footer ----------------------------- */
.footer { background: #171a20; color: rgba(255,255,255,0.6); padding: 30px 0; }
.footer-row { display: flex; flex-wrap: wrap; gap: 10px 24px; justify-content: center; }
.footer-row a { color: rgba(255,255,255,0.6); font-size: 12px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; transition: color 0.15s ease; }
.footer-row a:hover { color: #fff; }
.footer-copy { text-align: center; margin-top: 16px; font-size: 12px; color: rgba(255,255,255,0.4); }

/* ----------------------------- Tool page ----------------------------- */
.tool-page { padding: 56px 0; }
.tool-header { text-align: center; margin-bottom: 40px; }
.tool-header h1 { font-family: var(--font-display); font-size: clamp(32px, 5vw, 48px); font-weight: 600; letter-spacing: -0.02em; margin: 0 0 12px; }
.tool-header p { color: var(--text-secondary); font-size: 18px; margin: 0 auto; max-width: 580px; }

.dropzone { background: var(--bg-card); border: 2px dashed var(--border-strong); border-radius: var(--radius-xl); padding: 64px 24px; text-align: center; transition: all 0.2s ease; cursor: pointer; display: block; }
.dropzone:hover, .dropzone.is-drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone-icon { width: 56px; height: 56px; margin: 0 auto 16px; color: var(--accent); }
.dropzone h2 { font-family: var(--font-display); font-size: 22px; font-weight: 500; margin: 0 0 8px; }
.dropzone p { margin: 0; color: var(--text-muted); font-size: 14px; }
.dropzone input[type="file"] { display: none; }

.status { margin-top: 16px; text-align: center; font-size: 14px; color: var(--text-secondary); min-height: 20px; }
.status.error { color: #ff3b30; }
.status.success { color: #34c759; }

.action-bar { margin-top: 24px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* Workbench used by standalone tool pages */
.workbench { margin-top: 24px; display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.preview-pane {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-lg);
  min-height: 320px; display: flex; align-items: center; justify-content: center; padding: 20px; overflow: auto;
}
.preview-pane canvas, .preview-pane img { max-width: 100%; max-height: 70vh; border-radius: 6px; box-shadow: var(--shadow-md); background: #fff; }
.controls { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.controls h3 { font-family: var(--font-display); font-size: 17px; font-weight: 600; margin: 0 0 14px; }
@media (max-width: 760px) { .workbench { grid-template-columns: 1fr; } }

/* Fields / controls */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 500; color: var(--text-secondary); margin-bottom: 4px; }
.field input[type="text"], .field input[type="number"], .field select, .field textarea {
  width: 100%; padding: 8px 10px; background: var(--bg); border: 1px solid var(--border-strong);
  border-radius: 8px; font-family: inherit; font-size: 14px; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-row { display: flex; gap: 8px; }
.field-row .field { flex: 1; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.range-val { font-size: 13px; color: var(--text-muted); float: right; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); cursor: pointer; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.meta-line { font-size: 13px; color: var(--text-muted); margin: 8px 0 0; }
.meta-line strong { color: var(--text); }

/* Layers panel */
.layer-list { display: flex; flex-direction: column; gap: 6px; }
.layer-row { display: flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; }
.layer-row.layer-bg { opacity: 0.75; }
.layer-row .lr-name { flex: 1; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lr-btn { width: 26px; height: 26px; border: none; background: var(--bg-elevated); border-radius: 6px; color: var(--text); font-size: 13px; line-height: 1; flex-shrink: 0; }
.lr-btn:hover:not([disabled]) { background: var(--border); }
.lr-btn[disabled] { opacity: 0.5; }

/* Segmented buttons */
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; min-width: 56px; padding: 8px; background: var(--bg); border: 1px solid var(--border-strong); border-radius: 8px; color: var(--text); font-size: 13px; }
.seg button:hover { background: var(--bg-elevated); }
.seg button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ----------------------------- Editor ----------------------------- */
.editor-shell { display: grid; grid-template-columns: 220px 1fr 312px; height: calc(100vh - 52px); background: var(--bg-elevated); overflow: hidden; }
.editor-sidebar { background: var(--bg-card); border-right: 1px solid var(--border); padding: 20px 12px; overflow-y: auto; }
.editor-sidebar h3 { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin: 16px 8px 6px; }
.editor-sidebar h3:first-child { margin-top: 0; }
.tool-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; background: transparent; border: none; border-radius: 8px; color: var(--text); font-size: 14px; text-align: left; cursor: pointer; transition: background-color 0.12s ease; }
.tool-btn:hover { background: var(--bg-elevated); }
.tool-btn.active { background: var(--accent-soft); color: var(--accent); }
.tool-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.tool-btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.tool-btn-accent { color: var(--accent); font-weight: 600; }
.tool-btn-accent:not([disabled]) { background: var(--accent-soft); }

.editor-viewer { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.viewer-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px; background: var(--bg-card); border-bottom: 1px solid var(--border); }
.vt-group { display: flex; align-items: center; gap: 6px; }
.vt-file { flex: 1; text-align: center; min-width: 0; font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vt-btn { min-width: 30px; height: 30px; padding: 0 8px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 7px; color: var(--text); font-size: 16px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.vt-btn:hover { background: var(--border); }
.vt-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.viewer-scroll { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: safe center; padding: 28px; }
.editor-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; min-height: 60vh; }
.editor-empty .dropzone { width: 100%; max-width: 520px; }
.image-stage { position: relative; flex-shrink: 0; box-shadow: var(--shadow-lg); background: #fff; }
.image-stage canvas { display: block; }
.crop-overlay { position: absolute; inset: 0; cursor: crosshair; }
.crop-rect { position: absolute; border: 1px dashed #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,0.45); box-sizing: border-box; }

.editor-inspector { background: var(--bg-card); border-left: 1px solid var(--border); padding: 20px; overflow-y: auto; }
.editor-inspector h3 { font-family: var(--font-display); font-size: 17px; font-weight: 600; margin: 0 0 8px; }
.editor-inspector p.hint { font-size: 13px; color: var(--text-muted); margin: 0 0 16px; }

.editor-actionbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 20px; background: var(--bg-card); border-top: 1px solid var(--border); box-shadow: 0 -4px 16px rgba(0,0,0,0.05); }
.ab-summary { font-size: 13px; color: var(--text-secondary); min-width: 0; }
.ab-summary strong { color: var(--text); }
.btn-apply { background: var(--accent); color: #fff; border: none; border-radius: 6px; padding: 13px 28px; font-size: 14px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; display: inline-flex; align-items: center; gap: 8px; box-shadow: var(--shadow-md); white-space: nowrap; transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease; }
.btn-apply:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(232,33,39,0.28); }
.btn-apply svg { width: 20px; height: 20px; }

@media (max-width: 1000px) {
  .editor-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; height: auto; min-height: calc(100vh - 52px); min-height: calc(100dvh - 52px); overflow: visible; }
  .editor-sidebar { border-right: none; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; overflow-x: auto; padding: 12px; gap: 4px; }
  .editor-sidebar h3 { display: none; }
  .tool-btn { width: auto; padding: 8px 12px; white-space: nowrap; }
  .editor-viewer { min-height: 55vh; }
  .editor-inspector { border-left: none; border-top: 1px solid var(--border); max-height: 50vh; }
  .btn-apply { flex: 1; justify-content: center; }
}

/* ----------------------------- Legal / prose ----------------------------- */
.legal { padding: 56px 0 72px; }
.legal .container { max-width: 760px; }
.legal-head { margin-bottom: 36px; }
.legal-head h1 { font-family: var(--font-display); font-size: clamp(30px, 5vw, 44px); font-weight: 600; letter-spacing: -0.02em; margin: 0 0 8px; }
.legal-updated { color: var(--text-muted); font-size: 14px; margin: 0; }
.prose { color: var(--text-secondary); font-size: 16px; line-height: 1.7; }
.prose h2 { font-family: var(--font-display); font-size: 22px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); margin: 36px 0 12px; }
.prose p { margin: 0 0 16px; }
.prose ul { margin: 0 0 16px; padding-left: 22px; }
.prose li { margin: 0 0 8px; }
.prose a:not(.btn) { color: var(--accent); }
.prose a:not(.btn):hover { text-decoration: underline; }
.prose strong { color: var(--text); font-weight: 600; }

.contact-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin: 28px 0; }
.contact-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; }
.contact-card h3 { font-family: var(--font-display); font-size: 17px; font-weight: 600; margin: 0 0 6px; color: var(--text); }
.contact-card p { margin: 0 0 12px; font-size: 14px; color: var(--text-secondary); }

.editor-link { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; background: var(--bg-elevated); border: none; border-radius: var(--radius-md); padding: 22px 26px; margin: 32px auto; max-width: 760px; }
.editor-link .editor-link-text { font-size: 14px; color: var(--text-secondary); }
.editor-link .editor-link-text strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 2px; }

/* ----------------------------- Responsive ----------------------------- */
@media (max-width: 920px) {
  .tile-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .hero { padding: 80px 0 56px; }
  .dropzone { padding: 40px 20px; }
  /* compact nav: brand left, links wrap right */
  .nav-inner { justify-content: flex-end; }
  .brand { position: static; transform: none; margin-right: auto; }
  .nav-links { gap: 16px; }
  .footer-row { gap: 8px 16px; }
}
@media (max-width: 460px) {
  .tile-grid { grid-template-columns: 1fr; }
}
