/* ===== CSS Variables & Theme ===== */
:root {
  --bg: #f0f2f5;
  --bg-gradient: linear-gradient(135deg, #f0f2f5 0%, #e8ecf1 50%, #f5f0f5 100%);
  --sidebar-bg: linear-gradient(180deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  --sidebar-text: #a8b2d1;
  --sidebar-active: #64ffda;
  --sidebar-active-bg: rgba(100, 255, 218, 0.08);
  --panel-bg: rgba(255,255,255,0.85);
  --panel-border: rgba(255,255,255,0.6);
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --input-bg: #f9fafb;
  --input-focus: #6366f1;
  --input-focus-ring: rgba(99, 102, 241, 0.15);
  --btn-primary: linear-gradient(135deg, #6366f1, #8b5cf6);
  --btn-primary-text: #ffffff;
  --btn-secondary: #f3f4f6;
  --btn-secondary-text: #374151;
  --btn-secondary-hover: #e5e7eb;
  --btn-copy: #10b981;
  --btn-copy-text: #fff;
  --result-bg: #f9fafb;
  --error: #ef4444;
  --success: #10b981;
  --highlight: #fef3c7;
  --highlight-border: #fcd34d;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.05);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] .home-card {
  background: rgba(255,255,255,0.03);
  border-color: rgba(255,255,255,0.06);
}

[data-theme="dark"] .home-card:hover {
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: 0 12px 40px rgba(99, 102, 241, 0.12), 0 0 0 1px rgba(99, 102, 241, 0.08) inset;
}

[data-theme="dark"] .home-stat {
  background: rgba(255,255,255,0.03);
}

[data-theme="dark"] {
  --bg: #0f0f1a;
  --bg-gradient: linear-gradient(135deg, #0f0f1a 0%, #1a1025 50%, #0f1025 100%);
  --sidebar-bg: linear-gradient(180deg, #07070f 0%, #0a0a18 50%, #0d0d24 100%);
  --sidebar-text: #8892b0;
  --sidebar-active: #64ffda;
  --sidebar-active-bg: rgba(100, 255, 218, 0.08);
  --panel-bg: rgba(22, 22, 40, 0.8);
  --panel-border: rgba(255,255,255,0.06);
  --text: #e2e8f0;
  --text-secondary: #8892b0;
  --border: #1e293b;
  --input-bg: #1e1e36;
  --input-focus: #818cf8;
  --input-focus-ring: rgba(129, 140, 248, 0.15);
  --btn-primary: linear-gradient(135deg, #6366f1, #8b5cf6);
  --btn-primary-text: #ffffff;
  --btn-secondary: #1e293b;
  --btn-secondary-text: #cbd5e1;
  --btn-secondary-hover: #334155;
  --btn-copy: #10b981;
  --btn-copy-text: #fff;
  --result-bg: #15152a;
  --error: #f87171;
  --success: #34d399;
  --highlight: #78350f;
  --highlight-border: #f59e0b;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -2px rgba(0,0,0,0.2);
  --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.4), 0 8px 10px -6px rgba(0,0,0,0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background: var(--bg-gradient);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  transition: background 0.4s, color 0.4s;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 102, 241, 0.08), transparent),
              radial-gradient(ellipse 60% 50% at 80% 80%, rgba(139, 92, 246, 0.06), transparent);
  pointer-events: none;
  z-index: 0;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 28px 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(20px);
  border-right: 1px solid rgba(255,255,255,0.05);
}

.sidebar-header {
  padding: 0 20px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 16px;
}

.sidebar-header h1 {
  font-size: 1.35rem;
  font-weight: 800;
  background: linear-gradient(135deg, #64ffda, #48cae4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 1px;
}

.sidebar-header span {
  display: block;
  font-size: 0.72rem;
  color: var(--sidebar-text);
  opacity: 0.5;
  margin-top: 4px;
  letter-spacing: 0.5px;
}

.sidebar nav { flex: 1; overflow-y: auto; padding: 0 10px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--sidebar-text);
  transition: all var(--transition);
  user-select: none;
  margin-bottom: 2px;
  position: relative;
  font-weight: 500;
}

.nav-item:hover {
  background: rgba(255,255,255,0.04);
  color: #e2e8f0;
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--sidebar-active);
}

.nav-item .icon {
  font-size: 1rem;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: rgba(255,255,255,0.05);
  transition: all var(--transition);
  flex-shrink: 0;
}

.nav-item .icon svg {
  width: 16px;
  height: 16px;
}

.nav-item.active .icon {
  background: rgba(100, 255, 218, 0.12);
  color: var(--sidebar-active);
}

.sidebar-footer {
  padding: 16px 20px 0;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin-top: 12px;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  color: var(--sidebar-text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.84rem;
  width: 100%;
  transition: all var(--transition);
}

.theme-toggle:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.12);
}

.icp-number {
  display: block;
  text-align: center;
  margin-top: 12px;
  font-size: 0.68rem;
  color: var(--sidebar-text);
  opacity: 0.35;
  text-decoration: none;
  transition: opacity var(--transition);
}

.icp-number:hover { opacity: 0.65; }

/* ===== Main Content ===== */
.main-wrapper {
  margin-left: 260px;
  flex: 1;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

body.page-home .main-wrapper { margin-left: 0; }

body.page-home .sidebar { transform: translateX(-100%); }

body.page-home .mobile-nav-toggle { display: none !important; }

.main {
  flex: 1;
  padding: 36px 44px;
  position: relative;
  z-index: 1;
}

/* ===== Home Page ===== */

/* Full-bleed home page — remove panel frame */
body.page-home {
  background: var(--bg);
}

body.page-home .main {
  padding: 0;
}

#tool-home.tool-panel {
  background: none;
  border: none;
  backdrop-filter: none;
  padding: 0;
  box-shadow: none;
  border-radius: 0;
}

/* Animated background */
#tool-home::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background:
    radial-gradient(circle 40vw at 20% 30%, rgba(99, 102, 241, 0.04), transparent),
    radial-gradient(circle 50vw at 80% 20%, rgba(139, 92, 246, 0.04), transparent),
    radial-gradient(circle 35vw at 60% 70%, rgba(100, 255, 218, 0.03), transparent),
    radial-gradient(circle 45vw at 40% 80%, rgba(99, 102, 241, 0.03), transparent);
  animation: bgFloat 20s ease-in-out infinite alternate;
  pointer-events: none;
  z-index: 0;
}

@keyframes bgFloat {
  0% { transform: translate(0, 0) rotate(0deg); }
  33% { transform: translate(1%, 2%) rotate(1deg); }
  66% { transform: translate(-1%, -1%) rotate(-1deg); }
  100% { transform: translate(2%, -1%) rotate(0.5deg); }
}

.home-hero {
  text-align: center;
  padding: 60px 20px 20px;
  position: relative;
  z-index: 1;
}

.home-hero::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.06), transparent 70%);
  pointer-events: none;
}

.home-title {
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 900;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 40%, #64ffda 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 3px;
  margin-bottom: 16px;
  animation: titleShine 3s ease-in-out infinite alternate;
}

@keyframes titleShine {
  0% { filter: brightness(1); }
  100% { filter: brightness(1.2); }
}

.home-subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-weight: 400;
  letter-spacing: 1px;
}

/* Search Bar */
.home-search {
  display: flex;
  justify-content: center;
  margin: 24px auto 0;
  max-width: 480px;
  position: relative;
  z-index: 1;
}

.home-search input {
  width: 100%;
  padding: 14px 20px 14px 48px;
  border: 1px solid var(--border);
  border-radius: 50px;
  font-size: 0.92rem;
  font-family: inherit;
  background: var(--input-bg);
  backdrop-filter: blur(12px);
  color: var(--text);
  transition: all 0.3s ease;
  box-shadow: 0 2px 12px rgba(0,0,0,0.04);
}

.home-search input:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 4px 24px var(--input-focus-ring);
}

.home-search-icon {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  color: var(--text-secondary);
  pointer-events: none;
}

.home-search-clear {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px 8px;
  border-radius: 50%;
  display: none;
  transition: all var(--transition);
}

.home-search-clear:hover { background: var(--border); }

.home-search-clear.show { display: block; }

/* Stats */
.home-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  flex-wrap: wrap;
  margin-top: 20px;
  position: relative;
  z-index: 1;
}

.home-stat {
  text-align: center;
  padding: 10px 18px;
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(8px);
  border-radius: 40px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.home-stat:hover {
  border-color: var(--input-focus);
  box-shadow: 0 4px 16px var(--input-focus-ring);
}

.home-stat-num {
  display: block;
  font-size: 1.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Tool Grid */
.home-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
  padding: 32px clamp(24px, 4vw, 64px) 48px;
  position: relative;
  z-index: 1;
  max-width: 1500px;
  margin: 0 auto;
}

/* Card */
.home-card {
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 25px;
  padding: 18px;
  cursor: pointer;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  position: relative;
  overflow: hidden;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}

.home-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(600px circle at var(--mouse-x, 50%) var(--mouse-y, 50%), rgba(99, 102, 241, 0.08), transparent 50%);
  opacity: 0;
  transition: opacity 0.3s;
}

.home-card:hover::before { opacity: 1; }

.home-card:hover {
  transform: translateY(-4px);
  border-color: rgba(99, 102, 241, 0.3);
  box-shadow:
    0 12px 40px rgba(99, 102, 241, 0.1),
    0 0 0 1px rgba(99, 102, 241, 0.1) inset;
}

.home-card:active { transform: scale(0.96); }

.home-card-icon {
  width: 55px;
  height: 55px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.08));
  border-radius: 14px;
  transition: all var(--transition);
  position: relative;
  z-index: 1;
  color: #6366f1;
  flex-shrink: 0;
}

.home-card-icon svg {
  width: 20px;
  height: 20px;
}

.home-card:hover .home-card-icon {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(139, 92, 246, 0.14));
  transform: scale(1.05);
  color: #818cf8;
}

.home-card-body {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.home-card-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 3px;
}

.home-card-desc {
  font-size: 0.72rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Empty state when filtering */
.home-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px 20px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Nav separator */
.nav-separator {
  height: 1px;
  background: rgba(255,255,255,0.06);
  margin: 8px 12px;
}

/* ===== Tool Panel ===== */
.tool-panel {
  display: none;
  animation: fadeSlideIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow);
}

.tool-panel.active { display: block; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.tool-header {
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.tool-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--text), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tool-header p {
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.5;
}

/* ===== Form Elements ===== */
.form-group { margin-bottom: 18px; }

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

textarea, input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-family: "SF Mono", "Fira Code", "Fira Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  background: var(--input-bg);
  color: var(--text);
  transition: all var(--transition);
  resize: vertical;
  line-height: 1.6;
}

textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px var(--input-focus-ring);
}

textarea { min-height: 200px; }

select {
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}

input[type="color"] {
  width: 48px;
  height: 40px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--input-bg);
}

/* ===== Buttons ===== */
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  white-space: nowrap;
  letter-spacing: 0.3px;
  position: relative;
  overflow: hidden;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--btn-primary);
  color: var(--btn-primary-text);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--btn-secondary);
  color: var(--btn-secondary-text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--btn-secondary-hover);
  transform: translateY(-1px);
}

.btn-copy {
  background: var(--btn-copy);
  color: var(--btn-copy-text);
  font-size: 0.78rem;
  padding: 8px 16px;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}
.btn-copy:hover {
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.45);
  transform: translateY(-1px);
}

.btn-sm { padding: 7px 14px; font-size: 0.78rem; }

/* ===== Result Area ===== */
.result-area {
  background: var(--result-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  font-family: "SF Mono", "Fira Code", "Fira Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.84rem;
  line-height: 1.6;
  min-height: 80px;
  max-height: 420px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  transition: all var(--transition);
}

.result-area:empty::after {
  content: "输出结果将显示在这里...";
  color: var(--text-secondary);
  opacity: 0.4;
  font-style: italic;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.result-header span {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ===== Error & Success ===== */
.error-msg {
  color: var(--error);
  font-size: 0.84rem;
  margin-top: 10px;
  display: none;
  padding: 10px 14px;
  background: rgba(239, 68, 68, 0.08);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--error);
}

.error-msg.show { display: block; }

.success-msg {
  color: var(--success);
  font-size: 0.8rem;
  font-weight: 600;
}

/* ===== Regex Highlight ===== */
.regex-highlight {
  background: var(--highlight);
  border-radius: 3px;
  padding: 1px 2px;
  border-bottom: 2px solid var(--highlight-border);
}

.match-count {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 8px;
}

.match-list {
  margin-top: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.match-item {
  font-size: 0.8rem;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-family: "SF Mono", monospace;
}

.match-item span { color: var(--text-secondary); margin-right: 10px; font-weight: 600; }

/* ===== UUID & Output Lists ===== */
.uuid-list {
  font-family: "SF Mono", monospace;
  font-size: 0.84rem;
  line-height: 2.2;
}

/* ===== Two-column layout ===== */
.col-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

.col-2 .form-group { display: flex; flex-direction: column; }
.col-2 textarea { flex: 1; }

.col-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

/* ===== Inline Groups ===== */
.inline-group {
  display: flex;
  gap: 10px;
  align-items: center;
}

.inline-group input { flex: 1; }

/* ===== Color Swatch ===== */
.color-swatch {
  width: 100%;
  height: 80px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.color-value {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--result-bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-family: "SF Mono", monospace;
  font-size: 0.84rem;
  margin-top: 8px;
}

.color-value .color-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--btn-primary);
  color: var(--btn-primary-text);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 0.84rem;
  font-weight: 600;
  z-index: 1000;
  animation: slideUp 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-lg);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Markdown Preview ===== */
.markdown-preview {
  padding: 24px;
  background: var(--result-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  min-height: 120px;
  max-height: 500px;
  overflow-y: auto;
  line-height: 1.7;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.markdown-preview h1 { font-size: 1.8rem; margin: 16px 0 12px; font-weight: 800; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.markdown-preview h2 { font-size: 1.4rem; margin: 14px 0 10px; font-weight: 700; }
.markdown-preview h3 { font-size: 1.15rem; margin: 12px 0 8px; font-weight: 700; }
.markdown-preview p { margin: 8px 0; }
.markdown-preview code {
  background: var(--input-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: "SF Mono", monospace;
}
.markdown-preview pre {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  overflow-x: auto;
  margin: 10px 0;
}
.markdown-preview pre code { background: none; padding: 0; }
.markdown-preview blockquote {
  border-left: 4px solid var(--input-focus);
  padding: 8px 16px;
  margin: 10px 0;
  background: var(--input-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}
.markdown-preview table { border-collapse: collapse; width: 100%; margin: 10px 0; }
.markdown-preview th, .markdown-preview td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.markdown-preview th { background: var(--input-bg); font-weight: 700; }
.markdown-preview ul, .markdown-preview ol { padding-left: 24px; margin: 8px 0; }
.markdown-preview a { color: #6366f1; }
.markdown-preview img { max-width: 100%; border-radius: var(--radius-sm); }
.markdown-preview hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ===== Text Stats ===== */
.text-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.stat-card {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: center;
}

.stat-card .stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-card .stat-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ===== Diff View ===== */
.diff-container {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  max-height: 500px;
}

.diff-panel-header {
  padding: 8px 14px;
  font-weight: 700;
  font-size: 0.78rem;
  background: var(--input-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

.diff-divider { width: 1px; background: var(--border); flex-shrink: 0; }

.diff-line {
  padding: 2px 14px;
  font-family: "SF Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.6;
  white-space: pre;
  display: flex;
}

.diff-ln {
  display: inline-block;
  min-width: 36px;
  color: var(--text-secondary);
  opacity: 0.5;
  text-align: right;
  margin-right: 8px;
  user-select: none;
}

.diff-same { color: var(--text); }
.diff-add { background: rgba(16, 185, 129, 0.08); color: var(--success); }
.diff-del { background: rgba(239, 68, 68, 0.08); color: var(--error); }
.diff-empty { background: var(--input-bg); }

.diff-hunk-header {
  padding: 4px 14px;
  background: var(--input-bg);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 700;
}

.diff-stats { padding: 6px 0; }

/* ===== Range Input ===== */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--btn-primary);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
  cursor: pointer;
  transition: all var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

/* ===== Checkbox ===== */
input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #6366f1;
  cursor: pointer;
  margin-right: 4px;
}

/* ===== File Input ===== */
input[type="file"] {
  width: 100%;
  font-family: inherit;
  font-size: 0.84rem;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  cursor: pointer;
}

input[type="file"]::file-selector-button {
  margin-right: 12px;
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  background: var(--btn-primary);
  color: var(--btn-primary-text);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.8rem;
}

/* ===== Date Input ===== */
input[type="date"], input[type="datetime-local"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
  transition: all var(--transition);
}

input[type="date"]:focus, input[type="datetime-local"]:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px var(--input-focus-ring);
}

/* ===== Mobile Toggle ===== */
.mobile-nav-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  background: var(--sidebar-bg);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.1);
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: all var(--transition);
}

.mobile-nav-toggle:hover {
  transform: scale(1.05);
}

/* ===== Footer ICP ===== */
.main-footer {
  text-align: center;
  padding: 20px 16px 32px;
}

.main-footer a {
  color: var(--text-secondary);
  opacity: 0.6;
  font-size: 0.9rem;
  text-decoration: none;
  transition: opacity var(--transition);
}

.main-footer a:hover { opacity: 0.7; }

/* ===== Overlay ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  backdrop-filter: blur(4px);
}

/* ===== Responsive ===== */

/* ≥1280px — 5 columns (6 above 1500px is already in base) */
@media (max-width: 1500px) {
  .home-grid { grid-template-columns: repeat(5, 1fr); max-width: 1300px; }
}

@media (max-width: 1280px) {
  .home-grid { grid-template-columns: repeat(4, 1fr); gap: 14px; padding: 28px 28px 40px; max-width: 1100px; }
}

/* 1024px — 3 columns */
@media (max-width: 1100px) {
  .home-grid { grid-template-columns: repeat(3, 1fr); gap: 14px; padding: 24px 24px 36px; max-width: 1000px; }
}

/* Tablets / Phones — 2 columns */
@media (max-width: 850px) {
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    min-width: 280px;
  }

  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .mobile-nav-toggle { display: flex; align-items: center; justify-content: center; }

  .main-wrapper { margin-left: 0; }

  .main {
    padding: 16px 12px;
    padding-top: 72px;
  }

  .tool-panel { padding: 20px; border-radius: var(--radius); }
  .col-2 { grid-template-columns: 1fr; }
  .col-3 { grid-template-columns: 1fr; }
  .btn-row { flex-direction: column; }
  .btn { justify-content: center; }

  .tool-header h2 { font-size: 1.25rem; }

  .home-hero { padding: 40px 16px 10px; }
  .home-stats { gap: 8px; }
  .home-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 20px 16px 36px; max-width: 100%; }
  .home-search { max-width: 95%; }
}


/* Tiny phones — single column */
@media (max-width: 550px) {
  .home-grid { grid-template-columns: 1fr; gap: 8px; padding: 12px 10px 28px; }
  .home-card { padding: 14px; gap: 10px; border-radius: 14px; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ===== Selection ===== */
::selection {
  background: rgba(99, 102, 241, 0.2);
  color: inherit;
}
