@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

:root {
  --bg: #fff9f0;
  --card: #ffffff;
  --primary: #ff6b35;
  --secondary: #4ecdc4;
  --accent: #ffe66d;
  --purple: #a78bfa;
  --green: #6bcb77;
  --red: #ff4d6d;
  --text: #2d2d2d;
  --muted: #888;
  --shadow: 0 8px 30px rgba(0,0,0,0.12);
  --radius: 20px;
  --opt-bd: #e3ddd3;
  --chip-bg: #fff;
  --chip-on-bg: #fff1e9;
  --chip-on-bd: #ff6b35;
  --key-bg: #fff;
  --key-bd: #eadfce;
  --paper: #fffdf7;
  --paper-line: #d7e6f5;
  --paper-rule: #f4a6a6;
  --pile-back: #f1e7d8;
  --grad-a: rgba(78,205,196,.18);
  --grad-b: rgba(255,230,109,.28);
  --nav-bg: rgba(45,35,25,.78);
  --ovl-bg: rgba(20,15,10,.45);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0c1a;
    --card: #1a1930;
    --text: #eceaf8;
    --muted: #7e7ca0;
    --shadow: 0 8px 30px rgba(0,0,0,0.45);
    --opt-bd: #34325a;
    --chip-bg: #1a1930;
    --chip-on-bg: #3a2530;
    --chip-on-bd: #ff8c5a;
    --key-bg: #24223f;
    --key-bd: #3a3862;
    --paper: #23213d;
    --paper-line: #33315a;
    --paper-rule: #7a3b52;
    --pile-back: #2c2a4c;
    --grad-a: rgba(78,205,196,.10);
    --grad-b: rgba(167,139,250,.12);
    --nav-bg: rgba(0,0,0,.7);
    --ovl-bg: rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  padding: 64px 12px 32px;
  min-height: 100vh;
  font-family: 'Nunito', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 8%, var(--grad-a), transparent 45%),
    radial-gradient(circle at 90% 85%, var(--grad-b), transparent 50%),
    var(--bg);
}
button { font-family: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--secondary); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- nav ---------- */
#nav-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px; background: var(--nav-bg); backdrop-filter: blur(6px);
}
#nav-bar a {
  font-size: .95rem; font-weight: 800; color: #fff; background: rgba(255,255,255,.2);
  border-radius: 12px; padding: 5px 14px; text-decoration: none; white-space: nowrap;
}
#nav-bar a:hover { background: rgba(255,255,255,.35); }
.nav-r { display: flex; align-items: center; gap: 8px; }
#mute-nav { background: rgba(255,255,255,.2); border-radius: 12px; padding: 3px 10px; color: #fff; }

.wrap { max-width: 700px; margin: 0 auto; }
.screen { display: none; }
.screen.active { display: block; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px 20px; text-align: center;
}

/* ---------- menu ---------- */
.title-ico { font-size: 3rem; line-height: 1; }
h1 { font-weight: 900; font-size: 2.1rem; margin: 6px 0 4px; color: var(--primary); }
.sub { font-weight: 700; color: var(--muted); margin: 0 0 20px; }
.btn-primary {
  font-weight: 800; font-size: 1.4rem; color: #fff; border: none; border-radius: 16px;
  padding: 16px 40px; cursor: pointer;
  background: linear-gradient(135deg, var(--primary), #ff8c42);
  box-shadow: 0 4px 15px rgba(255,107,53,.4);
  transition: transform .15s, box-shadow .15s;
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(255,107,53,.5); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .55; cursor: default; }
.btn-secondary {
  font-weight: 700; font-size: 1rem; background: transparent; color: var(--text);
  border: 2px solid var(--opt-bd); border-radius: 12px; padding: 10px 20px; cursor: pointer;
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.sep {
  display: flex; align-items: center; gap: 10px; margin: 26px 0 14px;
  font-weight: 800; color: var(--muted); font-size: .95rem;
}
.sep::before, .sep::after { content: ''; flex: 1; height: 2px; background: var(--opt-bd); }
.btn-help {
  font-weight: 800; font-size: .92rem; background: transparent; border: 2px dashed var(--opt-bd);
  border-radius: 12px; padding: 9px 14px; color: var(--muted); cursor: pointer; width: 100%;
  margin: -4px 0 14px; transition: .15s;
}
.btn-help:hover { border-color: var(--secondary); color: var(--secondary); }
.opt { margin: 0 0 16px; text-align: left; }
.opt-l { font-weight: 700; font-size: .95rem; margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-weight: 800; font-size: 1rem; color: var(--text); background: var(--chip-bg);
  border: 2px solid var(--opt-bd); border-radius: 12px; padding: 9px 16px; cursor: pointer;
  min-height: 44px; transition: border-color .15s, background .15s;
}
.chip.on { background: var(--chip-on-bg); border-color: var(--chip-on-bd); color: var(--primary); }
.chip:disabled { opacity: .35; cursor: default; }
.note { font-weight: 700; font-size: .85rem; color: var(--muted); margin-top: 6px; min-height: 1em; }
.note.warn { color: var(--primary); text-align: center; }

.nav-footer { display: flex; justify-content: center; gap: 12px; margin-top: 20px; flex-wrap: wrap; }
.btn-nav {
  font-weight: 700; font-size: .95rem; background: transparent; border: 2px solid var(--opt-bd);
  border-radius: 12px; padding: 10px 18px; color: var(--muted); cursor: pointer; text-decoration: none;
  transition: border-color .2s, color .2s;
}
.btn-nav:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- game: scorebar + piles ---------- */
.scorebar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 14px; }
.cat-badge {
  font-weight: 900; font-size: .95rem; color: #fff; background: var(--purple);
  border-radius: 10px; padding: 4px 12px;
}
.sb-r { display: flex; align-items: center; gap: 6px; }
.qcnt { font-weight: 800; color: var(--muted); font-size: .95rem; margin-right: 4px; }
.muteb {
  background: transparent; border: none; font-size: 1.35rem; cursor: pointer;
  padding: 4px 6px; border-radius: 10px; line-height: 1;
}

.table { display: grid; grid-template-columns: 64px 1fr 64px; align-items: center; gap: 10px; }
.pile { text-align: center; }
.pile-stack {
  position: relative; width: 48px; height: 58px; margin: 0 auto 4px;
  border-radius: 8px; background: var(--paper); border: 2px solid var(--opt-bd);
  box-shadow: 4px 4px 0 -2px var(--pile-back), 4px 4px 0 0 var(--opt-bd),
              8px 8px 0 -2px var(--pile-back), 8px 8px 0 0 var(--opt-bd);
  display: grid; place-items: center; font-weight: 900; font-size: 1.3rem;
}
.pile-done .pile-stack { color: var(--green); }
.pile-todo .pile-stack { color: var(--primary); }
.pile-l { font-weight: 800; font-size: .75rem; color: var(--muted); }

/* the flashcard: an index card with a red header rule and blue lines */
.fcard {
  position: relative; min-height: 180px; border-radius: 14px; padding: 46px 12px 24px;
  background:
    linear-gradient(var(--paper-rule), var(--paper-rule)) 0 34px / 100% 2px no-repeat,
    repeating-linear-gradient(var(--paper) 0 31px, var(--paper-line) 31px 33px) 0 36px / 100% calc(100% - 36px) no-repeat,
    var(--paper);
  border: 2px solid var(--opt-bd);
  box-shadow: 0 6px 18px rgba(0,0,0,.08);
  display: flex; align-items: center; justify-content: center;
  transition: border-color .2s;
}
.fcard.ok { border-color: var(--green); }
.fcard.bad { border-color: var(--red); }
.q { font-weight: 900; font-size: clamp(2rem, 9vw, 3rem); line-height: 1.2; word-break: break-word; }
.gap {
  display: inline-block; min-width: 1.4em; padding: 0 .12em; margin: 0 .04em;
  border-bottom: 5px dashed var(--secondary); color: var(--primary); text-align: center;
}
.gap.empty { color: var(--muted); opacity: .45; }
.gap:not(.empty):not(.ghost) { min-width: 0; margin: 0; padding: 0; }
.gap.ok { color: var(--green); border-bottom-style: solid; border-color: var(--green); }
.gap.bad { color: var(--red); border-bottom-style: solid; border-color: var(--red); }
.gap.reveal { color: var(--green); border-bottom-style: solid; border-color: var(--red); }
.gap.ghost { color: var(--muted); opacity: .45; }

.fcard.fly { animation: fly .9s ease-in .15s forwards; }
@keyframes fly {
  to { transform: translate(55%, -18%) rotate(8deg) scale(.35); opacity: 0; }
}
.fcard.shake { animation: shake .35s; }
@keyframes shake {
  25% { transform: translateX(-6px); } 75% { transform: translateX(6px); }
}
@media (prefers-reduced-motion: reduce) {
  .fcard.fly { animation: none; }
  .fcard.shake { animation: none; }
  .btn-primary { transition: none; }
}

/* ---------- inputs ---------- */
.pad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  max-width: 320px; margin: 18px auto 0;
}
.key {
  font-weight: 900; font-size: 1.6rem; min-height: 58px; border-radius: 16px;
  background: var(--key-bg); border: 2px solid var(--key-bd); color: var(--text);
  cursor: pointer; touch-action: manipulation;
}
.key:active { transform: translateY(1px); }
.key-del { color: var(--muted); }
.key-ok { color: #fff; border: none; background: linear-gradient(135deg, var(--primary), #ff8c42); font-size: 1.3rem; }
.choices { display: flex; justify-content: center; gap: 14px; margin-top: 18px; }
.choice {
  font-weight: 900; font-size: 2rem; min-width: 120px; min-height: 72px; border-radius: 18px;
  background: var(--key-bg); border: 3px solid var(--key-bd); color: var(--text); cursor: pointer;
  touch-action: manipulation;
}
.choice.ok { border-color: var(--green); color: var(--green); }
.choice.bad { border-color: var(--red); color: var(--red); }
.choice.hint { border-color: var(--green); border-style: dashed; }

.feedback { font-weight: 900; font-size: 1.3rem; min-height: 2rem; margin: 14px 0 8px; }
.feedback.correct { color: var(--green); }
.feedback.wrong { color: var(--red); }
.feedback.copy { color: var(--secondary); }
#btn-next { margin-top: 4px; }

.back-lnk {
  background: none; border: none; color: var(--muted); font-size: .82rem; font-weight: 800;
  cursor: pointer; padding: 6px 8px; margin-top: 10px; display: block; width: 100%; text-align: center;
}
.back-lnk:hover { color: var(--primary); }

/* "Dwa razy dobrze": card answered once, needs a second correct round */
.confirm-tag {
  position: absolute; top: 7px; right: 10px;
  font-weight: 800; font-size: .8rem; color: var(--purple);
  border: 2px solid var(--purple); border-radius: 8px; padding: 0 8px;
}

/* leave guard */
.leave-card { text-align: center; max-width: 400px; }
.leave-text { font-weight: 700; margin: 0 0 20px; line-height: 1.45; }
.leave-btns { display: flex; flex-direction: column; align-items: center; gap: 10px; }

/* ---------- round interstitial ---------- */
.round-panel { padding: 30px 8px 14px; }
.rp-title { font-weight: 900; font-size: 2.4rem; color: var(--purple); margin: 0; }
.rp-text { font-weight: 800; font-size: 1.2rem; margin: 6px 0 22px; }

/* ---------- end ---------- */
.end-ico { font-size: 3.2rem; line-height: 1; }
.end-stars { font-size: 2.2rem; letter-spacing: 4px; margin: 8px 0; }
.end-stats { display: flex; justify-content: center; gap: 12px; margin: 12px 0 18px; flex-wrap: wrap; }
.stat { background: var(--chip-on-bg); border-radius: 14px; padding: 10px 18px; min-width: 120px; }
.stat b { display: block; font-weight: 900; font-size: 1.5rem; color: var(--primary); }
.stat span { font-weight: 700; font-size: .85rem; color: var(--muted); }
.hard-box { text-align: left; margin: 4px 0 18px; }
.hard-box h2 { font-weight: 900; font-size: 1.1rem; margin: 0 0 8px; }
.hard-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.hard-list li {
  font-weight: 800; background: var(--paper); border: 2px solid var(--opt-bd);
  border-radius: 10px; padding: 6px 12px;
}
.end-btns { display: flex; flex-direction: column; align-items: center; gap: 10px; }

/* ---------- help overlay ---------- */
.ovl {
  position: fixed; inset: 0; z-index: 2000; display: none; align-items: center; justify-content: center;
  background: var(--ovl-bg); padding: 16px;
}
.ovl.show { display: flex; }
.ovl-card {
  position: relative; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  max-width: 520px; width: 100%; max-height: 90vh; overflow: auto; padding: 24px 22px; text-align: left;
}
.ovl-x {
  position: absolute; top: 10px; right: 10px; background: none; border: none; font-size: 1.3rem;
  color: var(--muted); cursor: pointer; padding: 6px 10px;
}
.ovl-h { font-weight: 900; font-size: 1.5rem; margin: 0 0 10px; }
.ovl-list { padding-left: 20px; margin: 0 0 14px; font-weight: 600; line-height: 1.5; }
.ovl-sub { font-weight: 900; margin: 6px 0 6px; }
.ovl-table { width: 100%; border-collapse: collapse; margin-bottom: 18px; font-weight: 700; }
.ovl-table td { padding: 5px 4px; border-bottom: 1px solid var(--opt-bd); }
.ovl-table td:last-child { text-align: right; }
.ovl-card .btn-primary { display: block; margin: 0 auto; font-size: 1.2rem; padding: 12px 32px; }

@media (max-width: 520px) {
  .card { padding: 20px 14px; }
  .table { grid-template-columns: 1fr 1fr; grid-template-areas: 'todo done' 'card card'; gap: 10px; }
  .pile-todo { grid-area: todo; }
  .pile-done { grid-area: done; }
  .fcard { grid-area: card; }
  .pile { display: flex; align-items: center; justify-content: center; gap: 10px; }
  .pile-stack { width: 34px; height: 40px; margin: 0; font-size: 1rem; }
  .pile-l { font-size: .85rem; }
  .choice { min-width: 104px; }
}
