:root {
  --bg: #f6f4ee;
  --card: #ffffff;
  --text: #24302c;
  --muted: #6b7671;
  --line: #e2ded3;
  --main: #1f6f5c;
  --main-soft: #e3f0eb;
  --a: #c2562b;       /* A子音 */
  --a-soft: #fbe9e1;
  --o: #2d5fa8;       /* O子音 */       /* オ系 */
  --o-soft: #e4ecf8;
  --ok: #2e8b57;
  --ng: #c0392b;
  --on-main: #ffffff;
  --khmer: "Noto Sans Khmer", "Noto Serif Khmer", "Khmer Sangam MN", "Khmer UI", "Khmer OS", "Leelawadee UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161b19; --card: #212826; --text: #e9eeec; --muted: #9aa5a0; --line: #34403c;
    --main: #5cc0a2; --main-soft: #1e3a32;
    --a: #f08a5d; --a-soft: #3d2a22; --o: #7fa8f0; --o-soft: #22304a;
    --ok: #5ccf8a; --ng: #ff7b6b; --on-main: #0f221c;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 17px; line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
.km { font-family: var(--khmer); }
.roman, .ipa, .hint, .cell small, .pair b, .pair small, .miss b, .feedback, .kana {
  font-family: "Charis SIL", "Doulos SIL", "Noto Sans", "Segoe UI", "Helvetica Neue", "Lucida Sans Unicode", "Noto Sans JP", sans-serif;
}
button { font: inherit; color: inherit; cursor: pointer; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: #1f6f5c; color: #fff;
}
.top h1 { font-size: 18px; margin: 0; font-weight: 700; }
.back { background: none; border: 0; color: #fff; font-size: 32px; line-height: 1; padding: 0 8px 4px 0; }

main { max-width: 560px; margin: 0 auto; padding: 16px 16px 40px; }

/* ホーム */
.menu { display: grid; gap: 12px; }
.menu button {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px;
}
.menu .icon {
  flex: none; width: 56px; height: 56px; border-radius: 12px;
  display: grid; place-items: center; font-size: 30px;
  background: var(--main-soft); color: var(--main);
}
.menu b { display: block; font-size: 18px; }
.menu small { color: var(--muted); font-size: 14px; }
.progress { margin: 4px 0 18px; color: var(--muted); font-size: 14px; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--main); }
.hint {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 15px; color: var(--muted); margin: 16px 0;
}
.hint b { color: var(--text); }

/* 系列のラベル */
.tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 99px; }
.tag.a { background: var(--a-soft); color: var(--a); }
.tag.o { background: var(--o-soft); color: var(--o); }

/* 一覧 */
.row-name { font-size: 14px; color: var(--muted); margin: 18px 0 6px; }
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.cell {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px 2px 4px; text-align: center; position: relative;
}
.cell .km { font-size: 34px; line-height: 1.5; display: block; }
.cell small { font-size: 13px; color: var(--muted); display: block; line-height: 1.3; }
.cell.a { border-bottom: 3px solid var(--a); }
.cell.o { border-bottom: 3px solid var(--o); }
.cell.known::after { content: "✓"; position: absolute; top: 2px; right: 6px; font-size: 12px; color: var(--ok); }
.vgrid { grid-template-columns: repeat(4, 1fr); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.btn {
  border: 0; border-radius: 12px; padding: 13px 10px; font-weight: 700;
  background: var(--main); color: var(--on-main);
}
.btn.sub { background: var(--main-soft); color: var(--main); }
.btn.wide { grid-column: 1 / -1; }

/* くわしいカード */
.detail { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 20px; text-align: center; }
.detail .big { font-size: 110px; line-height: 1.35; display: block; }
.detail .roman { font-size: 22px; font-weight: 700; }
.detail .kana { font-size: 18px; color: var(--muted); }
.detail .note { font-size: 14px; color: var(--muted); margin-top: 10px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.pair > div { border-radius: 12px; padding: 10px 6px; }
.pair .a { background: var(--a-soft); }
.pair .o { background: var(--o-soft); }
.pair .km { font-size: 48px; line-height: 1.5; display: block; }
.navrow { display: flex; justify-content: space-between; margin-top: 14px; }
.navrow button { background: none; border: 0; color: var(--main); font-weight: 700; padding: 8px; }

/* フラッシュカード */
.counter { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.flash {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  min-height: 300px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 20px; text-align: center; width: 100%;
}
.flash .big { font-size: 110px; line-height: 1.35; }
.flash .tap { color: var(--muted); font-size: 14px; }

/* クイズ */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; }
.seg button { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 4px; font-size: 14px; }
.seg button.on { background: var(--main); color: var(--on-main); border-color: var(--main); }
.label { font-size: 14px; color: var(--muted); margin: 6px 0; }
.q { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px; text-align: center; margin-bottom: 14px; }
.q .big { font-size: 96px; line-height: 1.35; display: block; }
.q .ask { font-size: 15px; color: var(--muted); }
.q .roman { font-size: 26px; font-weight: 700; display: block; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choices button {
  background: var(--card); border: 2px solid var(--line); border-radius: 14px;
  padding: 12px 6px; min-height: 64px; font-size: 17px;
}
.choices button .km { font-size: 44px; line-height: 1.3; }
.choices button.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--card)); }
.choices button.wrong { border-color: var(--ng); background: color-mix(in srgb, var(--ng) 14%, var(--card)); }
.choices.two { grid-template-columns: 1fr 1fr; }
.feedback { min-height: 28px; text-align: center; font-weight: 700; margin: 10px 0; }
.feedback.ok { color: var(--ok); }
.feedback.ng { color: var(--ng); }
.score { text-align: center; font-size: 44px; font-weight: 800; color: var(--main); margin: 10px 0 0; }
.miss { display: grid; gap: 8px; margin-top: 10px; }
.miss div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; display: flex; align-items: center; gap: 12px; }
.miss .km { font-size: 34px; line-height: 1.4; min-width: 52px; text-align: center; }

/* カタカナの読み */
.yomi { font-size: 18px; color: var(--text); letter-spacing: .02em; }
.asp { background: #ffd84d; color: #2a2200; border-radius: 999px; padding: 0 .15em; }
.kfin { font-size: .7em; }
.exlist .yomi { font-size: 16px; }
.exlist .kfin { font-size: .8em; }

.kanahelp { font-size: 13px; color: var(--main); margin-left: 6px; white-space: nowrap; }
.kanalist { display: grid; gap: 8px; }
.kanarow { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.kanarow .yomi { font-size: 22px; text-align: center; }
.kanarow small { color: var(--muted); font-size: 14px; line-height: 1.5; display: inline-block; }
.hint a { color: var(--main); font-weight: 700; }

/* その他の記号 */
.marklist { display: grid; gap: 8px; }
.markrow {
  display: flex; align-items: center; gap: 14px; text-align: left; position: relative;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px 14px;
}
.markrow > .km { font-size: 36px; line-height: 1.5; min-width: 56px; text-align: center; }
.markrow.known::after { content: "✓"; position: absolute; top: 4px; right: 10px; font-size: 13px; color: var(--ok); }
.desc { text-align: left; font-size: 16px; margin-top: 8px; }
.exlist { display: grid; gap: 6px; margin-top: 12px; text-align: left; }
.exlist div { display: grid; grid-template-columns: auto 1fr; column-gap: 12px; align-items: center; background: var(--main-soft); border-radius: 10px; padding: 4px 12px; }
.exlist .km { font-size: 30px; line-height: 1.5; grid-row: span 2; }
.exlist .ipa { font-size: 17px; }
.exlist div > span:last-child { font-size: 14px; color: var(--muted); }
.exlist .yomi { color: var(--text); }
.mlabel { font-size: 14px; line-height: 1.4; display: block; }

@media (max-width: 360px) {
  .grid { gap: 6px; }
  .cell .km { font-size: 28px; }
}
