/* KIIP Prep – friendly study-app look: rounded type, chunky pressable buttons, colour-coded topics. */
:root {
  --bg: #f4f6fb; --card: #ffffff; --fg: #18192b; --muted: #5f6378; --line: #e3e6f0; --line-strong: #cfd4e3;
  --accent: #3d63f0; --accent-deep: #2746c4; --accent-soft: #eaf0ff;
  --ok: #1f9d55; --ok-deep: #157a41; --ok-soft: #e3f7eb;
  --bad: #e0414f; --bad-deep: #b52a37; --bad-soft: #fde8ea;
  --warn: #b26b00; --flame: #ff7a1a; --gold: #ffc83d;
  --hero-a: #3d63f0; --hero-b: #7b4dff;
  --radius: 18px; --shadow: 0 1px 2px rgba(24,25,43,.05), 0 8px 24px rgba(24,25,43,.06);
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1020; --card: #191a2e; --fg: #eef0fa; --muted: #a6aac4; --line: #2a2c45; --line-strong: #393c5c;
    --accent: #7d97ff; --accent-deep: #5672e6; --accent-soft: #232846;
    --ok: #4fd18b; --ok-deep: #2fa868; --ok-soft: #15301f; --bad: #ff7f8a; --bad-deep: #d85763; --bad-soft: #3a1b22;
    --warn: #f5b64a; --hero-a: #3450d8; --hero-b: #6a3de6; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1020; --card: #191a2e; --fg: #eef0fa; --muted: #a6aac4; --line: #2a2c45; --line-strong: #393c5c;
  --accent: #7d97ff; --accent-deep: #5672e6; --accent-soft: #232846;
  --ok: #4fd18b; --ok-deep: #2fa868; --ok-soft: #15301f; --bad: #ff7f8a; --bad-deep: #d85763; --bad-soft: #3a1b22;
  --warn: #f5b64a; --hero-a: #3450d8; --hero-b: #6a3de6; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.6 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
.wrap { max-width: 780px; margin: 0 auto; padding: 0 16px; }

/* ---------- header ---------- */
header.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
header.top .wrap { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; min-height: 60px; padding-top: 8px; padding-bottom: 8px; gap: 8px 12px; }
header.top .wrap > .row { flex-wrap: wrap; justify-content: flex-end; }
.brand { font-weight: 900; font-size: 1.15rem; text-decoration: none; color: var(--fg); letter-spacing: -.02em; display: inline-flex; align-items: center; gap: 8px; }
.brand::before { content: ""; width: 28px; height: 28px; border-radius: 9px; background: url("../favicon.svg") center / cover; flex: none; }
.brand small { color: var(--muted); font-weight: 600; font-size: .78rem; }

main { padding: 24px 0 72px; }
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 8px; letter-spacing: -.025em; font-weight: 900; }
h2 { font-size: 1.2rem; margin: 32px 0 12px; font-weight: 850; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.note { font-size: .9rem; color: var(--muted); }

/* ---------- cards & grid ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.mode { display: flex; flex-direction: column; gap: 6px; text-align: left; cursor: pointer; font: inherit; color: inherit;
  border: 2px solid var(--line); border-bottom-width: 5px; transition: transform .12s, border-color .12s; }
.mode:hover:not(:disabled) { border-color: var(--line-strong); transform: translateY(-2px); }
.mode:active:not(:disabled) { transform: translateY(2px); border-bottom-width: 2px; margin-top: 3px; }
.mode:disabled { opacity: .55; cursor: default; }
.mode .t { font-weight: 850; font-size: 1.05rem; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mode .ico { width: 42px; height: 42px; border-radius: 13px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.35rem; flex: none; background: var(--tone-soft, var(--accent-soft)); }
.mode .head { display: flex; align-items: center; gap: 12px; }
.mode .muted { font-size: .92rem; }

/* topic tones */
.tone-politics { --tone: #3d63f0; --tone-soft: #e6ecff; }
.tone-law { --tone: #7b4dff; --tone-soft: #efe8ff; }
.tone-history { --tone: #c7792a; --tone-soft: #fcf0e2; }
.tone-economy { --tone: #1f9d55; --tone-soft: #e3f7eb; }
.tone-society { --tone: #e0414f; --tone-soft: #fde8ea; }
.tone-culture { --tone: #e2509b; --tone-soft: #fde7f2; }
.tone-geography { --tone: #0f9bb5; --tone-soft: #e0f6fa; }
.tone-language { --tone: #e8a000; --tone-soft: #fff4d6; }
.tone-diag { --tone: #1f9d55; --tone-soft: #e3f7eb; }
.tone-mock { --tone: #3d63f0; --tone-soft: #e6ecff; }
.tone-review { --tone: #ff7a1a; --tone-soft: #fff0e3; }
.tone-oral { --tone: #7b4dff; --tone-soft: #efe8ff; }
.tone-writing { --tone: #0f9bb5; --tone-soft: #e0f6fa; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) [class*="tone-"] { --tone-soft: color-mix(in srgb, var(--tone) 22%, var(--card)); } }
:root[data-theme="dark"] [class*="tone-"] { --tone-soft: color-mix(in srgb, var(--tone) 22%, var(--card)); }
.mode[class*="tone-"] .progress > i { background: var(--tone); }

.badge { font-size: .7rem; font-weight: 800; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); letter-spacing: .01em; white-space: nowrap; }
.badge.free { background: var(--ok-soft); color: var(--ok); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; background: var(--accent); color: #fff;
  border-radius: 14px; padding: 11px 20px; font: inherit; font-weight: 850; letter-spacing: .01em; cursor: pointer; text-decoration: none; min-height: 48px;
  box-shadow: 0 4px 0 var(--accent-deep); transition: transform .08s, box-shadow .08s, filter .12s; }
.btn:hover:not(:disabled) { filter: brightness(1.06); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-deep); }
.btn.ghost { background: var(--card); color: var(--accent); border: 2px solid var(--line); box-shadow: 0 4px 0 var(--line); }
.btn.ghost:active:not(:disabled) { box-shadow: 0 1px 0 var(--line); }
.btn.ok { background: var(--ok); box-shadow: 0 4px 0 var(--ok-deep); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.danger { color: var(--bad); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }

/* ---------- progress ---------- */
.progress { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ok); width: 0; border-radius: 99px; transition: width .35s ease; }
.progress.done > i { background: linear-gradient(90deg, var(--gold), var(--flame)); }
.quizbar { height: 14px; }
.quizbar > i { background: linear-gradient(90deg, #46d27f, var(--ok)); box-shadow: inset 0 -3px 0 rgba(0,0,0,.08); }

/* ---------- habit hero ---------- */
.habit { position: relative; overflow: hidden; color: #fff; border: 0; padding: 20px;
  background: radial-gradient(120% 140% at 100% 0%, var(--hero-b) 0%, var(--hero-a) 55%, #2a46c9 100%); box-shadow: 0 10px 30px rgba(61,99,240,.28); }
.habit::after { content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px; border-radius: 50%; background: rgba(255,255,255,.08); }
.habit .note { color: rgba(255,255,255,.86); }
.habit strong { font-weight: 900; }
.habit .streak { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.habit .flame { font-size: 2.3rem; line-height: 1; filter: drop-shadow(0 4px 8px rgba(255,122,26,.5)); }
.habit .flame.off { filter: grayscale(1) opacity(.6); }
.habit .streak-n { font-size: 1.35rem; letter-spacing: -.01em; }
.habit .progress { background: rgba(255,255,255,.22); position: relative; z-index: 1; }
.habit .progress > i { background: #fff; }
.habit .progress.done > i { background: linear-gradient(90deg, var(--gold), #ffe08a); }
.habit .sep { height: 1px; background: rgba(255,255,255,.18); margin: 16px 0 12px; }
.habit .predict { font-size: 1.5rem; font-weight: 900; }
.gauge { position: relative; display: block; height: 12px; border-radius: 99px; background: rgba(255,255,255,.22); margin-top: 8px; }
.gauge > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #ffd36b, #ff9a3d); transition: width .5s ease; }
.gauge > i.pass { background: linear-gradient(90deg, #7ef0a8, #2fd27a); }
.gauge > b { position: absolute; top: -5px; bottom: -5px; width: 3px; border-radius: 2px; background: #fff; transform: translateX(-1px); }
.gauge > b::after { content: attr(title); position: absolute; top: -20px; left: 50%; transform: translateX(-50%); font-size: .7rem; font-weight: 800; }

/* ---------- quiz ---------- */
.qcard { margin-top: 16px; }
.qtext { font-size: 1.28rem; font-weight: 800; margin: 14px 0 4px; word-break: keep-all; line-height: 1.5; }
.qen { color: var(--muted); margin: 0 0 16px; }
.opts { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.opt { width: 100%; text-align: left; border: 2px solid var(--line); border-bottom-width: 4px; background: var(--card); color: var(--fg); border-radius: 16px;
  padding: 13px 14px; font: inherit; font-weight: 650; cursor: pointer; display: flex; gap: 12px; align-items: flex-start; min-height: 54px; word-break: keep-all;
  transition: transform .08s, border-color .12s, background .12s; }
.opt:hover:not(:disabled) { border-color: var(--line-strong); background: color-mix(in srgb, var(--accent-soft) 40%, var(--card)); }
.opt:active:not(:disabled) { transform: translateY(2px); border-bottom-width: 2px; margin-top: 2px; }
.opt .n { flex: none; width: 28px; height: 28px; border-radius: 9px; border: 2px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-size: .82rem; font-weight: 900; color: var(--muted); }
.opt .en { display: block; color: var(--muted); font-size: .88rem; font-weight: 500; margin-top: 2px; }
.opt.chosen { border-color: var(--accent); background: var(--accent-soft); }
.opt.chosen .n { border-color: var(--accent); background: var(--accent); color: #fff; }
.opt.right { border-color: var(--ok); background: var(--ok-soft); animation: pop .32s ease; }
.opt.right .n { border-color: var(--ok); background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake .35s ease; }
.opt.wrong .n { border-color: var(--bad); background: var(--bad); color: #fff; }
.opt:disabled { cursor: default; }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.025); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }

.explain { margin-top: 16px; padding: 14px 16px; border-radius: 16px; background: var(--accent-soft); border: 2px solid transparent; }
.explain.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.explain.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.explain .verdict { font-weight: 900; font-size: 1.05rem; }
.explain.ok .verdict { color: var(--ok); }
.explain.bad .verdict { color: var(--bad); }
.explain p { margin: 0 0 6px; }
.explain .ref { font-size: .85rem; color: var(--muted); margin: 0; }
.toggle { font-size: .88rem; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; color: var(--muted); font-weight: 650; }
.timer { font-variant-numeric: tabular-nums; font-weight: 900; padding: 2px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.timer.low { color: #fff; background: var(--bad); }

/* ---------- results ---------- */
.result-hero { text-align: center; padding: 26px 18px; }
.result-hero .warnbox, .result-hero .note { text-align: left; }
.ring { --p: 0; --c: var(--ok); width: 168px; height: 168px; margin: 6px auto 12px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--line) 0); position: relative; animation: ringIn .6s ease; }
.ring::before { content: ""; position: absolute; inset: 14px; border-radius: 50%; background: var(--card); }
.ring > span { position: relative; font-size: 2.1rem; font-weight: 900; letter-spacing: -.03em; }
.ring > span small { display: block; font-size: .85rem; color: var(--muted); font-weight: 700; letter-spacing: 0; }
.ring.mid { --c: var(--gold); }
.ring.low { --c: var(--bad); }
@keyframes ringIn { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.cheer { font-size: 1.25rem; font-weight: 900; margin: 0 0 4px; }
.score { font-size: 2.4rem; font-weight: 900; letter-spacing: -.03em; }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; opacity: .9; animation: fall 1.8s ease-in forwards; }
@keyframes fall { to { transform: translateY(260px) rotate(540deg); opacity: 0; } }
.bars { display: grid; gap: 10px; }
.bar { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr auto; gap: 10px; align-items: center; font-size: .92rem; font-weight: 650; }
.bar .track { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar .track i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.bar.low .track i { background: var(--bad); }

.warnbox { border: 1px solid var(--line); border-left: 5px solid var(--gold); padding: 12px 16px; border-radius: 14px; background: var(--card); font-size: .92rem; }
.list { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
footer { border-top: 1px solid var(--line); padding: 22px 0 44px; font-size: .85rem; color: var(--muted); }

/* ---------- misc ---------- */
@media (max-width: 480px) {
  h1 { font-size: 1.5rem; }
  .qtext { font-size: 1.12rem; }
  .bar { grid-template-columns: 1fr auto; }
  .bar .track { grid-column: 1 / -1; grid-row: 2; }
  .ring { width: 148px; height: 148px; }
}
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn:focus-visible, .opt:focus-visible, .mode:focus-visible { outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
.langsel { font: inherit; font-size: .9rem; font-weight: 700; padding: 6px 10px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); color: var(--fg); min-height: 40px; max-width: 9.5em; }
:lang(th) { font-family: "Nunito", system-ui, "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif; }
:lang(km) { font-family: "Nunito", system-ui, "Noto Sans Khmer", "Khmer UI", "Leelawadee UI", sans-serif; line-height: 1.8; }
:lang(zh) { font-family: "Nunito", system-ui, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif; }
:lang(ko) { font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif; }
@media (max-width: 420px) { #homeLink, .brand small { display: none; } }
.acct { position: relative; display: inline-flex; align-items: center; }
.acct-btn { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--line); background: var(--accent-soft); color: var(--accent); font: inherit; font-weight: 900; cursor: pointer; }
.acct-menu { position: absolute; right: 0; top: 46px; z-index: 30; min-width: 240px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px; box-shadow: 0 12px 32px rgba(24,25,43,.16); display: grid; gap: 8px; }
.acct-menu[hidden] { display: none; }

/* Ad units (AdSense) – clearly labelled, kept away from answer buttons */
.ad { margin: 28px 0; padding-top: 6px; border-top: 1px solid var(--line); min-height: 100px; }
.ad[hidden] { display: none; }
.ad-label { display: block; font-size: .75rem; color: var(--muted); margin-bottom: 4px; }
