/* ---------- Палитры. data-palette: flagyellow | flag | yellow. data-theme: light | dark (ставится скриптом) ---------- */
:root {
  --radius: 16px;
  --thai: "Noto Sans Thai", "Leelawadee UI", "Thonburi", "Tahoma", system-ui, sans-serif;
  --ui: "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --green: #2f8f5b; --red: #a51931; --orange: #d08a1f; --blue: #2f6fb3; --purple: #7b5fb8; --pink: #c0568f;
  /* цвета дней недели для колод */
  --day-mon: #f5c518; --day-tue: #e58ab4; --day-wed: #3fa56b; --day-fri: #5ba8d6; --day-sat: #8e6bc1;
}
/* 3. Флаг + жёлтый (по умолчанию) */
:root, :root[data-palette="flagyellow"] {
  color-scheme: light;
  --bg: #f7f7f9; --card: #ffffff; --text: #1e1d33; --muted: #6b6a80; --line: #e3e3ec;
  --primary-bg: #2d2a4a; --primary-text: #ffffff;
  --accent: #8a6d00; --accent-surface: #f5c518; --accent-on: #1e1d33; --accent-soft: #fff3c4;
  --link: #2d2a4a;
  --shadow: 0 1px 2px rgba(20,20,60,.06), 0 8px 24px rgba(20,20,60,.06);
}
:root[data-theme="dark"], :root[data-theme="dark"][data-palette="flagyellow"] {
  color-scheme: dark;
  --bg: #16152a; --card: #222040; --text: #f2f1f7; --muted: #a3a1be; --line: #33314f;
  --primary-bg: #f5c518; --primary-text: #1e1d33;
  --accent: #f5c518; --accent-surface: #f5c518; --accent-on: #1e1d33; --accent-soft: #3a3520;
  --link: #f5c518;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3);
}
/* 1. Флаг */
:root[data-palette="flag"] {
  --bg: #f8f7f5; --card: #ffffff; --text: #1f1e33; --muted: #6c6b7c; --line: #e5e3e0;
  --primary-bg: #2d2a4a; --primary-text: #ffffff;
  --accent: #a51931; --accent-surface: #a51931; --accent-on: #ffffff; --accent-soft: #f6dfe3;
  --link: #a51931;
}
:root[data-theme="dark"][data-palette="flag"] {
  --bg: #1b1a2e; --card: #26253f; --text: #f1f0f6; --muted: #a2a0b8; --line: #38364f;
  --primary-bg: #c8324a; --primary-text: #ffffff;
  --accent: #f07085; --accent-surface: #c8324a; --accent-on: #ffffff; --accent-soft: #452031;
  --link: #f07085;
}
/* 2. Королевский жёлтый */
:root[data-palette="yellow"] {
  --bg: #fffbef; --card: #ffffff; --text: #3a2e1f; --muted: #7a6b57; --line: #ede3cc;
  --primary-bg: #f2c230; --primary-text: #3a2e1f;
  --accent: #9c6b00; --accent-surface: #f2c230; --accent-on: #3a2e1f; --accent-soft: #fbebb5;
  --link: #9c6b00;
  --shadow: 0 1px 2px rgba(80,60,0,.06), 0 8px 24px rgba(80,60,0,.07);
}
:root[data-theme="dark"][data-palette="yellow"] {
  --bg: #1e1a14; --card: #2a2419; --text: #f5eedd; --muted: #b3a688; --line: #3e362a;
  --primary-bg: #f2c230; --primary-text: #2a2419;
  --accent: #f2c230; --accent-surface: #f2c230; --accent-on: #2a2419; --accent-soft: #3f3518;
  --link: #f2c230;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--ui); font-size: 16px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
a { color: var(--link); text-decoration: none; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 12px; padding: 10px 16px; background: var(--card); color: var(--text); box-shadow: var(--shadow); }
button:active { transform: translateY(1px); }
button.primary { background: var(--primary-bg); color: var(--primary-text); }
button.ghost { background: transparent; box-shadow: none; color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select { font: inherit; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); }
textarea { min-height: 90px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.thai { font-family: var(--thai); }
.hidden { display: none !important; }

header.top { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
header.top .bar { max-width: 760px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
header.top .brand { font-weight: 700; font-size: 18px; }
header.top .brand span { color: var(--accent); }
header.top .theme-btn { box-shadow: none; background: transparent; padding: 6px 8px; font-size: 18px; line-height: 1; }
header.top nav { margin-left: auto; display: flex; gap: 4px; }
header.top nav a { padding: 6px 10px; border-radius: 10px; color: var(--muted); font-size: 14px; }
header.top nav a.active { background: var(--accent-soft); color: var(--accent); }
header.top .userbox { font-size: 13px; white-space: nowrap; }
header.top .userbox a { margin-left: 4px; }
.login { display: flex; justify-content: center; padding-top: 24px; }
.login .card { max-width: 440px; width: 100%; }
@media (max-width: 480px) { header.top .userbox span { display: none; } }

main { max-width: 760px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 8px 0 16px; }
h2 { font-size: 17px; margin: 20px 0 10px; }
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

.decks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.deck { background: var(--card); border-radius: var(--radius); padding: 16px 16px 16px 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; border-left: 6px solid var(--deck-color, var(--line)); }
.deck[data-deck="consonants"] { --deck-color: var(--day-mon); } .deck[data-deck="vowels"] { --deck-color: var(--day-tue); } .deck[data-deck="tones"] { --deck-color: var(--day-wed); } .deck[data-deck="vocab"] { --deck-color: var(--day-fri); } .deck[data-deck="user"] { --deck-color: var(--day-sat); }
.deck .title { font-weight: 700; font-size: 17px; }
.deck .stats { display: flex; gap: 10px; font-size: 13px; color: var(--muted); }
.deck .stats b { color: var(--text); }
.deck .stats .due b { color: var(--accent); }
.deck .actions { display: flex; gap: 6px; margin-top: auto; }
.deck .actions button { padding: 8px 12px; font-size: 14px; flex: 1; }
.banner { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.banner .big { font-size: 28px; font-weight: 700; color: var(--accent); }

.card-wrap { perspective: 1200px; margin: 12px 0; }
.card { background: var(--card); border-radius: 20px; box-shadow: var(--shadow); min-height: 300px; padding: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; cursor: pointer; user-select: none; position: relative; }
.card .thai-big { font-family: var(--thai); font-size: 96px; line-height: 1.15; }
.card .thai-mid { font-family: var(--thai); font-size: 44px; line-height: 1.2; }
.card .translit { font-size: 24px; color: var(--accent); margin-top: 4px; }
.card .meaning { font-size: 22px; margin-top: 6px; }
.card .meaning-en { color: var(--muted); font-size: 16px; }
.card .sub { color: var(--muted); font-size: 14px; margin-top: 8px; white-space: pre-line; }
.card .example { margin-top: 12px; font-size: 15px; white-space: pre-line; background: var(--bg); border-radius: 10px; padding: 8px 12px; }
.card img { max-height: 160px; max-width: 70%; border-radius: 12px; margin: 8px 0; mix-blend-mode: multiply; }
:root[data-theme="dark"] .card img { mix-blend-mode: normal; background: #f3f1ea; padding: 6px; }
.card .hint { position: absolute; bottom: 10px; left: 0; right: 0; font-size: 12px; color: var(--muted); }
.card .tags { margin-top: 8px; }
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin: 2px; }
.chip.cls-mid { background: #e0ecf9; color: var(--blue); }
.chip.cls-high { background: #ece5f7; color: var(--purple); }
.chip.cls-low { background: #f9e2ee; color: var(--pink); }
.chip.short { background: #f9e2ee; color: var(--pink); }
.chip.long { background: #ece5f7; color: var(--purple); }

.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.rate button { padding: 14px 6px; font-weight: 600; color: #fff; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rate button small { font-weight: 400; opacity: .85; font-size: 12px; }
.rate .r1 { background: var(--red); } .rate .r2 { background: var(--orange); } .rate .r3 { background: var(--green); } .rate .r4 { background: var(--blue); }
.progressbar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 8px 0; }
.progressbar div { height: 100%; background: var(--accent-surface); transition: width .2s; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.speak { background: var(--accent-soft); color: var(--accent); padding: 8px 12px; border-radius: 999px; box-shadow: none; }
.palette-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.palette-opt { border: 2px solid var(--line); border-radius: 12px; padding: 10px; cursor: pointer; background: var(--card); box-shadow: none; text-align: left; display: flex; flex-direction: column; gap: 6px; }
.palette-opt.active { border-color: var(--accent-surface); }
.palette-opt .sw { display: flex; gap: 4px; } .palette-opt .sw i { display: block; width: 22px; height: 22px; border-radius: 6px; }
.theme-row button.active { background: var(--accent-soft); color: var(--accent); }

.list { display: flex; flex-direction: column; gap: 6px; }
.item { background: var(--card); border-radius: 12px; padding: 10px 14px; display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow); cursor: pointer; }
.item .thai { font-size: 26px; min-width: 90px; }
.item .info { flex: 1; min-width: 0; }
.item .info .tr { color: var(--accent); font-size: 14px; }
.item .info .m { font-size: 15px; }
.item .state { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }
.item .state.due { color: var(--accent); }
.item .state.learned { color: var(--green); }

.quiz .q { background: var(--card); border-radius: 20px; padding: 24px; text-align: center; box-shadow: var(--shadow); margin: 12px 0; }
.quiz .opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quiz .opts button { padding: 16px 10px; font-size: 18px; min-height: 64px; }
.quiz .opts button.thai { font-size: 32px; }
.quiz .opts button.ok { background: var(--green); color: #fff; }
.quiz .opts button.bad { background: var(--red); color: #fff; }
.quiz img { max-height: 120px; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.modal { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 20px; }
@media (min-width: 640px) { .modal-bg { align-items: center; } .modal { border-radius: 20px; } }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 30; font-size: 14px; max-width: 90vw; }
.toast.err { background: var(--red); color: #fff; }
.settings section { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.settings h2 { margin-top: 0; }
kbd { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; font-size: 12px; }
.done { text-align: center; padding: 40px 16px; }
.done .big { font-size: 48px; }
.stats-grid { display: flex; gap: 3px; align-items: flex-end; height: 60px; margin-top: 8px; }
.stats-grid div { flex: 1; background: var(--accent-surface); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .9; }
@media (max-width: 480px) { .card .thai-big { font-size: 80px; } h1 { font-size: 20px; } .rate button small { display: none; } }
