body {
  display:flex;
  min-height:100vh;
  margin:0;
  font-family:"Trebuchet MS",sans-serif;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  background:#fff;
  color:#111;
  padding:14px 10px 20px;
  box-sizing:border-box;
}

h1 {
  margin:4px 0 4px;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:12px;
  line-height:1.1;
}

.title-icon {
  height:1em;
  width:auto;
  display:block;
}

.credit { margin:0 0 8px; text-align:center; font-size:1rem; }
.credit a { color:#0b57d0; text-underline-offset:2px; }
p.lead { margin:0 0 10px; text-align:center; max-width:980px; }

.controls {
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  justify-content:center;
  margin:8px 0 14px;
}

.big-button {
  font-size:20px;
  padding:13px 24px;
  min-width:190px;
  height:58px;
  background:#000;
  color:#fff;
  border:none;
  border-radius:10px;
  cursor:pointer;
}

.big-button:disabled {
  opacity:.55;
  cursor:not-allowed;
}

.game-container {
  display:flex;
  width:min(1100px,95vw);
  min-height:min(60vh,540px);
  gap:12px;
  align-items:stretch;
}

.player {
  position:relative;
  flex:1;
  display:grid;
  grid-template-rows:auto auto auto 1fr auto;
  gap:10px;
  align-items:start;
  text-align:center;
  border:2px solid #000;
  border-radius:14px;
  padding:16px;
  background:#fff;
  min-height:0;
}

.player h2 {
  margin:0;
  font-size:clamp(1.12rem,2.1vw,1.45rem);
  line-height:1.1;
}

.active { background:#fffbe6; }
.wrong { animation:shake .35s linear; background:#ffdfdf !important; }
.correct { box-shadow:0 0 0 3px #c8f7c5 inset; }
.winner { background:#d6f6d6 !important; }
.loser { background:#ffd0d0 !important; }

@keyframes shake {
  0%,100% { transform:translateX(0); }
  20% { transform:translateX(-3px); }
  40% { transform:translateX(3px); }
  60% { transform:translateX(-2px); }
  80% { transform:translateX(2px); }
}

.crown { display:none; margin-left:8px; vertical-align:middle; width:22px; height:22px; }
.winner .crown { display:inline; }

.timer {
  font-size:2rem;
  line-height:1.1;
}
.question {
  font-size:clamp(1.08rem,2vw,1.34rem);
  min-height:86px;
  display:none;
  line-height:1.34;
  height:118px;
  overflow-y:auto;
  overflow-x:hidden;
  padding:2px 4px;
  box-sizing:border-box;
}
.q-main {
  min-height:74px;
  height:100%;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  text-align:center;
  width:100%;
  max-width:100%;
  overflow-wrap:break-word;
  word-break:normal;
}
.q-main.long-question { justify-content:flex-start; }
.q-main.short-question { font-size:1.12em; line-height:1.22; }
.q-main.with-think-progress {
  flex-direction:column;
  gap:8px;
}
.q-main .q-line {
  width:100%;
}
.topic-footer {
  min-height:20px;
  font-size:.78rem;
  color:rgba(0,0,0,.52);
  display:flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  flex-wrap:wrap;
}

.options {
  display:grid;
  grid-template-columns:repeat(2,1fr);
  gap:12px;
  min-height:210px;
  align-content:start;
}

.options button {
  min-height:94px;
  padding:10px 12px;
  font-size:clamp(.9rem,1.5vw,1.02rem);
  line-height:1.28;
  cursor:pointer;
  border-radius:14px;
  border:1px solid #bbb;
  background:#fff;
  white-space:normal;
  overflow-wrap:break-word;
  word-break:normal;
}

.options button:disabled {
  cursor:default;
  opacity:1;
}

.options button.option-correct {
  background:#dcfce7;
  border-color:#16a34a;
  color:#14532d;
}

.options button.option-wrong {
  background:#fee2e2;
  border-color:#dc2626;
  color:#7f1d1d;
}

.question mjx-container,
.options mjx-container,
#exampleQuestion mjx-container,
#exampleOptions mjx-container {
  max-width:100%;
  white-space:normal !important;
}

.question mjx-container[jax="SVG"] > svg,
.options mjx-container[jax="SVG"] > svg,
#exampleQuestion mjx-container[jax="SVG"] > svg,
#exampleOptions mjx-container[jax="SVG"] > svg {
  max-width:100%;
  height:auto !important;
}

.options button:hover { border-color:#777; }
.options button:active { transform:scale(.99); }

.think-time-progress {
  display:flex;
  align-items:center;
  justify-content:center;
  padding:6px 0 2px;
  width:min(360px,80%);
  margin:0 auto;
}

.think-time-progress-bar {
  width:100%;
  height:8px;
  border-radius:4px;
  background:#d9dce1;
  overflow:hidden;
  border:none;
  box-shadow:none;
}

.think-time-progress-bar-fill {
  display:block;
  width:0;
  height:100%;
  background:#1f2937;
  transition:width .08s linear;
}

.game-over { display:none; text-align:center; font-size:1.2rem; margin-top:14px; }

#statsToast {
  display:none;
  position:fixed;
  left:50%;
  top:50%;
  transform:translate(-50%,-50%);
  background:#111;
  color:#fff;
  padding:22px 24px;
  border-radius:16px;
  z-index:20;
  width:min(95vw,980px);
  max-height:min(85vh,780px);
  overflow:auto;
  box-shadow:0 20px 50px rgba(0,0,0,.38);
}

#statsToast h3 { margin:0 0 14px 0; font-size:1.3rem; }
#statsToast table { border-collapse:collapse; width:100%; }
#statsToast th,
#statsToast td { padding:9px 12px; border-bottom:1px solid rgba(255,255,255,.18); text-align:center; font-size:1.02rem; }
#statsToast tr:last-child td { border-bottom:none; }
#statsToast .right { text-align:center; }
#statsToast .row { display:flex; gap:10px; justify-content:center; margin-top:16px; flex-wrap:wrap; }
#statsToast .new-high { color:#86efac; font-size:.92rem; margin-left:8px; }
#statsToast .note { margin:12px 0 0; color:#d8d8d8; font-size:.96rem; }

.btn { padding:10px 14px; border-radius:10px; border:0; cursor:pointer; font-weight:600; }
.btn-secondary { background:#2a2a2a; color:#fff; }
.btn-primary { background:#0ea5e9; color:#001018; }

#topicPanel {
  width:min(1100px,95vw);
  border:2px solid #000;
  border-radius:12px;
  padding:10px;
  box-sizing:border-box;
  margin-top:10px;
}

#topicHeader {
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}

#topicButtons {
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

#topicToggle,
#topicSelectAll {
  padding:8px 12px;
  border-radius:8px;
  border:1px solid #777;
  background:#f7f7f7;
  cursor:pointer;
  font-weight:700;
}

#topicSections {
  margin-top:8px;
  display:grid;
  gap:16px;
}

#topicPanel.dimmed {
  opacity:.45;
  transition:opacity .2s ease;
}

#topicPanel.dimmed .topic-item input,
#topicPanel.dimmed .topic-item .ex-btn,
#topicPanel.dimmed #topicToggle,
#topicPanel.dimmed #topicSelectAll,
#topicPanel.dimmed .stage-btn {
  pointer-events:none;
}

.stage-block h3 {
  margin:0 0 8px;
  font-size:1rem;
}

.stage-head {
  display:flex;
  align-items:center;
  justify-content:flex-start;
  gap:8px;
  margin-bottom:6px;
}

.stage-head .row {
  display:flex;
  gap:6px;
}

.stage-btn {
  font-size:.7rem;
  padding:2px 6px;
  border:1px solid #c4c4c4;
  border-radius:6px;
  background:#fcfcfc;
  color:#444;
  cursor:pointer;
}

.topic-grid {
  display:grid;
  grid-template-columns:repeat(3,minmax(0,1fr));
  gap:8px 26px;
}

.topic-item {
  display:flex;
  gap:8px;
  align-items:center;
  min-width:0;
}

.topic-item .spacer { flex:1; }
.topic-item.selected label { font-weight:700; }
.topic-item.example-active { padding:2px 0; }
.topic-item.example-active label {
  color:#4b3f72;
  font-style:normal;
}
.topic-item input { margin:0; }

.topic-item label {
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  min-width:0;
}

.ex-btn {
  font-size:.8rem;
  padding:5px 8px;
  border:1px solid #999;
  background:#f4f4f4;
  border-radius:8px;
  cursor:pointer;
}

#exampleBox {
  display:none;
  margin-top:10px;
  border:1px solid #4b3f72;
  border-radius:10px;
  padding:10px;
  background:#faf9ff;
}

#exampleBox h4 { margin:0 0 8px; }
#exampleQuestion { min-height:36px; font-size:1.1rem; }
#exampleOptions { margin-top:8px; display:grid; grid-template-columns:repeat(2,1fr); gap:8px; }
#exampleOptions button {
  min-height:54px;
  font-size:1rem;
  border-radius:10px;
  border:1px solid #bbb;
  background:#fff;
  cursor:pointer;
}
#exampleFeedback { margin-top:8px; min-height:24px; font-weight:700; }

.settings-row {
  width:min(760px,92vw);
  margin:12px auto 0;
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(260px,1fr));
  gap:12px;
  align-items:stretch;
  justify-items:stretch;
}

.settings-row.classic-only {
  justify-items:center;
}

.container,
.mode-select {
  width:100%;
  text-align:center;
  margin:0 auto;
  border:none;
  border-radius:0;
  padding:0 4px 2px;
  box-sizing:border-box;
}
.mode-select {
  grid-column: 1 / -1;
}

.start-time-container {
  justify-self:center;
  width:min(520px,100%);
}
.settings-row.classic-only .start-time-container {
  grid-column: 1 / -1;
}

.container p,
.mode-select p { margin:0 0 8px; }

#startTimeSlider { width:min(520px,100%); }
.think-time-container {
  width:100%;
}
.think-time-container p {
  margin-bottom:8px;
}
#thinkTimeSlider {
  width:min(520px,100%);
}
.mode-select .row { display:flex; gap:14px; justify-content:center; align-items:center; flex-wrap:wrap; }
.mode-select label { font-size:.95rem; cursor:pointer; }

#statusBadge {
  position:fixed;
  top:34px;
  right:10px;
  border-radius:999px;
  padding:6px 10px;
  font-size:.8rem;
  display:none;
  z-index:30;
}

#statusBadge.ok {
  background:#16a34a;
  color:#fff;
}

#statusBadge.error {
  background:#dc2626;
  color:#fff;
}

#statusBadge.info {
  background:#334155;
  color:#fff;
}

#versionBadge {
  position:fixed;
  top:8px;
  right:10px;
  font-size:.78rem;
  color:#555;
  background:rgba(255,255,255,.86);
  border:1px solid #d0d0d0;
  border-radius:999px;
  padding:2px 8px;
  z-index:31;
  letter-spacing:.01em;
}

#topNav {
  position:fixed;
  top:8px;
  left:10px;
  display:flex;
  align-items:center;
  gap:6px;
  z-index:31;
}

#topNav .top-pill {
  display:inline-flex;
  align-items:center;
  gap:6px;
  font-size:.78rem;
  color:#555;
  background:rgba(255,255,255,.86);
  border:1px solid #d0d0d0;
  border-radius:999px;
  padding:2px 8px;
  letter-spacing:.01em;
  text-decoration:none;
}

#topNav a.top-pill {
  color:#111;
  font-weight:700;
}

#topNav a.top-pill:hover {
  text-decoration:underline;
}

#topNav .subject-label {
  color:#666;
  font-size:.74rem;
  font-weight:700;
}

#topNav select {
  border:none;
  background:transparent;
  color:#555;
  font-size:.78rem;
  padding:0;
  max-width:130px;
}

#topNav select:focus {
  outline:none;
}

.question code,
.options code,
#exampleQuestion code,
#exampleOptions code {
  font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono",monospace;
  font-size:.95em;
}

.question pre,
.options pre,
#exampleQuestion pre,
#exampleOptions pre {
  margin:6px 0;
  text-align:left;
  border:1px solid #ddd;
  border-radius:8px;
  padding:8px;
  background:#f8fafc;
  white-space:pre-wrap;
  word-break:break-word;
  overflow-x:hidden;
}

@media (max-width: 920px) {
  .game-container {
    width:min(1100px,97vw);
    min-height:min(56vh,500px);
    gap:10px;
  }
  .player {
    padding:12px;
    gap:8px;
    border-radius:12px;
  }
  .timer { font-size:clamp(1.35rem,3.9vw,1.8rem); }
  .question {
    height:108px;
    font-size:clamp(.96rem,2.1vw,1.17rem);
  }
  .options {
    gap:8px;
    min-height:182px;
  }
  .options button {
    min-height:74px;
    font-size:clamp(.8rem,1.7vw,.95rem);
    border-radius:12px;
  }
  .settings-row { grid-template-columns:1fr; }
  .topic-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
  #exampleOptions { grid-template-columns:1fr; }
}

@media (max-width: 760px) {
  .game-container {
    height:auto;
    flex-direction:column;
  }
  .question {
    height:auto;
    min-height:78px;
    font-size:clamp(.9rem,2.4vw,1.08rem);
  }
  .options {
    min-height:150px;
  }
}

@media (max-width: 620px) {
  body {
    padding:10px 8px 14px;
  }
  h1 {
    font-size:1.32rem;
    gap:8px;
  }
  p.lead {
    font-size:.9rem;
    margin-bottom:8px;
  }
  .controls {
    margin:6px 0 10px;
  }
  .big-button {
    font-size:1rem;
    padding:9px 14px;
    min-width:144px;
    height:44px;
    border-radius:9px;
  }
  .game-container {
    width:min(1100px,98vw);
    height:auto;
    gap:6px;
    flex-direction:column;
  }
  .player {
    padding:8px;
    gap:6px;
    border-radius:10px;
  }
  .player h2 {
    margin:0;
    font-size:1rem;
  }
  .timer {
    font-size:clamp(1.1rem,3.8vw,1.4rem);
  }
  .question {
    height:auto;
    min-height:74px;
    font-size:clamp(.86rem,2.5vw,1.02rem);
  }
  .q-main.short-question {
    font-size:1.08em;
  }
  .options {
    gap:6px;
    min-height:142px;
  }
  .options button {
    min-height:56px;
    padding:6px 8px;
    border-radius:9px;
    font-size:clamp(.72rem,2.2vw,.86rem);
    line-height:1.24;
  }
  .topic-footer {
    min-height:16px;
    font-size:.67rem;
  }
  .think-time-progress {
    width:min(220px,88%);
    padding:5px 0;
  }
  .think-time-progress-bar {
    height:7px;
  }
  .topic-grid { grid-template-columns:1fr; }
  #topNav {
    position:static;
    width:100%;
    justify-content:center;
    margin-bottom:6px;
    flex-wrap:wrap;
  }
}

@media (max-width: 540px) {
  .options { grid-template-columns:1fr; }
}
