@import url("https://fonts.googleapis.com/css2?family=Baloo+2:wght@600;800&family=Nunito:wght@400;600;700&display=swap");

:root {
  color-scheme: light dark;
  --bg: #fff8ef;
  --surface: #ffffff;
  --fg: #1d1d1b;
  --muted: #6a6a64;
  --line: #eadfce;
  --accent: #b5401a;
  --accent-soft: #f6e4dc;
  --on-accent: #ffffff;
  --good: #23743b;
  --good-soft: #dcefe1;
  --bad: #b3261e;
  --bad-soft: #f8dedb;
  --warn: #946200;
  --warn-soft: #f6ebcf;
  --info: #1f5fa8;
  --info-soft: #dce8f6;
  --band-1: #23743b;
  --band-2: #4d8a2a;
  --band-3: #946200;
  --band-4: #b5401a;
  --band-5: #8a2c6d;
  --radius: 14px;
  --font: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --display: "Baloo 2", "Nunito", ui-rounded, system-ui, sans-serif;
  --fun-1: #e4572e;
  --fun-2: #17a398;
  --fun-3: #7b4fd6;
  --fun-4: #f2a20c;
  --fun-5: #3a86ff;
  --shadow: 0 3px 0 rgb(0 0 0 / 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17131a;
    --surface: #221c26;
    --fg: #ecebe6;
    --muted: #a3a29b;
    --line: #3a3140;
    --accent: #f08a5d;
    --accent-soft: #3d2419;
    --on-accent: #1a0d07;
    --good: #6fcf8a;
    --good-soft: #1c3324;
    --bad: #f28b82;
    --bad-soft: #3e1f1c;
    --warn: #e3b55b;
    --warn-soft: #3a2f16;
    --info: #8ab4f8;
    --info-soft: #1b2a40;
    --band-1: #6fcf8a;
    --band-2: #a8d26a;
    --band-3: #e3b55b;
    --band-4: #f08a5d;
    --band-5: #e08ac6;
    --fun-1: #ff8a65;
    --fun-2: #4fd1c5;
    --fun-3: #b794f6;
    --fun-4: #f6c453;
    --fun-5: #7aa7ff;
    --shadow: 0 3px 0 rgb(0 0 0 / 0.35);
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 var(--font);
  overflow-wrap: anywhere;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 8px 16px 64px;
}

h1 {
  font-size: 1.75rem;
  line-height: 1.2;
  margin: 16px 0 8px;
}

h2 {
  font-size: 1.15rem;
  margin: 32px 0 12px;
}

p {
  margin: 0 0 12px;
}

a {
  color: var(--accent);
}

.muted {
  color: var(--muted);
}

.lead {
  color: var(--muted);
  max-width: 62ch;
}

[hidden] {
  display: none !important;
}

/* ---------- Header ---------- */

.site-header {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--fg);
  text-decoration: none;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
}

.nav a:hover,
.nav a[aria-current="page"] {
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* ---------- Controls ---------- */

.btn {
  font: inherit;
  font-size: 0.95rem;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  min-height: 40px;
}

.btn:hover {
  border-color: var(--muted);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover {
  border-color: var(--fg);
}

.btn-icon {
  min-height: 32px;
  padding: 2px 10px;
  font-size: 0.8rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

input,
select,
textarea {
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  min-height: 40px;
  max-width: 100%;
}

input[type="checkbox"],
input[type="radio"] {
  min-height: 0;
  accent-color: var(--accent);
}

textarea {
  width: 100%;
  resize: vertical;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  font-size: 0.9rem;
  color: var(--muted);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 16px;
  margin: 16px 0;
}

.controls input[type="number"] {
  width: 7em;
}

/* ---------- Panels and cards ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.tools {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.tools a {
  display: block;
  height: 100%;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--fg);
  text-decoration: none;
}

.tools a:hover {
  border-color: var(--accent);
}

.tools strong {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.tools span {
  color: var(--muted);
  font-size: 0.95rem;
}

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

.stats div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.stats dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.stats dd {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}

.chart {
  width: 100%;
  max-width: 640px;
  height: auto;
  display: block;
  margin: 0 auto;
}

.chart text {
  fill: var(--muted);
  font: 12px var(--font);
}

.chart .curve {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
}

.chart .grid {
  stroke: var(--line);
}

.chart .mark {
  fill: var(--accent);
}

.chart .you {
  stroke: var(--good);
  stroke-dasharray: 4 3;
}

.chart .you-label {
  fill: var(--good);
}

/* ---------- Word details ---------- */

.details-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
  margin-bottom: 8px;
}

.details-word {
  font-size: 1.4rem;
  font-weight: 600;
}

.ipa,
.rank {
  color: var(--muted);
}

.meanings {
  margin: 0 0 12px;
  padding-left: 1.4em;
}

.meanings li {
  margin-bottom: 6px;
}

.pos {
  display: inline-block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 5px;
  vertical-align: 1px;
}

.article {
  color: var(--muted);
}

.natural {
  color: var(--muted);
}

.form {
  font-size: 0.9rem;
  color: var(--muted);
}

.form span {
  color: var(--fg);
}

.example span {
  display: block;
}

.related {
  font-size: 0.9rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.status {
  font-size: 0.8rem;
  border-radius: 4px;
  padding: 1px 8px;
}

.status-new {
  background: var(--info-soft);
  color: var(--info);
}

.status-learning {
  background: var(--warn-soft);
  color: var(--warn);
}

.status-known {
  background: var(--good-soft);
  color: var(--good);
}

/* ---------- Study screens ---------- */

.study {
  max-width: 640px;
  margin: 0 auto;
}

.progress-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 16px;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 20px;
  min-height: 220px;
}

.prompt {
  text-align: center;
  padding: 16px 0;
}

.prompt-main {
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.25;
}

.prompt-sub {
  color: var(--muted);
  margin-top: 6px;
}

.grades {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.grades .btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 4px;
}

.grades small {
  color: var(--muted);
  font-size: 0.75rem;
}

.grade-again {
  border-color: var(--bad);
}

.grade-good {
  border-color: var(--good);
}

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.options .btn {
  text-align: left;
  min-height: 56px;
}

.options .correct {
  background: var(--good-soft);
  border-color: var(--good);
}

.options .wrong {
  background: var(--bad-soft);
  border-color: var(--bad);
}

.feedback {
  min-height: 1.5em;
  margin-top: 12px;
}

.feedback.ok {
  color: var(--good);
}

.feedback.no {
  color: var(--bad);
}

.answer-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.answer-row input {
  flex: 1;
  min-width: 0;
  font-size: 1.2rem;
}

.kbd-help {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 16px;
}

kbd {
  font: 0.8rem ui-monospace, monospace;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 4px;
}

/* ---------- Tables and lists ---------- */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

th,
td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.85rem;
}

.word-rows {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
}

.word-rows > li {
  border-bottom: 1px solid var(--line);
}

.word-row {
  display: grid;
  grid-template-columns: 4em minmax(6em, 10em) 1fr auto;
  gap: 4px 12px;
  align-items: baseline;
  width: 100%;
  padding: 10px 4px;
  background: none;
  border: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.word-row:hover {
  background: var(--surface);
}

.word-row .w {
  font-weight: 600;
}

.word-row .g {
  color: var(--muted);
}

.word-row .status {
  justify-self: end;
}

.word-rows .details {
  padding: 8px 4px 16px;
}

@media (max-width: 560px) {
  .word-row {
    grid-template-columns: 3.5em 1fr auto;
  }

  .word-row .g {
    grid-column: 2 / -1;
    grid-row: 2;
  }

  .word-row .status {
    grid-column: 3;
    grid-row: 1;
  }

  .options {
    grid-template-columns: 1fr;
  }

  .prompt-main {
    font-size: 1.6rem;
  }
}

/* ---------- Bars ---------- */

.bars {
  display: grid;
  gap: 8px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.bar {
  height: 10px;
  background: var(--line);
  border-radius: 5px;
  overflow: hidden;
  display: flex;
}

.bar span {
  display: block;
  height: 100%;
}

/* ---------- Reader ---------- */

.reader-text {
  white-space: pre-wrap;
  line-height: 1.9;
  font-size: 1.05rem;
}

.tok {
  border-radius: 3px;
  padding: 0 1px;
  line-height: 1.35;
  cursor: pointer;
  border: 0;
  font: inherit;
  color: inherit;
  background: none;
}

.tok-known {
  background: var(--good-soft);
}

.tok-learning {
  background: var(--warn-soft);
}

.tok-new {
  background: var(--info-soft);
}

.tok-out {
  text-decoration: underline dotted var(--muted);
  cursor: default;
}

.tok-band-1 { box-shadow: inset 0 -3px var(--band-1); }
.tok-band-2 { box-shadow: inset 0 -3px var(--band-2); }
.tok-band-3 { box-shadow: inset 0 -3px var(--band-3); }
.tok-band-4 { box-shadow: inset 0 -3px var(--band-4); }
.tok-band-5 { box-shadow: inset 0 -3px var(--band-5); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 8px 0;
}

.swatch {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  border-radius: 2px;
  vertical-align: -1px;
  margin-right: 4px;
}

.popover {
  position: absolute;
  z-index: 10;
  width: min(380px, calc(100vw - 32px));
  max-height: 70vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  padding: 0;
  margin: 8px 0;
}

.chips li {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.9rem;
  background: var(--surface);
}

/* ---------- Verb table ---------- */

.verb-table td {
  min-width: 6em;
}

.verb-table .rank {
  font-size: 0.8rem;
}

.verb-table td.empty {
  color: var(--line);
}

summary {
  cursor: pointer;
}

.study .panel {
  margin-bottom: 12px;
}

.card .btn-row {
  justify-content: center;
}

fieldset {
  border: 0;
  padding: 0;
  margin: 16px 0;
}

legend {
  padding: 0;
  margin-bottom: 4px;
}

.btn[aria-pressed="true"] {
  border-color: var(--fg);
  font-weight: 600;
}

.verb-table th,
.verb-table td {
  white-space: nowrap;
  overflow-wrap: normal;
}

[tabindex="-1"]:focus {
  outline: none;
}

/* ---------- Playful theme ---------- */

h1,
h2,
.brand,
.prompt-main,
.details-word,
.stats dd {
  font-family: var(--display);
}

h1 {
  font-size: 2.2rem;
  font-weight: 800;
}

h2 {
  font-size: 1.35rem;
}

.brand {
  font-size: 1.2rem;
  font-weight: 800;
}

.hero {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 16px 0 8px;
}

.hero h1 {
  font-size: clamp(2.2rem, 7vw, 3.4rem);
  margin: 0;
  color: var(--accent);
}

.hero-logo {
  flex: none;
  width: clamp(64px, 16vw, 96px);
  height: auto;
  animation: wobble 4s ease-in-out infinite;
}

.subtitle {
  font-family: var(--display);
  font-size: 1.25rem;
  color: var(--muted);
  margin: 0;
}

@keyframes wobble {
  0%, 100% { transform: rotate(0deg); }
  45% { transform: rotate(-6deg) translateY(-2px); }
  55% { transform: rotate(5deg) translateY(-2px); }
}

.btn {
  border-radius: 999px;
  border-width: 2px;
  font-weight: 700;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease;
}

.btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: none;
}

.btn-icon {
  border-width: 1px;
}

.options .btn,
.grades .btn {
  border-radius: var(--radius);
}

.panel,
.card,
.stats div,
.tools a {
  border-width: 2px;
  box-shadow: var(--shadow);
}

.tools a {
  --tool: var(--fun-1);
  border-color: var(--tool);
  border-top-width: 8px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.tools a:hover {
  border-color: var(--tool);
  transform: translateY(-3px) rotate(-1deg);
  box-shadow: 0 8px 0 var(--tool);
}

.tools em {
  display: inline-block;
  font-family: var(--display);
  font-style: normal;
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--tool);
  margin-bottom: 2px;
}

.tools strong {
  font-family: var(--display);
  font-size: 1.35rem;
}

.tools .tool-2 { --tool: var(--fun-2); }
.tools .tool-3 { --tool: var(--fun-3); }
.tools .tool-4 { --tool: var(--fun-4); }
.tools .tool-5 { --tool: var(--fun-5); }

.stats dd {
  color: var(--accent);
  font-size: 1.8rem;
}

.prompt-main {
  font-size: 2.4rem;
  font-weight: 800;
}

.feedback.ok,
.feedback.no {
  animation: pop 0.25s ease;
}

.options .correct {
  animation: pop 0.25s ease;
}

.options .wrong {
  animation: shake 0.3s ease;
}

@keyframes pop {
  0% { transform: scale(0.94); }
  60% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

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

.account {
  margin-left: auto;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}
