:root {
  color-scheme: light;
  --ink: #202327;
  --muted: #68727a;
  --paper: #f7fbf8;
  --surface: #ffffff;
  --line: #d9e2dd;
  --green: #176b52;
  --green-dark: #10513e;
  --green-soft: #e5f3ec;
  --red: #bd3d32;
  --gold: #c8821b;
  --blue-soft: #e6f1f7;
  --charcoal: #30363a;
  --shadow: 0 16px 42px rgba(29, 42, 38, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: default;
  opacity: 0.75;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 70px;
  padding: 12px 44px;
  background: rgba(247, 251, 248, 0.92);
  border-bottom: 1px solid rgba(216, 225, 220, 0.86);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-family: "Noto Sans Thai", Tahoma, sans-serif;
  font-size: 1.75rem;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 0.98rem;
}

.brand small {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.nav {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
}

.nav a {
  border-radius: 8px;
  color: var(--charcoal);
  padding: 8px 11px;
  text-decoration: none;
  white-space: nowrap;
}

.nav a:hover,
.nav a:focus-visible {
  background: var(--green-soft);
  outline: none;
}

main {
  overflow: hidden;
}

.hero {
  padding: 64px 44px 42px;
}

.hero-copy {
  max-width: 860px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--red);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  color: var(--charcoal);
  font-size: clamp(3rem, 8vw, 5.4rem);
  line-height: 0.96;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  color: var(--charcoal);
  font-size: 2.25rem;
  line-height: 1.08;
  letter-spacing: 0;
}

h3 {
  margin: 0;
  letter-spacing: 0;
}

.hero-subtitle {
  max-width: 780px;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 1.1rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 28px;
}

.primary-action,
.secondary-action,
.icon-button,
.play-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
}

.primary-action {
  gap: 10px;
  border: 0;
  background: var(--green);
  color: #fff;
  padding: 0 18px;
  box-shadow: 0 12px 24px rgba(23, 107, 82, 0.22);
}

.primary-action:hover,
.primary-action:focus-visible {
  background: var(--green-dark);
  outline: none;
}

.secondary-action {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--charcoal);
  padding: 0 16px;
}

.secondary-action:hover,
.secondary-action:focus-visible {
  border-color: var(--green);
  outline: none;
}

.small-action {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.9rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.stats span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  padding: 0 12px;
}

.stats strong {
  color: var(--green);
}

.control-strip {
  position: sticky;
  top: 70px;
  z-index: 16;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 14px 44px;
  background: rgba(255, 255, 255, 0.94);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 20px rgba(29, 42, 38, 0.05);
}

.control-strip > div {
  display: grid;
  gap: 4px;
}

.control-label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

select,
input[type="search"],
input[type="text"] {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

input[type="range"] {
  width: 126px;
  accent-color: var(--green);
}

.icon-button,
.play-button {
  width: 44px;
  min-width: 44px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--green);
  font-weight: 900;
}

.icon-button:hover,
.icon-button:focus-visible,
.play-button:hover,
.play-button:focus-visible {
  border-color: var(--green);
  background: var(--green-soft);
  outline: none;
}

.icon-button.large {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  font-size: 1.35rem;
}

.section {
  padding: 58px 44px;
}

.section-band {
  background: #fff;
  border-block: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.search-wrap input {
  width: min(420px, 72vw);
}

.sound-grid,
.letter-grid,
.vowel-grid {
  display: grid;
  gap: 16px;
}

.sound-grid {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.letter-grid {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.vowel-grid {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.sound-card,
.letter-card,
.vowel-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sound-card {
  padding: 16px;
}

.sound-card-top,
.letter-main,
.vowel-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rank {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.phoneme {
  margin-top: 10px;
  color: var(--green);
  font-size: 2.45rem;
  font-weight: 900;
  line-height: 1;
}

.sound-note {
  min-height: 44px;
  margin-top: 8px;
  color: var(--muted);
}

.letter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.letter-chip {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-family: "Noto Sans Thai", Tahoma, sans-serif;
  font-size: 1.35rem;
  font-weight: 800;
}

.letter-card {
  padding: 14px;
}

.thai-letter {
  color: var(--charcoal);
  font-family: "Noto Sans Thai", Tahoma, sans-serif;
  font-size: 3.1rem;
  font-weight: 900;
  line-height: 1;
}

.letter-name {
  margin-top: 8px;
  font-family: "Noto Sans Thai", Tahoma, sans-serif;
  font-size: 1.35rem;
  font-weight: 800;
}

.roman {
  color: var(--muted);
  font-weight: 700;
}

.letter-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.letter-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 8px;
  background: var(--blue-soft);
  color: var(--charcoal);
  padding: 0 9px;
  font-size: 0.86rem;
}

.vowel-card {
  padding: 16px;
}

.vowel-card h3 {
  font-family: "Noto Sans Thai", Tahoma, sans-serif;
  font-size: 1.7rem;
}

.vowel-card p {
  margin: 4px 0 0;
  color: var(--muted);
}

.vowel-forms {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.vowel-form {
  display: grid;
  grid-template-columns: 44px minmax(72px, auto) 1fr;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.vowel-thai {
  font-family: "Noto Sans Thai", Tahoma, sans-serif;
  font-size: 2rem;
  font-weight: 900;
}

.practice-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  gap: 20px;
  align-items: start;
}

.bank-panel,
.game-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.bank-panel {
  padding: 16px;
}

.bank-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.bank-list {
  display: grid;
  gap: 18px;
}

.bank-group h3 {
  margin-bottom: 10px;
}

.bank-items {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(136px, 1fr));
  gap: 8px;
}

.bank-item {
  display: grid;
  grid-template-columns: 20px auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 6px 8px;
}

.bank-item input {
  accent-color: var(--green);
}

.bank-char {
  font-family: "Noto Sans Thai", Tahoma, sans-serif;
  font-size: 1.35rem;
  font-weight: 900;
}

.bank-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.game-panel {
  min-height: 300px;
  padding: 22px;
}

.game-empty,
.game-running,
.game-results {
  display: grid;
  justify-items: center;
  gap: 18px;
  text-align: center;
}

.game-empty p,
.game-results p {
  margin: 0;
  color: var(--muted);
}

.game-progress {
  display: flex;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

.game-progress span {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 4px 10px;
}

.game-answer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.thai-answer {
  width: 7rem;
  max-width: 42vw;
  min-height: 48px;
  text-align: center;
  font-family: "Noto Sans Thai", Tahoma, sans-serif;
  font-size: 1.55rem;
  font-weight: 900;
}

.feedback {
  min-height: 24px;
  color: var(--green);
  font-weight: 800;
}

.score {
  color: var(--green);
  font-size: 3rem;
  font-weight: 900;
}

.wrong-list {
  display: grid;
  gap: 8px;
  width: 100%;
  text-align: left;
}

.wrong-list h3 {
  text-align: center;
}

.wrong-item {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 8px 10px;
}

.wrong-item strong {
  font-family: "Noto Sans Thai", Tahoma, sans-serif;
  font-size: 1.45rem;
}

.wrong-item small {
  color: var(--muted);
  text-align: right;
}

.chart-viewer {
  display: grid;
  gap: 16px;
}

.chart-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chart-tab.active {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green-dark);
  font-weight: 800;
}

.chart-frame {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chart-frame img {
  display: block;
  width: 100%;
  height: auto;
}

.chart-frame figcaption {
  border-top: 1px solid var(--line);
  color: var(--muted);
  padding: 10px 14px;
  font-weight: 800;
}

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 44px;
  border-top: 1px solid var(--line);
  background: var(--charcoal);
  color: #fff;
}

.footer span:last-child {
  color: #bfe5d8;
}

@media (max-width: 880px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 10px 18px;
  }

  .nav {
    width: 100%;
  }

  .hero,
  .section,
  .control-strip,
  .footer {
    padding-inline: 18px;
  }

  .control-strip {
    top: 105px;
    align-items: stretch;
  }

  .section-heading,
  .practice-layout {
    display: grid;
    grid-template-columns: 1fr;
  }

  .search-wrap input {
    width: 100%;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 3.1rem;
  }

  h2 {
    font-size: 1.8rem;
  }

  .hero {
    padding-top: 42px;
  }

  .control-strip {
    position: static;
  }

  .sound-grid,
  .letter-grid,
  .vowel-grid {
    grid-template-columns: 1fr;
  }

  .bank-items {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bank-item {
    grid-template-columns: 18px auto;
  }

  .bank-label {
    grid-column: 2;
  }

  .thai-answer {
    width: 5.5rem;
    max-width: 36vw;
    font-size: 1.35rem;
  }

  .wrong-item {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .wrong-item small {
    text-align: center;
  }
}
