:root {
  --bg: #0e1124;
  --panel: #171b38;
  --panel-2: #1f2448;
  --line: #2c3263;
  --text: #eef0ff;
  --muted: #98a0cc;
  --accent: #6f8fff;
  --accent-2: #8d6bff;
  --ok: #3ddc97;
  --bad: #ff5d6c;
  --warn: #ffb84d;
  --radius: 16px;
  --mono: "JetBrains Mono", "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(1200px 600px at 20% -10%, #1c2250 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }
body.teacher main { max-width: 1400px; }

h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h1 { font-size: 2rem; }
h2 { font-size: 1.35rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: 0.02em; margin-bottom: 18px; }
.brand .logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-size: 20px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.card + .card { margin-top: 16px; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 14px 0 6px; }
input, select, textarea {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(111, 143, 255, 0.25); }
textarea { resize: vertical; min-height: 140px; font-family: var(--mono); font-size: 0.95rem; line-height: 1.5; }
input.code { font-family: var(--mono); font-size: 2rem; letter-spacing: 0.4em; text-align: center; padding-left: 0.4em; }

button {
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 0;
  border-radius: 12px;
  padding: 12px 20px;
  cursor: pointer;
  transition: transform 0.05s ease, filter 0.15s ease, opacity 0.15s ease;
}
button:hover { filter: brightness(1.1); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.danger { background: linear-gradient(135deg, #ff5d6c, #d23a56); }
button.ok { background: linear-gradient(135deg, #2fc98a, #1fa36e); }
button.big { padding: 16px 28px; font-size: 1.15rem; }
button.tiny { padding: 4px 10px; font-size: 0.8rem; border-radius: 8px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 0; min-width: 0; }
.row > button { flex: 0 0 auto; }
.grow { flex: 1 1 auto !important; }

.err { color: var(--bad); min-height: 1.4em; margin-top: 10px; font-weight: 600; }
.note { color: var(--warn); font-size: 0.9rem; margin-top: 8px; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.badge.lobby { color: var(--accent); }
.badge.countdown { color: var(--warn); }
.badge.running { color: var(--ok); }
.badge.finished { color: var(--muted); }

.conn-badge {
  position: fixed; left: 50%; top: 10px; transform: translateX(-50%); z-index: 50;
  background: var(--bad); color: #fff; padding: 8px 16px; border-radius: 999px; font-weight: 700; font-size: 0.9rem;
}

/* ---------- O'quvchi: yozish */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; text-align: center; }
.stat b { display: block; font-size: 1.25rem; font-family: var(--mono); line-height: 1.15; }
.stat span { display: block; line-height: 1.1; font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.stat.time b { color: var(--warn); }
.stat.bads b { color: var(--bad); }

.typebox {
  position: relative;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 20px;
  font-family: var(--mono);
  font-size: 2.15rem;
  line-height: 3rem;
  height: calc(3rem * 4 + 28px);
  overflow: hidden;
  white-space: pre-wrap;
  word-break: normal;
  scroll-behavior: smooth;
  cursor: text;
  user-select: none;
  -webkit-user-select: none;
}
.typebox.focus { border-color: var(--accent); }
.typebox span { color: #6d75a8; border-radius: 3px; }
.typebox span.ok { color: var(--text); }
.typebox span.bad { color: var(--bad); background: rgba(255, 93, 108, 0.18); text-decoration: underline; }
.typebox span.cur { color: var(--text); background: rgba(111, 143, 255, 0.35); box-shadow: 0 2px 0 var(--accent); }

.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  background: rgba(14, 17, 36, 0.82); backdrop-filter: blur(3px); border-radius: var(--radius);
}
.overlay .num { font-size: 6rem; font-weight: 800; font-family: var(--mono); color: var(--warn); line-height: 1; }
.overlay .txt { font-size: 1.6rem; font-weight: 700; }
.overlay .sub { color: var(--muted); margin-top: 8px; font-size: 1rem; }
.hint { margin-top: 12px; color: var(--muted); text-align: center; font-size: 0.9rem; }

.cap {
  position: fixed; left: -9999px; top: 0; width: 1px; height: 1px; opacity: 0; font-size: 16px;
}

.me-line { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; }

/* ---------- Natijalar */
.hero { text-align: center; padding: 10px 0 18px; }
.hero .place { font-size: 3.4rem; font-weight: 800; font-family: var(--mono); }
.hero .place.gold { color: #ffd166; }
.hero .place.silver { color: #cfd6ff; }
.hero .place.bronze { color: #e0a070; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px 0; }
.kpi { background: var(--panel-2); border-radius: 14px; padding: 12px; text-align: center; }
.kpi b { display: block; font-size: 1.7rem; font-family: var(--mono); }
.kpi span { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.toplist { list-style: none; margin: 0; padding: 0; }
.toplist li { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; }
.toplist li:nth-child(odd) { background: var(--panel-2); }
.toplist li.me { outline: 2px solid var(--accent); }
.toplist .r { width: 2rem; font-family: var(--mono); font-weight: 800; }
.toplist .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toplist .w { font-family: var(--mono); font-weight: 700; }

/* ---------- O'qituvchi */
.t-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.t-head h1 { margin: 0; font-size: 1.5rem; }
.t-head .spacer { flex: 1; }
.t-grid { display: grid; grid-template-columns: 360px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .t-grid { grid-template-columns: 1fr; } }

.codebox { text-align: center; }
.codebox .code { font-family: var(--mono); font-size: 4.4rem; font-weight: 800; letter-spacing: 0.15em; padding-left: 0.15em; color: var(--accent); line-height: 1.1; }
.codebox .url { font-family: var(--mono); font-size: 1rem; background: var(--panel-2); border-radius: 10px; padding: 8px 10px; margin-top: 10px; word-break: break-all; }

.bigclock { text-align: center; font-family: var(--mono); font-size: 4.5rem; font-weight: 800; line-height: 1; margin: 6px 0 2px; }
.bigclock.cd { color: var(--warn); font-size: 7rem; }

.ctrls { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.ctrls .row > button { flex: 1 1 0; }

.players { list-style: none; margin: 14px 0 0; padding: 0; max-height: 360px; overflow: auto; }
.players li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; }
.players li:nth-child(odd) { background: var(--panel-2); }
.players .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.players li.off .dot { background: #5b628f; }
.players li.off .pn { color: var(--muted); }
.players .pn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

table.board { width: 100%; border-collapse: collapse; font-size: 1.15rem; }
table.board th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.board td { padding: 9px 10px; border-bottom: 1px solid rgba(44, 50, 99, 0.6); vertical-align: middle; }
table.board td.num, table.board th.num { text-align: right; font-family: var(--mono); }
table.board tr.nq td { color: var(--muted); }
table.board tr.nq td.rk { color: var(--bad); }
table.board td.rk { width: 3.2rem; font-family: var(--mono); font-weight: 800; }
table.board tr.r1 td.rk { color: #ffd166; }
table.board tr.r2 td.rk { color: #cfd6ff; }
table.board tr.r3 td.rk { color: #e0a070; }
.bar { height: 10px; background: var(--panel-2); border-radius: 999px; overflow: hidden; min-width: 120px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; transition: width 0.4s ease; }
.low { color: var(--bad); }
.empty { color: var(--muted); text-align: center; padding: 40px 10px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; width: min(640px, 94vw); }
dialog::backdrop { background: rgba(5, 7, 20, 0.7); }

@media (max-width: 640px) {
  body { font-size: 16px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .typebox { font-size: 1.5rem; line-height: 2.2rem; height: calc(2.2rem * 5 + 24px); padding: 12px 14px; }
  .overlay .num { font-size: 4.5rem; }
  .codebox .code { font-size: 3.4rem; }
  .bigclock { font-size: 3.4rem; }
  table.board { font-size: 1rem; }
}

/* ---------- Klaviatura sxemasini tekshirish */
.layoutcheck { background: var(--panel-2); border: 1px solid var(--warn); border-radius: 12px; padding: 14px; }
.layoutcheck .chips { display: flex; gap: 10px; margin: 10px 0; }
.layoutcheck .chip { font-family: var(--mono); font-size: 1.6rem; width: 2.6rem; height: 2.6rem; display: grid; place-items: center; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.layoutcheck .chip.ok { color: #fff; background: rgba(61, 220, 151, 0.3); border-color: var(--ok); }
.layoutcheck input { margin-bottom: 8px; }
.langrow { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.langrow button { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 10px 8px; font-size: 0.95rem; }
.langrow button.on { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(111, 143, 255, 0.25); }

/* Noto'g'ri tugma bosilganda joriy harf qisqa vaqt qizaradi (xato to'g'rilanmaguncha davom etilmaydi) */
.typebox span.cur.flash { background: rgba(255, 93, 108, 0.55); box-shadow: 0 2px 0 var(--bad); }
