/* ============ CSS Variables ============ */
:root {
  --bg: #0a0e1a;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-border: rgba(255, 255, 255, 0.10);
  --text: #e9ecf5;
  --text-muted: #9aa3ba;
  --accent-1: #6c5ce7;
  --accent-2: #22d3ee;
  --accent-grad: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  --danger: #ef5b6b;
  --success: #34d399;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --shadow-soft: 0 10px 30px rgba(0,0,0,0.35);
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --transition: 200ms cubic-bezier(.4,0,.2,1);
}

[data-theme="light"] {
  --bg: #f4f6fb;
  --surface: rgba(255, 255, 255, 0.7);
  --surface-border: rgba(20, 25, 50, 0.08);
  --text: #131826;
  --text-muted: #5b6178;
  --shadow-soft: 0 10px 30px rgba(30,40,80,0.10);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 15% 0%, rgba(108,92,231,0.18), transparent 45%),
    radial-gradient(circle at 85% 15%, rgba(34,211,238,0.14), transparent 40%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

.wrap { max-width: 1160px; margin: 0 auto; padding: 0 20px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}

.skip-link {
  position: absolute; left: 8px; top: -60px; background: var(--accent-1); color: #fff;
  padding: 10px 16px; border-radius: var(--radius-sm); z-index: 200; transition: top var(--transition);
}
.skip-link:focus { top: 8px; }

a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 3px; border-radius: 6px; }

.glass {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--shadow-soft);
}

/* ============ Header ============ */
.site-header { position: sticky; top: 0; z-index: 50; backdrop-filter: blur(14px); background: rgba(10,14,26,0.55); border-bottom: 1px solid var(--surface-border); }
[data-theme="light"] .site-header { background: rgba(244,246,251,0.7); }
.header-row { display: flex; align-items: center; gap: 20px; padding: 14px 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; text-decoration: none; color: var(--text); }
.top-nav { display: flex; gap: 18px; margin-left: auto; font-size: 0.92rem; }
.top-nav a { text-decoration: none; color: var(--text-muted); transition: color var(--transition); }
.top-nav a:hover { color: var(--text); }

.theme-toggle {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--surface-border);
  background: var(--surface); color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform var(--transition), background var(--transition);
}
.theme-toggle:hover { transform: translateY(-2px); }
.theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: block; }

/* ============ Breadcrumb ============ */
.breadcrumb { padding: 14px 20px 0; font-size: 0.85rem; color: var(--text-muted); }
.breadcrumb ol { list-style: none; display: flex; gap: 6px; padding: 0; margin: 0; }
.breadcrumb li:not(:last-child)::after { content: '/'; margin-left: 6px; opacity: 0.5; }
.breadcrumb a { text-decoration: none; color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent-2); }

/* ============ Hero ============ */
.hero { text-align: center; padding: 56px 20px 28px; }
.hero h1 {
  font-family: var(--font-display); font-size: clamp(2.2rem, 5vw, 3.4rem); font-weight: 700; margin: 0 0 14px;
  background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent;
  letter-spacing: -0.02em;
}
.hero-sub { max-width: 620px; margin: 0 auto; color: var(--text-muted); font-size: 1.05rem; }

/* ============ Tool layout ============ */
.tool { padding: 20px 20px 60px; }

/* Case selection grid */
.case-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 22px; }
.case-btn {
  font-family: var(--font-mono); font-size: 0.85rem; font-weight: 600; padding: 12px 14px; text-align: center;
  border-radius: var(--radius-sm); border: 1px solid var(--surface-border); background: rgba(255,255,255,0.04);
  color: var(--text); cursor: pointer; transition: transform var(--transition), background var(--transition), box-shadow var(--transition), border-color var(--transition);
}
[data-theme="light"] .case-btn { background: rgba(20,25,50,0.04); }
.case-btn:hover { transform: translateY(-2px); background: rgba(255,255,255,0.09); box-shadow: 0 8px 20px rgba(0,0,0,0.2); }
.case-btn.active { background: var(--accent-grad); color: #fff; border-color: transparent; box-shadow: 0 8px 22px rgba(108,92,231,0.4); }

/* Editor grid */
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; margin-bottom: 22px; }
.editor-panel { position: relative; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.editor-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.editor-toolbar h3 { margin: 0; font-family: var(--font-display); font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.active-case-label { font-family: var(--font-mono); font-size: 0.72rem; font-weight: 500; color: var(--accent-2); background: rgba(34,211,238,0.12); padding: 3px 9px; border-radius: 999px; }
.toolbar-group { display: flex; gap: 8px; flex-wrap: wrap; }

.tbtn {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-body); font-size: 0.85rem; font-weight: 500;
  padding: 8px 13px; border-radius: 999px; border: 1px solid var(--surface-border); background: rgba(255,255,255,0.04);
  color: var(--text); cursor: pointer; transition: transform var(--transition), background var(--transition);
}
.tbtn:hover:not(:disabled) { background: rgba(255,255,255,0.09); transform: translateY(-1px); }
.tbtn:disabled { opacity: 0.4; cursor: not-allowed; }
.tbtn.danger:hover { color: var(--danger); border-color: rgba(239,91,107,0.4); }
[data-theme="light"] .tbtn { background: rgba(20,25,50,0.04); }
[data-theme="light"] .tbtn:hover:not(:disabled) { background: rgba(20,25,50,0.08); }

#textInput, .output-area {
  width: 100%; min-height: 320px; background: rgba(0,0,0,0.18); color: var(--text);
  border: 1px solid var(--surface-border); border-radius: var(--radius-md); padding: 16px; font-family: var(--font-body);
  font-size: 1rem; line-height: 1.7; transition: border-color var(--transition), box-shadow var(--transition);
}
#textInput { resize: vertical; }
.output-area { overflow-y: auto; white-space: pre-wrap; word-break: break-word; }
[data-theme="light"] #textInput, [data-theme="light"] .output-area { background: rgba(255,255,255,0.6); }
#textInput:focus, .output-area:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(34,211,238,0.18); outline: none; }
#textInput::placeholder { color: var(--text-muted); }
.output-area:empty::before { content: 'Your converted text will appear here'; color: var(--text-muted); }
.output-area mark { background: rgba(34,211,238,0.28); color: inherit; border-radius: 3px; padding: 0 1px; }

.drop-overlay {
  position: absolute; inset: 16px; border-radius: var(--radius-md); border: 2px dashed var(--accent-2);
  background: rgba(34,211,238,0.10); display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: var(--accent-2); font-weight: 600; pointer-events: none; z-index: 5;
}
.editor-panel.dragging .drop-overlay { display: flex; }

.editor-footer { display: flex; align-items: center; gap: 10px; }

/* ============ Stats panel ============ */
.stats-panel { display: flex; flex-direction: column; gap: 16px; }
.hero-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.hero-stat { padding: 16px; text-align: center; }
.hero-stat-value {
  display: block; font-family: var(--font-mono); font-size: 1.9rem; font-weight: 600;
  background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-stat-label { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

.stat-group { padding: 16px 18px; }
.stat-group h3 { margin: 0 0 10px; font-family: var(--font-display); font-size: 1rem; }
.stat-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 24px; margin: 0; }
.stat-list > div { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; border-bottom: 1px dashed var(--surface-border); }
.stat-list dt { color: var(--text-muted); font-size: 0.88rem; }
.stat-list dd { margin: 0; font-family: var(--font-mono); font-weight: 600; }

/* ============ Guide / SEO content ============ */
.guide { padding: 40px 20px 90px; max-width: 900px; }
.guide h2 { font-family: var(--font-display); font-size: 1.6rem; margin: 2.2em 0 0.6em; scroll-margin-top: 90px; }
.guide h3 { font-family: var(--font-display); font-size: 1.15rem; margin: 1.6em 0 0.5em; }
.guide p { color: var(--text-muted); }
.guide li { color: var(--text-muted); }
.guide strong { color: var(--text); }

.toc { padding: 20px 24px; margin-bottom: 10px; }
.toc h2 { margin-top: 0; font-size: 1.1rem; }
.toc ol { columns: 2; column-gap: 30px; padding-left: 18px; margin: 0; }
.toc a { text-decoration: none; color: var(--text-muted); font-size: 0.9rem; line-height: 2; }
.toc a:hover { color: var(--accent-2); }

.data-table { width: 100%; border-collapse: collapse; margin: 14px 0 28px; font-size: 0.92rem; }
.data-table caption { text-align: left; color: var(--text-muted); font-size: 0.8rem; margin-bottom: 8px; }
.data-table th, .data-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--surface-border); }
.data-table th { font-family: var(--font-display); color: var(--text); }

.checklist { list-style: none; padding: 0; display: grid; gap: 8px; }
.checklist li { position: relative; padding-left: 28px; }
.checklist li::before {
  content: '✓'; position: absolute; left: 0; top: 0; width: 18px; height: 18px; border-radius: 5px;
  background: var(--accent-grad); color: #fff; font-size: 0.7rem; display: flex; align-items: center; justify-content: center;
}

.faq details { border-bottom: 1px solid var(--surface-border); padding: 14px 0; }
.faq summary { cursor: pointer; font-weight: 600; color: var(--text); font-family: var(--font-display); }
.faq p { margin: 10px 0 0; }

.cta { text-align: center; margin-top: 30px; }
.btn-primary {
  display: inline-block; padding: 13px 28px; border-radius: 999px; background: var(--accent-grad); color: #fff;
  font-weight: 600; text-decoration: none; box-shadow: 0 10px 24px rgba(108,92,231,0.35); transition: transform var(--transition);
}
.btn-primary:hover { transform: translateY(-2px); }

/* ============ Footer ============ */
.site-footer { border-top: 1px solid var(--surface-border); padding: 26px 20px; color: var(--text-muted); font-size: 0.85rem; }
.site-footer .wrap { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.site-footer nav { display: flex; gap: 16px; }
.site-footer a { text-decoration: none; color: var(--text-muted); }
.site-footer a:hover { color: var(--accent-2); }

/* ============ Toast ============ */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 11px 20px; border-radius: 999px; font-size: 0.88rem;
  opacity: 0; pointer-events: none; transition: opacity var(--transition), transform var(--transition); z-index: 300;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ Load animation ============ */
@keyframes pulseIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
.hero-stat, .stat-group, .toc, .editor-panel, .case-grid { animation: pulseIn 400ms ease both; }

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .editor-grid { grid-template-columns: 1fr; }
  .toc ol { columns: 1; }
  .hero-stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .header-row { flex-wrap: wrap; }
  .top-nav { order: 3; width: 100%; justify-content: space-between; margin-left: 0; }
  .hero { padding: 40px 16px 20px; }
  .case-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  #textInput, .output-area { min-height: 220px; }
  .stat-list { grid-template-columns: 1fr; }
}
@media (orientation: landscape) and (max-height: 500px) {
  #textInput, .output-area { min-height: 160px; }
}

/* Print */
@media print {
  .site-header, .editor-toolbar, .drop-overlay, .toc, .theme-toggle, .toast, .site-footer, .case-grid { display: none !important; }
  body { background: #fff; color: #000; }
  .guide, .tool { padding: 0; }
}
