/* FreeToolBox site-wide dark theme.
   The root filter inverts the whole page; media is inverted back so photos,
   video, canvas previews and embedded documents keep their natural colors.
   Applying the filter to the document root does not create a containing
   block for fixed/sticky descendants, so headers and overlays keep working. */

html.tb-dark {
  filter: invert(1) hue-rotate(180deg);
  background: #fff;
  /* Keep UA form controls in light mode so the root inversion turns them dark. */
  color-scheme: light;
}

/* Give every page a calm dark canvas instead of inverting vivid gradients. */
html.tb-dark body {
  background: #eef2f7 !important;
}

/* Keep real-world imagery and embedded content true to life. */
html.tb-dark img,
html.tb-dark picture,
html.tb-dark video,
html.tb-dark canvas,
html.tb-dark iframe,
html.tb-dark embed,
html.tb-dark object,
html.tb-dark [data-no-dark],
html.tb-dark .tb-keep-color,
html.tb-dark .tb-auto-keep {
  filter: invert(1) hue-rotate(180deg);
}

/* Never invert printed output. */
@media print {
  html.tb-dark,
  html.tb-dark img,
  html.tb-dark picture,
  html.tb-dark video,
  html.tb-dark canvas,
  html.tb-dark iframe,
  html.tb-dark embed,
  html.tb-dark object,
  html.tb-dark [data-no-dark],
  html.tb-dark .tb-keep-color,
  html.tb-dark .tb-auto-keep {
    filter: none;
  }
}

/* Readability: long-form guide/SEO copy must sit on a calm surface instead of
   the page's vivid gradient, in both themes. Inline padding on these blocks is
   overridden so the text never touches the card edge. */
.seo-content:not(.tb-seo-nested) {
  background: rgba(255, 255, 255, .96);
  border: 1px solid rgba(255, 255, 255, .75);
  border-radius: 18px;
  padding: 32px 30px !important;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .16);
}
.seo-content:not(.tb-seo-nested) details {
  background: rgba(248, 250, 252, .85);
}
.seo-content h2, .seo-content h3 { letter-spacing: .01em; }
.seo-content a {
  color: #4f46e5;
  text-decoration: none;
  border-bottom: 1px solid rgba(79, 70, 229, .35);
  transition: border-color .2s;
}
.seo-content a:hover { border-bottom-color: currentColor; }
.seo-content details { transition: background .2s; }
.seo-content:not(.tb-seo-nested) details[open] { background: rgba(241, 245, 249, .95); }

/* PWA install affordance (light values; root filter adapts for dark). */
#tb-pwa-banner {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 2147483645;
  display: grid; grid-template-columns: auto 1fr; gap: 10px 12px;
  width: min(92vw, 420px);
  background: #fff; border: 1px solid #e2e8f0; border-radius: 16px; padding: 14px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .22);
}
#tb-pwa-banner > img { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.tb-pwa-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tb-pwa-copy strong { font-size: .95rem; color: #0f172a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-pwa-copy span { font-size: .8rem; color: #64748b; line-height: 1.4; }
.tb-pwa-banner-actions { grid-column: 1 / -1; display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.tb-pwa-banner-actions .tb-pwa-primary { padding: 9px 18px; }

.tb-pwa-primary {
  font: inherit; font-weight: 600; font-size: .85rem; color: #fff;
  background: linear-gradient(135deg, #667eea, #764ba2); border: none; border-radius: 10px;
  padding: 10px 18px; cursor: pointer;
}
.tb-pwa-primary:hover { filter: brightness(1.06); }
.tb-pwa-close { font: inherit; font-size: 1.1rem; line-height: 1; color: #64748b; background: none; border: none; cursor: pointer; padding: 4px; flex: none; }

/* Install guide sheet, modelled on the iOS system sheet and Chrome's install
   bubble: drag handle, app header, glyph rows, full-width primary action. */
#tb-pwa-sheet {
  position: fixed; inset: 0; z-index: 2147483646;
  background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
/* In a Safari tab the browser toolbar floats over the page; keep clear of it. */
html:not(.tb-standalone) #tb-pwa-sheet { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
html:not(.tb-standalone) #tb-pwa-banner { bottom: calc(76px + env(safe-area-inset-bottom)); }
.tb-pwa-sheet-card {
  position: relative;
  background: #fff; border-radius: 24px; width: 100%; max-width: 420px;
  padding: 14px 20px 18px; color: #0f172a; box-shadow: 0 18px 48px rgba(15, 23, 42, .28);
  max-height: calc(100vh - 120px); overflow: auto;
}
.tb-pwa-handle {
  display: block; width: 36px; height: 4px; border-radius: 999px;
  background: #cbd5e1; margin: 0 auto 14px;
}
.tb-pwa-x {
  position: absolute; top: 10px; right: 10px; width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  font: inherit; font-size: 1.25rem; line-height: 1; color: #94a3b8;
  background: #f1f5f9; border: none; border-radius: 50%; cursor: pointer;
}
.tb-pwa-sheet-head { display: flex; align-items: center; gap: 12px; padding-right: 34px; }
.tb-pwa-sheet-head img { width: 44px; height: 44px; border-radius: 12px; flex: none; }
.tb-pwa-sheet-head h2 { margin: 0; font-size: 1.06rem; line-height: 1.3; }
.tb-pwa-sheet-head p { margin: 3px 0 0; font-size: .82rem; line-height: 1.4; color: #64748b; }
.tb-pwa-steps { list-style: none; margin: 16px 0 18px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.tb-pwa-steps li { display: flex; align-items: center; gap: 12px; font-size: .88rem; line-height: 1.45; color: #334155; }
.tb-pwa-steps i {
  flex: none; width: 38px; height: 38px; border-radius: 11px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #eef2ff; color: #4f46e5;
}
.tb-pwa-steps svg { width: 20px; height: 20px; }
.tb-pwa-cta { display: block; width: 100%; padding: 13px 18px; font-size: .92rem; border-radius: 14px; }
.tb-pwa-ghost {
  display: block; margin: 6px auto 0;
  font: inherit; font-size: .8rem; color: #94a3b8; background: none; border: none;
  padding: 8px 10px; cursor: pointer;
}
@media (min-width: 600px) {
  #tb-pwa-sheet { align-items: center; padding-bottom: 12px; }
}
@media (max-width: 480px) {
  #tb-pwa-banner { padding: 12px; bottom: 12px; }
  .tb-pwa-copy strong { font-size: .9rem; }
}

/* Immersive standalone chrome.
   With `black-translucent` the page owns the status bar area, so the top strip
   must simply be the page canvas. The dark theme inverts the whole root, so
   every colour here is the *pre-inversion* one: html stays white (renders
   near-black) and the body canvas carries the rest. */
html { background-color: #ffffff; }

body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* The status bar is transparent in the installed app, so the page paints that
   strip itself. White gets inverted with the rest of the page, which matches
   the black header in dark mode. */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: env(safe-area-inset-top);
  background: #ffffff;
  z-index: 2147483647;
  pointer-events: none;
}

/* Language select and theme toggle form one control row: centered against
   each other, with real breathing room between the two. Only the site header
   gets the shared 36px height; tool pages keep their own select styling. */
.tb-header-actions { display: inline-flex; align-items: center; gap: 8px; }
.header-right .tb-header-actions .lang-switcher { height: 36px; padding: 0 10px; }

/* Theme toggle (styled for light; the root filter adapts it for dark). */
.tb-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  color: #334155;
  cursor: pointer;
  line-height: 0;
  flex: none;
  transition: background .2s, border-color .2s, transform .1s;
}
.tb-theme-toggle:hover { background: #f1f5f9; border-color: #cbd5e1; }
.tb-theme-toggle:active { transform: scale(.94); }
.tb-theme-toggle:focus-visible { outline: 2px solid #667eea; outline-offset: 2px; }
.tb-theme-toggle svg { width: 18px; height: 18px; display: block; }

/* Fallback for pages without a header/language control. */
.tb-theme-toggle.tb-theme-float {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 2147483646;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
}

/* Comfortable tap target on touch screens. */
@media (max-width: 600px) {
  .tb-theme-toggle { width: 44px; height: 44px; }
  .header-right .tb-header-actions .lang-switcher { height: 44px; }
}

/* Global layout & readability guards (both themes).
   Blog grids use `1fr 280px`; without min-width:0 the article's min-content
   (long code lines) blows the track past the viewport. Cap the item so the
   track stays inside the container and <pre> scrolls internally. */
.article-content { min-width: 0; }
.article-content pre { max-width: 100%; }
/* Inline per-page link accent (#0ea5e9) is ~2.8:1 on white; darken to AA. */
.article-content a { color: #0284c7 !important; }
/* Dark mode: muted upload hints must stay legible on inverted panels. */
html.tb-dark .upload-hint { color: #475569; }


/* Shared phone controls: native inputs stay usable without browser zoom. */
@media (max-width: 768px) {
  html body button, html body select,
  html body input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]) { min-height: 44px !important; }
  html body input:not([type="range"]):not([type="checkbox"]):not([type="radio"]), html body textarea, html body select { font-size: 16px !important; }
  html body input[type="range"] { min-height: 44px; }
  html body input.slider[type="range"], html body .slider-container input[type="range"] {
    min-height: 0; height: 8px; padding-block: 18px; background-clip: content-box; box-sizing: content-box;
  }
  html body .toolbar-btn { min-width: 44px; }
}

/* Page-specific slider styling must not hide keyboard focus. */
html body :is(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid #4f46e5 !important;
  outline-offset: 3px;
}

/* Headers may wrap instead of expanding the phone's layout viewport. */
@media (max-width: 768px) {
  html body .header { flex-wrap: wrap; gap: 12px; }
  html body .header-left { min-width: 0; max-width: 100%; flex-wrap: wrap; }
  html body .header-left h1 { min-width: 0; overflow-wrap: anywhere; }
  html body .header-right { max-width: 100%; margin-left: auto; }
  html body table { display: block; max-width: 100%; overflow-x: auto; }
}

/* Long article tokens and nested grids must shrink within the page. */
html body .container > * { min-width: 0; }
html body .article-content { overflow-wrap: anywhere; }
html body .article-content :not(pre) > code { white-space: normal; overflow-wrap: anywhere; }
html body .article-content .step-content { min-width: 0; }
html body .article-content pre { overflow-x: auto; }
html body { overflow-wrap: anywhere; }
html body .main-content > .panel { min-width: 0; }
@media (max-width: 768px) {
  html body > header { flex-wrap: wrap; gap: 12px; }
  html body .setting-group, html body .setting-item { flex-wrap: wrap; min-width: 0; max-width: 100%; }
  html body .setting-group input, html body .setting-group select,
  html body .setting-item input, html body .setting-item select { min-width: 0; max-width: 100%; }
}
