:root {
  color-scheme: light;
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --surface-3: #eaf0f6;
  --text: #162433;
  --muted: #64748b;
  --line: #dbe4ee;
  --brand: #0f766e;
  --brand-strong: #115e59;
  --accent: #f59e0b;
  --success: #15803d;
  --danger: #dc2626;
  --shadow: 0 18px 50px rgba(15, 35, 55, .10);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1624;
  --surface: #142033;
  --surface-2: #1a2940;
  --surface-3: #22334d;
  --text: #eef5ff;
  --muted: #9fb0c7;
  --line: #30445f;
  --brand: #2dd4bf;
  --brand-strong: #5eead4;
  --accent: #fbbf24;
  --success: #4ade80;
  --danger: #fb7185;
  --shadow: 0 18px 50px rgba(0, 0, 0, .28);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    color-scheme: dark;
    --bg: #0d1624;
    --surface: #142033;
    --surface-2: #1a2940;
    --surface-3: #22334d;
    --text: #eef5ff;
    --muted: #9fb0c7;
    --line: #30445f;
    --brand: #2dd4bf;
    --brand-strong: #5eead4;
    --accent: #fbbf24;
    --success: #4ade80;
    --danger: #fb7185;
    --shadow: 0 18px 50px rgba(0, 0, 0, .28);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: radial-gradient(circle at 80% 0, color-mix(in srgb, var(--brand) 10%, transparent), transparent 30rem), var(--bg) !important;
  color: var(--text) !important;
  font-family: Vazirmatn, Tahoma, system-ui, sans-serif !important;
  transition: background-color .2s, color .2s;
}
a { color: inherit; }
button, input, textarea, select { font: inherit; }

.site-shell { width: min(1180px, calc(100% - 28px)); margin: 24px auto 56px; }
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.site-brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 900; }
.site-brand img { width: auto; height: 58px; object-fit: contain; }
.site-brand-mark { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; background: var(--brand); color: #fff; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.home-link, .theme-trigger {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  min-height: 42px;
  padding: 0 14px;
  border-radius: 13px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  cursor: pointer;
}
.theme-picker { position: relative; }
.theme-menu {
  position: absolute;
  z-index: 50;
  top: calc(100% + 8px);
  left: 0;
  min-width: 142px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.theme-menu[hidden] { display: none; }
.theme-option { width: 100%; border: 0; border-radius: 9px; background: transparent; color: var(--text); padding: 9px 10px; display: flex; gap: 9px; cursor: pointer; }
.theme-option:hover, .theme-option[aria-checked="true"] { background: var(--surface-3); color: var(--brand-strong); }

.hero {
  position: relative;
  overflow: hidden;
  padding: clamp(26px, 5vw, 56px);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.hero::after { content: "</>"; position: absolute; left: 28px; bottom: -30px; font: 900 8rem/1 monospace; color: color-mix(in srgb, var(--brand) 8%, transparent); direction: ltr; }
.eyebrow { color: var(--brand-strong); font-weight: 800; font-size: .82rem; letter-spacing: .04em; }
.hero h1 { max-width: 760px; margin: 10px 0 12px; font-size: clamp(1.8rem, 4vw, 3.8rem); line-height: 1.25; letter-spacing: -.04em; }
.hero p { max-width: 680px; margin: 0; color: var(--muted); line-height: 2; }

.section-title { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 30px 2px 14px; }
.section-title h2 { margin: 0; font-size: 1.2rem; }
.section-title p { margin: 0; color: var(--muted); font-size: .82rem; }
.quick-grid, .tools-grid { display: grid; gap: 12px; }
.quick-grid { grid-template-columns: repeat(4, 1fr); margin-top: 18px; }
.tools-grid { grid-template-columns: repeat(4, 1fr); }
.tool-tile {
  min-width: 0;
  min-height: 148px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  text-decoration: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  transition: transform .2s, border-color .2s, box-shadow .2s;
}
.tool-tile:hover { transform: translateY(-3px); border-color: var(--brand); box-shadow: 0 14px 26px color-mix(in srgb, var(--brand) 12%, transparent); }
.tool-icon { width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center; background: var(--surface-3); color: var(--brand-strong); font-size: 1.18rem; }
.tool-tile strong { display: block; margin-bottom: 4px; }
.tool-tile small { display: block; color: var(--muted); line-height: 1.6; }
.quick-grid .tool-tile { background: var(--brand); color: #fff; border-color: transparent; }
.quick-grid .tool-icon { background: rgba(255,255,255,.16); color: #fff; }
.quick-grid .tool-tile small { color: rgba(255,255,255,.78) !important; }

.tool-panel { border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.tool-panel__head { padding: 24px; border-bottom: 1px solid var(--line); }
.tool-panel__head h1 { margin: 0 0 8px; font-size: clamp(1.35rem, 3vw, 2rem); }
.tool-panel__head p { margin: 0; color: var(--muted); line-height: 1.8; }
.tool-form { padding: 20px 24px; display: flex; gap: 10px; align-items: flex-end; border-bottom: 1px solid var(--line); }
.field { flex: 1; min-width: 0; }
.field label { display: block; margin-bottom: 7px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.field input, .field textarea, .field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-2);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent); }
.btn { min-height: 46px; padding: 0 18px; border: 0; border-radius: 13px; background: var(--brand); color: #fff; font-weight: 800; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn.secondary { color: var(--text); background: var(--surface-3); }
.results { padding: 24px; }
.notice { padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); color: var(--muted); line-height: 1.8; }
.notice.error { border-color: color-mix(in srgb, var(--danger) 38%, var(--line)); color: var(--danger); }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { padding: 15px; border-radius: 15px; background: var(--surface-2); border: 1px solid var(--line); }
.stat span { display: block; color: var(--muted); font-size: .75rem; margin-bottom: 6px; }
.stat strong { overflow-wrap: anywhere; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 11px 12px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table th { color: var(--muted); font-size: .78rem; width: 34%; }
.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 5px 9px; background: var(--surface-3); color: var(--text); font-size: .76rem; }
.badge.good { color: var(--success); }
.badge.bad { color: var(--danger); }
.progress { height: 10px; overflow: hidden; border-radius: 999px; background: var(--surface-3); }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; }
.result-list { display: grid; gap: 9px; }
.result-row { padding: 13px 14px; border: 1px solid var(--line); border-radius: 13px; display: flex; gap: 12px; align-items: center; justify-content: space-between; background: var(--surface-2); }
.result-row code { direction: ltr; text-align: left; overflow-wrap: anywhere; }
.footer-note { color: var(--muted) !important; }

/* Theme bridge for legacy tool pages */
.dashboard, .ip-card, .whois-card, .ssl-card, .dns-card, .password-card, .speed-card, .redirect-card, .rbl-card,
.form-section, .results-section, .info-card, .result-card, .record-card, .result-item, .option-card, .password-display,
.back-btn, .search-form input, .input-group input, select, textarea { background-color: var(--surface) !important; color: var(--text) !important; border-color: var(--line) !important; }
.info-label, .card-desc, .empty-state, .footer-note, small { color: var(--muted) !important; }
.page-title h1, .card-title, .info-value, .record-value, .result-value { color: var(--text) !important; }

@media (max-width: 880px) {
  .tools-grid { grid-template-columns: repeat(3, 1fr); }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 620px) {
  .site-shell { width: min(100% - 20px, 1180px); margin-top: 12px; }
  .site-header { align-items: center; }
  .site-brand img { height: 46px; max-width: 150px; }
  .home-link span, .theme-trigger span { display: none; }
  .home-link, .theme-trigger { width: 42px; padding: 0; justify-content: center; }
  .hero { padding: 24px 18px; border-radius: 20px; }
  .hero::after { font-size: 5rem; }
  .quick-grid { gap: 7px; }
  .quick-grid .tool-tile { min-height: 92px; padding: 10px 4px; align-items: center; text-align: center; justify-content: center; gap: 7px; border-radius: 15px; }
  .quick-grid .tool-icon { width: 34px; height: 34px; border-radius: 11px; font-size: .95rem; }
  .quick-grid .tool-tile strong { font-size: .72rem; margin: 0; white-space: nowrap; }
  .quick-grid .tool-tile small { display: none; }
  .tools-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tool-tile { min-height: 126px; padding: 15px; border-radius: 16px; }
  .tool-icon { width: 40px; height: 40px; border-radius: 12px; }
  .tool-tile strong { font-size: .88rem; }
  .tool-tile small { font-size: .69rem; }
  .tool-form { flex-direction: column; align-items: stretch; padding: 16px; }
  .tool-panel__head, .results { padding: 18px 16px; }
  .stat-grid { grid-template-columns: 1fr; }
  .result-row { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
