@font-face { font-family: Nunito; font-weight: 600; font-display: swap; src: url(/fonts/nunito-latin-ext-600-normal.woff2) format('woff2'); unicode-range: U+0100-024F, U+1E00-1EFF; }
@font-face { font-family: Nunito; font-weight: 600; font-display: swap; src: url(/fonts/nunito-latin-600-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: Nunito; font-weight: 800; font-display: swap; src: url(/fonts/nunito-latin-ext-800-normal.woff2) format('woff2'); unicode-range: U+0100-024F, U+1E00-1EFF; }
@font-face { font-family: Nunito; font-weight: 800; font-display: swap; src: url(/fonts/nunito-latin-800-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: Nunito; font-weight: 900; font-display: swap; src: url(/fonts/nunito-latin-ext-900-normal.woff2) format('woff2'); unicode-range: U+0100-024F, U+1E00-1EFF; }
@font-face { font-family: Nunito; font-weight: 900; font-display: swap; src: url(/fonts/nunito-latin-900-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F; }

:root {
  --bg: #fff8e7;
  --bg-2: #ffe8a3;
  --ink: #1f2a37;
  --ink-soft: #4b5563;
  --brand: #2f9e44;
  --brand-dark: #237032;
  --accent: #f76707;
  --card: #ffffff;
  --line: #1f2a37;
  --ok: #2b8a3e;
  --ok-bg: #d3f9d8;
  --bad: #c92a2a;
  --bad-bg: #ffe3e3;
  --focus: #1c7ed6;
  --tile-a: #fff3bf;
  --tile-b: #d0ebff;
  --tile-c: #ffdeeb;
  --tile-d: #e5dbff;
  --radius: 1.4rem;
  --touch: max(96px, 4.6rem);
  --shadow: 0 0.35rem 0 var(--line);
  --min-text: 28px; /* minimum na tablicy */
}

* { box-sizing: border-box; }
html {
  /* Skala z szerokością i wysokością ekranu; drobne napisy mają twarde minimum --min-text. */
  font-size: clamp(14px, 0.9vw + 0.55vh, 34px);
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(circle at 20% 10%, var(--bg-2), var(--bg) 55%);
  color: var(--ink);
  font-family: Nunito, 'Trebuchet MS', system-ui, sans-serif;
  font-weight: 800;
  line-height: 1.2;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overflow-x: hidden;
}
img { max-width: 100%; -webkit-user-drag: none; }
button { font: inherit; color: inherit; touch-action: manipulation; }
:focus-visible { outline: 0.3rem solid var(--focus); outline-offset: 0.2rem; }

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: clamp(16px, 2vw, 48px);
  padding-bottom: calc(clamp(16px, 2vw, 48px) + var(--touch));
}
.loading { margin: auto; font-size: 2rem; }

.screen { flex: 1; display: flex; flex-direction: column; gap: 1.2rem; animation: enter .35s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(1rem); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

h1, h2, h3 { margin: 0; font-weight: 900; line-height: 1.1; }
h1 { font-size: 3.6rem; color: var(--brand-dark); }
h2 { font-size: 2.6rem; }
h3 { font-size: 1.8rem; }
.lead { font-size: 1.8rem; margin: 0; color: var(--ink-soft); }
.small { font-size: max(var(--min-text), 1.3rem); color: var(--ink-soft); margin: 0; }

/* ---------- przyciski ---------- */
.btn {
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0.6rem 2.2rem;
  border: 0.22rem solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 1.8rem;
  font-weight: 900;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  transition: transform .08s;
}
.btn:active { transform: translateY(0.3rem); box-shadow: 0 0.05rem 0 var(--line); }
.btn:disabled { opacity: .45; cursor: default; transform: none; box-shadow: var(--shadow); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-big { font-size: 2.4rem; padding: 0.8rem 3.4rem; }
.row { display: flex; gap: 1.2rem; flex-wrap: wrap; align-items: center; }
.center { justify-content: center; text-align: center; }
.spacer { flex: 1; }

/* ---------- start ---------- */
.start { align-items: center; justify-content: center; text-align: center; }
.hosts { display: flex; align-items: flex-end; justify-content: center; gap: 2rem; }
.hosts img { height: min(34dvh, 20rem); animation: bob 2.4s ease-in-out infinite; }
.hosts img:nth-child(2) { animation-delay: -1.2s; }
.hosts-small img { height: min(28dvh, 14rem); }
@keyframes bob { 50% { transform: translateY(-0.6rem); } }
.speech {
  position: relative;
  background: var(--card);
  border: 0.22rem solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.6rem;
  font-size: 1.8rem;
  max-width: 50rem;
}

/* ---------- klawiatura kodu ---------- */
.code-display {
  font-size: 3.4rem; letter-spacing: 0.5em; min-height: 1.4em; text-align: center;
  background: var(--card); border: 0.22rem solid var(--line); border-radius: var(--radius); padding: 0.4rem 1.6rem 0.4rem 2.1rem;
  min-width: 18rem;
}
.keypad { display: grid; grid-template-columns: repeat(3, var(--touch)); gap: 1rem; justify-content: center; }
.keypad .btn { border-radius: 1.2rem; font-size: 2.4rem; padding: 0; }
.error { color: var(--bad); font-size: max(var(--min-text), 1.6rem); min-height: 1.2em; margin: 0; text-align: center; }

/* ---------- wybór gracza ---------- */
.setup { display: grid; grid-template-columns: 1fr 1.1fr; gap: 1.6rem; flex: 1; align-content: start; }
.panel { background: rgba(255, 255, 255, .75); border: 0.22rem solid var(--line); border-radius: var(--radius); padding: 1.2rem; display: flex; flex-direction: column; gap: 1rem; }
.avatars { display: grid; grid-template-columns: repeat(auto-fill, minmax(max(96px, 7rem), 1fr)); gap: 1rem; }
.avatar-btn {
  min-height: calc(var(--touch) * 1.6);
  border: 0.22rem solid var(--line); border-radius: 1.2rem; background: var(--card);
  padding: 0.4rem; cursor: pointer; position: relative; box-shadow: var(--shadow);
}
.avatar-btn img { height: min(11rem, 22dvh); width: 100%; object-fit: contain; }
.avatar-btn[aria-pressed="true"] { background: var(--ok-bg); outline: 0.4rem solid var(--brand); }
.avatar-btn[aria-pressed="true"]::after, .class-btn[aria-pressed="true"]::after {
  content: '✓'; position: absolute; top: 0.2rem; right: 0.5rem; font-size: 1.8rem; color: var(--brand-dark);
}
.nick-row { flex-wrap: nowrap; }
.nick { font-size: 2.2rem; white-space: nowrap; color: var(--brand-dark); background: var(--card); border-radius: 1rem; padding: 0.4rem 1rem; border: 0.22rem dashed var(--brand); }
.classes { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--touch), 1fr)); gap: 0.8rem; }
.class-btn { position: relative; border-radius: 1rem; padding: 0; font-size: 1.8rem; }
.class-btn[aria-pressed="true"] { background: var(--ok-bg); outline: 0.4rem solid var(--brand); }

/* ---------- pasek gry ---------- */
.topbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; font-size: max(var(--min-text), 1.5rem); }
.chip { background: var(--card); border: 0.2rem solid var(--line); border-radius: 999px; padding: 0.3rem 1.1rem; white-space: nowrap; }
.chip-score { background: var(--bg-2); }
.timer { flex: 1; min-width: 10rem; display: flex; align-items: center; gap: 0.8rem; }
.timer-track { flex: 1; height: 1.6rem; border: 0.2rem solid var(--line); border-radius: 999px; background: var(--card); overflow: hidden; }
.timer-fill { height: 100%; width: 100%; background: var(--brand); transform-origin: left; }
.timer-fill.warn { background: var(--accent); }
.timer-fill.danger { background: var(--bad); }
.timer-label { font-size: max(var(--min-text), 1.6rem); min-width: 4.5em; text-align: right; }

/* ---------- pytanie ---------- */
.stage { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1.6rem; flex: 1; align-items: center; }
.qbox { display: flex; flex-direction: column; gap: 1.4rem; }
.question-row { display: flex; gap: 1rem; align-items: flex-start; }
.question {
  flex: 1; font-size: 2.4rem; font-weight: 900; margin: 0;
  background: var(--card); border: 0.22rem solid var(--line); border-radius: var(--radius); padding: 1rem 1.4rem;
}
.speaker { flex: none; border-radius: 50%; padding: 0; font-size: 2.2rem; }
.answers { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 1.2rem; }
.answer {
  position: relative; min-height: max(var(--touch), 8rem);
  border: 0.25rem solid var(--line); border-radius: var(--radius);
  font-size: max(var(--min-text), 1.9rem); font-weight: 900; text-align: left;
  display: flex; align-items: center; gap: 1rem; padding: 1rem 1.2rem;
  cursor: pointer; box-shadow: var(--shadow);
}
.answer:nth-child(1) { background: var(--tile-a); }
.answer:nth-child(2) { background: var(--tile-b); }
.answer:nth-child(3) { background: var(--tile-c); }
.answer:nth-child(4) { background: var(--tile-d); }
.answer .badge {
  flex: none; width: 3.4rem; height: 3.4rem; border-radius: 50%; border: 0.2rem solid var(--line);
  background: var(--card); display: grid; place-items: center; font-size: 1.8rem;
}
.answer.reading { outline: 0.5rem solid var(--focus); transform: scale(1.03); }
.answer:disabled { cursor: default; }
.answer.correct { background: var(--ok-bg) !important; border-color: var(--ok); }
.answer.wrong { background: var(--bad-bg) !important; border-color: var(--bad); }
.answer.dim { opacity: .45; }
.answer .mark { margin-left: auto; font-size: 2.6rem; }
.answer.correct .mark::before { content: '✓'; color: var(--ok); }
.answer.wrong .mark::before { content: '✗'; color: var(--bad); }
.answer.picked { outline: 0.45rem dashed var(--line); outline-offset: 0.25rem; }

.host-side { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; width: min(18rem, 22vw); }
.host-side img { height: min(46dvh, 20rem); }
.host-side.happy img { animation: jump .5s ease-out 2; }
.host-side.sad img { animation: shake .4s ease-out 1; }
@keyframes jump { 50% { transform: translateY(-1.2rem) rotate(-4deg); } }
@keyframes shake { 25% { transform: translateX(-0.6rem); } 75% { transform: translateX(0.6rem); } }
.bubble { background: var(--card); border: 0.22rem solid var(--line); border-radius: 1.2rem; padding: 0.5rem 1rem; font-size: max(var(--min-text), 1.6rem); text-align: center; min-height: 2.2em; }

.feedback {
  display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap;
  background: var(--card); border: 0.22rem solid var(--line); border-radius: var(--radius); padding: 1rem 1.4rem;
  animation: enter .3s ease-out;
}
.feedback .verdict { font-size: 2.2rem; }
.feedback .verdict.ok { color: var(--ok); }
.feedback .verdict.bad { color: var(--bad); }
.feedback .fact { flex: 1 1 24rem; font-size: max(var(--min-text), 1.8rem); margin: 0; }
.feedback .fact::before { content: 'Ciekawostka: '; color: var(--accent); }
.points-pop { font-size: 2rem; color: var(--brand-dark); }

/* ---------- podsumowania i ranking ---------- */
.summary { align-items: center; justify-content: center; text-align: center; }
.big-number { font-size: 6rem; font-weight: 900; color: var(--brand-dark); line-height: 1; }
.stats { display: flex; gap: 1.2rem; flex-wrap: wrap; justify-content: center; }
.stat { background: var(--card); border: 0.22rem solid var(--line); border-radius: var(--radius); padding: 0.8rem 1.6rem; font-size: max(var(--min-text), 1.6rem); }
.stat strong { display: block; font-size: 2.6rem; }
.stars { font-size: 4rem; letter-spacing: 0.2em; }
.stars .off { opacity: .2; }

.tabs { display: flex; gap: 1rem; flex-wrap: wrap; }
.tabs .btn[aria-selected="true"] { background: var(--brand); color: #fff; }
.ranking { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.ranking li {
  display: grid; grid-template-columns: 3.6rem 3.6rem 1fr auto; gap: 1rem; align-items: center;
  background: var(--card); border: 0.2rem solid var(--line); border-radius: 1rem; padding: 0.3rem 1rem; font-size: max(var(--min-text), 1.6rem);
}
.ranking li.me { background: var(--ok-bg); outline: 0.3rem solid var(--brand); }
.ranking .place { font-size: 2rem; text-align: center; }
.ranking img { height: 3.4rem; width: 3.4rem; object-fit: cover; object-position: top; border-radius: 50%; background: var(--bg-2); }
.ranking .who small { display: block; font-size: max(var(--min-text), 1.3rem); color: var(--ink-soft); }
.ranking .pts { font-size: 2rem; }
.empty { font-size: 1.8rem; text-align: center; color: var(--ink-soft); padding: 2rem; }

.voice-toggle {
  position: fixed; right: clamp(16px, 1.5vw, 40px); bottom: clamp(16px, 1.5vw, 40px);
  width: var(--touch); height: var(--touch); padding: 0; border-radius: 50%; border: 0.22rem solid var(--line);
  background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center; cursor: pointer; z-index: 10;
}
.voice-toggle .voice-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.voice-toggle .voice-icon::before { content: '🔊'; font-size: 2rem; }
.voice-toggle[aria-pressed="false"] .voice-icon::before { content: '🔇'; }
.voice-toggle[hidden] { display: none; }

/* ---------- mniejsze ekrany (V2: telefon/tablet) ---------- */
@media (max-width: 900px) {
  html { font-size: 15px; }
  :root { --min-text: 16px; --touch: 72px; }
  h1 { font-size: 2.6rem; }
  .setup, .stage { grid-template-columns: 1fr; }
  .nick-row { flex-wrap: wrap; }
  .answers { grid-template-columns: 1fr; }
  .host-side { flex-direction: row; width: auto; }
  .host-side img { height: 7rem; }
  .hosts img { height: 30dvh; }
}
@media (max-height: 820px) and (min-width: 901px) {
  .hosts img { height: 30dvh; }
  .host-side img { height: 40dvh; }
}
