:root {
  --sky-top: #5aa9e6;
  --sky-bottom: #cfe9ff;
  --ink: #1d2b3a;
  --muted: #5b6b7c;
  --card: #ffffff;
  --line: #d7e1ea;
  --brand: #2f6fd6;
  --brand-dark: #1f4fa0;
  --ok: #2e9d57;
  --ok-bg: #e3f6ea;
  --bad: #d64545;
  --bad-bg: #fde8e8;
  --brick: #c8743f;
  --brick-dark: #8f4b23;
  --me: #f2b705;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(20, 50, 90, .15);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom)) fixed;
  font-size: 17px;
  line-height: 1.45;
}
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
a { color: var(--brand); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.wrap { max-width: 1200px; margin: 0 auto; padding: 16px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.center-card { max-width: 420px; margin: 8vh auto 0; }
.logo { font-size: 28px; font-weight: 800; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.25); text-align: center; margin: 4vh 0 0; }
.logo small { display: block; font-size: 15px; font-weight: 500; opacity: .9; }

label { display: block; font-weight: 600; margin: 12px 0 4px; }
input[type=text], input[type=password], input[type=number], select {
  width: 100%; padding: 12px 14px; font-size: 18px; border: 2px solid var(--line); border-radius: 10px; outline: none;
}
input:focus { border-color: var(--brand); }
input.code { text-transform: uppercase; letter-spacing: .3em; font-weight: 700; text-align: center; font-size: 26px; }
button {
  font: inherit; cursor: pointer; border: 0; border-radius: 10px; padding: 12px 18px;
  background: var(--brand); color: #fff; font-weight: 700;
}
button:hover { background: var(--brand-dark); }
button:disabled { opacity: .5; cursor: default; }
button.secondary { background: #e8eef5; color: var(--ink); }
button.secondary:hover { background: #d6e0eb; }
button.danger { background: var(--bad); }
button.wide { width: 100%; margin-top: 16px; font-size: 19px; }
.error { color: var(--bad); font-weight: 600; min-height: 1.4em; margin-top: 10px; }

/* --- ekran ucznia --- */
.play { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 860px) { .play { grid-template-columns: 1fr; } }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: #fff; font-weight: 600; margin-bottom: 12px; text-shadow: 0 1px 4px rgba(0,0,0,.25); flex-wrap: wrap; }
.pill { background: rgba(255,255,255,.25); border-radius: 99px; padding: 4px 12px; }
.question { font-size: 20px; }
.question img { max-width: 100%; height: auto; border-radius: 8px; display: block; margin: 8px auto; }
.question p { margin: 0 0 .5em; }
.qtag { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.answers { display: grid; gap: 10px; margin-top: 14px; }
.answer {
  display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  background: #f3f7fb; color: var(--ink); border: 2px solid var(--line); font-weight: 500; padding: 12px 14px;
}
.answer:hover:not(:disabled) { background: #e6f0fb; border-color: var(--brand); }
.answer:disabled { opacity: 1; }
.answer .key {
  flex: 0 0 34px; height: 34px; border-radius: 8px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 800;
}
.answer img { max-width: 100%; height: auto; }
.answer.correct { background: var(--ok-bg); border-color: var(--ok); }
.answer.correct .key { background: var(--ok); }
.answer.wrong { background: var(--bad-bg); border-color: var(--bad); }
.answer.wrong .key { background: var(--bad); }
.result { margin-top: 14px; padding: 12px 14px; border-radius: 10px; }
.result.ok { background: var(--ok-bg); }
.result.bad { background: var(--bad-bg); }
.result .title { font-weight: 800; font-size: 19px; }
.result .fb { margin-top: 6px; font-size: 16px; }
.result .fb img { max-width: 100%; height: auto; }

.mytower { display: flex; align-items: baseline; gap: 8px; font-size: 15px; }
.mytower b { font-size: 40px; line-height: 1; }
.streak { font-size: 14px; color: var(--muted); margin-top: 4px; }
.place { margin-top: 10px; font-weight: 700; }

/* scena z wieżami: na komputerze cała szerokość w tle pod pytaniami, na telefonie mini-podgląd w panelu */
#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0; display: block; }
body.ingame .wrap { position: relative; z-index: 1; }
body:not(.ingame) #scene { display: none; }
.side #scene { position: static; width: 100%; height: 170px; border-radius: 10px; margin-top: 8px; z-index: auto; }
@media (max-width: 860px) {
  /* na telefonie mini-scena nad pytaniem, żeby nie trzeba było przewijać */
  .side { order: -1; padding: 10px 12px; }
  .side .mytower b { font-size: 28px; }
  .side .place { margin-top: 2px; }
}
@media (min-width: 861px) {
  body.ingame .card { background: rgba(255, 255, 255, .96); }
  /* po końcu gry wynik zjeżdża na dół, żeby nie zasłaniał podium */
  body.ended .play { position: fixed; left: 0; right: 0; bottom: 16px; margin: 0 auto; width: min(560px, 92vw); grid-template-columns: 1fr; }
  body.ended .side { display: none; }
  body.ended .big-msg { padding: 14px 20px; }
  body.ended .big-msg .emoji { font-size: 40px; }
}

/* lupa i podgląd obrazków */
.question img, .result .fb img, .answer img { cursor: zoom-in; }
.lens {
  position: fixed; width: 280px; height: 280px; border-radius: 50%; pointer-events: none; z-index: 50;
  border: 3px solid #fff; box-shadow: 0 6px 24px rgba(0,0,0,.35); background: #fff no-repeat;
}
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(10, 20, 30, .9); display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { width: 96vw; height: 88vh; object-fit: contain; background: #fff; border-radius: 6px; }
.lightbox .hint { color: #fff; font-size: 14px; opacity: .8; }

.big-msg { text-align: center; padding: 40px 20px; }
.big-msg .emoji { font-size: 64px; }

/* --- panel nauczyciela --- */
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 18px; }
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.tag { display: flex; gap: 6px; align-items: center; background: #eef3f9; border-radius: 99px; padding: 6px 12px; font-weight: 500; margin: 0; cursor: pointer; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 14px; color: var(--muted); }
.hardq img { max-width: 220px; height: auto; display: block; }
.hardq p { margin: 0; }
.codebig { font-size: 56px; font-weight: 900; letter-spacing: .15em; color: var(--brand); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.section { margin-top: 16px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); margin-right: 6px; }
.dot.off { background: #b8c2cc; }

/* --- panel nauczyciela: formularz nowej gry --- */
.small { font-size: 14px; font-weight: 400; }
.mono { font-family: Consolas, monospace; letter-spacing: .08em; }
.nowrap { white-space: nowrap; }
.step { display: flex; align-items: center; gap: 8px; margin: 22px 0 10px; font-size: 18px; }
.step:first-of-type { margin-top: 8px; }
.ico { font-size: 22px; line-height: 1; }
.qualcards { display: flex; flex-wrap: wrap; gap: 12px; }
.qualcard { display: flex; gap: 10px; align-items: center; margin: 0; padding: 12px 18px; border: 2px solid var(--line); border-radius: 12px; cursor: pointer; font-weight: 500; }
.qualcard b { font-size: 20px; display: block; }
.qualcard small { color: var(--muted); }
.qualcard:has(input:checked) { border-color: var(--brand); background: #eaf2fd; }
.settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.setting { display: grid; grid-template-columns: 34px 1fr minmax(84px, auto); gap: 10px; align-items: center; margin: 0; padding: 10px 12px; background: #f3f7fb; border-radius: 12px; font-weight: 500; cursor: default; }
.setting .txt b { display: block; }
.setting .txt small { color: var(--muted); font-size: 13px; line-height: 1.25; display: block; }
.setting input, .setting select { padding: 8px; font-size: 18px; text-align: center; }
.summary { margin-top: 18px; padding: 12px 14px; background: #eef6ee; border-radius: 10px; }
button.big { font-size: 21px; padding: 14px; }
.listrow { margin: 6px 0; }

/* pasek zerwanego połączenia u ucznia */
.conn {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: #fff3c4; color: #6b4e00; text-align: center; font-weight: 600;
  padding: 8px 12px; box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
/* dziennik połączeń w panelu nauczyciela */
.logbox { max-height: 360px; overflow: auto; background: #f4f7fa; border-radius: 10px; padding: 10px 12px;
  font: 13px/1.5 Consolas, "Courier New", monospace; white-space: pre-wrap; word-break: break-word; }
.logbox .warn { color: var(--bad); }
.drops { font-size: 13px; color: var(--bad); margin-left: 4px; }

/* przycisk dźwięku: na projektorze w prawym dolnym rogu, u ucznia w górnym pasku */
.soundbtn { position: fixed; right: 16px; bottom: 16px; z-index: 20; padding: 8px 14px; font-size: 20px; border-radius: 99px;
  background: rgba(255, 255, 255, .85); color: var(--ink); box-shadow: var(--shadow); width: auto; }
.soundbtn.inline { position: static; font-size: 16px; padding: 2px 10px; box-shadow: none; }
.soundbtn.blocked { background: #fff3c4; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.soundbtn:hover { background: #fff; }
.again { background: #fff3c4; color: #6b4e00; border-radius: 99px; padding: 1px 10px; margin-right: 6px; font-weight: 600; }
.setting input { width: 84px; justify-self: end; }
