:root {
  --cream: #fff7e8;
  --paper: #fffdf8;
  --ink: #34273e;
  --muted: #746b78;
  --coral: #ff7657;
  --coral-dark: #d94f3e;
  --teal: #22a88a;
  --blue: #3978cf;
  --purple: #7658c9;
  --gold: #f2b63f;
  --pink: #e45b72;
  --shadow: 0 8px 0 rgba(77, 52, 66, .14), 0 16px 35px rgba(77, 52, 66, .12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; height: 100dvh; margin: 0; overflow: hidden; }
body {
  color: var(--ink);
  background: var(--cream);
  font-family: ui-rounded, "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 4px solid #2366c4; outline-offset: 3px; }

#app { position: relative; width: 100%; height: 100%; overflow: hidden; isolation: isolate; }
.sky-shape { position: absolute; z-index: -1; border-radius: 50%; opacity: .55; pointer-events: none; }
.sky-shape--one { width: 45vmin; height: 45vmin; left: -17vmin; top: -15vmin; background: #bcebdd; }
.sky-shape--two { width: 34vmin; height: 34vmin; right: -12vmin; bottom: -11vmin; background: #ffd7a6; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  min-width: 0;
  min-height: 0;
  padding: calc(var(--safe-top) + 18px) calc(var(--safe-right) + 22px) calc(var(--safe-bottom) + 18px) calc(var(--safe-left) + 22px);
}
.screen.active { display: flex; }
.eyebrow { margin: 0; color: var(--coral-dark); font-size: clamp(.74rem, 1.5vw, .92rem); font-weight: 900; letter-spacing: .16em; }
h1, h2, p { text-wrap: balance; }
h2 { margin: 0; font-size: clamp(1.9rem, 5vmin, 3.35rem); line-height: 1.05; }

.round-button {
  display: grid; place-items: center; width: 48px; height: 48px; padding: 0;
  border: 2px solid rgba(52, 39, 62, .12); border-radius: 50%; background: rgba(255,255,255,.76);
  box-shadow: 0 4px 0 rgba(77,52,66,.11); font-size: 1.35rem; cursor: pointer;
}
.round-button:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(77,52,66,.11); }
.primary-button, .secondary-button {
  border: 0; border-radius: 20px; padding: 17px 28px; min-height: 58px; cursor: pointer; font-weight: 900; font-size: clamp(1rem, 2.4vw, 1.25rem);
}
.primary-button { color: white; background: linear-gradient(135deg, var(--coral), #ff9b55); box-shadow: 0 7px 0 #bf4939, 0 12px 25px rgba(217,79,62,.2); }
.secondary-button { background: white; border: 2px solid #eadfd3; box-shadow: 0 5px 0 #e5d8ca; }
.primary-button:active, .secondary-button:active { transform: translateY(4px); box-shadow: 0 2px 0 #bf4939; }

/* Family access */
.family-gate { align-items: center; justify-content: center; overflow-y: auto; }
.family-gate__card { display: flex; width: min(720px, 94vw); flex-direction: column; align-items: center; gap: 12px; padding: clamp(22px, 5vmin, 42px); border: 3px solid #eadfd3; border-radius: 30px; background: rgba(255,253,248,.96); box-shadow: var(--shadow); text-align: center; }
.family-gate .brand-mark img { width: clamp(60px, 10vmin, 88px); }
.family-gate h1 { margin: 0; font-size: clamp(2rem, 6vmin, 3.6rem); line-height: 1; }
.family-gate__copy { max-width: 48ch; margin: 0; color: var(--muted); font-weight: 700; }
.family-gate__actions { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 14px; width: 100%; margin-top: 5px; }
.family-form { text-align: left; }
.family-form label { display: block; margin: 0 0 6px 3px; color: var(--muted); font-size: .78rem; font-weight: 900; text-transform: uppercase; }
.family-form > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.family-form input { min-width: 0; padding: 13px 14px; border: 3px solid #ded2c6; border-radius: 15px; background: white; color: var(--ink); font-weight: 800; }
.family-form .primary-button, .family-form .secondary-button { min-height: 50px; padding: 11px 17px; border-radius: 15px; font-size: .92rem; }
.family-or { align-self: center; margin-top: 21px; color: var(--muted); font-size: .8rem; font-weight: 900; }
.family-message { min-height: 1.3em; margin: 0; color: var(--coral-dark); font-size: .84rem; font-weight: 900; }
.family-gate__card > small { color: var(--muted); }
.family-pill { position: absolute; top: calc(var(--safe-top) + 18px); left: calc(var(--safe-left) + 18px); max-width: min(55vw, 280px); padding: 9px 13px; border: 2px solid #eadfd3; border-radius: 999px; background: rgba(255,255,255,.78); box-shadow: 0 4px 0 rgba(77,52,66,.11); font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.family-dialog-body { display: grid; gap: 15px; padding: 22px; text-align: center; }
.family-dialog-body > p { margin: 0; color: var(--muted); line-height: 1.45; }
.invite-result { display: grid; gap: 8px; padding: 17px; border: 3px dashed var(--purple); border-radius: 18px; background: #f2edff; }
.invite-result[hidden] { display: none; }
.invite-result small { color: var(--muted); font-weight: 900; letter-spacing: .12em; }
.invite-result strong { color: var(--purple); font-size: clamp(1.45rem, 5vw, 2.2rem); letter-spacing: .08em; }
.invite-result .secondary-button { justify-self: center; min-height: 46px; padding: 10px 18px; font-size: .9rem; }
.family-leave { margin-top: 8px; color: var(--coral-dark); }

/* Home */
.home { flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: clamp(9px, 1.7vh, 17px); }
.home .sound-toggle { position: absolute; top: calc(var(--safe-top) + 18px); right: calc(var(--safe-right) + 18px); }
.brand-mark { display: flex; align-items: center; gap: 14px; color: var(--gold); font-size: clamp(1.5rem, 4vw, 2.4rem); }
.brand-mark img { width: clamp(72px, 13vmin, 116px); filter: drop-shadow(0 7px 0 rgba(77,52,66,.12)); }
.home h1 { margin: -4px 0 0; font-size: clamp(3rem, 10vmin, 6.4rem); letter-spacing: -.07em; line-height: .92; }
.home h1 em { color: var(--coral); font-style: normal; }
.home-copy { margin: 0; color: var(--muted); font-size: clamp(1rem, 2.4vw, 1.3rem); }
.home-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; width: min(760px, 94vw); margin-top: 5px; }
.mode-card {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 15px; min-height: 112px;
  padding: 17px 20px; border: 0; border-radius: 25px; text-align: left; cursor: pointer; box-shadow: var(--shadow);
}
.mode-card--duel { background: #fff0dc; border: 3px solid #ffbf74; }
.mode-card--team { background: #e5f7f1; border: 3px solid #8bd7c5; }
.mode-card__icon { display: grid; place-items: center; width: 62px; height: 62px; border-radius: 19px; background: rgba(255,255,255,.72); font-size: 2rem; }
.mode-card strong, .mode-card small { display: block; }
.mode-card strong { font-size: clamp(1.15rem, 2.8vw, 1.5rem); }
.mode-card small { margin-top: 5px; color: var(--muted); font-weight: 700; line-height: 1.25; }
.mode-card b { font-size: 2rem; }
.mode-card:active { transform: translateY(4px); box-shadow: 0 4px 0 rgba(77,52,66,.12); }
.text-button { border: 0; background: transparent; color: #5d4d68; text-decoration: underline; text-underline-offset: 4px; font-weight: 800; cursor: pointer; }
.sync-status { min-height: 1.1em; margin: -5px 0 0; color: var(--muted); font-size: .76rem; font-weight: 900; }
.sync-status.pending { color: #a85b00; }
.sync-status.synced { color: #14765f; }
.boot-error { margin: 0; padding: 8px 12px; border-radius: 10px; background: #ffe0d8; color: #9f3028; font-size: .84rem; font-weight: 900; }
.boot-error[hidden] { display: none; }
.home-foot { margin: 0; color: #8c818e; font-size: .77rem; }

/* Setup */
.setup { flex-direction: column; gap: 12px; overflow-y: auto; }
.screen-header { display: grid; grid-template-columns: 52px 1fr 52px; align-items: center; width: 100%; text-align: center; }
.screen-header h2 { margin-top: 2px; }
.setup-body { display: flex; flex: 1; min-height: 0; flex-direction: column; justify-content: center; gap: 17px; }
.players-setup { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 16px; width: min(850px, 95vw); margin: auto; }
.player-setup { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px 15px; padding: clamp(14px, 2.3vmin, 24px); border-radius: 26px; background: var(--paper); box-shadow: var(--shadow); border: 3px solid transparent; }
.player-setup--one { border-color: #ffb19f; }
.player-setup--two { border-color: #9cdccc; }
.player-avatar { grid-row: 1 / 3; display: grid; place-items: center; width: clamp(64px, 10vmin, 92px); height: clamp(64px, 10vmin, 92px); border-radius: 50%; background: #fff0d8; font-size: clamp(2.2rem, 6vmin, 3.7rem); }
.player-setup--two .player-avatar { background: #dff5ef; }
.player-setup label { color: var(--muted); font-size: .78rem; font-weight: 900; letter-spacing: .05em; text-align: left; text-transform: uppercase; }
.player-profile { display: block; width: 100%; min-width: 0; margin-top: 4px; padding: 6px 30px 6px 2px; border: 0; border-bottom: 3px solid #eadfd3; background-color: transparent; color: var(--ink); font-size: clamp(1.25rem, 3vw, 1.75rem); font-weight: 900; cursor: pointer; }
.difficulty-picker { grid-column: 1 / -1; margin: 2px 0 0; padding: 0; border: 0; }
.difficulty-picker legend { margin-bottom: 6px; color: var(--muted); font-size: .78rem; font-weight: 900; text-transform: uppercase; }
.difficulty-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.difficulty-options button, .segmented button { min-height: 42px; padding: 8px 10px; border: 0; border-radius: 12px; background: #f3ede5; color: #665a69; cursor: pointer; font-size: .86rem; font-weight: 900; }
.difficulty-options button.selected { color: white; background: var(--purple); }
.versus-badge { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; color: white; background: var(--ink); box-shadow: 0 5px 0 rgba(52,39,62,.22); font-weight: 1000; transform: rotate(-7deg); }
.seating { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 14px; font-weight: 900; }
.segmented { display: flex; gap: 5px; padding: 5px; border-radius: 15px; background: #eadfd3; }
.segmented button.selected { color: white; background: var(--blue); }
.segmented button small { display: block; margin-top: 2px; font-size: .64rem; font-weight: 800; opacity: .78; }
.layout-hint { flex-basis: 100%; color: var(--muted); text-align: center; font-size: .75rem; }
.setup > .primary-button { align-self: center; min-width: min(420px, 85vw); }

/* Intro */
.round-intro { flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 11px; }
.round-number { margin: 0; padding: 7px 14px; border-radius: 999px; background: #efe6dc; color: var(--muted); font-size: .82rem; font-weight: 900; letter-spacing: .1em; }
.category-orbit { display: grid; place-items: center; width: clamp(95px, 16vmin, 140px); height: clamp(95px, 16vmin, 140px); margin: 3px; border: 7px solid white; border-radius: 38%; background: #dff5ef; box-shadow: var(--shadow); font-size: clamp(3rem, 8vmin, 5rem); transform: rotate(-4deg); }
.category-orbit::first-letter { transform: rotate(4deg); }
.picker-note { min-height: 1.35em; margin: 0; color: var(--muted); font-weight: 800; }
.activity-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; width: min(670px, 92vw); }
.activity-card { min-height: 125px; padding: 18px; border: 3px solid #e7d9ca; border-radius: 24px; background: white; box-shadow: var(--shadow); cursor: pointer; }
.activity-card strong, .activity-card span { display: block; }
.activity-card strong { font-size: clamp(1.15rem, 3vw, 1.5rem); }
.activity-card span { margin-top: 7px; color: var(--muted); font-size: .9rem; font-weight: 700; line-height: 1.25; }
.activity-card:active { transform: translateY(4px); box-shadow: 0 4px 0 rgba(77,52,66,.12); }

/* Countdown */
.countdown { flex-direction: column; align-items: center; justify-content: center; background: var(--ink); color: white; text-align: center; }
.countdown p { margin: 0 0 18px; color: #ffe0a1; font-size: clamp(1.3rem, 4vw, 2rem); font-weight: 900; }
.countdown strong { display: grid; place-items: center; width: min(43vmin, 260px); height: min(43vmin, 260px); border-radius: 50%; background: var(--coral); box-shadow: 0 0 0 15px rgba(255,255,255,.12); font-size: clamp(6rem, 24vmin, 12rem); line-height: 1; animation: count-pop .45s cubic-bezier(.2,.8,.2,1); }
.countdown span { margin-top: 22px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
@keyframes count-pop { from { transform: scale(.35) rotate(-8deg); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Game */
.game { padding: 0; flex-direction: column; overflow: hidden; background: #f7eddf; touch-action: none; }
.arena { position: relative; display: flex; flex: 1 1 0; width: 100%; min-width: 0; min-height: 0; flex-direction: column; overflow: hidden; padding: 11px clamp(12px, 2vw, 24px); }
.arena--one { background: #fff3e5; transform: rotate(180deg); }
.arena--two { background: #eaf8f4; }
.arena-hud { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 35px; font-size: clamp(.88rem, 2vw, 1.1rem); }
.arena-player { display: flex; align-items: center; gap: 7px; min-width: 0; }
.arena-name { max-width: 15ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arena-avatar { font-size: 1.35em; }
.arena-score { color: #c56f00; font-size: 1.1em; white-space: nowrap; }
.round-pips { display: flex; justify-content: center; gap: 7px; height: 14px; }
.round-pips i { width: 25px; height: 7px; border-radius: 999px; background: rgba(52,39,62,.13); }
.round-pips i.done { background: var(--teal); }
.puzzle-stage { display: flex; flex: 1; min-height: 0; flex-direction: column; align-items: center; justify-content: center; gap: clamp(7px, 1.3vh, 13px); text-align: center; }
.puzzle-title { margin: 0; font-size: clamp(1.05rem, 3vmin, 1.55rem); line-height: 1.1; }
.visual { display: flex; align-items: center; justify-content: center; min-height: 42px; max-width: 100%; }
.icon-cloud { display: grid; grid-template-columns: repeat(var(--cols, 6), 1fr); gap: 2px 8px; padding: 5px 12px; border-radius: 15px; background: rgba(255,255,255,.72); font-size: clamp(1.05rem, 3vmin, 1.8rem); }
.pattern-line { display: flex; align-items: center; gap: clamp(6px, 1.5vw, 13px); font-size: clamp(1.4rem, 4vmin, 2.5rem); }
.pattern-line b { display: grid; place-items: center; min-width: 1.4em; height: 1.4em; border-radius: 10px; background: white; }
.rule-machine { display: grid; grid-template-columns: auto auto auto; align-items: center; gap: 4px 12px; padding: 7px 16px; border-radius: 15px; background: rgba(255,255,255,.72); font-size: clamp(1rem, 2.8vmin, 1.45rem); font-weight: 900; }
.rule-machine .machine { color: var(--purple); }
.rotate-visual { display: flex; align-items: center; gap: 18px; }
.rotate-arrow { display: grid; place-items: center; width: 65px; height: 65px; border-radius: 18px; background: white; color: var(--blue); font-size: 3.1rem; box-shadow: 0 4px 0 rgba(52,39,62,.12); }
.rotate-turn { color: var(--purple); font-size: clamp(1rem, 2.7vmin, 1.35rem); font-weight: 900; }
.rotate-turn { display: flex; flex-wrap: wrap; gap: 6px; max-width: 150px; }
.rotate-turn b { padding: 6px 8px; border-radius: 10px; background: #eee8ff; }
.answers { display: grid; grid-template-columns: repeat(var(--answer-cols, 2), minmax(74px, 1fr)); gap: 9px; width: min(470px, 94%); }
.answer-button, .grid-item, .pad-button {
  min-height: 54px; border: 0; border-radius: 16px; background: white; box-shadow: 0 5px 0 rgba(52,39,62,.16); cursor: pointer; font-weight: 900;
}
.answer-button { padding: 8px 14px; font-size: clamp(1.2rem, 4vmin, 2rem); }
.answer-button:active, .grid-item:active, .pad-button:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(52,39,62,.15); }
.answer-button.correct, .grid-item.correct { background: #6dd9b6; }
.answer-button.wrong, .grid-item.wrong { background: #ffd0c6; }
.tap-grid { display: grid; grid-template-columns: repeat(var(--grid-cols), minmax(42px, 1fr)); gap: clamp(5px, 1vw, 9px); width: min(470px, 92%); }
.tap-grid.dense { width: min(310px, 70%); gap: 4px; }
.grid-item { display: grid; place-items: center; aspect-ratio: 1; min-height: 0; font-size: clamp(1.15rem, 3.4vmin, 2rem); }
.path-grid { width: min(280px, 65%); }
.path-grid .grid-item { border: 2px dashed #b9c8d9; color: var(--blue); }
.puzzle-help { max-width: 42ch; margin: 0; color: var(--muted); font-size: clamp(.72rem, 1.8vmin, .9rem); font-weight: 800; line-height: 1.15; }
.move-line { display: flex; gap: 6px; color: var(--blue); font-weight: 1000; }
.move-line span { position: relative; display: grid; place-items: center; width: clamp(34px, 5vmin, 44px); height: clamp(38px, 5.5vmin, 48px); border: 2px solid #b9d0ee; border-radius: 11px; background: white; box-shadow: 0 3px 0 rgba(52,39,62,.1); }
.move-line small { position: absolute; top: 2px; left: 5px; color: var(--muted); font-size: .55rem; line-height: 1; }
.move-line b { font-size: clamp(1.25rem, 3.1vmin, 1.8rem); line-height: 1; }
.memory-row { display: flex; gap: 11px; padding: 12px 18px; border-radius: 18px; background: white; font-size: clamp(1.8rem, 5vmin, 3rem); box-shadow: 0 5px 0 rgba(52,39,62,.12); }
.memory-row.dense { gap: 6px; padding: 9px 12px; font-size: clamp(1.35rem, 3.8vmin, 2.25rem); }
.memory-row > span { display: grid; place-items: center; min-width: 1.15em; min-height: 1.15em; }
.memory-row .missing-slot { border: 3px dashed var(--purple); border-radius: 12px; background: #f2edff; color: var(--purple); font-size: .72em; font-weight: 1000; }
.light-pads { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; width: min(320px, 76%); }
.pad-button { height: clamp(55px, 8vmin, 76px); background: var(--pad); border: 5px solid rgba(255,255,255,.7); opacity: .78; }
.pad-button.flash, .pad-button:active { opacity: 1; filter: brightness(1.18); transform: scale(1.06); box-shadow: 0 0 0 6px rgba(255,255,255,.8), 0 0 25px var(--pad); }
.order-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 9px; width: min(500px, 94%); }
.order-row .answer-button { min-width: 65px; }
.order-row .answer-button.picked { opacity: .25; transform: scale(.87); box-shadow: none; pointer-events: none; }
.balloon-field { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: center; gap: clamp(2px, .7vw, 7px); width: min(620px, 98%); min-height: 125px; }
.balloon-button { position: relative; display: flex; width: max(48px, var(--balloon-width)); height: calc(var(--balloon-size) + 28px); min-height: 72px; flex: 0 0 auto; align-items: center; justify-content: flex-start; flex-direction: column; padding: 0; border: 0; background: transparent; cursor: pointer; touch-action: manipulation; }
.balloon-body { position: relative; display: block; width: var(--balloon-width); height: var(--balloon-size); border: 3px solid rgba(52,39,62,.22); border-radius: 52% 48% 48% 52% / 58% 58% 42% 42%; background: radial-gradient(circle at 32% 24%, rgba(255,255,255,.75) 0 8%, transparent 9%), var(--balloon-color); box-shadow: inset -7px -8px 0 rgba(52,39,62,.08), 0 4px 0 rgba(52,39,62,.12); }
.balloon-body::after { position: absolute; left: 50%; bottom: -8px; width: 0; height: 0; border-right: 6px solid transparent; border-bottom: 0; border-left: 6px solid transparent; border-top: 10px solid var(--balloon-color); content: ''; transform: translateX(-50%); }
.balloon-string { width: 1px; height: 17px; margin-top: 7px; background: rgba(52,39,62,.42); }
.balloon-button:active .balloon-body { transform: scale(.92); }
.balloon-button.wrong .balloon-body { outline: 4px solid #d85c48; outline-offset: 2px; }
.balloon-button.correct .balloon-body { outline: 4px solid #279a79; outline-offset: 2px; }
.balloon-button.popped { pointer-events: none; animation: balloon-pop .28s ease-out forwards; }
@keyframes balloon-pop { 55% { opacity: 1; transform: scale(1.18); filter: brightness(1.25); } 100% { opacity: 0; transform: scale(.1); } }
.arena-feedback { position: absolute; inset: 50% auto auto 50%; z-index: 4; transform: translate(-50%,-50%); pointer-events: none; font-size: clamp(3rem, 10vmin, 6rem); font-weight: 1000; text-shadow: 0 5px 0 white; }
.arena-feedback.pop { animation: feedback-pop .65s ease both; }
@keyframes feedback-pop { 0% { transform: translate(-50%,-50%) scale(.3) rotate(-12deg); opacity: 0; } 35% { opacity: 1; transform: translate(-50%,-50%) scale(1.15) rotate(4deg); } 100% { opacity: 0; transform: translate(-50%,-65%) scale(1); } }
.game-divider { position: absolute; z-index: 5; top: 50%; left: 0; right: 0; height: 4px; background: var(--ink); transform: translateY(-2px); pointer-events: none; }
.game-divider span { position: absolute; left: 50%; top: 50%; min-width: 62px; padding: 5px 10px; border: 4px solid var(--ink); border-radius: 999px; background: var(--cream); font-size: .75rem; font-weight: 1000; text-align: center; transform: translate(-50%,-50%); }
.game-divider button { position: absolute; left: calc(50% + 58px); top: 50%; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 3px solid var(--ink); border-radius: 50%; background: var(--paper); color: var(--ink); font-size: 1.25rem; font-weight: 1000; pointer-events: auto; cursor: pointer; transform: translate(-50%,-50%); }
.game.side-by-side { flex-direction: row; }
.game.side-by-side .arena--one { transform: none; }
.game.side-by-side .game-divider { top: 0; bottom: 0; left: 50%; right: auto; width: 4px; height: auto; transform: translateX(-2px); }
.game.side-by-side .game-divider span { top: 50%; left: 50%; }
.game.side-by-side .game-divider button { top: calc(50% + 57px); left: 50%; }

/* Tim Kompak: both players contribute one directly-tapped number. */
.team-game { flex-direction: column; align-items: center; justify-content: center; gap: clamp(9px, 1.7vh, 16px); overflow: hidden; background: linear-gradient(145deg, #e9faf4, #fff3df); touch-action: manipulation; }
.team-topbar { position: absolute; z-index: 3; top: calc(var(--safe-top) + 14px); left: calc(var(--safe-left) + 18px); right: calc(var(--safe-right) + 18px); display: flex; align-items: center; justify-content: space-between; pointer-events: none; }
.team-topbar > span { padding: 7px 13px; border-radius: 999px; background: rgba(255,255,255,.82); color: var(--muted); font-size: .8rem; font-weight: 1000; letter-spacing: .08em; }
.team-topbar button { pointer-events: auto; }
.team-target { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: min(560px, 78vw); border: 4px solid var(--ink); border-radius: 24px; background: var(--ink); color: white; box-shadow: var(--shadow); overflow: hidden; }
.team-target-copy { display: grid; grid-template-columns: auto auto; align-items: center; justify-content: center; gap: 0 12px; min-width: 0; padding: 9px 18px; text-align: center; }
.team-target-copy + .team-target-copy { border-left: 2px solid rgba(255,255,255,.2); }
.team-target-copy small { grid-column: 1 / -1; color: #ffe09a; font-size: clamp(.55rem, 1.3vw, .72rem); font-weight: 900; letter-spacing: .1em; }
.team-target-copy strong { font-size: clamp(2.2rem, 7vmin, 4.6rem); line-height: .95; }
.team-game[data-category="space"] .team-target-copy strong { max-width: 13ch; font-size: clamp(1rem, 3vmin, 1.7rem); line-height: 1.05; }
.team-target-copy span { color: #d8d0df; font-size: clamp(.8rem, 2vw, 1rem); font-weight: 900; }
.team-target-copy--one { transform: rotate(180deg); }
.team-zones { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: stretch; gap: clamp(8px, 2vw, 20px); width: min(1000px, 96vw); min-height: 0; }
.team-zone { display: flex; min-width: 0; flex-direction: column; align-items: center; justify-content: center; padding: clamp(12px, 2.5vmin, 24px); border: 4px solid transparent; border-radius: 27px; background: rgba(255,255,255,.88); box-shadow: var(--shadow); }
.team-zone--one { border-color: #ffb19f; transform: rotate(180deg); }
.team-zone--two { border-color: #8bd7c5; }
.team-zone header { display: flex; align-items: center; gap: 8px; font-size: clamp(1rem, 2.6vw, 1.35rem); }
.team-avatar { font-size: 1.6em; }
.team-zone p { margin: 2px 0 10px; color: var(--muted); font-size: .8rem; font-weight: 900; }
.team-number-options { display: grid; grid-template-columns: repeat(3, minmax(64px, 1fr)); gap: clamp(8px, 1.5vw, 14px); width: 100%; }
.team-number { min-height: clamp(74px, 13vmin, 118px); padding: 8px; border: 3px solid #eadfd3; border-radius: 20px; background: white; color: var(--ink); box-shadow: 0 6px 0 rgba(52,39,62,.16); font-size: clamp(1.7rem, 5vmin, 3.2rem); font-weight: 1000; cursor: pointer; touch-action: manipulation; }
.team-number:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(52,39,62,.16); }
.team-number.selected { border-color: var(--purple); background: #eee8ff; box-shadow: 0 0 0 4px rgba(118,88,201,.18); }
.team-number.correct { border-color: #279a79; background: #91e5ca; }
.team-number.wrong { border-color: #d85c48; background: #ffd0c6; }
.team-secret { display: grid; place-items: center; grid-column: 1 / -1; min-height: clamp(74px, 13vmin, 118px); border: 4px dashed var(--purple); border-radius: 22px; background: #f2edff; font-size: clamp(2.8rem, 9vmin, 5.5rem); animation: gentle-float 1.2s ease-in-out infinite; }
.team-plus { align-self: center; display: grid; place-items: center; width: clamp(45px, 7vmin, 64px); height: clamp(45px, 7vmin, 64px); border-radius: 50%; background: var(--gold); color: var(--ink); box-shadow: 0 5px 0 rgba(52,39,62,.16); font-size: 2.2rem; font-weight: 1000; }
.team-feedback { min-height: 1.4em; color: var(--teal); font-size: clamp(1rem, 2.7vw, 1.35rem); font-weight: 1000; text-align: center; }
.team-score { font-weight: 900; }
.team-score strong { color: #b96a00; font-size: 1.35em; }
.team-game.side-by-side .team-zone--one, .team-game.side-by-side .team-target-copy--one { transform: none; }
.team-memory-board[hidden], .team-memory-turn[hidden] { display: none; }
.team-game.memory-board .team-target, .team-game.memory-board .team-zones { display: none; }
.team-memory-turn { display: flex; align-items: center; justify-content: center; gap: 9px; }
.team-memory-turn span { padding: 7px 12px; border: 3px solid transparent; border-radius: 999px; background: rgba(255,255,255,.8); color: var(--muted); font-size: clamp(.75rem, 2vw, .95rem); font-weight: 900; opacity: .62; transition: opacity .15s ease, transform .15s ease, border-color .15s ease; }
.team-memory-turn span.active { border-color: var(--gold); color: var(--ink); opacity: 1; transform: scale(1.06); }
.team-memory-board { display: grid; grid-template-columns: repeat(var(--memory-cols), minmax(62px, 96px)); justify-content: center; gap: clamp(8px, 1.6vmin, 14px); width: min(92vw, 680px); }
.team-memory-card { position: relative; display: grid; place-items: center; aspect-ratio: 4 / 5; min-height: 0; padding: 0; border: 4px solid #7658c9; border-radius: clamp(13px, 2.4vmin, 20px); background: linear-gradient(145deg, #8c70d8, #684bb9); color: white; box-shadow: 0 6px 0 #4d358f; font: inherit; cursor: pointer; touch-action: manipulation; overflow: hidden; }
.team-memory-card:active { transform: translateY(4px); box-shadow: 0 2px 0 #4d358f; }
.team-memory-card__back { font-size: clamp(1.7rem, 5vmin, 3rem); font-weight: 1000; }
.team-memory-card__face { position: absolute; inset: 0; display: grid; place-items: center; background: #fff9ec; font-size: clamp(2rem, 6vmin, 3.7rem); opacity: 0; transform: rotateY(90deg); transition: transform .18s ease, opacity .12s ease; }
.team-memory-card.flipped .team-memory-card__back, .team-memory-card.matched .team-memory-card__back { opacity: 0; }
.team-memory-card.flipped .team-memory-card__face, .team-memory-card.matched .team-memory-card__face { opacity: 1; transform: rotateY(0); }
.team-memory-card.matched { border-color: #279a79; background: #91e5ca; box-shadow: 0 5px 0 #18745b; pointer-events: none; }
.team-memory-card.matched .team-memory-card__face { background: #dff9ee; }

@media (max-width: 700px), (orientation: portrait) {
  .team-target { width: min(440px, 88vw); }
  .team-zones { grid-template-columns: 1fr; gap: 7px; width: min(520px, 94vw); }
  .team-plus { position: absolute; left: 50%; transform: translateX(-50%); }
  .team-zone { padding: 10px 15px; }
  .team-number { min-height: 62px; }
  .team-memory-board { grid-template-columns: repeat(4, minmax(58px, 82px)); width: min(94vw, 390px); }
}

/* Results and records */
.results { flex-direction: column; align-items: center; justify-content: center; gap: 11px; text-align: center; }
.result-burst { display: grid; place-items: center; width: 90px; height: 90px; border-radius: 34% 66% 55% 45%; background: var(--gold); color: white; font-size: 3.4rem; box-shadow: var(--shadow); animation: gentle-float 2.2s ease-in-out infinite; }
@keyframes gentle-float { 50% { transform: translateY(-6px) rotate(5deg); } }
.results-subtitle { margin: 0; color: var(--muted); font-weight: 800; }
.save-status { min-height: 1.25em; margin: -2px 0 0; color: var(--muted); font-size: .82rem; font-weight: 800; }
.result-cards { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; width: min(700px, 94vw); }
.result-card { padding: 16px; border: 3px solid #eadfd3; border-radius: 22px; background: white; box-shadow: var(--shadow); }
.result-card.winner { border-color: var(--gold); background: #fff8d9; }
.result-card .big-avatar { font-size: 2.5rem; }
.result-card h3 { margin: 2px 0; font-size: 1.35rem; }
.result-card .final-score { color: #bf6f00; font-size: 2rem; font-weight: 1000; }
.result-card small { display: block; color: var(--muted); font-weight: 800; }
.result-actions { display: flex; gap: 12px; }
dialog { width: min(740px, 94vw); max-height: 88dvh; padding: 0; border: 0; border-radius: 27px; background: var(--paper); color: var(--ink); box-shadow: 0 30px 90px rgba(52,39,62,.32); }
dialog::backdrop { background: rgba(52,39,62,.62); backdrop-filter: blur(5px); }
.dialog-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: 22px; background: var(--paper); border-bottom: 2px solid #eee3d7; }
.dialog-head h2 { margin-top: 4px; font-size: 1.8rem; }
#records-body { display: grid; gap: 12px; padding: 20px 22px 28px; overflow-y: auto; }
.record-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.record-stat { padding: 13px 8px; border-radius: 15px; background: #f3ece4; text-align: center; }
.record-stat strong, .record-stat span { display: block; }
.record-stat strong { font-size: 1.5rem; }
.record-stat span { color: var(--muted); font-size: .78rem; font-weight: 800; }
.records-section-title, .history-title { margin: 8px 2px 0; font-size: 1.15rem; }
.record-player { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: center; gap: 10px 14px; padding: 13px 15px; border: 2px solid #eadfd3; border-radius: 18px; background: white; }
.record-rank { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 14px; background: #f3ece4; color: var(--muted); font-size: 1.15rem; font-weight: 1000; }
.record-rank--1 { background: #fff0b8; }
.record-rank--2 { background: #eceef2; }
.record-rank--3 { background: #f4d5bd; }
.record-identity { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; }
.record-identity > strong { font-size: 1.12rem; }
.record-wins { padding: 3px 7px; border-radius: 999px; background: #fff4cf; color: #815100; font-size: .72rem; font-weight: 900; }
.record-total { text-align: right; }
.record-total strong, .record-total small { display: block; }
.record-total strong { color: #bf6f00; font-size: 1.35rem; line-height: 1; }
.record-total small { margin-top: 3px; color: var(--muted); font-size: .67rem; font-weight: 800; }
.record-metrics { grid-column: 2 / -1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.record-metric { padding: 7px 9px; border-radius: 11px; background: #f7f2ec; }
.record-metric small, .record-metric strong { display: block; }
.record-metric small { color: var(--muted); font-size: .66rem; font-weight: 800; }
.record-metric strong { margin-top: 1px; font-size: .9rem; }
.history-match { padding: 13px 15px; border-radius: 16px; background: #f3ece4; }
.history-match__head { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: .76rem; font-weight: 900; }
.history-match__players { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-top: 8px; }
.history-chip { display: flex; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 12px; background: white; font-size: .8rem; font-weight: 900; }
.history-chip.winner { background: #fff0b8; color: #815100; }
.empty-records { padding: 30px; color: var(--muted); text-align: center; }

@media (max-height: 650px) and (orientation: landscape) {
  .home { gap: 7px; }
  .brand-mark img { width: 64px; }
  .home h1 { font-size: 3.6rem; }
  .home-actions { margin: 0; }
  .mode-card { min-height: 92px; padding: 12px 17px; }
  .mode-card__icon { width: 54px; height: 54px; }
  .setup { padding-top: 8px; padding-bottom: 8px; }
  .player-setup { padding: 12px; }
  .player-avatar { width: 62px; height: 62px; font-size: 2.25rem; }
  .setup-body { gap: 8px; }
  .difficulty-options button { min-height: 34px; padding: 5px 7px; font-size: .76rem; }
  .setup > .primary-button { min-height: 48px; padding: 11px 24px; }
}

@media (max-height: 820px) and (orientation: landscape) {
  .puzzle-stage { gap: 5px; }
  .puzzle-title { font-size: clamp(.95rem, 2.4vmin, 1.22rem); }
  .tap-grid { width: min(330px, 72%); gap: 5px; }
  .tap-grid.dense { width: min(260px, 58%); gap: 4px; }
  .path-grid { width: min(190px, 46%); }
  .puzzle-help { max-width: 48ch; font-size: .68rem; }
  .move-line { gap: 4px; }
  .move-line span { width: 31px; height: 35px; }
  .grid-item { font-size: clamp(1rem, 2.7vmin, 1.5rem); }
  .answer-button { min-height: 46px; }
  .arena-feedback { font-size: clamp(2.5rem, 8vmin, 4.5rem); }
}

@media (max-width: 700px) {
  .family-gate__actions { grid-template-columns: 1fr; gap: 8px; }
  .family-or { margin: 0; }
  .family-gate__card { padding: 20px 16px; }
  .home-actions { grid-template-columns: 1fr; }
  .mode-card { min-height: 92px; }
  .players-setup { grid-template-columns: 1fr; gap: 9px; }
  .versus-badge { position: absolute; left: 50%; transform: translate(-50%,-50%) rotate(-7deg); }
  .setup { overflow-y: auto; }
  .player-setup { grid-template-columns: auto 1fr; }
  .dialog-head { padding: 17px; }
  .dialog-head h2 { font-size: 1.45rem; }
  #records-body { padding: 15px 14px 22px; }
  .record-stat { padding: 10px 5px; }
  .record-stat strong { font-size: 1.25rem; }
  .record-stat span { font-size: .68rem; }
  .record-player { grid-template-columns: 38px minmax(0, 1fr) auto; gap: 8px 10px; padding: 11px; }
  .record-rank { width: 36px; height: 36px; border-radius: 12px; }
  .record-total strong { font-size: 1.15rem; }
  .record-metrics { grid-column: 1 / -1; }
  .history-match__players { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
