@font-face { font-family: "Andika"; src: url(fonts/Andika-Bold.ttf) format("truetype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Comic Neue"; src: url(fonts/ComicNeue-Bold.ttf) format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --n: 3;                 /* number of slots, set by app.js */
  --gap: 20px;
  --slot: min(190px, 19vh,calc((100vw - 32px - (var(--n) - 1) * var(--gap)) / var(--n)));
  --card: calc(var(--slot) - 20px);
  --card-font: "Andika", "Comic Neue", sans-serif;
  --focus: #1a5fb4;
  --grey: #9a9a9a;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: #fff; color: #111; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  touch-action: manipulation;              /* no double-tap zoom */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
img, svg { -webkit-user-drag: none; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }

.sheet { max-width: 1100px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 16px 24px; }

.progress { position: fixed; top: max(8px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); margin: 0; font-size: 16px; color: #666; }

/* 1. Scene */
.scene { margin: 0 0 16px; display: flex; justify-content: center; }
.scene img { height: clamp(140px, 30vh, 360px); aspect-ratio: 4 / 3; max-width: 100%; object-fit: contain; border: 3px solid #222; display: block; }

/* 2 + 3. Question headers and drop slots */
.board { display: grid; grid-template-columns: repeat(var(--n), var(--slot)); justify-content: center; gap: var(--gap); }
.col { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.qcard {
  width: calc(var(--slot) * .55); aspect-ratio: 1; background: var(--c); border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 4px 2px; font-weight: 700; font-size: calc(var(--slot) * .085); line-height: 1; color: var(--ink, #000);
  text-align: center; overflow-wrap: anywhere;
}
.qcard b { font-size: 1.2em; }
.qcard svg { width: 45%; height: auto; }
.slot {
  width: var(--slot); height: var(--slot); background: #fff; border: 6px solid var(--c); border-radius: 10px;
  display: grid; place-items: center; transition: transform .2s, background-color .2s, box-shadow .3s;
}
.slot.over { background: #f3f3f3; transform: scale(1.04); }
.col.speaking .slot { box-shadow: 0 0 0 5px #fff, 0 0 0 11px var(--c); transform: scale(1.05); }

/* 4. Divider */
.divider { border: 0; border-top: 4px dotted #555; margin: 20px 0; }

/* 5. Card tray and cards */
.tray { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; min-height: calc(var(--card) + 8px); }
.card {
  --c: var(--grey);
  appearance: none; -webkit-appearance: none; margin: 0; font: inherit; color: inherit; background: #fff;
  width: var(--card); height: var(--card); padding: 4px; border: 4px dotted var(--c); border-radius: 12px;
  position: relative; touch-action: none; cursor: grab;
  transition: transform .3s cubic-bezier(.2, .8, .3, 1);
}
.level-3 .card { --c: var(--grey) !important; }   /* no colour clue */
.card-inner { display: grid; grid-template-rows: minmax(0, 1fr) auto; height: 100%; border: 4px solid var(--c); border-radius: 8px; overflow: hidden; }
.card-inner svg, .card-inner img { width: 100%; height: 100%; display: block; object-fit: contain; pointer-events: none; }
.card-text { font-family: var(--card-font); font-weight: 700; font-size: calc(var(--card) * .13); line-height: 1.15; padding: 2px 4px 5px; white-space: nowrap; text-align: center; background: #fff; }
.card.dragging { transition: none; z-index: 50; cursor: grabbing; box-shadow: 0 12px 28px rgba(0, 0, 0, .22); scale: 1.06; }
.card.selected { box-shadow: 0 0 0 4px var(--focus); }

@keyframes bounce { 0% { scale: 1; } 40% { scale: 1.14; } 70% { scale: .95; } 100% { scale: 1; } }
@keyframes wobble { 0%, 100% { rotate: 0deg; } 20% { rotate: -9deg; } 40% { rotate: 8deg; } 60% { rotate: -5deg; } 80% { rotate: 3deg; } }
.card.bounce { animation: bounce .42s ease; }
.card.wobble { animation: wobble .45s ease; }

/* Celebration */
.celebrate { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.celebrate p { margin: 0; font: 700 clamp(28px, 5vw, 44px) var(--card-font); }
.stars span { display: inline-block; margin: 0 6px; font-size: 52px; color: #FFD400; -webkit-text-stroke: 2px #b38900; animation: pop .6s cubic-bezier(.2, 1.6, .4, 1) backwards; }
.stars span:nth-child(2) { animation-delay: .15s; }
.stars span:nth-child(3) { animation-delay: .3s; }
@keyframes pop { from { scale: 0; rotate: -90deg; } }
.next {
  min-height: 84px; min-width: 240px; padding: 0 32px; font: 700 34px var(--card-font); color: #000;
  background: #3AB54A; border: 4px solid #1f7a2c; border-radius: 42px; cursor: pointer;
}

/* Settings gear: press and hold */
.gear {
  position: fixed; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); z-index: 60;
  width: 64px; height: 64px; padding: 6px; border: 0; border-radius: 50%; background: transparent; color: #999;
  touch-action: none; cursor: pointer;
}
.gear svg { width: 100%; height: 100%; }
.gear .ring { stroke-dasharray: 188.5; stroke-dashoffset: 188.5; }
.gear.holding .ring { stroke-dashoffset: 0; transition: stroke-dashoffset 3s linear; }

/* Settings dialog */
dialog { width: min(520px, 92vw); border: 3px solid #222; border-radius: 14px; padding: 20px 24px; }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 12px; }
fieldset { border: 2px solid #ddd; border-radius: 10px; margin: 0 0 12px; padding: 4px 12px 8px; }
fieldset label, .row { display: flex; align-items: center; gap: 12px; min-height: 56px; font-size: 18px; }
.row select { margin-left: auto; font-size: 18px; min-height: 48px; padding: 0 8px; }
input[type=radio], input[type=checkbox] { width: 28px; height: 28px; margin: 0; flex: none; }
.actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; }
.actions button { min-height: 64px; padding: 0 22px; font-size: 18px; border-radius: 10px; border: 2px solid #222; background: #fff; cursor: pointer; }
.actions .primary { background: #222; color: #fff; }
.wide { display: flex; align-items: center; justify-content: center; min-height: 64px; margin-top: 12px; font-size: 18px; color: inherit; text-decoration: none; border: 2px solid #222; border-radius: 10px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .gear.holding .ring { transition: stroke-dashoffset 3s linear !important; }  /* hold progress is feedback, not decoration */
}
