@import url("https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@600;700;800&family=Open+Sans:wght@400;600;700&display=swap");

:root {
  --bg: #f4f7f5;
  --bg-card: #ffffff;
  --bg-soft: #eef3ef;
  --text: #4d4e4c;
  --muted: #6b6d6a;
  --accent: #007aae;
  --accent-2: #9ab876;
  --accent-3: #efa167;
  --accent-4: #7c596d;
  --danger: #b87563;
  --ok: #9ab876;
  --border: #dbdcdb;
  --shadow: 0 10px 28px rgba(77, 78, 76, 0.08);
  --radius: 16px;
  --font: "Open Sans", system-ui, -apple-system, sans-serif;
  --font-display: "Barlow Condensed", "Open Sans", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background:
    radial-gradient(circle at top right, rgba(0, 122, 174, 0.08), transparent 42%),
    radial-gradient(circle at bottom left, rgba(154, 184, 118, 0.12), transparent 38%),
    linear-gradient(180deg, #ffffff 0%, var(--bg) 45%, #e8f0ea 100%);
  color: var(--text);
}

html:has(body.host-page),
body.host-page {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.brand-bar img {
  height: 48px;
  width: auto;
  display: block;
}

.app {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 1.25rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.eyebrow {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
}

h1,
h2,
h3 {
  margin: 0 0 0.75rem;
  line-height: 1.1;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--text);
}

h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

p {
  color: var(--muted);
  line-height: 1.5;
}

.muted {
  color: var(--muted);
}

.form {
  display: grid;
  gap: 0.9rem;
  margin-top: 1.25rem;
}

label {
  display: grid;
  gap: 0.4rem;
  font-weight: 600;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"] {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 122, 174, 0.15);
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 0.95rem 1.2rem;
  font-weight: 700;
  font-family: var(--font-display);
  letter-spacing: 0.02em;
  font-size: 1.1rem;
  background: var(--accent);
  color: #fff;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn:hover {
  filter: brightness(1.05);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-sound-on {
  background: rgba(0, 122, 174, 0.12);
  color: var(--accent);
  border: 1px solid rgba(0, 122, 174, 0.35);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-accent {
  background: var(--accent-2);
  color: #2f3a28;
}

.error {
  color: #8a3d30;
  background: rgba(184, 117, 99, 0.12);
  border: 1px solid rgba(184, 117, 99, 0.35);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin-top: 1rem;
}

.success {
  color: #3d5630;
  background: rgba(154, 184, 118, 0.18);
  border: 1px solid rgba(154, 184, 118, 0.45);
  border-radius: 12px;
  padding: 0.75rem 1rem;
}

.timer-wrap {
  margin: 1rem 0 1.25rem;
}

.timer-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.4rem;
  font-weight: 700;
}

.timer-bar {
  height: 14px;
  border-radius: 999px;
  background: rgba(77, 78, 76, 0.1);
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.2s linear;
}

.answers {
  display: grid;
  gap: 0.85rem;
}

.answer-btn {
  text-align: left;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.9rem;
  align-items: center;
  padding: 1.1rem 1.15rem;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
}

.answer-btn .key {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(0, 122, 174, 0.12);
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 800;
}

.answer-btn.selected,
.answer-btn.correct {
  border-color: var(--ok);
  box-shadow: 0 0 0 2px rgba(154, 184, 118, 0.35);
}

.answer-btn.correct {
  background: rgba(154, 184, 118, 0.18);
}

.answer-btn:disabled {
  opacity: 0.7;
}

.estimate-slider {
  display: grid;
  gap: 1rem;
  margin-top: 0.5rem;
}

.estimate-value {
  text-align: center;
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  font-weight: 800;
  font-family: var(--font-display);
  color: var(--accent);
  letter-spacing: 0.02em;
}

.estimate-slider input[type="range"] {
  width: 100%;
  height: 2.2rem;
  appearance: none;
  background: transparent;
  padding: 0;
}

.estimate-slider input[type="range"]::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: 999px;
  background: rgba(77, 78, 76, 0.12);
}

.estimate-slider input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 36px;
  height: 36px;
  margin-top: -12px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 4px 14px rgba(0, 122, 174, 0.35);
}

.estimate-slider input[type="range"]::-moz-range-track {
  height: 12px;
  border-radius: 999px;
  background: rgba(77, 78, 76, 0.12);
}

.estimate-slider input[type="range"]::-moz-range-thumb {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 4px 14px rgba(0, 122, 174, 0.35);
}

.estimate-scale {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
}

.estimate-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  align-items: end;
}

.wait-box {
  text-align: center;
  padding: 2rem 1rem;
}

.wait-box h2 {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
}

.player-result {
  text-align: center;
  padding: 1.1rem 0.35rem 0.5rem;
}

.player-result-rank {
  font-family: var(--font-display);
  font-size: clamp(2.1rem, 8vw, 3rem);
  font-weight: 800;
  color: var(--text);
  margin: 0.85rem 0 1.1rem;
  line-height: 1.05;
}

.player-result-rank strong {
  color: var(--accent);
}

.player-result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin: 0 0 0.75rem;
}

.player-result-stats .stat {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 0.4rem;
}

.player-result-stats .stat strong {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 7vw, 2.4rem);
  color: var(--accent);
  line-height: 1;
  margin-bottom: 0.3rem;
}

.player-result-stats .stat span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.player-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
  margin: 0.35rem 0 1rem;
}

.player-stats .stat {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem 0.4rem;
  text-align: center;
}

.player-stats .stat strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 0.25rem;
}

.player-stats .stat span {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.25;
}

/* Host layout — projector: one viewport, no page scroll */
.host-app {
  width: 100%;
  max-width: none;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  padding: clamp(0.28rem, 0.7vh, 0.55rem) clamp(0.45rem, 1vw, 0.9rem) clamp(0.3rem, 0.7vh, 0.55rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.host-app:has(#login-view:not(.hidden)) {
  overflow: auto;
}

.host-app > .brand-bar {
  flex-shrink: 0;
  margin-bottom: clamp(0.2rem, 0.5vh, 0.4rem);
  gap: 0.5rem;
}

.host-app > .brand-bar img {
  height: clamp(24px, 3.6vh, 36px);
}

.host-app #login-view {
  width: min(28rem, 100%);
  margin: auto;
}

.host-app #host-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.host-app .card {
  padding: clamp(0.45rem, 0.9vh, 0.75rem) clamp(0.55rem, 1vw, 0.9rem);
}

.host-header {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: clamp(0.25rem, 0.6vh, 0.45rem);
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.host-header h1 {
  font-size: clamp(1rem, 1.35vw + 0.5vh, 1.45rem);
  margin: 0;
  line-height: 1.1;
}

.host-header .eyebrow {
  font-size: clamp(0.58rem, 0.9vw, 0.72rem);
  margin: 0 0 0.08rem;
}

.host-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.host-app .host-actions .btn {
  padding: 0.28rem 0.55rem;
  font-size: clamp(0.82rem, 1.05vw, 1rem);
  border-radius: 8px;
  white-space: nowrap;
}

.host-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 17.5rem);
  gap: clamp(0.35rem, 0.8vw, 0.65rem);
  overflow: hidden;
}

.host-grid-finished {
  grid-template-columns: 1fr;
}

.host-grid-finished #main-panel {
  min-height: 0;
  overflow: hidden;
}

.host-app #main-panel {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@media (max-width: 900px) {
  .host-header {
    flex-wrap: wrap;
  }

  .host-actions {
    flex-wrap: wrap;
  }

  .host-grid {
    grid-template-columns: 1fr;
  }
}

.host-app .question-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.host-app .timer-meta {
  flex-shrink: 0;
  margin-bottom: 0.2rem;
  font-size: clamp(0.85rem, 1.2vw + 0.4vh, 1.15rem);
  align-items: center;
}

.host-app #q-timer {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.15rem, 1.6vw + 0.6vh, 1.7rem);
  color: var(--accent);
}

.host-app .timer-bar {
  flex-shrink: 0;
  height: clamp(7px, 1vh, 11px);
  margin: 0 0 clamp(0.25rem, 0.6vh, 0.45rem);
}

.host-app .question-text {
  font-size: clamp(1.55rem, 2.6vw + 1.6vh, 3.85rem);
  font-weight: 800;
  font-family: var(--font-display);
  margin: 0 0 clamp(0.25rem, 0.7vh, 0.5rem);
  line-height: 1.12;
  flex-shrink: 0;
}

.host-app .q-subhint {
  flex-shrink: 0;
  margin: 0 0 clamp(0.2rem, 0.5vh, 0.4rem);
  font-size: clamp(0.8rem, 1vw, 1rem);
  line-height: 1.3;
}

.host-options {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-auto-rows: 1fr;
  gap: clamp(0.28rem, 0.75vh, 0.55rem);
}

.host-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: clamp(0.55rem, 1.1vw, 1rem);
  align-items: center;
  min-height: 0;
  padding: clamp(0.28rem, 0.8vh, 0.7rem) clamp(0.55rem, 1.1vw, 1rem);
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  font-size: clamp(1.2rem, 1.75vw + 1.45vh, 2.7rem);
  font-weight: 600;
  line-height: 1.18;
}

.host-option .key {
  width: clamp(2.5rem, 3.2vw + 1.3vh, 4.5rem);
  height: clamp(2.5rem, 3.2vw + 1.3vh, 4.5rem);
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(0, 122, 174, 0.12);
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.35rem, 2.15vw + 1vh, 2.7rem);
  flex-shrink: 0;
}

.host-option.correct {
  border-color: var(--ok);
  background: rgba(154, 184, 118, 0.22);
}

.host-app .host-hint {
  flex-shrink: 0;
  margin-top: clamp(0.25rem, 0.6vh, 0.45rem);
  padding: 0.4rem 0.7rem;
  border-radius: 10px;
  background: rgba(239, 161, 103, 0.18);
  border: 1px solid rgba(239, 161, 103, 0.45);
  color: #8a5428;
  font-weight: 700;
  font-size: clamp(0.9rem, 1.2vw, 1.15rem);
}

.host-app .q-correct-label {
  flex-shrink: 0;
  margin-top: clamp(0.25rem, 0.6vh, 0.45rem);
  padding: 0.4rem 0.7rem;
  font-size: clamp(1rem, 1.4vw, 1.3rem);
}

.lobby-center {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
}

.lobby-center h2 {
  font-size: clamp(1.2rem, 2vw + 0.8vh, 2rem);
  margin: 0.35rem 0 0.2rem;
}

.lobby-center > p {
  margin: 0.15rem 0;
  font-size: clamp(0.85rem, 1.1vw, 1rem);
}

.qr-box {
  margin: clamp(0.35rem, 1vh, 0.7rem) auto;
  width: min(34vh, 320px, 90%);
  padding: clamp(0.35rem, 0.8vh, 0.65rem);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
}

.qr-box img {
  width: 100%;
  display: block;
}

.player-count {
  font-size: clamp(1.8rem, 4.5vh, 3.1rem);
  font-weight: 800;
  font-family: var(--font-display);
  color: var(--accent);
  margin: 0.15rem 0;
  line-height: 1;
}

.ranking-card {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ranking-card h3 {
  margin-bottom: 0.35rem;
  color: var(--accent);
  font-size: clamp(0.95rem, 1.3vw, 1.2rem);
}

.rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.28rem;
}

.rank-list li {
  display: grid;
  grid-template-columns: 1.7rem minmax(0, 1fr) auto;
  gap: 0.4rem;
  align-items: center;
  padding: 0.28rem 0.45rem;
  border-radius: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  font-size: clamp(0.78rem, 0.95vw + 0.25vh, 0.95rem);
  min-width: 0;
}

.rank-list li > span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.final-board .rank-list li > span:nth-child(2) {
  white-space: normal;
}

.rank-list .pos {
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 800;
}

.rank-list .meta {
  text-align: right;
  line-height: 1.15;
}

.rank-list .score {
  font-weight: 800;
  font-family: var(--font-display);
  color: var(--accent-2);
  display: block;
}

.rank-list .corrects {
  font-size: 0.75em;
  color: var(--muted);
  font-weight: 600;
}

.rank-block + .rank-block {
  margin-top: 0.55rem;
}

.ranking-note {
  margin: 0.45rem 0 0;
  font-size: 0.72rem;
}

.finished-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.final-title {
  font-size: clamp(1.5rem, 2.4vw + 1vh, 2.6rem);
  text-align: center;
  margin-bottom: 0.15rem;
  flex-shrink: 0;
}

.final-thanks {
  text-align: center;
  margin: 0 0 0.25rem;
  flex-shrink: 0;
  font-size: clamp(0.85rem, 1.1vw, 1.05rem);
}

.final-meta {
  text-align: center;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 clamp(0.35rem, 0.8vh, 0.6rem);
  font-size: clamp(0.85rem, 1.1vw, 1.05rem);
  flex-shrink: 0;
}

.final-boards {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(0.5rem, 1.4vw, 1.25rem);
  overflow: hidden;
}

.final-board {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.final-board h3 {
  flex-shrink: 0;
  margin: 0 0 clamp(0.3rem, 0.7vh, 0.5rem);
  font-size: clamp(1.35rem, 2.2vw + 0.8vh, 2.3rem);
  color: var(--accent);
}

.final-board .rank-list {
  flex: 1;
  min-height: 0;
  gap: clamp(0.3rem, 0.8vh, 0.55rem);
  grid-template-rows: repeat(5, minmax(0, 1fr));
}

.final-board .rank-list li {
  font-size: clamp(1.15rem, 1.7vw + 0.7vh, 2.05rem);
  padding: clamp(0.3rem, 0.9vh, 0.7rem) clamp(0.5rem, 1vw, 0.95rem);
  grid-template-columns: 2.4rem minmax(0, 1fr) auto;
  border-radius: 12px;
}

.final-board .rank-list .pos {
  font-size: 1.15em;
}

.final-board .rank-list .corrects {
  font-size: 0.78em;
}

.final-board:first-child .rank-list li:nth-child(-n + 3) {
  background: rgba(0, 122, 174, 0.08);
  border-color: rgba(0, 122, 174, 0.28);
}

.final-board:first-child .rank-list li:first-child {
  background: rgba(154, 184, 118, 0.2);
  border-color: rgba(154, 184, 118, 0.55);
}

.host-app .phase-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgba(0, 122, 174, 0.12);
  color: var(--accent);
  font-size: clamp(0.68rem, 0.95vw, 0.82rem);
  font-weight: 700;
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

@media (max-width: 900px) {
  .final-boards {
    grid-template-columns: 1fr;
  }
}
