/* ============ CSS Variables ============ */
:root {
  --bg: #0a0e1a;
  --bg-alt: #0f1424;
  --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;
  --bg-alt: #eef1f8;
  --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);
  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; }
.tool-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 22px; align-items: start; }

.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; }
.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), box-shadow var(--transition);
}
.tbtn:hover { background: rgba(255,255,255,0.09); transform: translateY(-1px); }
.tbtn:active { transform: translateY(0); }
.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 { background: rgba(20,25,50,0.08); }

.autosave-indicator {
  font-size: 0.75rem; color: var(--text-muted); padding: 5px 11px; border-radius: 999px;
  background: rgba(52,211,153,0.12); border: 1px solid rgba(52,211,153,0.3); color: var(--success);
  transition: opacity var(--transition);
}

#textInput {
  width: 100%; min-height: 320px; resize: vertical; 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);
}
[data-theme="light"] #textInput { background: rgba(255,255,255,0.6); }
#textInput: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); }

.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: 14px; flex-wrap: wrap; justify-content: space-between; }
.platform-select { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--text-muted); }
.platform-select select {
  background: rgba(255,255,255,0.05); color: var(--text); border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm); padding: 7px 10px; font-family: var(--font-body); font-size: 0.85rem;
}
.limit-hint { font-size: 0.82rem; color: var(--text-muted); margin: 0; flex: 1 1 160px; }
.limit-hint.over { color: var(--danger); font-weight: 600; }
.limit-hint.near { color: #f5b942; font-weight: 600; }

/* ============ Stats panel ============ */
.stats-panel { display: flex; flex-direction: column; gap: 16px; }

.hero-stats { display: grid; grid-template-columns: repeat(2, 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; }
.muted-note { font-size: 0.78rem; color: var(--text-muted); margin: -4px 0 10px; }

.stat-list { display: grid; gap: 8px; 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 > div:last-child { border-bottom: none; }
.stat-list dt { color: var(--text-muted); font-size: 0.88rem; }
.stat-list dd { margin: 0; font-family: var(--font-mono); font-weight: 600; }

.keyword-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.keyword-list li { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.keyword-list .kw-name { min-width: 84px; font-family: var(--font-mono); }
.keyword-list .kw-bar-track { flex: 1; height: 7px; border-radius: 5px; background: rgba(255,255,255,0.08); overflow: hidden; }
.keyword-list .kw-bar { height: 100%; border-radius: 5px; background: var(--accent-grad); transition: width 400ms ease; }
.keyword-list .kw-pct { color: var(--text-muted); min-width: 40px; text-align: right; font-family: var(--font-mono); }
.empty-state { color: var(--text-muted); font-size: 0.85rem; list-style: none; }

.freq-chart { display: flex; align-items: flex-end; gap: 3px; height: 90px; padding-top: 6px; }
.freq-bar { flex: 1; background: var(--accent-grad); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; transition: height 400ms ease; }
.freq-bar span { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 0.62rem; color: var(--text-muted); font-family: var(--font-mono); }

/* ============ 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); }

/* ============ Loading pulse ============ */
@keyframes pulseIn { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: scale(1); } }
.hero-stat, .stat-group, .toc, .editor-panel { animation: pulseIn 420ms ease both; }

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .tool-grid { grid-template-columns: 1fr; }
  .toc ol { columns: 1; }
}
@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; }
  .hero-stats { grid-template-columns: repeat(2, 1fr); }
  #textInput { min-height: 240px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  #textInput { min-height: 160px; }
}

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