/* Shared lesson player: page frame, progress, games, start screen. Colours come from the variables on :root;
   a topic changes them in its own topic.css. Everything sits in the "core" layer, so any rule in a topic.css wins. */
@layer core {
  :root {
    --bg: #f3f8ec;
    --card: #ffffff;
    --ink: #26303a;
    --muted: #6d7a72;
    --accent: #ff7a59;
    --accent-ink: #ffffff;
    --blue: #3b82f6;
    --green: #22a06b;
    --yellow: #ffd166;
    --purple: #8b5cf6;
    --red: #e5484d;
    --line: #dbe6cf;
    /* soft tints used by boxes, chips, hover and the progress dots */
    --tint: #fbfdf7;
    --chip: #e9f4dc;
    --hover: #f6fbef;
    --done: #bcd3a5;
    --star-off: #c3d2b3;
    --topic-bg: var(--green);
  }
  * { box-sizing: border-box; }
  [hidden] { display: none !important; }
  html, body { height: 100%; margin: 0; }
  body {
    background: var(--bg);
    color: var(--ink);
    font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Comic Sans MS", system-ui, sans-serif;
    display: flex;
    flex-direction: column;
    -webkit-tap-highlight-color: transparent;
  }

  header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
  }
  .topic {
    font-weight: 800; color: #fff; background: var(--topic-bg); font-size: 15px; white-space: nowrap;
    border-radius: 999px; padding: 4px 14px;
  }
  .dots { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; justify-content: center; }
  .dot {
    width: 11px; height: 11px; border-radius: 50%;
    background: var(--line); border: 0; padding: 0; cursor: pointer;
    transition: transform .15s, background .15s;
  }
  .dot.first { margin-left: 9px; }
  .dot.done { background: var(--done); }
  .dot.now { background: var(--accent); transform: scale(1.45); }
  /* a slide with a puzzle is drawn as a star: grey until the star is won */
  .dot.puzzle, .dot.puzzle.done, .dot.puzzle.now {
    background: none; width: auto; height: 11px; border-radius: 0;
    font-size: 17px; line-height: 11px; color: var(--star-off);
  }
  .dot.puzzle.star { color: #f2a900; }
  .dot.puzzle.now { color: var(--accent); }
  .stars {
    font-weight: 800; font-size: 17px; white-space: nowrap;
    background: #fff; border: 2px solid var(--yellow); border-radius: 999px; padding: 3px 12px;
  }
  .stars.bump { animation: bump .5s; }
  @keyframes bump { 40% { transform: scale(1.5) rotate(-6deg); } }
  .counter { color: var(--muted); font-weight: 700; font-size: 15px; white-space: nowrap; }

  main {
    flex: 1;
    min-height: 0;
    display: flex;
    justify-content: center;
    padding: 0 16px;
  }
  .card {
    background: var(--card);
    border: 3px solid var(--line);
    border-radius: 28px;
    width: min(1100px, 100%);
    padding: 18px 30px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .card h1 {
    font-size: clamp(24px, 3.4vw, 38px);
    margin: 0 0 10px;
    line-height: 1.15;
  }
  .body {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    font-size: clamp(18px, 2.3vw, 27px);
    line-height: 1.4;
  }
  .body.dense { font-size: clamp(16px, 1.9vw, 22px); gap: 10px; }
  .body p { margin: 0; }

  /* --- games ------------------------------------------------------------ */
  .game { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
  .opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; width: min(820px, 100%); }
  .opts.one { grid-template-columns: 1fr; width: min(640px, 100%); }
  .opts.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .opt {
    font: inherit; font-weight: 700; color: var(--ink); cursor: pointer;
    background: #fff; border: 3px solid var(--line); border-radius: 18px; padding: 12px 16px;
    box-shadow: 0 5px 0 var(--line); transition: transform .05s, box-shadow .05s, background .15s;
  }
  .opt:hover { background: var(--hover); }
  .opt:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--line); }
  .opt.good { background: #e3f7ec; border-color: var(--green); box-shadow: 0 5px 0 #8fd0b1; }
  .opt.bad { background: #ffe9e9; border-color: var(--red); box-shadow: none; opacity: .6; animation: shake .35s; cursor: default; }
  .game.solved .opt:not(.good) { display: none; }
  .game.solved .opts { grid-template-columns: 1fr; width: auto; }
  @keyframes shake { 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }
  .shake { animation: shake .35s; }

  .fb { border-radius: 18px; padding: 10px 18px; font-size: .86em; max-width: 900px; width: 100%; }
  .fb[hidden] { display: none; }
  .fb.no { background: #fff0e6; border: 3px solid #ffc9a8; font-weight: 700; }
  .fb.ok { background: #f0fbf5; border: 3px solid var(--green); display: flex; flex-direction: column; gap: 8px; align-items: center; }
  .fb .fbhead { font-weight: 800; color: var(--green); }
  .fb .split .fig img { max-height: min(26vh, 230px); }
  .fb .split > .txt { align-items: flex-start; text-align: left; }

  .sort { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
  .sort .item {
    border: 3px solid var(--line); border-radius: 22px; background: var(--tint); padding: 12px 26px;
    font-weight: 800; font-size: 1.2em; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 300px;
  }
  .sort .item img { max-height: min(26vh, 230px); max-width: 100%; border-radius: 14px; display: block; }
  .sort .item .emo { font-size: 2.2em; line-height: 1.1; }
  .sort .prog { font-size: .7em; color: var(--muted); font-weight: 700; }
  .sort .bins { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
  .sort .bins .opt { min-width: 190px; }
  .sort .why { font-size: .86em; font-weight: 700; color: var(--green); min-height: 1.4em; }
  .sort .why.no { color: var(--accent); }

  .ask { font-weight: 700; margin: 0; }
  .ask { font-weight: 700; margin: 0; }
  .emo { font-size: 1.6em; line-height: 1.1; }
  .yr { font-weight: 800; font-size: 1.5em; line-height: 1.15; }
  .item small, .opt small { display: block; font-weight: 700; font-size: .68em; color: var(--muted); line-height: 1.25; }
  .ropts { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
  .ropts .opt { min-width: 150px; font-size: 1.05em; }
  .ropts.locked .opt:not(.good) { opacity: .45; cursor: default; }
  .game.solved .prog { display: none; }
  .duel .item { border: 0; background: none; padding: 0; min-width: 0; font-size: 1em; }
  .duel .ropts .opt, .opt.card {
    min-width: 230px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 18px;
  }

  .ord-cards { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; min-height: 1em; width: 100%; }
  .opt.card { min-width: 150px; flex: 0 1 190px; font-size: .9em; padding: 10px 8px; }
  .opt.card .yr { font-size: 1.1em; }
  .ord-line {
    display: flex; align-items: center; gap: 10px; width: 100%; min-height: 3.6em;
    border-bottom: 5px solid var(--ink); padding: 0 6px 8px; font-size: .78em;
  }
  .ord-end { font-weight: 800; color: var(--muted); white-space: nowrap; }
  .ord-slots { flex: 1; display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
  .ord-slots span {
    background: #e3f7ec; border: 3px solid var(--green); border-radius: 14px; padding: 2px 12px; font-weight: 800;
    display: flex; flex-direction: column; line-height: 1.25; animation: pop .3s;
  }
  .ord-slots span.bce { background: #f5f0ff; border-color: var(--purple); }
  .ord-slots small { font-weight: 700; color: var(--muted); font-size: .8em; }
  @keyframes pop { from { transform: scale(.5); opacity: 0; } }
  .missions { display: flex; flex-direction: column; gap: 8px; width: 100%; text-align: left; font-size: .76em; line-height: 1.3; }
  .mis {
    display: flex; gap: 12px; align-items: flex-start; cursor: pointer;
    border: 3px solid var(--line); border-radius: 16px; padding: 7px 14px; background: var(--tint);
  }
  .mis input { width: 1.5em; height: 1.5em; flex: none; margin: .1em 0 0; accent-color: var(--green); }
  .mis:has(input:checked) { border-color: var(--green); background: #f0fbf5; }
  .mis b { display: block; }
  .mis span { color: var(--muted); }

  .rank { font-size: 1.5em; font-weight: 800; }
  .meter { width: min(520px, 90%); height: 22px; background: var(--line); border-radius: 999px; overflow: hidden; }
  .meter > i { display: block; height: 100%; background: var(--yellow); border-radius: 999px; }

  /* --- start screen, toast, confetti ------------------------------------ */
  .start {
    position: fixed; inset: 0; z-index: 10; background: var(--bg);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
    text-align: center; padding: 24px; overflow: auto;
  }
  .start[hidden] { display: none; }
  .start h2 { font-size: clamp(28px, 5vw, 50px); margin: 0; }
  .start .nav { font-size: 30px; padding: 18px 46px; }
  .levels { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 900px; }
  .levels button {
    font: inherit; font-weight: 700; font-size: 16px; color: var(--ink); cursor: pointer;
    background: #fff; border: 3px solid var(--line); border-radius: 16px; padding: 8px 14px;
  }
  .levels button:hover { border-color: var(--accent); }
  .levels button small { display: block; color: var(--muted); font-size: 13px; }
  .levels button.full { border-color: var(--yellow); background: #fffbea; }

  .toast {
    position: fixed; left: 50%; top: 38%; z-index: 9; transform: translate(-50%, -50%) scale(.6); opacity: 0;
    background: var(--topic-bg); color: #fff; font-weight: 800; font-size: clamp(22px, 3.5vw, 40px);
    border-radius: 28px; padding: 18px 40px; pointer-events: none; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.2);
  }
  .toast small { display: block; font-size: .5em; letter-spacing: .12em; opacity: .9; }
  .toast.show { animation: toast 1.7s ease-out; }
  @keyframes toast {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(.6); }
    15%, 75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
  }
  .confetti { position: fixed; z-index: 8; pointer-events: none; font-size: 30px; animation: fly 1.1s ease-out forwards; }
  @keyframes fly { to { transform: translate(var(--dx), var(--dy)) rotate(var(--r)); opacity: 0; } }

  .caption {
    width: min(1100px, 100%);
    margin: 10px auto 0;
    padding: 0 24px;
    color: var(--muted);
    font-size: 18px;
    line-height: 1.4;
    text-align: center;
    min-height: 1.4em;
  }
  .caption[hidden] { display: none; }

  footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 14px 16px 18px;
  }
  button.nav {
    font: inherit;
    font-size: 22px;
    font-weight: 800;
    border: 0;
    border-radius: 999px;
    padding: 14px 30px;
    cursor: pointer;
    background: var(--accent);
    color: var(--accent-ink);
    box-shadow: 0 5px 0 #d95c3e;
    transition: transform .05s, box-shadow .05s, opacity .15s;
  }
  button.nav:active { transform: translateY(4px); box-shadow: 0 1px 0 #d95c3e; }
  button.nav:disabled { opacity: .35; cursor: default; }
  button.nav.soft { background: #fff; color: var(--ink); box-shadow: 0 5px 0 var(--line); border: 3px solid var(--line); }
  button.nav.soft:active { box-shadow: 0 1px 0 var(--line); }
  button.nav.go { animation: pulse 1s infinite; }
  /* small controls; "mini" is the header button, so that a topic's own .small text style cannot touch it */
  button.small, button.mini {
    font: inherit; font-size: 15px; font-weight: 700;
    border: 2px solid var(--line); background: transparent; color: var(--muted);
    border-radius: 999px; padding: 6px 14px; cursor: pointer;
  }
  button.small[aria-pressed="true"], button.mini[aria-pressed="true"] { background: var(--yellow); color: var(--ink); border-color: var(--yellow); }
  .speaking #replay { animation: pulse 1s infinite; }
  @keyframes pulse { 50% { transform: scale(1.06); } }


  /* --- site links ---------------------------------------------------------- */
  .home {
    text-decoration: none; font-size: 20px; line-height: 1; border-radius: 999px; padding: 5px 9px;
    border: 2px solid var(--line); background: #fff;
  }
  .home:hover { border-color: var(--accent); }
  .start-emoji { font-size: 84px; line-height: 1; }
  .start .back { color: var(--muted); font-weight: 700; font-size: 16px; }

  @media (max-width: 700px) {
    .topic, .counter { display: none; }
    header { padding: 10px 12px; gap: 8px; }
    .dot { width: 7px; height: 7px; }
    .dot.puzzle, .dot.puzzle.done, .dot.puzzle.now { height: 7px; line-height: 7px; font-size: 12px; }
    .dots { gap: 3px; }
    .dot.first { margin-left: 5px; }
    main { padding: 0 8px; }
    .card { padding: 14px 12px; border-radius: 20px; }
    .opts, .opts.three { grid-template-columns: 1fr; }
    .duel .ropts .opt, .opt.card { min-width: 0; flex: 1 1 130px; }
    .ord-line { flex-wrap: wrap; }
    footer { gap: 8px; padding: 12px 8px 14px; }
    button.nav { font-size: 16px; padding: 12px 14px; }
  }
}
