/* Capingo – kindgerechtes, helles Design mit großen Touch-Zielen.
   Mobile-first, Portrait und Landscape, keine externen Fonts. */

:root {
  --sky1: #8ed3f7;
  --sky2: #e9f7ff;
  --ink: #17324a;
  --muted: #5b7690;
  --card: #ffffff;
  --accent: #ff7a3c;
  --accent-dark: #e8611f;
  --blue: #2f80ed;
  --gold: #ffb703;
  --stroke: rgba(23, 50, 74, 0.12);
  --radius: 20px;
  --shadow: 0 6px 20px rgba(23, 50, 74, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: linear-gradient(180deg, var(--sky1) 0%, var(--sky2) 55%, #f7fbff 100%) fixed;
  color: var(--ink);
  font-family: ui-rounded, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}
input { user-select: text; -webkit-user-select: text; }

/* ---------- Screens ---------- */
.screen {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
           max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}
.screen.active { display: flex; }

.pagehead {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 0 10px;
}
.pagehead h2 { margin: 0; font-size: 24px; }
.backbtn {
  font: inherit; font-size: 28px; line-height: 1;
  width: 46px; height: 46px; border-radius: 14px;
  border: 1px solid var(--stroke); background: var(--card); color: var(--ink);
  cursor: pointer; box-shadow: var(--shadow);
}

h3 { margin: 20px 0 10px; font-size: 17px; }
.hint { color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.hint.center { text-align: center; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-size: 18px; font-weight: 700; color: var(--ink);
  background: var(--card); border: 1px solid var(--stroke); border-radius: var(--radius);
  min-height: 56px; padding: 12px 20px; cursor: pointer;
  box-shadow: var(--shadow); transition: transform 0.12s ease, filter 0.12s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-dark) 100%);
  border: none; color: #fff;
}
.btn.small { min-height: 44px; font-size: 15px; padding: 8px 16px; }
.btn.bigcta { width: 100%; margin-top: 22px; font-size: 20px; min-height: 62px; }
.btn small { display: block; font-size: 12px; font-weight: 500; opacity: 0.85; }

.chip {
  font: inherit; font-size: 15px; font-weight: 700; color: var(--ink);
  background: var(--card); border: 2px solid var(--stroke); border-radius: 16px;
  padding: 10px 14px; min-height: 48px; cursor: pointer;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
}
.chip small { font-size: 11.5px; font-weight: 500; color: var(--muted); }
.chip.on { border-color: var(--accent); background: #fff3ec; }
.chip.on small { color: var(--accent-dark); }
.chip:disabled { opacity: 0.4; cursor: default; }
.chiprow { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Home ---------- */
#screen-home { justify-content: center; align-items: center; text-align: center; gap: 26px; }
.home-logo {
  width: min(72vw, 340px); height: auto;
  /* Radius etwas größer als die Rundung im Motiv -> weiße Bildecken verschwinden */
  border-radius: 22%;
  animation: wiggle 2.4s ease-in-out infinite;
  filter: drop-shadow(0 12px 16px rgba(23, 50, 74, 0.28));
}
@keyframes wiggle {
  0%, 100% { transform: rotate(-1.5deg) translateY(0); }
  50% { transform: rotate(1.5deg) translateY(-6px); }
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.home-sub { margin: 4px 0 0; color: var(--muted); font-size: 17px; }
.home-actions { display: flex; flex-direction: column; gap: 14px; width: min(90vw, 340px); }
.home-actions .btn { width: 100%; flex-direction: column; gap: 2px; }
.home-foot { color: var(--muted); font-size: 12.5px; }

/* ---------- Setup ---------- */
.setup-body, .share-body, .join-body {
  width: min(96vw, 560px); margin: 0 auto; padding-bottom: 30px;
}
.switchrow {
  display: flex; align-items: center; gap: 12px; margin-top: 18px;
  background: var(--card); border: 1px solid var(--stroke); border-radius: 16px;
  padding: 12px 14px; font-size: 14.5px; cursor: pointer; box-shadow: var(--shadow);
}
.switchrow input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.prow {
  display: grid; grid-template-columns: auto 1fr auto auto auto;
  gap: 8px; align-items: center; margin-bottom: 8px;
}
.panimal {
  font-size: 26px; width: 52px; height: 52px; border-radius: 16px;
  background: var(--card); border: 3px solid var(--pc); cursor: pointer;
}
.pname {
  font: inherit; font-size: 16px; min-width: 0; height: 52px; padding: 0 14px;
  border: 1px solid var(--stroke); border-radius: 16px; background: var(--card); color: var(--ink);
}
.pname:focus { outline: 2px solid var(--pc); }
.pcolor {
  width: 40px; height: 40px; border-radius: 50%; border: 3px solid #fff;
  background: var(--pc); box-shadow: 0 0 0 2px var(--pc); cursor: pointer;
}
.pdriver {
  font-size: 22px; width: 48px; height: 48px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--stroke); cursor: pointer; opacity: 0.35;
}
.pdriver.on { opacity: 1; border: 3px solid var(--blue); background: #eaf2fe; }
.pdel {
  font-size: 16px; width: 40px; height: 40px; border-radius: 12px;
  background: none; border: none; color: var(--muted); cursor: pointer;
}
.pdel:disabled { opacity: 0.25; cursor: default; }

.animal-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 12px; }
.acell {
  font-size: 26px; aspect-ratio: 1; border-radius: 12px; border: 1px solid var(--stroke);
  background: #f7fbff; cursor: pointer;
}
.acell:active { background: #fff3ec; }
.acell.used { opacity: 0.3; }

.color-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-top: 14px; padding: 4px; }
.ccell {
  aspect-ratio: 1; border-radius: 50%; cursor: pointer;
  background: var(--pc); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--pc);
}
.ccell.sel { box-shadow: 0 0 0 4px var(--ink); }
.ccell.used { opacity: 0.25; cursor: default; }

/* ---------- Einladen / QR ---------- */
.qrbox {
  width: min(70vw, 280px); aspect-ratio: 1; margin: 14px auto;
  background: #fff; border-radius: 20px; padding: 10px; box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.qrbox svg { width: 100%; height: 100%; }
.coderow { display: flex; gap: 8px; margin-top: 10px; }
.coderow input {
  flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; font-size: 12px;
  height: 46px; padding: 0 12px; border: 1px solid var(--stroke); border-radius: 14px;
  background: var(--card); color: var(--ink);
}

.pselect-list { display: flex; flex-direction: column; gap: 8px; }
.pselect {
  font: inherit; font-size: 17px; font-weight: 700; color: var(--ink);
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--card); border: 3px solid var(--stroke); border-radius: 18px;
  min-height: 60px; padding: 8px 16px; cursor: pointer;
}
.pselect .ps-a { font-size: 26px; }
.pselect .ps-n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pselect .ps-d { font-size: 12.5px; font-weight: 600; color: var(--blue); background: #eaf2fe; border-radius: 999px; padding: 4px 10px; }
.pselect .ps-check {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff; font-size: 18px;
  background: #dde7ef;
}
.pselect.on { border-color: var(--pc); background: color-mix(in srgb, var(--pc) 10%, #fff); }
.pselect.on .ps-check { background: var(--pc); }

/* ---------- Beitreten / Scanner ---------- */
.scanarea {
  position: relative; width: min(78vw, 320px); aspect-ratio: 1; margin: 8px auto 14px;
  border-radius: 22px; overflow: hidden; background: #14293d;
  display: grid; place-items: center; box-shadow: var(--shadow);
}
.scanarea::before { content: "📷"; font-size: 44px; opacity: 0.5; }
.scanarea.scanning::before { content: ""; }
#scanVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanframe {
  position: absolute; inset: 12%; border-radius: 16px; pointer-events: none;
  border: 3px dashed rgba(255, 255, 255, 0.65);
}
#joinScan .btn.primary, #startScan { display: flex; margin: 0 auto; }
.divider {
  display: flex; align-items: center; gap: 12px; margin: 22px 0 6px; color: var(--muted); font-size: 13px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--stroke); }
.joinsummary {
  background: var(--card); border: 1px solid var(--stroke); border-radius: 16px;
  padding: 14px 16px; font-size: 15.5px; box-shadow: var(--shadow);
}
#joinInfo .btn.small { display: flex; margin: 12px auto 0; }

/* ---------- Boards-Screen ---------- */
#screen-boards { height: 100dvh; }
.gamebar { display: flex; align-items: center; gap: 8px; padding-bottom: 8px; }
.gamelogo { font-size: 17px; }
.spacer { flex: 1; }
.gamebar .chip { flex-direction: row; min-height: 42px; padding: 6px 12px; font-size: 13.5px; }

#boardsGrid {
  flex: 1; min-height: 0; display: grid; gap: 10px;
}
#boardsGrid[data-n="1"] { grid-template-columns: 1fr; }
#boardsGrid[data-n="2"] { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
#boardsGrid[data-n="3"], #boardsGrid[data-n="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
@media (orientation: landscape) {
  #boardsGrid[data-n="2"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
}
.boards-hint { text-align: center; color: var(--muted); font-size: 12px; margin: 6px 0 0; }

/* ---------- Board (mini + groß) ---------- */
.board {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: color-mix(in srgb, var(--pc) 14%, #fff);
  border: 3px solid var(--pc); border-radius: var(--radius);
  padding: 8px; box-shadow: var(--shadow);
}
.board.mini .bhead { cursor: pointer; }
.bhead {
  display: flex; align-items: center; gap: 8px; padding: 0 4px 6px; min-height: 30px;
}
.ba { font-size: 20px; }
.bn { font-weight: 800; font-size: 15px; color: color-mix(in srgb, var(--pc) 75%, #000); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bd { font-size: 15px; }
.headright { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.zoom { font-size: 15px; opacity: 0.6; }
.speak {
  font: inherit; font-size: 13px; font-weight: 700;
  background: var(--blue); color: #fff; border: none; border-radius: 999px;
  padding: 8px 14px; cursor: pointer; box-shadow: var(--shadow);
}

.bgrid {
  flex: 1; min-height: 0; align-self: center; aspect-ratio: 1; max-width: 100%;
  display: grid; gap: 4px;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  container-type: size;
}
.cell {
  position: relative; min-width: 0; min-height: 0; border: none; border-radius: 12px;
  background: #fff; box-shadow: inset 0 0 0 1px var(--stroke);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 2px; overflow: hidden; font: inherit; cursor: pointer;
}
.cell .ci { font-size: calc(52cqw / var(--n)); line-height: 1.15; pointer-events: none; }
.cell img.ci { width: calc(60cqw / var(--n)); height: auto; }
.cell .cn {
  font-size: clamp(9px, calc(15cqw / var(--n)), 14px); font-weight: 700; text-align: center;
  line-height: 1.1; color: var(--muted); pointer-events: none;
}
.cell .mk {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  font-size: calc(55cqw / var(--n)); font-weight: 900; color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  background: color-mix(in srgb, var(--pc) 78%, transparent);
  pointer-events: none;
}
.cell.marked .mk { display: flex; }
.cell.marked .ci, .cell.marked .cn { opacity: 0.55; }
.cell.win { box-shadow: inset 0 0 0 3px var(--gold), 0 0 12px var(--gold); animation: winpulse 1.4s ease-in-out infinite; }
@keyframes winpulse {
  0%, 100% { box-shadow: inset 0 0 0 3px var(--gold), 0 0 6px var(--gold); }
  50% { box-shadow: inset 0 0 0 3px var(--gold), 0 0 16px var(--gold); }
}

/* Großes Board im Overlay – Höhe ergibt sich aus der Breite (aspect-ratio),
   damit das Grid auch im Grid-zentrierten Modal eine definierte Größe hat */
.board-modal { padding: 3vmin; }
#bigBoard { width: min(94vw, 78vh); }
.board.big { width: 100%; padding: 12px; }
.board.big .bgrid { flex: none; align-self: stretch; width: 100%; aspect-ratio: 1; }
.board.big .bhead { padding-bottom: 10px; }
.board.big .ba { font-size: 26px; }
.board.big .bn { font-size: 19px; }
.board.big .speak { font-size: 15px; padding: 10px 18px; }
.board.big .cell { border-radius: 14px; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 200; display: none; place-items: center;
  background: rgba(13, 34, 52, 0.5); backdrop-filter: blur(3px); padding: 18px;
}
.modal.open { display: grid; }
.modal-card {
  background: var(--card); border-radius: 24px; padding: 22px;
  width: 100%; max-width: 420px; max-height: 86dvh; overflow: auto;
  box-shadow: 0 18px 50px rgba(13, 34, 52, 0.35);
}
.modal-card h3 { margin: 0 0 8px; }
.modal-card p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.45; }
.modal-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

.item-card { text-align: center; }
.item-big-icon { font-size: 110px; line-height: 1.2; display: inline-block; }
img.item-big-icon { width: 140px; height: 140px; object-fit: contain; }
.item-card h3 { font-size: 26px; margin-top: 8px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; font-size: 14.5px; font-weight: 600;
  padding: 12px 20px; border-radius: 999px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s;
  z-index: 400; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Bingo-Feier ---------- */
.confetti-canvas { position: fixed; z-index: 290; pointer-events: none; }
.bingo-banner {
  position: fixed; z-index: 300; transform: translate(-50%, -50%) rotate(-6deg) scale(0);
  font-size: clamp(44px, 13vw, 90px); font-weight: 900; letter-spacing: 0.03em;
  color: var(--gold); -webkit-text-stroke: 3px #fff;
  text-shadow: 0 6px 0 rgba(180, 110, 0, 0.35), 0 10px 30px rgba(0, 0, 0, 0.3);
  pointer-events: none; white-space: nowrap;
  animation: bingopop 2.4s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}
@keyframes bingopop {
  0% { transform: translate(-50%, -50%) rotate(-6deg) scale(0); }
  18% { transform: translate(-50%, -50%) rotate(3deg) scale(1.15); }
  28% { transform: translate(-50%, -50%) rotate(-2deg) scale(1); }
  80% { transform: translate(-50%, -50%) rotate(-2deg) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) rotate(-2deg) scale(1.1); opacity: 0; }
}
