/* Mirrors the app: iOS system colors, SF font, monochrome 語 icon, red pinyin accent */
:root {
  --bg: #ffffff;
  --bg-grouped: #f2f2f7; /* systemGroupedBackground */
  --fill: #f2f2f7; /* systemGray6 */
  --label: #000000;
  --secondary: rgba(60, 60, 67, 0.6); /* secondaryLabel */
  --separator: rgba(60, 60, 67, 0.29);
  --accent: #ff3b30; /* systemRed, used for pinyin */
  --link: #007aff; /* systemBlue */
  --class-low: #248a3d; /* systemGreen, darkened for text */
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-grouped: #000000;
    --fill: #1c1c1e;
    --label: #ffffff;
    --secondary: rgba(235, 235, 245, 0.6);
    --separator: rgba(84, 84, 88, 0.6);
    --accent: #ff453a;
    --link: #0a84ff;
    --class-low: #30d158;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--label);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Navigation bar, like the app's inline-title toolbar */
.navbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}

.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--label);
  font-weight: 600;
}

.brand:hover {
  text-decoration: none;
}

.brand img {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}

.navlinks {
  display: flex;
  gap: 20px;
  font-size: 15px;
}

@media (max-width: 480px) {
  .navlinks {
    gap: 12px;
  }
}

/* Icon that swaps with the color scheme, like the app's light/dark AppIcon */
.app-icon {
  display: block;
  border-radius: 22.37%;
}

.app-icon.light-only {
  box-shadow: 0 0 0 0.5px var(--separator), 0 8px 24px rgba(0, 0, 0, 0.08);
}

.dark-only {
  display: none;
}

@media (prefers-color-scheme: dark) {
  .light-only {
    display: none;
  }
  .dark-only {
    display: block;
  }
}

/* Home */
.hero {
  text-align: center;
  padding: 64px 0 40px;
}

.hero .app-icon {
  width: 128px;
  height: 128px;
  margin: 0 auto 24px;
}

.hero h1 {
  font-size: 40px;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}

.pinyin {
  color: var(--accent);
  font-weight: 600;
  font-size: 17px;
  margin: 0 0 12px;
}

.tagline {
  color: var(--secondary);
  font-size: 20px;
  margin: 0;
}

.app-store-badge {
  display: inline-block;
  margin-top: 28px;
}

.app-store-badge img {
  height: 44px;
  width: auto;
}

.screenshot {
  display: block;
  width: 100%;
  max-width: 320px;
  height: auto;
  margin: 0 auto 48px;
  border-radius: 24px;
  border: 0.5px solid var(--separator);
}

/* Grouped list, like the app's dictionary rows and About sheet */
.list {
  background: var(--fill);
  border-radius: 12px;
  overflow: hidden;
  margin: 0 0 64px;
  padding: 0;
  list-style: none;
}

.row {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 14px 16px;
}

.row + .row {
  border-top: 0.5px solid var(--separator);
}

.row .hanzi {
  flex: 0 0 56px;
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
}

.row h2,
.row h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 2px;
}

.row h2 .py,
.row h3 .py {
  color: var(--accent);
  font-weight: 600;
  margin-right: 8px;
}

.row p {
  color: var(--secondary);
  font-size: 15px;
  margin: 0;
}

.row .hanzi.thai {
  flex-basis: 64px;
  font-size: 28px;
  font-weight: 600;
  line-height: 1.3;
}

.language-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin: 0 0 56px;
}

.language-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 20px;
  background: var(--fill);
  border-radius: 12px;
  color: var(--label);
  text-align: center;
  text-decoration: none;
}

.language-card:hover {
  text-decoration: none;
}

.language-glyph {
  font-size: 40px;
  font-weight: 700;
  line-height: 1.3;
}

.language-name {
  font-size: 19px;
  font-weight: 600;
}

.language-blurb {
  color: var(--secondary);
  font-size: 15px;
}

.home-language {
  scroll-margin-top: 64px;
}

.home-language h2 {
  font-size: 28px;
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin: 0 0 8px;
}

.home-language .list {
  margin-bottom: 40px;
}

.home-intro {
  color: var(--secondary);
  font-size: 17px;
  margin: 0 0 16px;
}

.home-subheading {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 8px;
}

.home-links {
  margin: 0 0 56px;
  padding: 0 0 0 20px;
}

/* Legal pages */
.legal {
  padding: 40px 0 64px;
}

.legal h1 {
  font-size: 34px;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 4px;
}

.legal .updated {
  color: var(--secondary);
  font-size: 15px;
  margin: 0 0 32px;
}

.legal h2 {
  font-size: 20px;
  margin: 36px 0 8px;
}

.legal p,
.legal li {
  font-size: 16px;
}

.legal ul {
  padding-left: 22px;
}

.legal .summary {
  background: var(--fill);
  border-radius: 12px;
  padding: 4px 20px;
}

.legal address {
  font-style: normal;
}

.caps {
  text-transform: uppercase;
  font-size: 14px !important;
}

/* Footer */
.footer {
  border-top: 0.5px solid var(--separator);
  color: var(--secondary);
  font-size: 13px;
  padding: 24px 0 40px;
}

.footer .container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  justify-content: space-between;
}

.footer nav {
  display: flex;
  gap: 16px;
}

.footer a {
  color: var(--secondary);
}

/* IPA guide */
.ipa-glyph {
  font-family: "Charis SIL", "Doulos SIL", "Gentium Plus", "Noto Sans", -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Lucida Grande", "Arial Unicode MS", sans-serif;
}

.ipa-intro {
  text-align: center;
  padding: 48px 0 32px;
}

.ipa-intro h1 {
  font-size: 40px;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}

.ipa-intro .pinyin {
  font-family: "Charis SIL", "Doulos SIL", "Noto Sans", -apple-system, sans-serif;
}

.ipa-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 0 0 40px;
}

.ipa-toc a {
  background: var(--fill);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
}

.ipa section[id] {
  scroll-margin-top: 72px;
}

.ipa-article h2,
.ipa-section-title {
  font-size: 26px;
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin: 48px 0 12px;
}

.ipa-article h3 {
  font-size: 18px;
  margin: 28px 0 10px;
}

.ipa-article p,
.ipa-article li,
.ipa-lead {
  font-size: 17px;
}

.ipa-article ol,
.ipa-article ul:not(.list) {
  padding-left: 22px;
}

.ipa-article li + li {
  margin-top: 10px;
}

.ipa-inline {
  display: inline-block;
  min-width: 1.2em;
  text-align: center;
  font-size: 20px;
  color: var(--accent);
}

.ipa-vowel-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  margin-bottom: 0;
}

.ipa-vowel-list li {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 16px;
  margin: 0 !important;
  font-size: 15px;
  color: var(--secondary);
  border-bottom: 0.5px solid var(--separator);
}

.ipa-vowel-list .ipa-glyph {
  flex: 0 0 44px;
  font-size: 22px;
  color: var(--label);
}

.ipa-words {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.ipa-word {
  margin: 0;
  background: var(--fill);
  border-radius: 12px;
  padding: 16px;
}

.ipa-word figcaption {
  font-size: 20px;
  margin-bottom: 12px;
}

.ipa-segments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ipa-segment {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 72px;
  padding: 8px 6px;
  background: var(--bg);
  border-radius: 10px;
  text-align: center;
}

.ipa-segment .ipa-glyph {
  font-size: 28px;
  line-height: 1.2;
}

.ipa-segment small {
  font-size: 11px;
  line-height: 1.3;
  color: var(--secondary);
}

.ipa-segment .ipa-letters {
  color: var(--accent);
}

.ipa-word p {
  margin: 12px 0 0;
  font-size: 15px !important;
  color: var(--secondary);
}

.ipa-traps .row {
  align-items: center;
  margin: 0 !important;
}

.ipa-traps .ipa-glyph {
  flex: 0 0 36px;
  font-size: 28px;
  text-align: center;
}

.ipa-traps p {
  margin: 0;
  font-size: 15px !important;
}

.ipa-practice {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.ipa-card {
  background: var(--fill);
  border-radius: 12px;
  padding: 12px 16px;
}

.ipa-card summary {
  cursor: pointer;
  font-weight: 600;
}

.ipa-card p {
  margin: 6px 0 0;
  font-size: 14px !important;
  color: var(--secondary);
}

.ipa-card .ipa-answer {
  font-size: 22px !important;
  color: var(--accent);
}

.ipa-detail {
  position: sticky;
  top: 60px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  background: color-mix(in srgb, var(--fill) 92%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 8px;
}

.ipa-detail-symbol {
  flex: 0 0 56px;
  font-size: 44px;
  line-height: 1;
  text-align: center;
}

.ipa-detail h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 2px;
}

.ipa-detail h2::first-letter {
  text-transform: uppercase;
}

.ipa-detail p {
  color: var(--secondary);
  font-size: 15px;
  margin: 0;
}

.ipa-example {
  color: var(--accent);
}

.ipa-heading {
  font-size: 22px;
  letter-spacing: -0.01em;
  margin: 32px 0 12px;
}

.ipa-scroll {
  overflow-x: auto;
  margin: 0 -16px;
  padding: 0 16px;
}

.ipa-table {
  border-collapse: collapse;
  font-size: 12px;
}

.ipa-table th {
  color: var(--secondary);
  font-weight: 500;
  padding: 4px;
}

.ipa-table thead th {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  text-align: left;
  height: 92px;
}

.ipa-table tbody th {
  text-align: right;
  white-space: nowrap;
  padding-right: 8px;
}

.ipa-table td {
  border: 0.5px solid var(--separator);
  min-width: 64px;
  height: 44px;
  padding: 2px;
  text-align: center;
  white-space: nowrap;
}

.ipa-sym {
  min-width: 28px;
  height: 36px;
  padding: 0 6px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--label);
  font: 22px/1 "Charis SIL", "Doulos SIL", "Noto Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
}

.ipa-sym:hover {
  background: var(--fill);
}

.ipa-sym.selected {
  background: var(--accent);
  color: #fff;
}

.ipa-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ipa-grid .ipa-sym {
  min-width: 52px;
  height: 52px;
  background: var(--fill);
}

.ipa-grid .ipa-sym.selected {
  background: var(--accent);
}

.ipa-vowels svg {
  display: block;
  width: 100%;
  max-width: 480px;
  height: auto;
}

.ipa-trapezoid {
  fill: var(--fill);
  stroke: var(--separator);
}

.ipa-vowel {
  cursor: pointer;
  outline: none;
}

.ipa-vowel circle {
  fill: transparent;
}

.ipa-vowel:hover circle,
.ipa-vowel:focus-visible circle {
  fill: var(--separator);
}

.ipa-vowel text {
  fill: var(--label);
  font-size: 18px;
}

.ipa-vowel.selected circle {
  fill: var(--accent);
}

.ipa-vowel.selected text {
  fill: #fff;
}

.ipa-axis {
  display: flex;
  justify-content: space-between;
  max-width: 480px;
  padding: 0 4% 0 30%;
  color: var(--secondary);
  font-size: 12px;
}

.ipa-prompt {
  font-size: 19px;
  margin: 0 0 16px;
}

.ipa-quiz-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  color: var(--secondary);
  font-size: 15px;
}

.ipa-primary {
  border: none;
  border-radius: 12px;
  background: var(--link);
  color: #fff;
  font: inherit;
  font-weight: 600;
  padding: 10px 22px;
  cursor: pointer;
}

.ipa-footnote {
  color: var(--secondary);
  font-size: 15px;
  margin: 0 0 64px;
}

/* Lessons */
.thai {
  font-family: "Thonburi", "Noto Sans Thai", "Leelawadee UI", -apple-system, BlinkMacSystemFont, sans-serif;
}

.lesson {
  padding-bottom: 64px;
}

.lesson .hero {
  padding-bottom: 16px;
}

/* One scrolling row that sticks under the navbar, so it never takes up much of a phone screen */
.lesson-toc {
  position: sticky;
  top: 52px;
  z-index: 5;
  flex-wrap: nowrap;
  justify-content: flex-start;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -16px;
  padding: 8px 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.lesson-toc::-webkit-scrollbar {
  display: none;
}

.lesson-toc a {
  flex: none;
}

/* Wide screens have no swipe to reach a clipped link, so everything has to fit */
@media (min-width: 720px) {
  .lesson-toc {
    flex-wrap: wrap;
    gap: 6px;
  }
  .lesson-toc a {
    padding: 6px 10px;
  }
}

.lesson section[id] {
  scroll-margin-top: 112px;
}

.lesson-phrase {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.3;
  margin: 0 0 4px;
}

.lesson-ipa {
  color: var(--secondary);
  margin: 0 0 12px;
}

.lesson h2 {
  font-size: 26px;
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin: 48px 0 12px;
}

.lesson-note {
  background: var(--fill);
  border-radius: 12px;
  padding: 4px 20px;
}

.lesson-words {
  margin: 16px 0;
}

.lesson-words .thai {
  flex: 0 0 136px;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.3;
}

.lesson-sound {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  color: var(--secondary) !important;
}

.lesson-sound .py {
  color: var(--accent);
  font-weight: 600;
}

.lesson-words p:not(.lesson-sound) {
  color: var(--label);
  font-size: 16px;
}

.lesson-aside {
  color: var(--secondary);
  font-size: 15px;
}

/* Word pages: spelling breakdown, tone working */
.spelling-list .thai {
  flex: 0 0 56px;
  font-size: 28px;
  text-align: center;
}

.lesson-words p.spelling-letter {
  color: var(--secondary);
  font-size: 14px;
  margin-top: 2px;
}

.spelling-letter .thai,
.tone-list .thai {
  flex: none;
  font-size: inherit;
  font-weight: 600;
}

.class-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 0 8px;
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 14%, transparent);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.class-mid {
  color: var(--link);
}

.class-high {
  color: var(--accent);
}

.class-low {
  color: var(--class-low);
}

.tone-steps {
  margin: 16px 0;
  padding-left: 22px;
}

.tone-steps li + li {
  margin-top: 6px;
}

/* Tone rules page */
.tone-list .row {
  align-items: center;
}

.tone-contour {
  flex: 0 0 44px;
  width: 44px;
  height: 32px;
  overflow: visible;
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
}

.rule-table .row b {
  flex: 0 0 168px;
  font-weight: 600;
}

.rule-table .row span {
  color: var(--secondary);
}

.rule-example {
  margin: 16px 0;
}

.rule-example .lesson-phrase {
  color: var(--accent);
}

/* IPA spelling quiz */
.ipa-spell-word {
  font-size: 24px;
}

.ipa-spell-answer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 64px;
  padding: 10px 14px;
  margin-bottom: 16px;
  border-radius: 12px;
  border: 1px dashed var(--separator);
}

.ipa-slash {
  color: var(--secondary);
  font-size: 28px;
}

.ipa-spell-placeholder {
  color: var(--secondary);
  font-size: 15px;
}

.ipa-spell-slot {
  min-width: 40px;
  height: 44px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--fill);
  font-size: 26px;
}

.ipa-spell-slot.correct {
  background: #34c759;
  color: #fff;
}

.ipa-spell-slot.wrong {
  background: var(--accent);
  color: #fff;
}

.ipa-spell-slot.missing {
  border: 1px dashed var(--accent);
  background: transparent;
  color: var(--accent);
}

.ipa-spell-tiles .ipa-sym {
  min-width: 56px;
}

.ipa-link {
  border: none;
  background: none;
  color: var(--link);
  font: inherit;
  font-size: 15px;
  padding: 0;
  margin-left: 16px;
  cursor: pointer;
}

.ipa-link:first-child {
  margin-left: 0;
}

.ipa-link:disabled,
.ipa-primary:disabled {
  opacity: 0.4;
  cursor: default;
}

.ipa-spell-verdict {
  font-weight: 600;
}

.ipa-spell-verdict.correct {
  color: #34c759;
}

.ipa-spell-verdict .ipa-glyph {
  color: var(--accent);
}

.ipa-explanations {
  margin: 0;
}

.ipa-explanations .row {
  margin: 0 !important;
}

.ipa-explain-symbol {
  flex: 0 0 44px;
  font-size: 30px;
  text-align: center;
  color: var(--accent);
}

.ipa-explanations h3 {
  font-size: 16px;
  margin: 0 0 2px;
}

.ipa-explanations p {
  margin: 0;
  font-size: 15px !important;
  color: var(--secondary);
}
