/* ─── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --surface2:    #22263a;
  --border:      #2e3350;
  --text:        #e4e8f7;
  --text-muted:  #8891b4;
  --accent:      #6c9eff;
  --accent2:     #a78bfa;
  --accent3:     #34d399;
  --danger:      #f87171;
  --hiragana-c:  #60a5fa;
  --katakana-c:  #a78bfa;
  --kanji-c:     #f472b6;
  --bar-bg:      #2e3350;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 2px 12px rgba(0,0,0,0.4);
  --transition:  0.18s ease;
}

[data-theme="light"] {
  --bg:          #f4f6fb;
  --surface:     #ffffff;
  --surface2:    #eef1f8;
  --border:      #d0d5e8;
  --text:        #1a1d2e;
  --text-muted:  #6b738f;
  --accent:      #3b6fe8;
  --accent2:     #7c3aed;
  --accent3:     #059669;
  --danger:      #dc2626;
  --hiragana-c:  #2563eb;
  --katakana-c:  #7c3aed;
  --kanji-c:     #db2777;
  --bar-bg:      #d0d5e8;
  --shadow:      0 2px 12px rgba(0,0,0,0.08);
}

/* ─── Reset / base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

/* ─── Header ────────────────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}
.brand .subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 1px;
}
.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.45rem 1rem;
  transition: background var(--transition), color var(--transition), opacity var(--transition);
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { opacity: 0.85; }

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); background: var(--surface2); }

.btn-icon { padding: 0.45rem 0.65rem; }

/* ─── Layout ─────────────────────────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ─── Input section ─────────────────────────────────────────────────────────── */
.input-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.main-input {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  font-size: 0.95rem;
  line-height: 1.65;
  font-family: inherit;
  transition: border-color var(--transition), background var(--transition);
  outline: none;
}
.main-input:focus { border-color: var(--accent); }
.main-input::placeholder { color: var(--text-muted); }

.input-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}

/* ─── Panel ──────────────────────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
}
.panel-title {
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.panel-title.mt { margin-top: 1.2rem; }

/* ─── Stats grid ─────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  text-align: center;
  transition: border-color var(--transition);
}
.stat-card.accent { border-color: var(--accent); }
.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 0.35rem;
}
.stat-value.small { font-size: 1.1rem; padding-top: 0.4rem; }
.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─── Time section ───────────────────────────────────────────────────────────── */
.time-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.time-item {
  flex: 1 1 200px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  gap: 0.5rem;
}
.time-label { font-size: 0.85rem; color: var(--text-muted); }
.time-value { font-size: 1rem; font-weight: 600; color: var(--accent3); }

/* ─── Japanese chars ─────────────────────────────────────────────────────────── */
.jp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.65rem;
}
.jp-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
  text-align: center;
}
.jp-card.hiragana { border-color: var(--hiragana-c); }
.jp-card.katakana { border-color: var(--katakana-c); }
.jp-card.kanji    { border-color: var(--kanji-c); }
.jp-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-bottom: 0.25rem;
}
.jp-card.hiragana .jp-value { color: var(--hiragana-c); }
.jp-card.katakana .jp-value { color: var(--katakana-c); }
.jp-card.kanji    .jp-value { color: var(--kanji-c); }
.jp-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ─── Two-column ─────────────────────────────────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
.freq-panel { min-height: 220px; }

/* ─── Word frequency ─────────────────────────────────────────────────────────── */
.word-freq-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.word-freq-list li {
  display: grid;
  grid-template-columns: 100px 1fr 36px;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}
.word-freq-list li.no-data {
  display: block;
  color: var(--text-muted);
  font-style: italic;
}
.wf-word {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.wf-bar-wrap {
  height: 8px;
  background: var(--bar-bg);
  border-radius: 4px;
  overflow: hidden;
}
.wf-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.25s ease;
}
.wf-count {
  text-align: right;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ─── Character frequency chart ──────────────────────────────────────────────── */
.char-freq-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 160px;
}
.cf-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
}
.cf-bar-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  background: var(--bar-bg);
  border-radius: 3px 3px 0 0;
  overflow: hidden;
  cursor: default;
}
.cf-bar {
  width: 100%;
  background: linear-gradient(180deg, var(--accent2), var(--accent));
  border-radius: 3px 3px 0 0;
  transition: height 0.25s ease;
  min-height: 2px;
}
.cf-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
}

/* ─── Platform limits ────────────────────────────────────────────────────────── */
.limits-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.75rem;
}
.limit-item { padding: 0.75rem; background: var(--surface2); border-radius: var(--radius-sm); }
.limit-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
  gap: 0.5rem;
}
.limit-name { font-size: 0.85rem; font-weight: 500; color: var(--text); }
.limit-status {
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.limit-status.ok   { color: var(--accent3); }
.limit-status.over { color: var(--danger); }
.limit-bar-wrap {
  height: 6px;
  background: var(--bar-bg);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.3rem;
}
.limit-bar {
  height: 100%;
  background: var(--accent3);
  border-radius: 3px;
  transition: width 0.25s ease;
}
.limit-bar.over { background: var(--danger); }
.limit-nums { font-size: 0.72rem; color: var(--text-muted); text-align: right; }

/* ─── Footer ─────────────────────────────────────────────────────────────────── */
.site-footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}
.site-footer a { color: var(--accent); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .two-col { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .header-inner { padding: 0.7rem 1rem; }
  .container { padding: 1rem; }
}
@media (max-width: 400px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 1.6rem; }
}
