/* Layout for the games engine (js/game.js).

   Structure only — sizes, grids, the flip animation, the feedback states.
   Colour and personality come from the page's own skin, which is why every
   colour here reads a --g-* variable the page defines. The kids page wants
   loud and round; a JLPT page will want the Bee & Honey tokens. */

:root {
  --g-bg: #fff;
  --g-surface: #f4f4f5;
  --g-line: #d4d4d8;
  --g-ink: #18181b;
  --g-ink-soft: #52525b;
  --g-accent: #f59e0b;
  --g-accent-2: #6366f1;
  --g-right: #16a34a;
  --g-wrong: #dc2626;
  --g-radius: 18px;
}

.game-wrap { max-width: 900px; margin: 0 auto; padding: 18px 16px 60px; }
.view { display: none; }
.view.active { display: block; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- content picker ---------- */
.pick-head h2 { margin: 0 0 4px; font-size: 22px; }
.pick-head p { margin: 0 0 16px; color: var(--g-ink-soft); font-size: 14px; }
.pick-actions { display: flex; gap: 8px; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--g-line); background: var(--g-bg); border-radius: 999px;
  padding: 7px 15px; font-size: 13px; font-weight: 600;
}
.chip:hover { border-color: var(--g-accent); }

.pick-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
}
.pick-card {
  position: relative; display: flex; flex-direction: column; align-items: center;
  gap: 6px; padding: 12px 8px 10px; background: var(--g-bg);
  border: 2px solid var(--g-line); border-radius: var(--g-radius);
  transition: border-color .15s ease, transform .1s ease;
}
.pick-card:hover { border-color: var(--g-accent); }
.pick-card:active { transform: scale(.97); }
.pick-card img { width: 56px; height: 56px; object-fit: contain; }
.pick-title { font-size: 13px; font-weight: 700; text-align: center; line-height: 1.25; }
.pick-count { font-size: 11px; color: var(--g-ink-soft); }
.pick-tick {
  position: absolute; top: 6px; right: 8px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--g-accent); color: var(--k-white);
  font-size: 13px; font-weight: 700; display: flex; align-items: center;
  justify-content: center; opacity: 0; transition: opacity .15s ease;
}
.pick-card.is-on { border-color: var(--g-accent); background: var(--g-surface); }
.pick-card.is-on .pick-tick { opacity: 1; }

.pick-foot {
  position: sticky; bottom: 0; margin-top: 18px; padding: 14px 0 10px;
  background: linear-gradient(to top, var(--g-bg) 70%, transparent);
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.pick-sum { font-size: 13px; color: var(--g-ink-soft); }
.btn-go {
  background: var(--g-accent); color: var(--k-white); border: none;
  border-radius: 999px; padding: 14px 34px; font-size: 17px; font-weight: 800;
}
.btn-go:disabled { opacity: .4; cursor: default; }
.btn-plain {
  background: none; border: 2px solid var(--g-line); border-radius: 999px;
  padding: 12px 26px; font-size: 15px; font-weight: 700;
}

/* ---------- game menu ---------- */
.menu-head { display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.back-link { background: none; border: none; font-size: 14px; font-weight: 600;
  color: var(--g-ink-soft); padding: 6px 0; }
.back-link:hover { color: var(--g-ink); }
.menu-sum { font-size: 13px; color: var(--g-ink-soft); }
.menu-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.game-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 26px 18px; background: var(--g-bg); border: 2px solid var(--g-line);
  border-radius: 24px; transition: border-color .15s ease, transform .1s ease;
}
.game-card:hover { border-color: var(--g-accent); }
.game-card:active { transform: scale(.98); }
.game-art svg { width: 76px; height: 76px; }
.game-title { font-size: 18px; font-weight: 800; }
.game-hint { font-size: 13px; color: var(--g-ink-soft); text-align: center; }
.star-bar { display: flex; align-items: center; gap: 6px; justify-content: center;
  margin-top: 22px; font-size: 18px; font-weight: 800; }
.star-bar .star { color: var(--g-accent); }

/* ---------- playing ---------- */
body.in-game { overflow-x: hidden; }
.play-top { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.quit { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--g-line);
  background: var(--g-bg); font-size: 16px; line-height: 1; flex-shrink: 0; }
.pips { display: flex; gap: 5px; flex: 1; }
.pip { flex: 1; height: 7px; border-radius: 999px; background: var(--g-surface); }
.pip.on { background: var(--g-accent); }

.tap-wrap { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.big-speaker {
  width: 108px; height: 108px; border-radius: 50%; border: none;
  background: var(--g-accent); color: var(--k-white); display: flex; align-items: center;
  justify-content: center; box-shadow: 0 6px 0 var(--k-press);
}
.big-speaker svg { width: 56px; height: 56px; }
.big-speaker:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--k-press); }

.tap-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr);
  width: 100%; max-width: 520px; }
.tap-card {
  aspect-ratio: 1; background: var(--g-bg); border: 3px solid var(--g-line);
  border-radius: 22px; display: flex; align-items: center; justify-content: center;
  padding: 10px; transition: border-color .15s ease, transform .1s ease;
}
.tap-card img { width: 100%; height: 100%; object-fit: contain; }
.tap-card:active { transform: scale(.96); }
.tap-card.is-right { border-color: var(--g-right); background: color-mix(in srgb, var(--g-right) 12%, transparent); }
.tap-card.is-wrong { border-color: var(--g-wrong); animation: shake .4s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

/* ---------- memory pairs ---------- */
.pairs-grid { display: grid; gap: 10px; grid-template-columns: repeat(4, 1fr);
  max-width: 560px; margin: 0 auto; }
.flip-card { aspect-ratio: 1; background: none; border: none; padding: 0; perspective: 700px; }
.flip-inner { position: relative; display: block; width: 100%; height: 100%;
  transform-style: preserve-3d; transition: transform .35s; }
.flip-card.is-open .flip-inner, .flip-card.is-done .flip-inner { transform: rotateY(180deg); }
.flip-back, .flip-front {
  position: absolute; inset: 0; backface-visibility: hidden;
  border-radius: 18px; display: flex; align-items: center; justify-content: center;
  padding: 8px;
}
.flip-back { background: var(--g-accent-2); }
.flip-front { background: var(--g-bg); border: 3px solid var(--g-line);
  transform: rotateY(180deg); }
.flip-front img { width: 100%; height: 100%; object-fit: contain; }
.flip-card.is-done { opacity: .35; pointer-events: none; }
.flip-card.is-done .flip-front { border-color: var(--g-right); }

/* The speaker half of a pair, and any icon-only face the page supplies. */
.card-speaker { width: 60%; height: 60%; color: var(--g-accent); }
.card-speaker svg { width: 100%; height: 100%; }

/* ---------- reward ---------- */
.reward { text-align: center; padding: 8vh 12px 0; }
.reward-stars { font-size: 54px; color: var(--g-accent); line-height: 1; }
.rs { display: inline-block; animation: pop .5s backwards; }
@keyframes pop { from { transform: scale(0) rotate(-40deg); opacity: 0; } }
.reward h2 { font-size: 30px; margin: 14px 0 4px; }
.reward-sum { color: var(--g-ink-soft); font-size: 15px; margin: 0 0 26px; }
.reward-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

@media (max-width: 520px) {
  .tap-grid { max-width: 100%; gap: 10px; }
  .pairs-grid { grid-template-columns: repeat(4, 1fr); gap: 7px; }
  .big-speaker { width: 92px; height: 92px; }
  .reward h2 { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  .flip-inner, .rs, .tap-card { transition: none !important; animation: none !important; }
}

/* One heading per subject in the picker — the seam along which a second
   course is added. */
.pick-subject { font-size: 15px; font-weight: 800; margin: 22px 0 10px;
  color: var(--g-ink-soft); letter-spacing: .01em; }
.pick-subject:first-of-type { margin-top: 4px; }

/* Attribution for the CC BY-SA artwork. Out of the way, but present on the
   page that shows the pictures — which is what the licence asks for. */
.credit { margin: 30px 0 0; font-size: 11.5px; color: var(--g-ink-soft);
  text-align: center; line-height: 1.7; }
.credit a { color: inherit; }
body.in-game .credit { display: none; }

/* Emoji badge on a game card, tucked on the artwork's corner. */
.game-card { position: relative; }
.game-icon { position: absolute; top: 14px; right: 16px; font-size: 26px;
  line-height: 1;
  font-family: "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif; }
