*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg2: #181c27;
  --bg3: #1e2335;
  --bg4: #252b3e;
  --border: #2e3450;
  --text: #d0d6f0;
  --text2: #8890b0;
  --accent: #5b7ef5;
  --accent2: #7c5bf5;
  --green: #4ec97a;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: "SF Mono", "Fira Mono", "Cascadia Mono", "Consolas", monospace;
}

html { font-size: 14px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.4;
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

/* ── Controls ── */
.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex: 1;
}

.search-wrap {
  position: relative;
}

.search-wrap input {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px 5px 30px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  width: 200px;
  outline: none;
  transition: border-color 0.15s;
}

.search-wrap input:focus { border-color: var(--accent); }

.search-wrap::before {
  content: "⌕";
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text2);
  font-size: 1rem;
  pointer-events: none;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text2);
}

.filter-group label { cursor: pointer; display: flex; align-items: center; gap: 3px; }
.filter-group input[type=checkbox] { accent-color: var(--accent); cursor: pointer; }

.tristate {
  display: flex;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.tristate button {
  background: none;
  border: none;
  color: var(--text2);
  padding: 4px 8px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
}

.tristate button.active {
  background: var(--accent);
  color: #fff;
}

.corpus-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text2);
  margin-left: auto;
}

.corpus-wrap select {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: var(--radius);
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
}

.count-badge {
  font-size: 0.75rem;
  color: var(--text2);
  white-space: nowrap;
  padding: 4px 8px;
  background: var(--bg3);
  border-radius: var(--radius);
}

/* ── Table container ── */
.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 60px);
}

#scroll-sentinel { height: 1px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

thead th {
  background: var(--bg2);
  border-bottom: 2px solid var(--border);
  padding: 7px 8px;
  text-align: right;
  font-weight: 600;
  color: var(--text2);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}

thead th:first-child,
thead th:nth-child(2),
thead th:nth-child(3) { text-align: left; }

thead th:hover { color: var(--text); }
thead th.sort-asc, thead th.sort-desc { color: var(--accent); }

thead th .sort-arrow { margin-left: 3px; font-size: 0.7rem; }

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.08s;
}

tbody tr:hover { background: var(--bg3); }
tbody tr.expanded { background: var(--bg3); }

tbody td {
  padding: 5px 8px;
  text-align: right;
  color: var(--text);
  white-space: nowrap;
}

tbody td:first-child { text-align: left; font-weight: 600; color: var(--accent); }
tbody td:nth-child(2) { text-align: left; color: var(--text2); }
tbody td:nth-child(3) { text-align: left; }

.fmap-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.fmap-standard    { background: #1a3a5c; color: #5aabf5; }
.fmap-angle-mod   { background: #2a1f4a; color: #a07af5; }
.fmap-nokwts      { background: #1a3a2a; color: #5af5a0; }
.fmap-nightlight  { background: #3a2a1a; color: #f5a05a; }
.fmap-other       { background: #2a2e3e; color: #8890b0; }

.thumb-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  vertical-align: middle;
  margin-left: 3px;
}

/* ── Detail expand row ── */
.detail-row td {
  padding: 0;
  background: var(--bg2);
  border-bottom: 2px solid var(--accent);
}

.detail-inner {
  padding: 16px 20px;
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  align-items: flex-start;
}

/* ── Keyboard ── */
.keyboard-wrap {
  flex: 0 0 auto;
}

.keyboard-wrap h3 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text2);
}

.keyboard {
  position: relative;
  font-family: var(--mono);
}

.key-row {
  display: flex;
  margin-bottom: 3px;
  gap: 3px;
}

.key {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.12);
  transition: transform 0.1s;
  flex-shrink: 0;
}

.key:hover { transform: scale(1.12); z-index: 2; }

/* Finger colors: cool=left, warm=right, neutral=thumb */
.f-LP { background: #2a4a8a; }
.f-LR { background: #1a6a8a; }
.f-LM { background: #1a7a6a; }
.f-LI { background: #2a7a3a; }
.f-LT { background: #6a6a6a; }
.f-RT { background: #7a5a6a; }
.f-RI { background: #8a5a1a; }
.f-RM { background: #8a3a1a; }
.f-RR { background: #8a1a2a; }
.f-RP { background: #7a1a5a; }

/* ── Finger legend ── */
.finger-legend {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  color: var(--text2);
}

.legend-color {
  width: 12px; height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ── Stats panel ── */
.stats-panel {
  flex: 1;
  min-width: 220px;
}

.stats-panel h3 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text2);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px;
}

.stat-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 10px;
}

.stat-label {
  font-size: 0.68rem;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

/* ── Loading spinner ── */
.loading {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-left: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text2);
  font-size: 0.9rem;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── Responsive ── */
@media (max-width: 768px) {
  header { padding: 10px 12px; gap: 10px; }
  .controls { gap: 8px; }
  .search-wrap input { width: 140px; }
  .detail-inner { flex-direction: column; }
  .table-wrap { max-height: none; }
}
