@font-face { font-family: "Pacifico"; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/pacifico-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Cormorant Garamond"; font-style: italic; font-weight: 400; font-display: swap; src: url(fonts/cormorant-garamond-latin-400-italic.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Cormorant Garamond"; font-style: italic; font-weight: 400; font-display: swap; src: url(fonts/cormorant-garamond-latin-ext-400-italic.woff2) format("woff2"); unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Cormorant Garamond"; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/cormorant-garamond-latin-500-normal.woff2) format("woff2"); }
@font-face { font-family: "Jost"; font-style: normal; font-weight: 300; font-display: swap; src: url(fonts/jost-latin-300-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Jost"; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/jost-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Jost"; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/jost-latin-500-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
/* latin-ext carries the rising-tone letters ǎ ě ǐ ǒ ǔ */
@font-face { font-family: "Jost"; font-style: normal; font-weight: 300; font-display: swap; src: url(fonts/jost-latin-ext-300-normal.woff2) format("woff2"); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Jost"; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/jost-latin-ext-400-normal.woff2) format("woff2"); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Jost"; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/jost-latin-ext-500-normal.woff2) format("woff2"); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Noto Sans Thai"; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/noto-sans-thai-thai-400-normal.woff2) format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Noto Sans Thai"; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/noto-sans-thai-thai-500-normal.woff2) format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }

:root {
  /* Thai flag palette (red, white, navy) with Vayuputra gold */
  --bg: #1d1c44;
  --flag-red: #a51931;
  --flag-white: #f4f5f8;
  --flag-blue: #2d2a4a;
  --ink-d: #f4f5fb;
  --muted-d: #b3b6d6;
  --line-d: rgba(255, 255, 255, .14);
  --chip-d: rgba(255, 255, 255, .08);
  --yellow: #f5b82e;
  --purple: #9d6bf2;
  --violet: #c6a6ff;

  --panel: #fffaf0;
  --ink: #24143a;
  --muted: #7a6a8c;
  --border: #ece2d0;

  --accent: var(--yellow);
  --accent-bg: var(--yellow);
  --accent-on: #24103a;
  --accent-card: #9a6400;

  --easy: #2f8a55;
  --easy-soft: #e3f3e8;
  --medium: #c07d0c;
  --medium-soft: #fcefd2;
  --hard: #c0392b;
  --hard-soft: #fbe3df;
  --radius: 18px;

  /* tones */
  --t-mid: #6f6a78;
  --t-low: #2f6fd0;
  --t-falling: #c0392b;
  --t-high: #c07d0c;
  --t-rising: #2f8a55;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif;
  background:
    radial-gradient(900px 520px at 10% -12%, rgba(165, 25, 49, .42), transparent 62%),
    radial-gradient(700px 440px at 94% 2%, rgba(244, 245, 248, .10), transparent 60%),
    radial-gradient(900px 600px at 50% 110%, rgba(60, 64, 140, .45), transparent 65%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink-d);
  line-height: 1.45;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; width: 100%; max-width: 640px; margin: 0 auto; padding: 0 18px; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }
/* thin flag stripe along the top: red, white, blue, white, red */
body::before {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 5px;
  z-index: 10;
  background: linear-gradient(180deg, var(--flag-red) 0 16.66%, var(--flag-white) 16.66% 33.33%, #3a3f8f 33.33% 66.66%, var(--flag-white) 66.66% 83.33%, var(--flag-red) 83.33%);
  opacity: .85;
}
.th { font-family: "Noto Sans Thai", "Jost", sans-serif; }

/* header */
.top {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 18px 18px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--yellow);
  font-family: "Pacifico", "Brush Script MT", cursive;
  font-size: 1.75rem;
  line-height: 1;
}
.brand span { padding-bottom: 4px; }
.brand svg { display: block; transition: transform .2s; }
.brand:hover svg { transform: rotate(-6deg) scale(1.05); }
.top-nav { display: flex; background: var(--chip-d); border: 1px solid var(--line-d); border-radius: 999px; padding: 3px; }
.top-nav a {
  padding: 6px 14px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted-d);
  font-size: .9rem;
  font-weight: 600;
}
.top-nav a.on { background: var(--accent-bg); color: var(--accent-on); }

/* landing */
.home { text-align: center; padding: 36px 0 20px; }
.home h1 { margin: 0; font-family: "Jost", "Segoe UI", sans-serif; font-weight: 300; font-size: clamp(2.2rem, 7vw, 3.2rem); line-height: 1.12; }
.tagline {
  margin: 6px 0 14px;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-style: italic;
  font-weight: 400;
  font-size: clamp(1.45rem, 4.6vw, 1.9rem);
  color: var(--yellow);
}
.lede { margin: 0 auto 24px; color: var(--muted-d); max-width: 30em; }
.start {
  display: inline-block;
  background: var(--accent-bg);
  color: var(--accent-on);
  text-decoration: none;
  font-weight: 700;
  padding: 12px 30px;
  border-radius: 999px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .3);
  transition: transform .15s;
}
.start:hover, .start:focus-visible { transform: translateY(-2px); }

.guide {
  text-align: left;
  margin: 34px 0 0;
  background: var(--chip-d);
  border: 1px solid var(--line-d);
  border-radius: var(--radius);
  padding: 8px 20px 18px;
}
.guide h3 { font-family: "Jost", "Segoe UI", sans-serif; font-weight: 500; font-size: 1.05rem; color: var(--yellow); margin: 18px 0 6px; }
.guide p { margin: 0 0 10px; color: var(--muted-d); font-size: .92rem; }
.tone-list, .sound-list { list-style: none; margin: 0; padding: 0; }
.tone-list li {
  display: grid;
  grid-template-columns: 78px 56px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid var(--line-d);
  font-size: .92rem;
}
.tone-list li:first-child { border-top: 0; }
.tone-list b { font-family: "Jost", sans-serif; font-weight: 500; font-size: 1.1rem; }
.tone-list span:not(.tone) { color: var(--muted-d); }
.tone-list em { font-style: normal; color: var(--muted-d); font-size: .85rem; white-space: nowrap; }
.tone-list .tone { justify-self: start; }
.sound-list li { color: var(--muted-d); font-size: .9rem; padding: 5px 0 5px 14px; position: relative; }
.sound-list li::before { content: ""; position: absolute; left: 0; top: 13px; width: 5px; height: 5px; border-radius: 50%; background: var(--flag-red); }
.sound-list b { color: var(--ink-d); font-weight: 600; }

/* tone chip, shared by the guide and the cards */
.tone { --tc: var(--t-mid); display: inline-flex; flex-direction: column; align-items: center; border-radius: 10px; padding: 3px 9px; font-size: .78rem; font-weight: 600; color: #fff; background: var(--tc); letter-spacing: .02em; }
.tone.L { --tc: var(--t-low); }
.tone.F { --tc: var(--t-falling); }
.tone.H { --tc: var(--t-high); }
.tone.R { --tc: var(--t-rising); }

/* level filter */
.levels { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; padding: 14px 0 16px; }
.levels button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line-d);
  background: var(--chip-d);
  color: var(--ink-d);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: .9rem;
}
.levels button i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.levels .lv-e i { background: var(--easy); }
.levels .lv-m i { background: var(--medium); }
.levels .lv-h i { background: var(--hard); }
.levels .lv-f i { background: #e0559a; }
.levels .n { color: var(--muted-d); font-size: .8rem; }
.levels button.on { background: var(--ink-d); border-color: var(--ink-d); color: var(--ink); }
.levels button.on .n { color: var(--muted); }
.levels button.lv-e.on .n, .levels button.lv-m.on .n, .levels button.lv-h.on .n, .levels button.lv-f.on .n { color: rgba(255, 255, 255, .75); }
.levels button.lv-e.on { background: var(--easy); border-color: var(--easy); color: #fff; }
.levels button.lv-m.on { background: var(--medium); border-color: var(--medium); color: #fff; }
.levels button.lv-h.on { background: var(--hard); border-color: var(--hard); color: #fff; }
.levels button.lv-f.on { background: #e0559a; border-color: #e0559a; color: #fff; }

/* card */
.stage { perspective: 1400px; }
.card {
  --lv: var(--easy);
  --lv-soft: var(--easy-soft);
  position: relative;
  height: min(62vh, 410px);
  min-height: 330px;
  cursor: pointer;
  outline: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.card.lv-m { --lv: var(--medium); --lv-soft: var(--medium-soft); }
.card.lv-h { --lv: var(--hard); --lv-soft: var(--hard-soft); }
.card-inner { position: absolute; inset: 0; transition: transform .45s cubic-bezier(.3, .7, .3, 1); transform-style: preserve-3d; }
.card.flipped .card-inner { transform: rotateY(180deg); }
.card.instant .card-inner { transition: none; }
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  background: var(--panel);
  border: 2px solid var(--lv);
  color: var(--ink);
  font-family: "Jost", "Segoe UI", "Noto Sans Thai", sans-serif;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .35), inset 0 6px 0 var(--lv);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 34px 22px 24px;
  overflow: auto;
}
.card:focus-visible .face { box-shadow: 0 0 0 4px var(--lv-soft), inset 0 6px 0 var(--lv); }
.front { background: linear-gradient(180deg, var(--lv-soft), var(--panel) 55%); }
.back { transform: rotateY(180deg); justify-content: flex-start; padding-top: 48px; }
.pill {
  position: absolute;
  top: 16px;
  left: 16px;
  font-size: .72rem;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--lv);
  background: var(--lv-soft);
  border-radius: 999px;
  padding: 3px 10px;
}
.word { font-size: clamp(2.4rem, 10vw, 3.8rem); font-weight: 400; line-height: 1.5; overflow-wrap: anywhere; }
.say { margin-top: 8px; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px; }
.pron { color: var(--accent-card); font-size: 1.2rem; font-weight: 400; letter-spacing: .04em; }
.speak {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.speak.playing { border-color: var(--accent-card); box-shadow: 0 0 0 3px var(--medium-soft); }
.back .mini { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px 8px; }
.back .speak { width: 32px; height: 32px; font-size: .85rem; }
.hint { position: absolute; bottom: 16px; font-size: .8rem; color: var(--muted); }

.mini { color: var(--muted); font-size: 1.05rem; }
.mini .w { font-weight: 500; color: var(--ink); }
.mini .pron { font-size: .9rem; }
.meaning { font-size: clamp(1.7rem, 6.5vw, 2.4rem); font-weight: 300; margin: 8px 0 16px; line-height: 1.15; }
.tones { width: 100%; border-top: 1px solid var(--border); padding-top: 14px; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.tones .tone b { font-weight: 500; font-size: .95rem; letter-spacing: .02em; }
.tones .tone small { font-size: .66rem; font-weight: 500; text-transform: uppercase; letter-spacing: .08em; opacity: .85; }
.note:empty { display: none; }
.note {
  margin: 14px 0 0;
  font-size: .9rem;
  background: var(--medium-soft);
  color: #6e4500;
  border-radius: 10px;
  padding: 8px 12px;
  max-width: 28em;
}

/* progress and controls */
.progress { display: flex; align-items: center; gap: 12px; margin: 16px 2px 0; }
.bar { flex: 1; height: 4px; background: var(--line-d); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.counter { font-size: .85rem; color: var(--muted-d); font-variant-numeric: tabular-nums; white-space: nowrap; }
.controls { display: flex; justify-content: center; gap: 10px; margin-top: 14px; }
.nav-btn, .flip-btn {
  border-radius: 12px;
  padding: 9px 18px;
  font-size: .9rem;
  font-weight: 600;
  border: 1px solid var(--line-d);
  background: var(--chip-d);
  color: var(--ink-d);
}
@media (hover: hover) { .nav-btn:hover { border-color: var(--accent); color: var(--accent); } .speak:hover { border-color: var(--accent); } }
.flip-btn { background: var(--accent-bg); border-color: var(--accent-bg); color: var(--accent-on); padding: 9px 26px; }
.flip-btn:hover { filter: brightness(1.08); }
.tools { display: flex; align-items: center; justify-content: space-between; margin: 12px 2px 0; gap: 10px; }
.tool { border: 1px solid var(--line-d); background: transparent; color: var(--muted-d); border-radius: 999px; padding: 5px 13px; font-size: .85rem; }
.tool[aria-pressed="true"] { background: var(--accent-bg); border-color: var(--accent-bg); color: var(--accent-on); }
.keys { font-size: .78rem; color: var(--muted-d); }
@media (hover: none) { .keys { display: none; } }

.credits { text-align: center; color: var(--muted-d); font-size: .8rem; padding: 34px 20px 70px; max-width: 640px; margin: 0 auto; }

@media (max-width: 420px) {
  .nav-btn { font-size: .86rem; padding: 9px 14px; }
  .levels { gap: 4px; flex-wrap: nowrap; }
  .levels button { padding: 5px 8px; font-size: .8rem; gap: 4px; }
  .levels button i { width: 7px; height: 7px; }
  .levels .n { display: none; }
  .tone-list li { grid-template-columns: 70px 48px 1fr; }
  .tone-list em { grid-column: 2 / -1; }
  .top-nav a { padding: 6px 10px; font-size: .82rem; }
}
@media (prefers-reduced-motion: reduce) {
  .card-inner, .start, .bar span { transition: none; }
}
