:root {
  --aqua: #27c4ea;
  --pool: #0e86d0;
  --blue: #1d4ed8;
  --deep: #082a6b;
  --yellow: #ffe66d;
  --ink: #0b1b3f;
  --muted: #546a92;
  --line: #d3e1f7;
  --tint: #edf5ff;
  --good: #128a4b;
  --good-bg: #e0f6ea;
  --bad: #c4332b;
  --bad-bg: #fde7e4;
  --radius: 20px;
  --shadow: 0 18px 40px rgba(3, 24, 74, 0.35);
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #0a3d94;
}

/* ================= swimming pool backdrop ================= */
.pool {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(180deg, #0e86d0 0%, #0b66c4 38%, #0a45a0 72%, #082a6b 100%);
}

/* drifting patches of light, like sun on the water */
.caustic { position: absolute; inset: -25%; opacity: 0.55; will-change: transform; }
.c1 {
  background:
    radial-gradient(40% 22% at 20% 25%, rgba(255,255,255,.30), transparent 70%),
    radial-gradient(32% 18% at 70% 15%, rgba(255,255,255,.24), transparent 70%),
    radial-gradient(36% 20% at 55% 60%, rgba(120,225,255,.24), transparent 70%),
    radial-gradient(30% 16% at 15% 80%, rgba(255,255,255,.20), transparent 70%);
  animation: drift1 22s ease-in-out infinite alternate;
}
.c2 {
  background:
    radial-gradient(34% 18% at 80% 40%, rgba(255,255,255,.22), transparent 70%),
    radial-gradient(38% 20% at 30% 55%, rgba(120,225,255,.22), transparent 70%),
    radial-gradient(28% 15% at 85% 85%, rgba(255,255,255,.18), transparent 70%);
  animation: drift2 28s ease-in-out infinite alternate;
}
@keyframes drift1 { to { transform: translate3d(6%, 4%, 0) scale(1.08) rotate(2deg); } }
@keyframes drift2 {
  from { transform: translate3d(5%, -3%, 0) scale(1.05); }
  to   { transform: translate3d(-6%, 5%, 0) scale(1.12) rotate(-2deg); }
}

/* slanted light shafts */
.rays {
  position: absolute;
  left: -10%; right: -10%; top: 0; bottom: 0;
  background: repeating-linear-gradient(105deg, rgba(255,255,255,.08) 0 3%, transparent 3% 12%);
  -webkit-mask-image: linear-gradient(180deg, #000, transparent 65%);
  mask-image: linear-gradient(180deg, #000, transparent 65%);
  animation: sway 14s ease-in-out infinite alternate;
  will-change: transform;
}
@keyframes sway { to { transform: translateX(5%); } }

/* tiled pool floor in perspective */
.floor {
  position: absolute;
  left: -60%; right: -60%; bottom: -8%;
  height: 55%;
  background:
    linear-gradient(rgba(255,255,255,.11) 2px, transparent 2px) 0 0 / 72px 72px,
    linear-gradient(90deg, rgba(255,255,255,.11) 2px, transparent 2px) 0 0 / 72px 72px;
  transform: perspective(520px) rotateX(64deg);
  transform-origin: 50% 100%;
  -webkit-mask-image: linear-gradient(to top, #000 5%, transparent 90%);
  mask-image: linear-gradient(to top, #000 5%, transparent 90%);
}

.bubble {
  position: absolute;
  bottom: -60px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,.85), rgba(255,255,255,.15) 45%, rgba(255,255,255,.05) 70%);
  border: 1px solid rgba(255,255,255,.35);
  opacity: 0;
  will-change: transform;
  animation: rise var(--d, 16s) linear infinite;
  animation-delay: var(--delay, 0s);
}
@keyframes rise {
  0%   { transform: translate3d(0, 0, 0) scale(.8); opacity: 0; }
  10%  { opacity: .85; }
  50%  { transform: translate3d(var(--sway, 20px), -55vh, 0) scale(1); }
  90%  { opacity: .5; }
  100% { transform: translate3d(calc(var(--sway, 20px) * -1), -110vh, 0) scale(1.1); opacity: 0; }
}

/* ================= header ================= */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.brand {
  font-family: var(--serif);
  font-size: clamp(2rem, 7vw, 2.6rem);
  font-weight: 700;
  line-height: 1;
  color: #fff;
  text-decoration: none;
  letter-spacing: -0.03em;
  /* stacked shadows give the letters a solid, extruded 3D look */
  text-shadow:
    0 1px 0 #7fd3ff,
    0 3px 0 #0b57b5,
    0 5px 0 #0a3f8c,
    0 12px 18px rgba(2, 18, 60, 0.45);
  transition: transform 0.2s ease;
}
.brand:hover { transform: translateY(-2px) rotate(-1deg); }

.streak {
  font-size: 0.88rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border: 1.5px solid rgba(255, 255, 255, 0.4);
  white-space: nowrap;
}
.streak b { color: var(--yellow); }

/* ================= layout ================= */
main {
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 8px 20px 40px;
  outline: none;
}

h1, h2 {
  font-family: var(--serif);
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 0;
}

/* every new screen swings in from slightly tilted back */
.screen { animation: screenIn 0.5s cubic-bezier(.2,.8,.2,1) backwards; transform-origin: 50% 0; }
@keyframes screenIn {
  from { opacity: 0; transform: perspective(1000px) rotateX(-9deg) translateY(18px); }
}

.hero { padding: 24px 0 22px; color: #fff; }
.hero h1 { font-size: clamp(2.2rem, 8vw, 3.8rem); text-shadow: 0 6px 20px rgba(2,18,60,.35); }
.hero h1 em { font-style: italic; color: var(--yellow); white-space: nowrap; }
.hero p { color: rgba(255,255,255,.9); max-width: 46ch; margin: 14px 0 0; font-size: 1.05rem; }

.group-head { color: #fff; margin: 0 0 14px; }
.group-head h2 { font-size: clamp(1.4rem, 5vw, 1.8rem); text-shadow: 0 4px 14px rgba(2,18,60,.35); }
.group-head p { margin: 6px 0 0; color: rgba(255,255,255,.88); font-size: .98rem; max-width: 52ch; }

.grid { display: grid; gap: 16px; }
@media (min-width: 700px) { .grid { grid-template-columns: 1fr 1fr; } }

/* lane rope divider */
.rope {
  position: relative;
  height: 16px;
  margin: 36px 0 28px;
  border-radius: 99px;
  background: repeating-linear-gradient(90deg, #e8384f 0 28px, #fff 28px 56px, #1d4ed8 56px 84px, #fff 84px 112px);
  box-shadow: 0 6px 12px rgba(2, 18, 60, 0.35);
  animation: bob 4.5s ease-in-out infinite;
}
.rope::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255,255,255,.55), rgba(255,255,255,0) 40%, rgba(0,0,40,.28));
}
@keyframes bob { 50% { transform: translateY(3px); } }

/* white tiles */
.slide, .card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow), inset 0 -4px 0 #d6e4fb;
}
.slide { padding: 22px; }
.card { padding: 18px; }

/* 3D tilt (pointer position sets --rx/--ry from app.js) and entrance */
.tilt {
  transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateY(var(--ty, 0px));
  transition: transform 0.15s ease-out, box-shadow 0.2s ease;
  animation: dealIn 0.65s cubic-bezier(.2,.8,.2,1) backwards;
  animation-delay: calc(var(--i, 0) * 80ms);
}
.tilt:hover { --ty: -4px; }
.tilt:active { transform: perspective(900px) scale(.98); }
@keyframes dealIn {
  from { opacity: 0; transform: perspective(900px) rotateX(-22deg) translateY(30px) scale(.96); }
}

.qcard { display: flex; flex-direction: column; gap: 6px; border-top: 6px solid var(--aqua); }
.qcard h2 { font-size: 1.35rem; color: var(--deep); }
.qcard p { margin: 0; color: var(--muted); font-size: .95rem; }
.qcard .meta { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; font-size: .85rem; color: var(--muted); }
.qcard .actions { margin-top: auto; padding-top: 14px; }

.tiles { display: grid; gap: 16px; }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile {
  appearance: none;
  border: 0;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow), inset 0 -4px 0 #d6e4fb;
}
.tile .ico {
  width: 48px; height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--aqua), var(--blue));
  box-shadow: 0 8px 16px rgba(29, 78, 216, 0.4);
}
.tile b { font-family: var(--serif); font-size: 1.35rem; color: var(--deep); }
.tile .sub { color: var(--muted); font-size: .92rem; }

/* ================= buttons ================= */
.btn {
  appearance: none;
  border: 2px solid var(--blue);
  background: #fff;
  color: var(--blue);
  font: inherit;
  font-weight: 700;
  padding: 11px 18px;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 4px 0 #b9cdf3;
  transition: transform .08s ease, box-shadow .08s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #b9cdf3; }
.btn.accent { background: var(--blue); border-color: var(--blue); color: #fff; box-shadow: 0 4px 0 var(--deep); }
.btn.accent:hover { background: #2559e6; }
.btn.accent:active { box-shadow: 0 1px 0 var(--deep); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; box-shadow: 0 4px 0 #0a5d32; }
.btn.warn { background: #fff; border-color: #e0792b; color: #b4560f; box-shadow: 0 4px 0 #f1c9a6; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }

.btn:focus-visible, .opt:focus-visible, .brand:focus-visible, .tile:focus-visible,
.pill:focus-visible, .linkbtn:focus-visible, .flip:focus-visible, .search:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
}
.slide .btn:focus-visible, .slide .opt:focus-visible, .slide .pill:focus-visible,
.slide .linkbtn:focus-visible, .card .btn:focus-visible, .slide .flip:focus-visible,
.card .tile:focus-visible, .slide .search:focus-visible {
  outline-color: var(--blue);
}

.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

.linkbtn {
  appearance: none; background: none; border: 0; padding: 4px 2px;
  font: inherit; font-weight: 700; color: var(--blue); cursor: pointer;
}
.linkbtn:hover { text-decoration: underline; }

/* ================= quiz ================= */
.qhead {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  font-size: .9rem; color: var(--muted); margin: 0 0 10px; font-weight: 600;
}
.qhead-r { display: flex; align-items: center; gap: 14px; }
.bar { height: 10px; background: var(--tint); border-radius: 99px; overflow: hidden; }
.bar > i {
  display: block; height: 100%; width: 0; border-radius: 99px;
  background: linear-gradient(90deg, var(--aqua), var(--blue));
  transition: width .3s ease;
}

.qlabel { margin: 22px 0 0; font-size: .85rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.prompt {
  font-family: var(--serif);
  font-size: clamp(1.4rem, 5vw, 1.9rem);
  line-height: 1.25;
  margin: 24px 0 18px;
  color: var(--ink);
}
.qlabel + .prompt { margin-top: 8px; }

.opts { display: grid; gap: 10px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%;
  font: inherit; color: var(--ink); background: #fff;
  border: 2px solid var(--line); border-radius: 14px; padding: 14px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--line);
  transition: border-color .12s ease, background .12s ease, transform .08s ease, box-shadow .08s ease;
}
.opt:hover:not([disabled]) { border-color: var(--blue); background: var(--tint); }
.opt:active:not([disabled]) { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.opt .k {
  flex: none; width: 28px; height: 28px; border-radius: 8px; background: var(--tint);
  display: grid; place-items: center; font-size: .82rem; font-weight: 700; color: var(--blue);
}
.opt[disabled] { cursor: default; box-shadow: none; transform: translateY(2px); }
.opt.right { border-color: var(--good); background: var(--good-bg); animation: pop .35s ease; }
.opt.right .k { background: var(--good); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); animation: shake .35s ease; }
.opt.wrong .k { background: var(--bad); color: #fff; }
@keyframes pop { 40% { transform: translateY(2px) scale(1.025); } }
@keyframes shake { 25% { transform: translate(-5px, 2px); } 60% { transform: translate(4px, 2px); } }

.why {
  margin-top: 16px; padding: 14px; border-radius: 12px; background: var(--tint);
  border-left: 5px solid var(--blue); font-size: .95rem; white-space: pre-line;
  animation: fadeUp .3s ease;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } }
.why strong { display: block; margin-bottom: 2px; }
.why.good { border-left-color: var(--good); }
.why.good strong { color: var(--good); }
.why.bad { border-left-color: var(--bad); }
.why.bad strong { color: var(--bad); }

/* ================= results ================= */
.score { text-align: center; padding: 34px 22px 26px; }
.score .big { font-family: var(--serif); font-size: clamp(3.5rem, 18vw, 6rem); line-height: 1; letter-spacing: -.04em; color: var(--blue); }
.score .big small { font-size: .4em; color: var(--muted); letter-spacing: 0; }
.score p { color: var(--muted); margin: 10px 0 0; }
.score .row { justify-content: center; }

.missed { margin-top: 28px; }
.missed h2 { font-size: 1.3rem; margin-bottom: 12px; color: #fff; text-shadow: 0 4px 14px rgba(2,18,60,.35); }
.missed .card { margin-bottom: 12px; padding: 16px; }
.missed .q { font-weight: 700; margin-bottom: 6px; color: var(--deep); }
.missed .a { color: var(--good); font-size: .95rem; font-weight: 600; }
.missed .y { color: var(--bad); font-size: .95rem; }
.missed .e { color: var(--muted); font-size: .9rem; margin-top: 4px; white-space: pre-line; }

/* ================= setup ================= */
.setup h2 { font-size: 1.7rem; color: var(--deep); margin: 8px 0 4px; }
.setup .lead { margin: 0 0 18px; color: var(--muted); }
.setup .label { font-weight: 700; font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.setup .label .linkbtn { text-transform: none; letter-spacing: 0; font-size: .9rem; }

.chips { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.chip {
  position: relative; display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border: 2px solid var(--line); border-radius: 14px; background: #fff;
  font-weight: 600; cursor: pointer; transition: border-color .12s ease, background .12s ease;
}
.chip input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.chip .box::after { content: "\2713"; }
.chip .box {
  flex: none; width: 22px; height: 22px; border-radius: 7px; border: 2px solid #9db6e0;
  display: grid; place-items: center; color: transparent; font-size: 14px; line-height: 1;
}
.chip input:checked ~ .box { background: var(--blue); border-color: var(--blue); color: #fff; }
.chip:has(input:checked) { border-color: var(--blue); background: var(--tint); }
.chip:has(input:focus-visible) { outline: 3px solid var(--blue); outline-offset: 2px; }
.chip small { margin-left: auto; color: var(--muted); font-weight: 500; }

.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  appearance: none; font: inherit; font-weight: 700; cursor: pointer; color: var(--ink);
  background: #fff; border: 2px solid var(--line); border-radius: 99px; padding: 8px 18px;
  transition: background .12s ease, border-color .12s ease;
}
.pill:hover { border-color: var(--blue); }
.pill[aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: #fff; }

.summary { margin: 20px 0 0; color: var(--muted); font-size: .95rem; }
.warning { color: var(--bad); font-weight: 600; margin: 10px 0 0; }

/* ================= flashcards ================= */
.stage { perspective: 1400px; margin: 18px 0 8px; }
.flip {
  appearance: none; display: block; width: 100%; padding: 0; border: 0; background: none;
  font: inherit; color: inherit; text-align: center; cursor: pointer; border-radius: var(--radius);
}
.flip-inner {
  display: grid;
  transform-style: preserve-3d;
  transition: transform .65s cubic-bezier(.3,.7,.2,1);
}
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.face {
  grid-area: 1 / 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  min-height: 300px; padding: 28px 22px;
  background: linear-gradient(180deg, #fff, #f1f7ff);
  border-radius: var(--radius);
  border: 2px solid var(--line);
  box-shadow: 0 14px 30px rgba(3, 24, 74, .22), inset 0 -5px 0 #d6e4fb;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
}
.face.back { transform: rotateY(180deg); background: linear-gradient(180deg, #f1f7ff, #e3efff); }
.fc-term { font-family: var(--serif); font-size: clamp(1.8rem, 7vw, 2.6rem); line-height: 1.15; color: var(--deep); }
.fc-hint { color: var(--muted); font-size: .88rem; }
.fc-def { font-size: 1.15rem; font-weight: 600; color: var(--ink); }
.fc-tr { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.fc-tr span { background: #fff; border: 1.5px solid var(--line); border-radius: 12px; padding: 6px 12px; font-size: .95rem; }
.fc-tr b { font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-right: 6px; }
.fc-ex { font-style: italic; color: #2b3a63; font-size: .98rem; max-width: 46ch; }

.tag {
  display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--blue); background: var(--tint); border: 1.5px solid var(--line); border-radius: 99px; padding: 3px 10px;
}

.fc-nav { display: flex; gap: 10px; justify-content: space-between; margin-top: 16px; }
.fc-mark { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.keyhint { margin: 14px 0 0; color: var(--muted); font-size: .8rem; text-align: center; }
@media (max-width: 640px) { .keyhint { display: none; } }

.stats { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 18px 0 8px; }
.stats div { min-width: 96px; padding: 10px 16px; border-radius: 16px; background: var(--tint); color: var(--muted); font-size: .85rem; }
.stats b { display: block; font-size: 1.8rem; font-family: var(--serif); color: var(--ink); }
.stats .g b { color: var(--good); }
.stats .s b { color: #b4560f; }

/* ================= vocabulary list ================= */
.vhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.vhead .count { color: var(--muted); font-size: .9rem; font-weight: 600; }
.search {
  width: 100%; margin: 12px 0 0; font: inherit; padding: 13px 14px;
  border: 2px solid var(--line); border-radius: 14px; background: #fff; color: var(--ink);
}
.vlist { display: grid; gap: 14px; margin-top: 18px; }
.vitem { content-visibility: auto; contain-intrinsic-size: auto 170px; }
.vitem-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.vterm { font-family: var(--serif); font-size: 1.25rem; font-weight: 700; color: var(--deep); }
.vdef { margin: 4px 0 8px; }
.vtr { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: .92rem; color: #2b3a63; }
.vtr b { font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-right: 6px; }
.vex { margin: 8px 0 0; font-style: italic; color: var(--muted); font-size: .93rem; }
.vempty { text-align: center; color: #fff; padding: 24px 0 8px; font-weight: 600; }

/* ================= footer ================= */
.foot { text-align: center; color: rgba(255,255,255,.9); font-size: .85rem; padding: 18px 20px 28px; }
.foot p { margin: 0; }
.noscript { padding: 20px; text-align: center; color: #fff; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .tilt { transform: none; }
}
