:root {
  --paper: #f6f4ee;
  --paper-2: #ece8de;
  --ink: #12142a;
  --ink-2: #3f4363;
  --muted: #6c7090;
  --line: #dcd8cc;
  --yellow: #ffd84d;
  --pink: #ff6fae;
  --mint: #3ddba8;
  --blue: #5aaeff;
  --violet: #9584ff;
  --orange: #ff9a4d;
  --good: #129b6a;
  --bad: #dc3651;
  --radius: 14px;
  --shadow: 3px 3px 0 var(--ink);
  --shadow-sm: 2px 2px 0 var(--ink);
  --font-head: 'Bricolage Grotesque', 'DM Sans', system-ui, sans-serif;
  --font: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background-color: var(--paper);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px 48px; }
h1, h2, h3 { font-family: var(--font-head); line-height: 1.1; margin: 0 0 .4em; font-weight: 700; letter-spacing: -.02em; }
h1 { font-weight: 800; letter-spacing: -.035em; }
h1 { font-size: clamp(2rem, 6vw, 3.4rem); }
h2 { font-size: clamp(1.4rem, 3.5vw, 1.9rem); }
h3 { font-size: 1.2rem; }
a { color: inherit; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* Highlighter swipe behind a word */
.hl { background: linear-gradient(transparent 58%, var(--yellow) 58%, var(--yellow) 92%, transparent 92%); padding: 0 .06em; }
.hl.pink { background: linear-gradient(transparent 58%, var(--pink) 58%, var(--pink) 92%, transparent 92%); }
.hl.mint { background: linear-gradient(transparent 58%, var(--mint) 58%, var(--mint) 92%, transparent 92%); }

/* ---- Header / footer ---- */
.site-header { max-width: 1080px; margin: 0 auto; padding: 14px 16px; display: flex; align-items: center; gap: 12px; width: 100%; }
.logo { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; font-family: var(--font-head); font-weight: 700; font-size: 1.18rem; letter-spacing: -.02em; }
.logo-mark { width: 34px; height: 34px; display: block; flex: none; }
.logo b { background: var(--pink); padding: 0 .22em; border-radius: 6px; }
.site-header nav { margin-left: auto; display: flex; gap: 8px; }
.site-footer { border-top: 2px solid var(--ink); background: var(--paper-2); padding: 20px 16px; text-align: center; font-size: .9rem; color: var(--ink-2); }
.site-footer a { margin: 0 8px; }

/* ---- Cards and buttons ---- */
.card { background: #fff; border: 2px solid var(--ink); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 700 1rem var(--font); color: var(--ink); background: #fff;
  border: 2px solid var(--ink); border-radius: 10px; padding: 10px 16px; min-height: 44px;
  box-shadow: var(--shadow-sm); cursor: pointer; text-decoration: none;
  transition: transform .08s, box-shadow .08s, background .15s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--ink); }
.btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: var(--shadow-sm); }
.btn-primary { background: var(--yellow); }
.btn-pink { background: var(--pink); }
.btn-mint { background: var(--mint); }
.btn-blue { background: var(--blue); }
.btn-big { font-size: 1.12rem; padding: 14px 24px; min-height: 54px; border-radius: 12px; }
.btn-small { padding: 6px 10px; min-height: 36px; font-size: .9rem; }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; }
.btn-ghost:hover { box-shadow: none; background: rgba(29, 33, 64, .06); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

input[type=text], select, textarea {
  font: 1rem var(--font); color: var(--ink); background: #fff;
  border: 2px solid var(--ink); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
textarea { resize: vertical; min-height: 140px; line-height: 1.5; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
label { font-weight: 700; }

.pill { display: inline-block; border: 2px solid var(--ink); border-radius: 999px; padding: 1px 10px; font-size: .8rem; font-weight: 700; background: #fff; }
.error { background: #ffe1e6; border: 2px solid var(--bad); border-radius: 12px; padding: 10px 14px; color: #8a1328; font-weight: 600; }

/* ---- Modals / toast / confetti ---- */
.overlay { position: fixed; inset: 0; background: rgba(29, 33, 64, .55); display: grid; place-items: center; padding: 16px; z-index: 50; overflow-y: auto; }
.modal { width: 100%; max-width: 460px; text-align: center; display: grid; gap: 12px; }
.modal h2 { margin: 0; }
.modal p { margin: 0; }
.modal-emoji { font-size: 2.6rem; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 700; transition: .25s; z-index: 60; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { top: 105%; transform: rotate(720deg) translateX(40px); } }

/* ---- Ads ---- */
.ad-slot { margin: 28px auto; max-width: 728px; min-height: 100px; text-align: center; }
.ad-label { display: block; font-size: .72rem; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .06em; }

/* ---- Home ---- */
.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 36px; align-items: center; margin-top: 8px; padding: clamp(22px, 4vw, 44px); background: var(--ink); color: #fff; border-radius: 24px; position: relative; overflow: hidden; }
.hero::before { content: ''; position: absolute; inset: auto -120px -160px auto; width: 420px; height: 420px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 111, 174, .35), transparent 65%); pointer-events: none; }
.hero > * { position: relative; }
.hero h1 { color: #fff; font-size: clamp(2.4rem, 6.4vw, 4.2rem); }
.hero .hl, .hero .hl.pink { color: var(--ink); background: var(--yellow); padding: 0 .14em; border-radius: 8px; }
.hero .hl.pink { background: var(--pink); }
.hero p.lead { font-size: 1.12rem; color: #c9cbe0; max-width: 34em; }
.hero p.lead b, .hero p.lead em { color: #fff; }
.hero .muted { color: #a5a8c4; }
.hero .card .muted { color: var(--muted); }
.hero .btn:not(.btn-primary) { box-shadow: 2px 2px 0 #000; }
.hero .card { color: var(--ink); box-shadow: 4px 4px 0 var(--pink); border-color: #000; }
.hero-games { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 18px; }
.hero-games span { border: 1.5px solid #3a3e63; color: #e4e5f2; border-radius: 999px; padding: 3px 11px; font-size: .82rem; font-weight: 600; }
.sticker { display: inline-block; background: var(--mint); border: 2px solid var(--ink); border-radius: 999px; padding: 3px 12px; font-weight: 700; font-size: .85rem; margin-bottom: 14px; letter-spacing: .01em; }
.maker { display: grid; gap: 14px; }
.drop { border: 2px dashed var(--ink); border-radius: 12px; background: var(--paper-2); padding: 22px 16px; text-align: center; cursor: pointer; transition: background .15s; }
.drop.over { background: #fff6bf; }
.drop strong { display: block; font-size: 1.1rem; }
.file-list { display: grid; gap: 6px; }
.file-chip { display: flex; align-items: center; gap: 8px; background: #fff; border: 2px solid var(--ink); border-radius: 10px; padding: 6px 10px; font-size: .92rem; }
.file-chip span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 700; font-size: .85rem; }
.or::before, .or::after { content: ''; flex: 1; border-top: 2px dashed var(--line); }
.progress { display: grid; gap: 10px; text-align: center; padding: 10px 0; }
.progress .bar { height: 14px; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; background: #fff; }
.progress .bar i { display: block; height: 100%; width: 0; background: repeating-linear-gradient(45deg, var(--yellow) 0 12px, var(--orange) 12px 24px); transition: width .6s; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 36px 0; }
.step { text-align: center; }
.step .num { font-family: var(--font-head); font-weight: 800; font-size: 1.6rem; width: 50px; height: 50px; border: 2px solid var(--ink); border-radius: 12px; display: grid; place-items: center; margin: 0 auto 8px; background: var(--blue); }
.join-box { display: flex; gap: 8px; }
.join-box input { text-transform: uppercase; letter-spacing: .2em; font-weight: 800; }
.my-packs { display: grid; gap: 8px; }
.my-pack { display: flex; align-items: center; gap: 10px; text-decoration: none; background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 10px 14px; }
.my-pack:hover { background: #fffbe0; }
.my-pack b { flex: 1; }

/* ---- Game cards (home showcase + pack page) ---- */
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.game-card { display: flex; flex-direction: column; gap: 8px; padding: 18px; position: relative; }
.game-card .icon { width: 50px; height: 50px; border: 2px solid var(--ink); border-radius: 12px; display: grid; place-items: center; font-size: 1.55rem; }
.game-card h3 { margin: 6px 0 0; }
.game-card p { margin: 0; color: var(--ink-2); font-size: .95rem; flex: 1; }
.game-card .tags { display: flex; gap: 6px; flex-wrap: wrap; }
.game-card .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.game-card .actions .wide { grid-column: 1 / -1; }
.game-card.off { opacity: .55; }
.c-yellow { background: var(--yellow); } .c-pink { background: var(--pink); } .c-mint { background: var(--mint); }
.c-blue { background: var(--blue); } .c-violet { background: var(--violet); } .c-orange { background: var(--orange); }
.new-tag { position: absolute; top: -10px; right: 14px; background: var(--pink); }

/* ---- Pack page ---- */
.pack-head { padding: 22px 0 8px; display: grid; gap: 10px; }
.pack-head .row { gap: 8px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { font: 700 .9rem var(--font); border: 2px solid var(--ink); background: #fff; border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.tabs button[aria-selected=true] { background: var(--ink); color: #fff; }
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.board li { display: flex; gap: 10px; align-items: center; background: #fff; border: 2px solid var(--ink); border-radius: 10px; padding: 6px 12px; }
.board li .rank { font-family: var(--font-head); width: 28px; }
.board li .name { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.board li .score { font-family: var(--font-head); }
.board li.me { background: #fff6bf; }
.board li.done .name::after { content: ' ✓'; color: var(--good); }

/* ---- Play page ---- */
.play-bar { display: flex; align-items: center; gap: 10px; padding: 8px 0 14px; flex-wrap: wrap; }
.play-bar h1 { font-size: clamp(1.4rem, 4vw, 2rem); margin: 0; }
.play-bar .stats { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.stat { background: #fff; border: 2px solid var(--ink); border-radius: 10px; padding: 4px 10px; font-weight: 800; font-family: var(--font-head); font-size: 1.05rem; }
.stat small { font-family: var(--font); font-weight: 700; color: var(--muted); font-size: .72rem; display: block; line-height: 1; text-transform: uppercase; }
.play-layout { display: grid; grid-template-columns: 1fr; gap: 18px; }
.play-layout.with-room { grid-template-columns: 1fr 260px; }
.room-panel { align-self: start; position: sticky; top: 12px; }
.room-panel h3 { display: flex; justify-content: space-between; align-items: baseline; }
.game-root { min-width: 0; }
.intro { text-align: center; max-width: 560px; margin: 20px auto; display: grid; gap: 14px; justify-items: center; }
.intro .icon { font-size: 3rem; }
.intro ul { text-align: left; margin: 0; padding-left: 1.2em; }

.result { max-width: 520px; }
.result .big-score { font-family: var(--font-head); font-size: 3.4rem; line-height: 1; }
.result .lb-form { display: flex; gap: 8px; }
.result .summary { text-align: left; max-height: 240px; overflow-y: auto; display: grid; gap: 6px; font-size: .92rem; }

/* Shared feedback chips */
.fb { border-radius: 12px; padding: 10px 14px; border: 2px solid var(--ink); font-weight: 600; }
.fb.good { background: #d6f8ea; }
.fb.bad { background: #ffe1e6; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-3px); } }
.pop { animation: pop .3s; }
@keyframes pop { 50% { transform: scale(1.08); } }

/* ---- Print page ---- */
.print-tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 0; }
.print-tools label { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.print-tools select { width: auto; }
.sheet { background: #fff; color: #000; max-width: 210mm; margin: 0 auto 24px; padding: 14mm 14mm; border: 1px solid #ccc; box-shadow: 0 4px 20px rgba(0,0,0,.08); font-family: var(--font); }
.sheet + .sheet { break-before: page; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid #000; padding-bottom: 6px; margin-bottom: 12px; gap: 12px; }
.sheet-head h1 { font-size: 1.7rem; margin: 0; }
.sheet-head .sub { font-size: .85rem; }
.sheet-name { font-size: .9rem; white-space: nowrap; }
.sheet-brand { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-family: var(--font-head); font-size: 1rem; }
.sheet-mark { width: 24px; height: 24px; display: block; }
.sheet-word b { border: 1.5px solid #000; border-radius: 4px; padding: 0 .2em; background: var(--pink); }
.sheet-label { margin-left: auto; font-family: var(--font); font-weight: 700; font-size: .85rem; }
.sheet-foot { margin-top: 14px; padding-top: 8px; border-top: 1px solid #999; font-size: .74rem; color: #333; display: flex; align-items: center; gap: 10px; break-inside: avoid; }
.sheet-qr { width: 17mm; height: 17mm; flex: none; }
.sheet-brand * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.key-badge { display: inline-block; border: 2px solid #000; padding: 0 8px; border-radius: 6px; font-weight: 800; font-size: .8rem; margin-left: 8px; vertical-align: middle; }

@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; }
  .site-header, .site-footer, .print-tools, .ad-slot, .no-print { display: none !important; }
  main { padding: 0; max-width: none; }
  .sheet { border: 0; box-shadow: none; padding: 0; margin: 0; max-width: none; }
}

/* ---- Small screens ---- */
@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; border-radius: 18px; }
  .play-layout.with-room { grid-template-columns: 1fr; }
  .room-panel { position: static; order: 2; }
  .steps { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .site-header nav .btn span { display: none; }
  .game-card .actions { grid-template-columns: 1fr; }
  .card { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Game versions on pack cards */
.versions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.vchip { font: 800 .85rem var(--font); min-width: 32px; height: 32px; border: 2px solid var(--ink); border-radius: 8px; background: #fff; color: var(--ink); cursor: pointer; padding: 0 8px; }
.vchip.on { background: var(--ink); color: #fff; }
.vchip.new { background: var(--yellow); }
.vchip:disabled { opacity: .6; cursor: wait; }

/* ---- Plus ---- */
.plus-tag { font: 800 .68rem var(--font); background: var(--yellow); border: 1.5px solid var(--ink); border-radius: 999px; padding: 1px 7px; vertical-align: middle; }
.plus-list { text-align: left; margin: 0; padding-left: 1.1em; display: grid; gap: 4px; }
.plus-card { background: #fff8d6; }
.sample-note { margin: 0; background: #fff8d6; border: 2px dashed var(--ink); border-radius: 12px; padding: 8px 12px; font-weight: 700; }
.compare { width: 100%; border-collapse: collapse; font-size: 1rem; }
.compare th, .compare td { padding: 10px 8px; border-bottom: 1.5px solid #e3e1d6; text-align: center; }
.compare th[scope=row] { text-align: left; font-weight: 700; }
.compare thead th { font-family: var(--font-head); font-size: 1.1rem; }
.compare td:last-child { background: #fff8d6; font-weight: 800; }

/* ---- Editor (Plus) ---- */
.edit-layout { display: grid; gap: 14px; margin-top: 18px; }
.edit-tabs { flex-wrap: wrap; }
.ed-list { display: grid; gap: 14px; margin-bottom: 14px; }
.ed-item { border: 2px solid var(--ink); border-radius: 14px; padding: 12px; display: grid; gap: 10px; background: #fff; }
.ed-item-head { display: flex; justify-content: space-between; align-items: center; }
.ed-field { display: grid; gap: 4px; font-weight: 700; font-size: .9rem; }
.ed-field input, .ed-field textarea, .ed-field select, .ed-items4 input, .ed-choice input[type=text] { font-weight: 500; width: 100%; }
.ed-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ed-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ed-choice { display: flex; gap: 6px; align-items: center; }
.ed-right { display: flex; align-items: center; gap: 2px; font-weight: 800; flex: none; }
.ed-group { border-left: 6px solid var(--yellow); padding-left: 10px; display: grid; gap: 6px; }
.ed-group.g1 { border-color: var(--pink); } .ed-group.g2 { border-color: var(--blue); } .ed-group.g3 { border-color: var(--mint); }
.ed-items4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ed-toggles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.ed-toggle { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.ed-save { position: sticky; bottom: 0; display: flex; justify-content: flex-end; align-items: center; gap: 12px; padding: 12px 0 4px; background: linear-gradient(transparent, var(--card, #fff) 30%); }
#panel { display: grid; gap: 12px; }
#panel h2, #panel h3 { margin: 0; }
@media (max-width: 640px) {
  .ed-row, .ed-choices { grid-template-columns: 1fr; }
  .ed-items4 { grid-template-columns: 1fr 1fr; }
}
.socials { margin-top: 6px; }

/* ---- Games fill the screen on phones ---- */
@media (max-width: 700px) {
  .play-page .site-header, .play-page .site-footer { display: none; }
  .play-page main { display: flex; flex-direction: column; min-height: 100dvh; padding: 0 max(8px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right)); }
  .play-page .play-bar { position: sticky; top: 0; z-index: 5; flex-wrap: nowrap; gap: 8px; margin: 0 -8px 8px; padding: max(6px, env(safe-area-inset-top)) 8px 6px; background: var(--paper); border-bottom: 2px solid var(--ink); }
  .play-page .play-bar > div:nth-child(2) { flex: 1; min-width: 0; }
  .play-page .play-bar h1 { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .play-page #pack-title { display: none; }
  .play-page .play-bar .btn { padding: 6px 10px; flex: none; }
  .play-page .play-bar .stats { flex-wrap: nowrap; gap: 4px; }
  .play-page .stat { padding: 2px 7px; font-size: .9rem; border-radius: 8px; }
  .play-page .stat small { font-size: .6rem; }
  .play-page .play-layout { flex: 1; gap: 10px; }
  .play-page .game-root { display: flex; flex-direction: column; }
  .play-page .game-root > .card { flex: 1; padding: 12px; box-shadow: none; border-width: 2px; }
  .play-page .game-root > .intro { margin: 0; max-width: none; align-content: center; }
  /* Per game: bigger Clumped tiles, a tall flashcard */
  .play-page .clumped { align-content: start; width: 100%; }
  .play-page .cl-tile { min-height: 86px; font-size: .88rem; border-radius: 10px; }
  .play-page .cl-tile.long { font-size: .78rem; }
  .play-page .flash { flex: 1; align-content: center; width: 100%; }
  .play-page .fc-card { aspect-ratio: auto; height: min(58dvh, 520px); }
  .play-page .fc-term { font-size: 2.2rem; }
  .play-page .fc-def { font-size: 1.15rem; }
}
.plus-code { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; background: #fff8d6; border: 2px dashed var(--ink); border-radius: 12px; padding: 10px 12px; }
.plus-code span { flex-basis: 100%; }
.plus-code code { font: 700 1.1rem ui-monospace, Consolas, monospace; letter-spacing: .04em; }
