:root {
  --red: #AA151B; --red-d: #85100f; --gold: #F1BF00; --gold-d: #c99d00; --gold-soft: #fff1b8;
  --cream: #fffaf0; --ink: #2a1b1b; --muted: #6f5e5e; --line: #eadfc8; --card: #fff;
  --ok: #1b7a3d; --ok-bg: #e4f5ea; --bad: #b3261e; --bad-bg: #fde8e6; --radius: 14px;
  --shadow: 0 1px 2px rgba(80, 40, 20, .08), 0 4px 14px rgba(80, 40, 20, .06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--cream); color: var(--ink); line-height: 1.45; min-height: 100vh; }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.9rem; } h2 { font-size: 1.4rem; } h3 { font-size: 1.1rem; }
a { color: var(--red); }
p { margin: 0 0 .75rem; }
.boot { padding: 2rem; text-align: center; color: var(--muted); }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.wrap.narrow { max-width: 640px; }
main.wrap { padding-top: 22px; padding-bottom: 60px; }
.muted { color: var(--muted); } .small { font-size: .875rem; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; }
.hidden { display: none !important; }
.mt { margin-top: 16px; }

/* header */
.flagbar { height: 12px; background: linear-gradient(var(--red) 0 25%, var(--gold) 25% 75%, var(--red) 75% 100%); }
header.top { background: var(--red); color: #fff; border-bottom: 3px solid var(--gold); }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 10px; padding-bottom: 10px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand b { font-family: Georgia, serif; font-size: 1.2rem; display: block; line-height: 1.1; }
.brand small { color: var(--gold); font-weight: 600; letter-spacing: .04em; }
.brand-mark { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(var(--red-d) 0 25%, var(--gold) 25% 75%, var(--red-d) 75% 100%); display: grid; place-items: center; font-weight: 800; color: var(--red-d); font-size: .95rem; border: 2px solid #fff3; }
.nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.navlink { color: #fff; text-decoration: none; padding: 7px 12px; border-radius: 999px; font-weight: 600; font-size: .95rem; }
.navlink:hover, .navlink.active { background: #ffffff26; }

/* buttons & forms */
.btn { appearance: none; border: 0; background: var(--red); color: #fff; font: inherit; font-weight: 700; padding: 11px 18px; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-block; text-align: center; box-shadow: 0 2px 0 var(--red-d); }
.btn:hover { background: var(--red-d); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn.gold { background: var(--gold); color: #3b2a00; box-shadow: 0 2px 0 var(--gold-d); } .btn.gold:hover { background: #ffd21f; }
.btn.ghost { background: transparent; color: inherit; box-shadow: inset 0 0 0 2px currentColor; }
header .btn.ghost { color: #fff; } header .btn.ghost:hover { background: #ffffff26; }
main .btn.ghost { color: var(--red); } main .btn.ghost:hover { background: #aa151b12; }
.btn.danger { background: #fff; color: var(--bad); box-shadow: inset 0 0 0 2px var(--bad); } .btn.danger:hover { background: var(--bad-bg); }
.btn.sm { padding: 6px 12px; font-size: .875rem; border-radius: 8px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
:focus-visible { outline: 3px solid #1f5fbf; outline-offset: 2px; }
label.field { display: block; margin-bottom: 12px; font-weight: 600; font-size: .9rem; }
label.field > span { display: block; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=search], textarea, select { width: 100%; font: inherit; padding: 10px 12px; border: 2px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
input:focus, textarea:focus, select:focus { border-color: var(--red); outline: none; }
textarea { min-height: 140px; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9rem; }
.err { background: var(--bad-bg); color: var(--bad); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-weight: 600; }
.notice { background: var(--gold-soft); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid > .card { margin: 0; }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 18px; }
.tile { background: #fff; border: 1px solid var(--line); border-left: 6px solid var(--gold); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.tile b { display: block; font-size: 1.7rem; font-family: Georgia, serif; color: var(--red); line-height: 1.1; }
.tile span { color: var(--muted); font-size: .85rem; }
.unit-card { text-decoration: none; color: inherit; display: block; border-top: 6px solid var(--red); transition: transform .12s; }
.unit-card:hover { transform: translateY(-2px); }
.unit-card h3 { color: var(--red); }
.unit-num { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--gold); color: #3b2a00; font-weight: 800; margin-right: 8px; font-family: system-ui; font-size: .9rem; }
.bar-track { height: 10px; border-radius: 999px; background: #efe6d2; overflow: hidden; display: flex; margin: 10px 0 6px; }
.bar-track .m { background: var(--ok); } .bar-track .l { background: var(--gold); }
.legend { font-size: .8rem; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #d9d0bc; }
.dot.l { background: var(--gold); } .dot.m { background: var(--ok); }

/* study modes */
.modes { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin: 16px 0; }
.mode { border: 2px solid var(--line); background: #fff; border-radius: var(--radius); padding: 16px; text-decoration: none; color: inherit; display: block; box-shadow: var(--shadow); }
.mode:hover { border-color: var(--red); } .mode b { display: block; color: var(--red); font-size: 1.1rem; margin-bottom: 2px; }
.mode .ico { font-size: 1.6rem; display: block; margin-bottom: 4px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 2px solid var(--line); background: #fff; padding: 6px 14px; border-radius: 999px; font: inherit; font-weight: 600; cursor: pointer; color: var(--ink); }
.chip[aria-pressed=true] { background: var(--red); border-color: var(--red); color: #fff; }
.frame-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.frame-top h2 { margin: 0; font-size: 1.15rem; }
.progress { height: 12px; background: #efe6d2; border-radius: 999px; overflow: hidden; margin-bottom: 18px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--red), var(--gold)); width: 0; transition: width .25s; }
.flashcard { width: 100%; min-height: 240px; border: 3px solid var(--red); background: #fff; border-radius: 20px; padding: 24px; font: inherit; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; color: var(--ink); }
.flashcard.flipped { background: var(--gold-soft); border-color: var(--gold-d); }
.fc-lang, .langtag { font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--red); font-weight: 800; }
.fc-text { font-family: Georgia, serif; font-size: clamp(1.5rem, 5vw, 2.3rem); font-weight: 700; overflow-wrap: anywhere; }
.fc-hint { color: var(--muted); font-size: .85rem; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.actions .btn { padding: 14px; font-size: 1.05rem; }
.prompt { font-family: Georgia, serif; font-size: clamp(1.4rem, 4.5vw, 2rem); font-weight: 700; margin: 6px 0 16px; overflow-wrap: anywhere; }
input.answer { font-size: 1.2rem; padding: 14px; }
.accents { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.accents button { min-width: 40px; padding: 8px; font: inherit; font-weight: 700; border: 2px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer; color: var(--ink); }
.accents button:hover { border-color: var(--gold-d); background: var(--gold-soft); }
.feedback { margin-top: 14px; border-radius: 12px; padding: 12px 14px; font-weight: 600; }
.feedback.ok { background: var(--ok-bg); color: var(--ok); } .feedback.bad { background: var(--bad-bg); color: var(--bad); }
.feedback .ans { color: var(--ink); font-size: 1.15rem; display: block; margin-top: 2px; }
.options { display: grid; gap: 10px; margin-bottom: 14px; }
.option { text-align: left; border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 14px 16px; font: inherit; font-size: 1.05rem; cursor: pointer; display: flex; gap: 12px; align-items: baseline; color: var(--ink); }
.option:hover:not(:disabled) { border-color: var(--red); }
.option kbd { background: var(--gold-soft); border-radius: 6px; padding: 1px 8px; font-weight: 800; font-family: inherit; }
.option.right { background: var(--ok-bg); border-color: var(--ok); } .option.wrong { background: var(--bad-bg); border-color: var(--bad); }
.tiles-match { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.mtile { min-height: 76px; border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 10px; font: inherit; font-weight: 600; cursor: pointer; color: var(--ink); overflow-wrap: anywhere; }
.mtile.es { border-bottom: 5px solid var(--red); } .mtile.en { border-bottom: 5px solid var(--gold); }
.mtile.sel { background: var(--gold-soft); border-color: var(--gold-d); }
.mtile.done { visibility: hidden; }
.mtile.shake { animation: shake .35s; background: var(--bad-bg); border-color: var(--bad); }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.big-score { font-family: Georgia, serif; font-size: 3.4rem; color: var(--red); font-weight: 700; }
.summary { text-align: center; }
.misslist { text-align: left; padding-left: 20px; max-height: 300px; overflow: auto; }

/* tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
td input[type=text] { padding: 6px 8px; }
.tag { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .8rem; font-weight: 700; background: var(--gold-soft); }
.minibar { width: 90px; height: 8px; background: #efe6d2; border-radius: 999px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 6px; }
.minibar > div { height: 100%; background: var(--ok); }
.cred { font-family: ui-monospace, Menlo, Consolas, monospace; }
.wordlist .es { font-weight: 700; }
.sticky-tools { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; align-items: center; }
.sticky-tools input[type=search] { max-width: 320px; }

/* login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(var(--red) 0 25%, var(--gold) 25% 75%, var(--red) 75% 100%); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 20px; padding: 26px; box-shadow: 0 10px 40px rgba(60, 10, 10, .35); border: 3px solid var(--red-d); }
.login-card h1 { color: var(--red); text-align: center; margin-bottom: 2px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 18px; }
.login-card .btn { width: 100%; padding: 13px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px; z-index: 50; box-shadow: var(--shadow); max-width: 90vw; }
.toast.bad { background: var(--bad); }

@media (max-width: 560px) {
  h1 { font-size: 1.55rem; }
  .navlink { padding: 6px 9px; font-size: .88rem; }
  .actions { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- v2: games, live, homework, badges ---------- */
.tag.big { font-size: 1.05rem; padding: 4px 14px; }
.tag.late, .hw.late { background: var(--bad-bg); color: var(--bad); }
.tag.soon { background: var(--gold-soft); }
.btn.big { padding: 15px 28px; font-size: 1.15rem; }
label.check { display: block; padding: 5px 0; font-weight: 500; cursor: pointer; }
label.check input { margin-right: 6px; width: 1.05em; height: 1.05em; accent-color: var(--red); }
.option.sel { border-color: var(--red); background: var(--gold-soft); }
.announce { background: var(--gold-soft); border: 2px solid var(--gold); border-radius: 12px; padding: 12px 16px; margin-bottom: 16px; }
.xp { margin: 4px 0 16px; }
.xpbar, .goalbar { position: relative; height: 12px; background: #efe6d2; border-radius: 999px; overflow: hidden; margin-bottom: 4px; }
.xpbar > div { height: 100%; background: linear-gradient(90deg, var(--red), var(--gold)); border-radius: 999px; }
.goalbar { height: 14px; overflow: visible; }
.goalbar > div:first-child { height: 100%; background: var(--gold); border-radius: 999px; }
.goalbar > div.done { background: var(--ok); }
.goalbar .tick { position: absolute; top: -3px; width: 3px; height: 20px; background: var(--ink); border-radius: 2px; }
.card.hw { display: block; text-decoration: none; color: inherit; margin-top: 10px; border-left: 6px solid var(--gold); }
.card.hw.late { border-left-color: var(--bad); } .card.hw.finished { border-left-color: var(--ok); opacity: .8; }
.livecta { display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; border: 3px solid var(--red); background: var(--gold-soft); }
.bigicon { font-size: 2.4rem; line-height: 1; }
.badges { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.badge { background: #fff; border: 1px dashed var(--line); border-radius: 12px; padding: 12px; text-align: center; display: grid; gap: 2px; opacity: .55; filter: grayscale(1); }
.badge.on { opacity: 1; filter: none; border: 2px solid var(--gold); background: var(--gold-soft); }
.badge .bi { font-size: 1.8rem; }
.lbtable { width: 100%; } .lbtable td { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.lbtable .rank { width: 48px; font-size: 1.2rem; } .lbtable .pts { text-align: right; font-weight: 800; color: var(--red); }
.lbtable tr.me { background: var(--gold-soft); font-weight: 700; }
.hearts { font-size: 1.4rem; letter-spacing: 2px; margin-bottom: 6px; }
.hm-word { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: clamp(1.4rem, 5vw, 2.1rem); font-weight: 800; letter-spacing: .12em; margin: 14px 0; overflow-wrap: anywhere; }
.hm-word.lost { color: var(--bad); }
.keyboard { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 10px 0; }
.key { width: 40px; height: 44px; border: 2px solid var(--line); background: #fff; border-radius: 8px; font: inherit; font-weight: 800; cursor: pointer; color: var(--ink); }
.key:hover:not(:disabled) { border-color: var(--red); } .key:disabled { cursor: default; }
.key.right { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); } .key.wrong { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); opacity: .7; }
.tilerow { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 12px 0 16px; }
.ltile { width: 46px; height: 52px; display: grid; place-items: center; background: var(--gold); color: #3b2a00; font-weight: 800; font-size: 1.5rem; border-radius: 10px; box-shadow: 0 3px 0 var(--gold-d); }
.mode.pickable { text-align: left; font: inherit; cursor: pointer; }
.mode.pickable[aria-pressed=true] { border-color: var(--red); background: var(--gold-soft); box-shadow: 0 0 0 3px var(--red) inset; }
.speak { padding: 4px 10px; }

/* live */
.hostscreen { font-size: 1.05rem; }
.livecode { font-family: Georgia, serif; font-weight: 700; font-size: clamp(3rem, 14vw, 7rem); letter-spacing: .12em; color: var(--red); background: #fff; border: 4px solid var(--red); border-radius: 20px; display: inline-block; padding: 4px 28px; margin: 10px 0 18px; }
.joininfo { font-size: 1.2rem; }
.lobby { text-align: center; }
.chips2 { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; min-height: 40px; }
.pchip { background: #fff; border: 2px solid var(--gold); border-radius: 999px; padding: 6px 8px 6px 16px; font-weight: 700; display: inline-flex; gap: 8px; align-items: center; }
.pchip .x { border: 0; background: #0001; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; font-weight: 800; }
.cd { margin: 8px 0; } .cd-num { font-family: Georgia, serif; font-size: 2.4rem; font-weight: 700; color: var(--red); }
.hostprompt { font-family: Georgia, serif; font-size: clamp(1.8rem, 6vw, 3.2rem); font-weight: 700; margin: 16px 0; text-align: center; overflow-wrap: anywhere; }
.hostopts, .playopts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hopt, .popt { display: flex; gap: 10px; align-items: center; border-radius: 14px; padding: 16px; color: #fff; font: inherit; font-weight: 700; font-size: clamp(1rem, 3.2vw, 1.5rem); border: 0; text-align: left; }
.popt { cursor: pointer; min-height: 84px; box-shadow: 0 4px 0 #0003; } .popt:active { transform: translateY(2px); box-shadow: none; }
.lo0 { background: #c62828; } .lo1 { background: #d9a400; color: #2a1b00; } .lo2 { background: #1f5fbf; } .lo3 { background: #1b7a3d; }
.hopt .shape, .popt .shape { font-size: 1.5rem; } .hopt .ocount { margin-left: auto; background: #0003; border-radius: 999px; padding: 2px 14px; }
.hopt.dim { opacity: .35; } .hopt.right { outline: 5px solid var(--ink); }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin: 18px 0; }
.pod { text-align: center; min-width: 90px; } .pname { font-weight: 800; } .pscore { color: var(--red); font-weight: 800; }
.pblock { margin-top: 6px; border-radius: 10px 10px 0 0; font-size: 2rem; padding-top: 8px; background: var(--gold); }
.p1 .pblock { height: 120px; } .p2 .pblock { height: 84px; background: #d9d9d9; } .p3 .pblock { height: 60px; background: #e0a96d; }
.statbar { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; justify-content: space-between; background: var(--red); color: #fff; border-radius: 12px; padding: 10px 16px; margin-bottom: 14px; font-weight: 700; }
.playscreen { max-width: 640px; margin: 0 auto; }
.okbox { border: 3px solid var(--ok); background: var(--ok-bg); } .badbox { border: 3px solid var(--bad); background: var(--bad-bg); }
.chests { display: flex; gap: 14px; justify-content: center; margin: 16px 0; }
.chest { font-size: 3.6rem; background: var(--gold-soft); border: 3px solid var(--gold-d); border-radius: 18px; padding: 14px 20px; cursor: pointer; box-shadow: 0 5px 0 var(--gold-d); }
.chest:hover { background: var(--gold); } .chest:active { transform: translateY(3px); box-shadow: none; }
.codeinput { text-align: center; letter-spacing: .3em; font-size: 2rem; }
.wrap-narrow { max-width: 720px; margin: 0 auto; }
.hw .goalbar { margin-top: 10px; }
@media (max-width: 560px) { .hostopts, .playopts { grid-template-columns: 1fr; } }
