:root {
  --bg: #f7f3ec;
  --card: #ffffff;
  --soft: #f1ebe0;
  --text: #22262b;
  --muted: #6a7078;
  --line: #e2dccf;
  --accent: #b4532a;
  --accent-2: #1f7a6b;
  --accent-soft: #f6e4d8;
  --accent-text: #ffffff;
  --ref: #2f6fb3;
  --me: #c2410c;
  --again: #b3261e;
  --hard: #8a6100;
  --good: #1e7a3c;
  --easy: #1f5fa8;
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.06), 0 6px 20px rgba(60, 40, 20, 0.06);
  --ui: 'Inter', 'Noto Sans', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --thai-modern: 'IBM Plex Sans Thai', 'Noto Sans Thai', 'Noto Sans', sans-serif;
  --thai-klassisch: 'Noto Sans Thai Looped', 'IBM Plex Sans Thai Looped', 'Noto Serif Thai', serif;
  --thai-font: var(--thai-modern);
}
:root[data-font='klassisch'] {
  --thai-font: var(--thai-klassisch);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --card: #1f2226;
    --soft: #272b30;
    --text: #ecebe7;
    --muted: #9ba1a8;
    --line: #33373d;
    --accent: #e58a5e;
    --accent-2: #5cc4b0;
    --accent-soft: #3a2a22;
    --accent-text: #17181a;
    --ref: #7ab3ea;
    --me: #f59e6b;
    --again: #f08a82;
    --hard: #e0b450;
    --good: #6fcf8e;
    --easy: #7ab3ea;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--ui);
}
[lang='th'],
.th {
  font-family: var(--thai-font), var(--ui);
}
a {
  color: var(--accent);
}

/* Kopf und Menü */
header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.head-in {
  max-width: 980px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
}
.brand .logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 700;
}
nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
nav a {
  padding: 7px 14px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
}
nav a:hover {
  background: var(--soft);
  color: var(--text);
}
nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
main {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 16px 72px;
}
main.narrow > div {
  max-width: 760px;
  margin: 0 auto;
}
h1 {
  font-size: 28px;
  line-height: 1.25;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
h2 {
  font-size: 19px;
  margin: 34px 0 12px;
}
.lead {
  color: var(--muted);
  margin: 0 0 20px;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 14px;
}
.back {
  display: inline-block;
  margin-bottom: 10px;
  font-size: 14px;
  text-decoration: none;
}

/* Bedienelemente */
select,
button,
input[type='text'],
input[type='number'] {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
}
button {
  cursor: pointer;
  transition: border-color 0.12s, transform 0.05s, background 0.12s;
}
button:hover {
  border-color: var(--accent);
}
button:active {
  transform: translateY(1px);
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  padding: 11px 22px;
}
button.primary:hover {
  filter: brightness(1.07);
}
button.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  justify-content: space-between;
  margin: 14px 0 16px;
}
.score {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}

/* Flächen */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.hero {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
  padding: 26px 28px;
  border-radius: 20px;
  color: #fff;
  background: linear-gradient(135deg, #b4532a 0%, #c9772f 55%, #d59a3a 100%);
  box-shadow: var(--shadow);
}
.hero .hello {
  font-size: 34px;
  font-weight: 700;
  line-height: 1.3;
}
.hero p {
  margin: 4px 0 0;
  opacity: 0.95;
}
.hero button.primary {
  background: #fff;
  border-color: #fff;
  color: #9a431f;
  font-size: 17px;
  padding: 13px 26px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.grid .stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 14px;
  color: var(--muted);
  box-shadow: var(--shadow);
}
.stat b {
  display: block;
  font-size: 28px;
  line-height: 1.15;
  color: var(--text);
}
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 14px;
}
.tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  text-decoration: none;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  transition: transform 0.12s, border-color 0.12s;
}
.tile:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}
.tile .icon {
  align-self: flex-start;
  min-width: 46px;
  height: 46px;
  padding: 0 10px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 21px;
  font-weight: 700;
}
.tile:nth-child(3n + 2) .icon {
  background: color-mix(in srgb, var(--accent-2) 16%, var(--card));
  color: var(--accent-2);
}
.tile b {
  font-size: 17px;
}
.tile span.text {
  font-size: 14px;
  color: var(--muted);
}
.notice {
  margin-top: 14px;
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  font-size: 14px;
  background: var(--card);
  border-radius: 0 10px 10px 0;
}

/* Lektionen */
.lessons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}
.lesson-link {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  padding: 0;
  overflow: hidden;
  transition: transform 0.12s, border-color 0.12s;
}
.lesson-link:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}
.lesson-link img.thumb {
  width: 100%;
  height: 120px;
  object-fit: cover;
  object-position: center 60%;
  border-bottom: 1px solid var(--line);
}
.lesson-link .body {
  padding: 14px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.lesson-link .top {
  display: flex;
  align-items: center;
  gap: 10px;
}
.num {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
}
.lesson-link .pattern {
  font-size: 14px;
  color: var(--muted);
  flex: 1;
}
.count {
  white-space: nowrap;
  font-size: 13px;
  color: var(--muted);
}
.tag {
  font-size: 12px;
  border-radius: 999px;
  padding: 2px 10px;
  background: var(--soft);
  color: var(--muted);
  font-weight: 500;
  margin-left: auto;
}
.pattern-box {
  font-size: 19px;
  margin: 12px 0 16px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
table {
  width: 100%;
  border-collapse: collapse;
}
td {
  padding: 12px 8px;
  border-top: 1px solid var(--line);
  vertical-align: top;
}
td.play {
  width: 48px;
}
.sent-th {
  font-size: 23px;
  line-height: 1.5;
}
.tr {
  color: var(--accent);
}
.formal {
  font-size: 14px;
  color: var(--muted);
}

/* Karten und Übungen */
.card {
  text-align: center;
  padding: 32px 22px;
  min-height: 300px;
}
.card .big {
  font-size: 40px;
  line-height: 1.5;
  margin: 8px 0;
}
.card .de {
  font-size: 23px;
  margin: 8px 0;
  font-weight: 500;
}
.card .tr {
  font-size: 20px;
}
.card hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 22px 0;
}
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}
.row.left {
  justify-content: flex-start;
}
.grade {
  min-width: 110px;
  padding: 9px 10px;
  font-weight: 600;
}
.grade small {
  display: block;
  font-weight: 400;
  color: var(--muted);
}
.g1 {
  color: var(--again);
}
.g2 {
  color: var(--hard);
}
.g3 {
  color: var(--good);
}
.g4 {
  color: var(--easy);
}
.slots,
.bank {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 14px 0;
}
.slots {
  min-height: 64px;
  padding: 10px;
  border: 2px dashed var(--line);
  border-radius: 14px;
  align-items: center;
}
.slots.right {
  border-color: var(--good);
  border-style: solid;
}
.slots.wrong {
  border-color: var(--again);
  border-style: solid;
}
.chip {
  font-size: 24px;
  line-height: 1.4;
  padding: 6px 14px;
  border-radius: 12px;
}
.bank .chip.used {
  visibility: hidden;
}
.frame {
  font-size: 30px;
  line-height: 1.6;
}
.frame .gap {
  display: inline-block;
  min-width: 2.2em;
  margin: 0 0.15em;
  padding: 0 0.3em;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
}
.drill {
  margin-bottom: 12px;
}
.drill .frame {
  font-size: 24px;
}
.fills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.fill {
  background: var(--soft);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 14px;
  color: var(--muted);
}
.fill b {
  display: block;
  font-size: 19px;
  font-weight: 500;
  color: var(--text);
}
.numbig {
  font-size: 54px;
  font-weight: 700;
  line-height: 1.2;
  margin: 8px 0;
}
input.answer {
  font-size: 26px;
  width: 200px;
  text-align: center;
}
.settings label {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.settings label:first-child {
  border-top: 0;
}
.settings small {
  display: block;
  color: var(--muted);
}
canvas {
  width: 100%;
  height: 140px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
.legend {
  font-size: 13px;
  color: var(--muted);
}
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin: 0 4px 0 10px;
}
.progress-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 10px;
}
kbd {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 5px;
  font-size: 12px;
  background: var(--soft);
}
.alt-script {
  font-family: var(--thai-klassisch);
  color: var(--muted);
}
.card img.pic {
  max-width: 100%;
  max-height: 260px;
  border-radius: 10px;
  margin-bottom: 8px;
}
td img.pic {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
}
.bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 120px;
}
.bars .col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  font-size: 11px;
  color: var(--muted);
}
.bars .bar {
  width: 100%;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 1px;
}
.bars .bar.soft {
  background: var(--ref);
}
.meter {
  height: 8px;
  background: var(--soft);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
}
.meter span {
  display: block;
  height: 100%;
}
@media (max-width: 560px) {
  .card .big {
    font-size: 32px;
  }
  .hero .hello {
    font-size: 27px;
  }
  td:first-child {
    padding-left: 0;
  }
  /* breite Tabellen (Wortreihen) seitlich wischen statt die Seite zu verbreitern */
  table {
    display: block;
    overflow-x: auto;
  }
}

/* Töne: Farbe und Verlaufslinie je Silbe */
:root {
  --t-mid: #5f6570;
  --t-low: #2f6fb3;
  --t-fall: #c2412d;
  --t-high: #2e8b57;
  --t-rise: #8a4fc2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --t-mid: #a9afb9;
    --t-low: #7ab3ea;
    --t-fall: #f08a75;
    --t-high: #6fcf97;
    --t-rise: #c39bf0;
  }
}
.tones {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  row-gap: 4px;
}
.card .tones {
  justify-content: center;
}
.syl {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  font-weight: 600;
}
.syl svg {
  width: 26px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}
.tones .sep {
  color: var(--muted);
}
.t-mid { color: var(--t-mid); }
.t-low { color: var(--t-low); }
.t-fall { color: var(--t-fall); }
.t-high { color: var(--t-high); }
.t-rise { color: var(--t-rise); }
.legend-tones {
  gap: 14px;
  font-size: 13px;
  margin: 6px 0 10px;
}
.legend-tones .syl {
  font-weight: 400;
}

/* Tontraining */
.choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 14px 0;
}
.choice {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 96px;
  padding: 10px 12px;
}
.choice small {
  color: var(--muted);
}
.choice .tones {
  justify-content: center;
}
.choice.right {
  border-color: var(--t-high);
  box-shadow: 0 0 0 2px var(--t-high);
}
.choice.wrong {
  border-color: var(--t-fall);
  box-shadow: 0 0 0 2px var(--t-fall);
}
.choice.dim {
  opacity: 0.45;
}
.ok {
  color: var(--t-high);
  font-weight: 600;
}
.bad {
  color: var(--t-fall);
  font-weight: 600;
}

img.scene {
  display: block;
  width: 100%;
  max-width: 820px;
  border-radius: 12px;
  border: 1px solid var(--line);
  margin: 12px 0;
}
img.scene.scene-card {
  max-width: 560px;
  margin: 0 auto 12px;
}
.chip small {
  margin-left: 8px;
  font-size: 11px;
  color: var(--muted);
}
