/* ==================== CSS Variables ==================== */
:root {
  --primary: #c9a96e;
  --primary-dark: #b8956a;
  --primary-light: #d4bb82;
  --primary-rgb: 201, 169, 110;
  --text: #333;
  --bg: #fff;
  --bg-secondary: #f5f5f5;
  --border: #eee;
  --card-bg: #fafafa;
  --input-bg: #ffffff;
  --card-shadow: 0 2px 10px rgba(0,0,0,0.06);
  --shadow-hover: rgba(201, 169, 110, 0.15);
  --radius: 12px;
  --transition: 0.2s ease;
  --text-secondary: #888;
}

[data-theme="dark"] {
  --primary: #c9a96e;
  --primary-dark: #b8956a;
  --primary-light: #d4bb82;
  --primary-rgb: 201, 169, 110;
  --text: #e8e8e8;
  --bg: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --border: #2a2a2a;
  --card-bg: #1e1e1e;
  --input-bg: #1e1e1e;
  --card-shadow: 0 2px 12px rgba(0,0,0,0.45);
  --shadow-hover: rgba(201, 169, 110, 0.12);
  --text-secondary: #888;
}

/* 阻止浏览器自动暗黑模式对 logo/favicon 的影响 */
[data-theme="dark"] .site-logo img,
[data-theme="dark"] .hero-logo-wrap img {
  color-scheme: light;
  forced-color-adjust: none;
}

/* ==================== Reset ==================== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ==================== Layout ==================== */
.container { max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; }

@media (max-width: 480px) {
  .container { padding: 0 1rem; }
}

/* ==================== Header ==================== */
.site-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.site-logo {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.site-logo span { font-size: 1.2rem; }
.site-nav { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.theme-toggle {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--text);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle:hover { background: var(--border); opacity: 0.85; }
.theme-toggle svg { width: 1.1rem; height: 1.1rem; }
.site-nav a {
  color: var(--text);
  text-decoration: none;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: var(--transition);
  opacity: 0.8;
}
.site-nav a:hover { opacity: 1; background: var(--border); }

/* ==================== Page Body ==================== */
.page-body { padding: 2rem 0 4rem; }

/* ==================== Hero ==================== */
.hero { text-align: center; padding: 3rem 1.5rem 2rem; }
.hero h1 { font-size: 2.8rem; color: var(--primary); margin-bottom: 0.75rem; }
.hero .subtitle { font-size: 1.1rem; opacity: 0.7; margin-bottom: 1.5rem; }
.search-box { max-width: 500px; margin: 0 auto; }
#tool-search {
  width: 100%;
  padding: 0.8rem 1.1rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--text);
  outline: none;
  transition: var(--transition);
}
#tool-search:focus { border-color: var(--primary); }

/* ==================== Quick Tools Row (mobile-friendly) ==================== */
.quick-tools-row {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-start;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.5rem;
}
.quick-tool-card {
  scroll-snap-align: start;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .categories { column-count: 1 !important; }
  .hero { padding: 2rem 1rem 1.5rem; }
  .hero h1 { font-size: 2rem; }
  .hero .subtitle { font-size: 0.95rem; }
  .search-box { max-width: 100%; }
  .page-hero { padding: 2rem 0 1.5rem; }
  .stats-bar { gap: 0.75rem; }
  .stats-bar li { font-size: 0.9rem; }
  .stats-bar li .stats-num { font-size: 1.1rem; }
  .stats-bar li .stats-label { font-size: 0.78rem; }
  .stats-bar li + li::before { display: none; }
  .quick-tools { margin: 1.5rem auto 0; }
}

@media (max-width: 480px) {
  .hero h1 { font-size: 1.7rem; }
  .quick-tools-row { gap: 0.5rem; }
  .quick-tool-card { padding: 0.5rem 0.8rem; font-size: 0.82rem; }
}

/* ==================== Category Grid ==================== */
.categories {
  column-count: auto;
  column-width: 320px;
  column-gap: 1.5rem;
  margin-top: 2rem;
}
.category {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--card-shadow);
  transition: var(--transition);
  break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 1.5rem;
}
.category:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.1); }
.category h2 {
  font-size: 1.15rem;
  color: var(--primary);
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.category ul { list-style: none; }
.category li { margin: 0.5rem 0; }
.category a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-decoration: none;
  color: var(--text);
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  transition: var(--transition);
  gap: 0.5rem;
}
.category a:hover { background: var(--border); color: var(--primary); }
.category a .tool-name { font-weight: 500; flex-shrink: 0; }
.category a .tool-desc { font-size: 0.82rem; opacity: 0.6; text-align: right; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ==================== Tool Page ==================== */
.tool-header { margin-bottom: 2rem; }
.tool-header h1 { font-size: 2rem; color: var(--primary); margin-bottom: 0.5rem; }
.tool-header .description { opacity: 0.75; font-size: 1.05rem; }

/* ==================== Tool Layout ==================== */
.tool-layout { display: grid; gap: 1.5rem; }
.tool-layout.two-col { grid-template-columns: 1fr 1fr; }
@media (max-width: 768px) { .tool-layout.two-col { grid-template-columns: 1fr; } }

.tool-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--card-shadow);
}
.tool-card h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.6;
  margin-bottom: 0.75rem;
}
textarea, input[type="text"], input[type="number"] {
  width: 100%;
  padding: 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.9rem;
  resize: none;
  outline: none;
  transition: var(--transition);
}
textarea:focus, input:focus { border-color: var(--primary); }
textarea { min-height: 200px; }

/* ==================== Buttons ==================== */
.btn-row { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1rem; }
.btn {
  padding: 0.65rem 1.4rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { opacity: 0.8; }
.btn:active { transform: translateY(0); }

/* ==================== Output / Result ==================== */
.output-box {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--card-shadow);
}
.output-box h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.6;
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.output-box textarea { border-color: var(--primary); }
.copy-btn {
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  opacity: 0.85;
  transition: var(--transition);
}
.copy-btn:hover { opacity: 1; }

/* ==================== Options Row ==================== */
.options-row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; margin-top: 0.75rem; }
.options-row label { font-size: 0.88rem; display: flex; align-items: center; gap: 0.3rem; cursor: pointer; }
.options-row input[type="checkbox"] { accent-color: var(--primary); }

/* ==================== Toast ==================== */
#toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--primary);
  color: #fff;
  padding: 0.7rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: transform 0.3s ease;
  z-index: 999;
}
#toast.show { transform: translateX(-50%) translateY(0); }

/* ==================== Share Button ==================== */
.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: var(--border);
  color: var(--text);
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  opacity: 0.75;
}
.share-btn:hover {
  opacity: 1;
  background: var(--primary);
  color: #fff;
  transform: translateY(-1px);
}
.share-btn:active { transform: translateY(0); }

/* ==================== Random Tool Button ==================== */
.btn-random {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 1.2rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.btn-random:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}
.btn-random:active { transform: translateY(0); }

/* ==================== Footer ==================== */
.site-footer {
  text-align: center;
  padding: 2rem;
  opacity: 0.5;
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* ==================== Keyboard Shortcut Badge ==================== */
.kbd {
  display: inline-block;
  padding: 0.15em 0.55em;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.75em;
  line-height: 1.4;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: 1.5px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 2px 0 var(--border);
  font-weight: 500;
  vertical-align: middle;
  user-select: none;
}
.kbd-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  opacity: 0.7;
}
.site-footer-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/* ==================== SVG Icon Classes ==================== */
.nav-icon { width: 1.1rem; height: 1.1rem; vertical-align: middle; }
.nav-icon-link { display: inline-flex !important; align-items: center; gap: 0.1rem; }
.nav-icon-link span { font-size: 0.9rem; }
.nav-dropdown { position: relative; }
.nav-dropdown-toggle { cursor: pointer; }
.nav-dropdown-menu { display: none; position: absolute; right: 0; top: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); min-width: 100px; z-index: 100; padding: 0.25rem 0; }
.nav-dropdown:hover .nav-dropdown-menu { display: block; }
.nav-dropdown-item { display: block; padding: 0.4rem 0.8rem; color: var(--text); text-decoration: none; font-size: 0.85rem; white-space: nowrap; }
.nav-dropdown-item:hover { background: var(--border); }
.nav-text-link { font-size: 0.9rem; color: var(--text-secondary); text-decoration: none; padding: 0 0.5rem; }
.nav-text-link:hover { color: var(--primary); }
.btn-icon { width: 1.1rem; height: 1.1rem; vertical-align: middle; margin-right: 0.3rem; }
.share-icon { width: 1rem; height: 1rem; vertical-align: middle; margin-right: 0.25rem; }

/* ==================== Mobile Sidebar ==================== */
.site-nav-desktop { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.hamburger-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: 0.3rem;
  border-radius: 6px;
}
.hamburger-btn:hover { background: var(--border); }

.mobile-sidebar {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
}
.mobile-sidebar.open { display: block; }
.mobile-sidebar-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}
.mobile-sidebar-panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 260px;
  max-width: 80vw;
  background: var(--bg);
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  animation: slideInRight 0.2s ease;
}
@keyframes slideInRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
.mobile-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
.mobile-sidebar-title { font-weight: 700; font-size: 1rem; }
.mobile-sidebar-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: 0.25rem;
  border-radius: 4px;
}
.mobile-sidebar-close:hover { background: var(--border); }
.mobile-sidebar-links { padding: 0.75rem 0; flex: 1; overflow-y: auto; }
.mobile-sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1.2rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  transition: background 0.15s;
}
.mobile-sidebar-link:hover { background: var(--border); }
.mobile-sidebar-divider { height: 1px; background: var(--border); margin: 0.5rem 0; }
.aiti-mobile-link { color: #F59E0B; font-weight: 700; }

@media (max-width: 768px) {
  .site-nav-desktop { display: none !important; }
  .hamburger-btn { display: flex !important; }
}

/* ==================== Upload Area ==================== */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  position: relative;
  overflow: hidden;
}
.upload-area::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.03) 0%, transparent 60%);
  pointer-events: none;
}
.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--primary);
  background: var(--card-bg);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12);
}
.upload-area.drag-over {
  border-style: solid;
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.22);
  transform: scale(1.01);
}
.upload-icon {
  width: 44px;
  height: 44px;
  color: var(--primary);
  opacity: 0.7;
  transition: all var(--transition);
}
.upload-area:hover .upload-icon,
.upload-area.drag-over .upload-icon {
  opacity: 1;
  transform: translateY(-3px);
}
.upload-hint {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.4;
}
.upload-hint-main {
  font-weight: 600;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 0.2rem;
}
.upload-hint-sub {
  font-size: 0.82rem;
  opacity: 0.65;
}

/* ==================== Animations & Micro-interactions ==================== */

/* --- Page fade-in on load --- */
body {
  animation: pageFadeIn 0.4s ease;
}
@keyframes pageFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Scroll-triggered reveal --- */
.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* --- Button hover lift & glow --- */
.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.3);
}
.btn:active {
  transform: translateY(0);
}
.btn.loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Tool card hover lift --- */
.tool-card {
  transition: box-shadow 0.25s ease, transform 0.25s ease, border-color 0.25s ease;
}
.tool-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  border-color: var(--primary) !important;
}

/* --- Copy button success pulse --- */
.copy-btn.success {
  animation: copyPulse 0.3s ease;
}
@keyframes copyPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* --- Input focus glow --- */
input:focus,
textarea:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
}

/* --- Category card hover --- */
.category {
  transition: box-shadow 0.25s ease, transform 0.25s ease;
}
.category:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

/* --- Reduced motion: disable all animations --- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  body { animation: none; }
  .reveal { opacity: 1; transform: none; }
  .btn:hover, .btn:active { transform: none; box-shadow: none; }
  .tool-card:hover { transform: none; box-shadow: var(--card-shadow); }
  .category:hover { box-shadow: var(--card-shadow); }
  .btn.loading::after { animation: none; }
}

/* ==================== Select & Input Styling ==================== */
select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--input-bg, #1e1e2e);
  color: var(--text, #e0e0e0);
  border: 1.5px solid var(--border, #333);
  border-radius: 8px;
  padding: 0.5rem 2.2rem 0.5rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  min-width: 110px;
}
select:hover {
  border-color: var(--primary, #60af50);
}
select:focus {
  outline: none;
  border-color: var(--primary, #60af50);
  box-shadow: 0 0 0 3px rgba(96, 175, 80, 0.18);
}
select option {
  background: var(--bg, #ffffff);
  color: var(--text, #1a1a1a);
  padding: 0.3rem;
}

/* Number input */
input[type="number"] {
  background: var(--input-bg, #1e1e2e);
  color: var(--text, #e0e0e0);
  border: 1.5px solid var(--border, #333);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  width: 100%;
  box-sizing: border-box;
}
input[type="number"]:focus {
  outline: none;
  border-color: var(--primary, #60af50);
  box-shadow: 0 0 0 3px rgba(96, 175, 80, 0.18);
}

/* Checkbox styled */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 17px;
  height: 17px;
  border: 1.5px solid var(--border, #444);
  border-radius: 4px;
  background: var(--input-bg, #1e1e2e);
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
input[type="checkbox"]:checked {
  background: var(--primary, #60af50);
  border-color: var(--primary, #60af50);
}
input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 6px;
  height: 10px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}
input[type="checkbox"]:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(96, 175, 80, 0.18);
}
