:root {
  color-scheme: light;
  --ink: #202327;
  --muted: #68717a;
  --paper: #fffdf8;
  --surface: #ffffff;
  --line: #d7ddd8;
  --green: #176b52;
  --green-soft: #e1f1e9;
  --red: #bf3c30;
  --gold: #d68b1f;
  --sky: #d8edf4;
  --charcoal: #2f3437;
  --shadow: 0 16px 45px rgba(35, 42, 45, 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,
select {
  font: inherit;
}

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

button:disabled {
  cursor: progress;
  opacity: 0.68;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 12px clamp(18px, 4vw, 56px);
  background: rgba(255, 253, 248, 0.92);
  border-bottom: 1px solid rgba(215, 221, 216, 0.82);
  backdrop-filter: blur(18px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--green);
  color: white;
  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;
}

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

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

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

.workspace {
  padding: clamp(26px, 4vw, 52px) clamp(18px, 4vw, 56px) clamp(44px, 7vw, 76px);
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.34fr);
  gap: 20px;
  align-items: end;
  margin-bottom: 16px;
}

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

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

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

h1 {
  margin: 0;
  color: var(--charcoal);
  font-size: clamp(3.2rem, 7vw, 6.4rem);
  line-height: 0.92;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.hero-subtitle {
  max-width: 680px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.8vw, 1.2rem);
}

.readout {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
}

.readout span,
.readout strong,
.readout small {
  display: block;
}

.readout span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.readout strong {
  margin-top: 6px;
  color: var(--green);
  font-size: 2rem;
  line-height: 1.05;
}

.readout small {
  margin-top: 6px;
  color: var(--charcoal);
}

.control-strip {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) minmax(150px, 0.8fr) minmax(130px, 0.7fr) minmax(130px, 0.7fr) auto auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.control-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

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

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

.primary-action:hover,
.primary-action:focus-visible {
  background: #125942;
  outline: none;
}

.icon-button {
  width: 44px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--charcoal);
}

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

.trainer-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.42fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.tone-grid {
  display: grid;
  gap: 10px;
}

.tone-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--charcoal);
  cursor: pointer;
  padding: 16px;
  text-align: left;
}

.tone-card:hover,
.tone-card:focus-visible,
.tone-card.is-active {
  border-color: var(--green);
  outline: none;
}

.tone-card.is-active {
  background: var(--green-soft);
}

.tone-name {
  display: block;
  color: var(--green);
  font-size: 1.25rem;
  font-weight: 900;
}

.tone-thai {
  display: block;
  margin-top: 2px;
  font-family: "Noto Sans Thai", Tahoma, sans-serif;
  font-size: 1.05rem;
  font-weight: 800;
}

.tone-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  background: #eef3f6;
  color: var(--charcoal);
  padding: 0 9px;
  font-size: 0.78rem;
  font-weight: 700;
}

.tone-play {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 900;
}

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

.graph-panel {
  overflow: hidden;
}

#curveSvg {
  display: block;
  width: 100%;
  min-height: 390px;
  background: linear-gradient(#ffffff, #fbfdfb);
}

.graph-grid {
  stroke: #dfe5e2;
  stroke-width: 1;
}

.graph-axis {
  stroke: #87918c;
  stroke-width: 1.4;
}

.graph-label {
  fill: var(--muted);
  font: 700 13px Inter, sans-serif;
}

.curve-muted {
  fill: none;
  stroke-width: 3;
  opacity: 0.22;
}

.curve-active {
  fill: none;
  stroke: var(--red);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 6;
}

.curve-marker {
  fill: var(--red);
  stroke: #fff;
  stroke-width: 4;
}

.graph-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.reference-panel {
  margin-top: 16px;
  padding: 22px;
  box-shadow: none;
}

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

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.level-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
}

.level-card strong,
.level-card span {
  display: block;
}

.level-card strong {
  color: var(--green);
  font-size: 1.6rem;
}

.level-card span {
  margin-top: 4px;
  color: var(--muted);
  font-weight: 800;
}

@media (max-width: 960px) {
  .topbar,
  .hero-panel {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    display: flex;
  }

  .control-strip,
  .trainer-grid {
    grid-template-columns: 1fr 1fr;
  }

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

  .level-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .topbar {
    gap: 10px;
    min-height: 112px;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .nav {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .workspace {
    padding-top: 24px;
  }

  h1 {
    font-size: clamp(3rem, 15vw, 4.2rem);
  }

  .control-strip,
  .level-grid {
    grid-template-columns: 1fr;
  }

  .primary-action,
  .icon-button {
    width: 100%;
  }

  .tone-card {
    grid-template-columns: 1fr;
  }

  .tone-play {
    justify-self: start;
  }

  #curveSvg {
    min-height: 320px;
  }

  .graph-footer {
    align-items: stretch;
    flex-direction: column;
  }
}
