:root {
  --primary: #fc8c33;
  --primary-dark: #eb6b1a;
  --success: #44cc80;
  --warning: #ffb533;
  --danger: #f57272;
  --bg: #fdf8ec;
  --surface: #ffffff;
  --surface-tint: #fbf6e9;
  --text: #2c211a;
  --text-muted: #6e655c;
  --border: #ece2cc;
  --shadow: 0 4px 16px rgba(0,0,0,0.06);
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "SF Pro Rounded",
               system-ui, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 18px;
}
.brand small { color: var(--text-muted); font-weight: 500; font-size: 13px; }

.container { max-width: 960px; margin: 0 auto; padding: 24px; }
.container.narrow { max-width: 520px; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.error { color: var(--danger); margin-top: 8px; font-size: 14px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.form { display: flex; flex-direction: column; gap: 8px; }
.form label { font-size: 13px; color: var(--text-muted); margin-top: 8px; }
.form input {
  font-size: 28px;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, "SFMono-Regular", monospace;
  letter-spacing: 6px;
  text-align: center;
  text-transform: uppercase;
  background: var(--bg);
  color: var(--text);
}
.form input:focus { outline: none; border-color: var(--primary); }

button {
  font: inherit;
  border: none;
  border-radius: 999px;
  padding: 14px 22px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}
button:active { transform: scale(0.98); }
button.primary { background: var(--primary); color: white; }
button.primary:hover { background: var(--primary-dark); }
button.ghost { background: transparent; color: var(--text-muted); }
button.ghost:hover { color: var(--text); }
button:disabled { opacity: 0.6; cursor: progress; }

.how {
  margin-top: 24px;
  background: var(--surface-tint);
  padding: 16px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.how summary { cursor: pointer; font-weight: 600; }
.how ol { margin: 12px 0 0 20px; padding: 0; color: var(--text-muted); }
.how li { margin-bottom: 6px; }

.kid-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.kid-avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: rgba(252, 140, 51, 0.15);
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
  flex-shrink: 0;
}
.kid-info h2 { margin: 0; font-size: 22px; }
.kid-info .badges { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.badge {
  background: var(--surface-tint);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--surface);
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  flex: 1;
  background: transparent;
  color: var(--text-muted);
  padding: 10px 14px;
  font-weight: 600;
  border-radius: 999px;
  white-space: nowrap;
}
.tab.active { background: var(--primary); color: white; }

.panel { display: none; }
.panel.active { display: block; }

.grid.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-tile {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  border: 1px solid var(--border);
}
.stat-tile .emoji { font-size: 28px; }
.stat-tile .value { font-size: 24px; font-weight: 800; }
.stat-tile .label { color: var(--text-muted); font-size: 13px; }

.chart-card { margin-bottom: 16px; }
.chart-card h3 { margin: 0 0 12px 0; font-size: 16px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.list-item .meta { flex: 1; }
.list-item .meta .title { font-weight: 700; }
.list-item .meta .sub { color: var(--text-muted); font-size: 13px; }
.list-item .stars { color: var(--warning); font-size: 18px; letter-spacing: 2px; }
.list-item .score { font-weight: 700; color: var(--primary); }

.cat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.cat-card summary {
  cursor: pointer;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  list-style: none;
}
.cat-card summary::-webkit-details-marker { display: none; }
.cat-card .summary-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.cat-card .summary-bar > span {
  display: block;
  height: 100%;
  background: var(--success);
}
.cat-card .word-list {
  padding: 0 20px 16px 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.word-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface-tint);
  border-radius: 8px;
}
.word-row .word { font-weight: 600; }
.word-row .accuracy {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--success);
  color: white;
}
.word-row .accuracy.warn { background: var(--warning); }
.word-row .accuracy.bad { background: var(--danger); }
.word-row.new .accuracy { background: var(--text-muted); }

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.footer {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 13px;
}

@media (max-width: 600px) {
  .container { padding: 16px; }
  .form input { font-size: 22px; letter-spacing: 4px; }
  .kid-header { flex-direction: column; text-align: center; }
}
