/* ============================================================
   YourMiniTools — Global Stylesheet v1.0.0
   Design System: Refined Utilitarian
   Constraints: System fonts, no unsafe-inline, WCAG 2.2 AA
   ============================================================ */

/* --- Reset -------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  hanging-punctuation: first last;
}

body {
  min-height: 100dvh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeSpeed;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: inherit;
  text-decoration: none;
}

ul,
ol {
  list-style: none;
}

h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
  line-height: 1.2;
}

p {
  overflow-wrap: break-word;
}

table {
  border-collapse: collapse;
}

/* --- Design Tokens ------------------------------------------ */
:root {
  /* Palette — Light Mode */
  --color-bg:            #f4f7f6;
  --color-surface:       #ffffff;
  --color-text:          #333333;
  --color-text-muted:    #636b72;
  --color-primary:       #2576ae;
  --color-primary-hover: #1f6a9c;
  --color-success:       #27ae60;
  --color-success-hover: #219a52;
  --color-danger:        #e74c3c;
  --color-warning:       #f39c12;

  /* Borders & Dividers */
  --color-border:        #e0e4e3;
  --color-border-focus:  var(--color-primary);

  /* Elevation */
  --shadow-card:         0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-card-hover:   0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-header:       0 1px 3px rgba(0, 0, 0, 0.06);

  /* Typography — system stack, zero downloads, CJK/Cyrillic fallbacks */
  --font-primary: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                  'Helvetica Neue', Arial,
                  'Noto Sans SC', 'Microsoft YaHei',
                  'Noto Sans', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;

  /* Spacing scale (4px base) */
  --spacing-xs:  0.25rem;
  --spacing-sm:  0.5rem;
  --spacing-md:  1rem;
  --spacing-lg:  1.5rem;
  --spacing-xl:  2rem;
  --spacing-2xl: 3rem;
  --spacing-3xl: 4rem;

  /* Radii */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast:   150ms ease;
  --transition-normal: 250ms ease;

  /* Layout */
  --header-height: 60px;
  --max-width:     1200px;
  --content-pad:   var(--spacing-lg);
}

/* --- Dark Mode: system preference (no manual override set) -- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg:          #1a1a2e;
    --color-surface:     #16213e;
    --color-text:        #e0e0e0;
    --color-text-muted:  #a0a0a0;
    --color-border:      #2a2a4a;
    --shadow-card:       0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-card-hover: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-header:     0 1px 3px rgba(0, 0, 0, 0.25);
  }
}

/* --- Dark Mode: manual toggle ------------------------------- */
[data-theme="dark"] {
  --color-bg:          #1a1a2e;
  --color-surface:     #16213e;
  --color-text:        #e0e0e0;
  --color-text-muted:  #a0a0a0;
  --color-border:      #2a2a4a;
  --shadow-card:       0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-card-hover: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-header:     0 1px 3px rgba(0, 0, 0, 0.25);
}

/* --- Light Mode: manual toggle ------------------------------ */
[data-theme="light"] {
  --color-bg:            #f4f7f6;
  --color-surface:       #ffffff;
  --color-text:          #333333;
  --color-text-muted:    #636b72;
  --color-border:        #e0e4e3;
  --shadow-card:         0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-card-hover:   0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-header:       0 1px 3px rgba(0, 0, 0, 0.06);
}

/* --- Base --------------------------------------------------- */
body {
  font-family: var(--font-primary);
  font-size: 16px;
  color: var(--color-text);
  background-color: var(--color-bg);
  padding-top: var(--header-height);
  display: flex;
  flex-direction: column;
}

/* --- Skip Link ---------------------------------------------- */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--spacing-md);
  z-index: 1000;
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--color-primary);
  color: #fff;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-weight: 600;
  font-size: 0.875rem;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: 0;
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* --- Header ------------------------------------------------- */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  min-height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-header);
  display: flex;
  align-items: center;
}

.header-inner {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--content-pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-md);
}

.site-logo {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--color-text);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.site-logo:hover {
  color: var(--color-primary);
}

.site-logo-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  flex-shrink: 0;
}


/* Theme Toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
  transition: color var(--transition-fast), background-color var(--transition-fast);
  flex-shrink: 0;
}

.theme-toggle:hover {
  color: var(--color-primary);
  background: var(--color-bg);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  display: none;
}

/* Light mode: show moon (to switch to dark) */
.theme-toggle .icon-moon {
  display: block;
}
.theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}
[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-moon {
    display: none;
  }
  :root:not([data-theme="light"]) .theme-toggle .icon-sun {
    display: block;
  }
}

/* Language Selector */
.lang-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.375rem 0.5rem;
  font-size: 0.8125rem;
  font-family: var(--font-primary);
  color: var(--color-text);
  cursor: pointer;
  min-height: 36px;
  min-width: 36px;
  transition: border-color var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}

.lang-select:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.lang-select:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

@media (max-width: 479px) {
  .lang-select {
    appearance: auto;
    -webkit-appearance: menulist;
    font-size: 1rem;
    padding: 0.25rem 0.375rem;
    min-height: 32px;
  }
}

/* --- Main Content ------------------------------------------- */
.site-main {
  flex: 1;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--spacing-2xl) var(--content-pad);
}

/* --- Homepage Hero ------------------------------------------ */
.hero {
  text-align: center;
  padding: var(--spacing-2xl) 0 var(--spacing-xl);
}

.hero-title {
  font-size: clamp(1.75rem, 5vw, 2.75rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--color-text);
  margin-bottom: var(--spacing-sm);
}

.hero-subtitle {
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  color: var(--color-text-muted);
  max-width: 600px;
  margin: 0 auto;
  line-height: 1.5;
}

/* --- Tool Grid (Homepage) ----------------------------------- */
.tools-grid {
  display: grid;
  gap: var(--spacing-lg);
  grid-template-columns: 1fr;
}

@media (min-width: 480px) {
  .tools-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 768px) {
  .tools-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1024px) {
  .tools-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* --- Tool Card ---------------------------------------------- */
.tool-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-xl) var(--spacing-lg);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  text-decoration: none;
  text-align: center;
  transition: box-shadow var(--transition-normal),
              transform var(--transition-normal),
              border-color var(--transition-normal);
  min-height: 180px;
}

.tool-card:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-2px);
  border-color: var(--color-primary);
}

.tool-card-icon {
  width: 48px;
  height: 48px;
  color: var(--color-primary);
  flex-shrink: 0;
}

.tool-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
}

.tool-card-desc {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  line-height: 1.4;
}

/* --- Footer ------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: var(--spacing-xl) var(--content-pad);
  margin-top: auto;
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-md);
  text-align: center;
}

.footer-links {
  display: flex;
  gap: var(--spacing-lg);
  flex-wrap: wrap;
  justify-content: center;
}

.footer-links a {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer-links a:hover {
  color: var(--color-primary);
}

.footer-copy {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

/* --- Back to Top -------------------------------------------- */
.back-to-top {
  position: fixed;
  bottom: var(--spacing-lg);
  right: var(--spacing-lg);
  z-index: 50;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-full);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity var(--transition-normal),
              visibility var(--transition-normal),
              transform var(--transition-normal),
              background-color var(--transition-fast);
}

.back-to-top[data-visible="true"] {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.back-to-top:hover {
  background: var(--color-primary-hover);
}

.back-to-top svg {
  width: 20px;
  height: 20px;
}

/* --- Buttons ------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: 0.625rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  transition: background-color var(--transition-fast),
              color var(--transition-fast),
              border-color var(--transition-fast),
              box-shadow var(--transition-fast);
  white-space: nowrap;
  min-height: 44px;
  min-width: 44px;
  text-decoration: none;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn-secondary {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-border);
}

.btn-secondary:hover {
  border-color: var(--color-primary);
  background: var(--color-bg);
}

.btn-success {
  background: var(--color-success);
  color: #fff;
  border-color: var(--color-success);
}

.btn-success:hover {
  background: var(--color-success-hover);
  border-color: var(--color-success-hover);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}

.btn-danger:hover {
  opacity: 0.9;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-icon {
  padding: 0.5rem;
  border-radius: var(--radius-full);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* --- Notification Toast ------------------------------------- */
.notification-container {
  position: fixed;
  top: calc(var(--header-height) + var(--spacing-md));
  right: var(--spacing-md);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  pointer-events: none;
  max-width: min(400px, calc(100vw - 2 * var(--spacing-md)));
}

.notification {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-sm);
  padding: var(--spacing-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  font-size: 0.875rem;
  line-height: 1.4;
  transform: translateX(100%);
  opacity: 0;
  transition: transform var(--transition-normal),
              opacity var(--transition-normal);
}

.notification[data-visible="true"] {
  transform: translateX(0);
  opacity: 1;
}

.notification[data-type="success"] {
  border-left: 3px solid var(--color-success);
}

.notification[data-type="error"] {
  border-left: 3px solid var(--color-danger);
}

.notification[data-type="warning"] {
  border-left: 3px solid var(--color-warning);
}

.notification[data-type="info"] {
  border-left: 3px solid var(--color-primary);
}

.notification-message {
  flex: 1;
}

.notification-close {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.notification-close:hover {
  color: var(--color-text);
}

/* --- Utility Classes ---------------------------------------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--content-pad);
}

.text-center { text-align: center; }
.text-muted  { color: var(--color-text-muted); }
.font-mono   { font-family: var(--font-mono); }

/* --- Focus Styles (WCAG 2.2) -------------------------------- */
:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* Remove default focus ring for mouse users */
:focus:not(:focus-visible) {
  outline: none;
}

/* Ensure focus not obscured by fixed header */
:target {
  scroll-margin-top: calc(var(--header-height) + var(--spacing-lg));
}

/* --- Reduced Motion ----------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .tool-card:hover {
    transform: none;
  }

  .back-to-top {
    transition: none;
  }
}

/* --- Service Pages (Privacy, About, 404) -------------------- */
.page-content {
  max-width: 720px;
  margin: 0 auto;
}

.page-content h1 {
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: var(--spacing-lg);
}

.page-content h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: var(--spacing-xl);
  margin-bottom: var(--spacing-sm);
}

.page-content p {
  margin-bottom: var(--spacing-md);
  color: var(--color-text);
  line-height: 1.7;
}

.page-content ul {
  margin-bottom: var(--spacing-md);
  padding-left: var(--spacing-lg);
  list-style: disc;
}

.page-content li {
  margin-bottom: var(--spacing-xs);
  line-height: 1.6;
}

.page-content a {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.page-content a:hover {
  color: var(--color-primary-hover);
}

/* --- 404 Page ----------------------------------------------- */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 50vh;
  gap: var(--spacing-md);
}

.error-code {
  font-size: clamp(4rem, 15vw, 8rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--color-primary);
  line-height: 1;
  opacity: 0.15;
}

.error-title {
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  font-weight: 700;
}

.error-desc {
  color: var(--color-text-muted);
  max-width: 400px;
}

/* --- Cookie Banner (minimal, informational) ----------------- */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 150;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
  padding: var(--spacing-md) var(--content-pad);
  transform: translateY(100%);
  transition: transform var(--transition-normal);
}

.cookie-banner[data-visible="true"] {
  transform: translateY(0);
}

body.has-cookie-banner {
  padding-bottom: 60px;
}

.cookie-banner-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-md);
  flex-wrap: wrap;
}

.cookie-banner-text {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  flex: 1;
  min-width: 200px;
}

.cookie-banner-text a {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* --- Responsive tweaks -------------------------------------- */
@media (max-width: 479px) {
  :root {
    --content-pad: var(--spacing-md);
  }

  .site-logo {
    font-size: 1rem;
  }

  .hero {
    padding: var(--spacing-xl) 0 var(--spacing-lg);
  }

  .tool-card {
    padding: var(--spacing-lg) var(--spacing-md);
    min-height: 150px;
  }

  .footer-inner {
    gap: var(--spacing-sm);
  }
}

@media (min-width: 768px) {
  .footer-inner {
    flex-direction: row;
    justify-content: space-between;
    text-align: left;
  }
}
