:root {
  --bg: #f4f2ec;
  --panel: #ffffff;
  --ink: #1c1d1b;
  --muted: #6d6c66;
  --line: #e4e0d6;
  --accent: #0e7268;
  --accent-ink: #ffffff;
  --accent-soft: #dcefeb;
  --warn: #b26a00;
  --warn-soft: #fbecd2;
  --bad: #b3261e;
  --stage: #e6e1d5;
  --stage-hi: #f7f4ed;
  --stage-lo: #d6cfbf;
  --skin: #e2b892;
  --skin-line: #a0704f;
  --shirt: #2f5d62;
  --shirt-dark: #234649;
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121412;
    --panel: #1b1e1c;
    --ink: #ecebe6;
    --muted: #a3a29b;
    --line: #2d312e;
    --accent: #35b3a5;
    --accent-ink: #06201d;
    --accent-soft: #173733;
    --warn: #f0b04f;
    --warn-soft: #3a2c14;
    --bad: #f2867f;
    --stage: #222624;
    --stage-hi: #323834;
    --stage-lo: #161917;
    --shirt: #3f7d83;
    --shirt-dark: #2d5d61;
    color-scheme: dark;
  }
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Manrope', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px clamp(16px, 4vw, 40px);
  max-width: 1200px;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 12px; }
.mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
}
.mark svg { width: 24px; height: 24px; }
.name { font-weight: 800; font-size: 22px; letter-spacing: -0.02em; line-height: 1.1; }
.sub { color: var(--muted); font-size: 13px; }

.tabs {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}
.tab-btn {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 600;
  padding: 8px 16px; border-radius: 999px; cursor: pointer;
  white-space: nowrap;
}
.tab-btn.active { background: var(--ink); color: var(--bg); }

main { max-width: 1200px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px) 48px; }

.grid2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 20px;
  align-items: start;
}
#tab-watch .grid2, #tab-teach .grid2 { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.dict-panel { margin-top: 20px; }
h2 { margin: 0; font-size: 18px; }
.count { color: var(--muted); font-weight: 500; font-size: 15px; }

.lbl { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

textarea, input[type="text"], input[type="search"] {
  width: 100%;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  resize: vertical;
}
textarea:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.slider label { font-size: 14px; color: var(--muted); min-width: 64px; }
.slider input { flex: 1; accent-color: var(--accent); }
.slider output { font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-weight: 700;
  border-radius: 12px; padding: 10px 16px;
  border: 1px solid var(--line);
  background: var(--panel); color: var(--ink);
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { justify-content: center; padding: 14px; font-size: 16px; }
.btn.rec { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.listening { background: var(--bad); color: #fff; border-color: var(--bad); }

.stage, .mini {
  background:
    radial-gradient(120% 90% at 50% 30%, var(--stage-hi) 0%, var(--stage) 60%, var(--stage-lo) 100%);
}
.stage {
  position: relative;
  border-radius: var(--radius);
  aspect-ratio: 4 / 3.4;
  overflow: hidden;
}
.stage canvas, .mini canvas { width: 100%; height: 100%; display: block; }
.caption {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  font-weight: 800; font-size: 20px;
  padding: 6px 16px; border-radius: 999px;
  max-width: calc(100% - 32px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.caption:empty { display: none; }
.caption.small { font-size: 14px; bottom: 8px; padding: 3px 10px; }

.mini { position: relative; border-radius: 12px; aspect-ratio: 4 / 3; overflow: hidden; }

.tokens { display: flex; flex-wrap: wrap; gap: 6px; }
.tok { padding: 4px 10px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.tok.sign { background: var(--accent-soft); color: var(--accent); }
.tok.spell { background: var(--warn-soft); color: var(--warn); }
.tok.demo { background: var(--line); color: var(--ink); }

.abc { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.letter .dot, .hint .dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--warn);
}
.letter .dot { position: absolute; top: 5px; right: 5px; }

.loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  color: var(--muted); font-weight: 600;
}
.loading b { color: var(--ink); font-variant-numeric: tabular-nums; }
.spin {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.tok .miss { text-decoration: line-through; opacity: 0.6; }

.hint { margin: 0; color: var(--muted); font-size: 13.5px; }

.camslot { min-width: 0; }
.cam {
  position: relative;
  background: #0d0f0e;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
}
.cam video, .cam canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* ko'zgu kabi ko'rinsin */
}
.camstate {
  position: absolute; left: 12px; top: 12px;
  background: rgba(0, 0, 0, 0.6); color: #fff;
  font-size: 13px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
}
.camstate.live::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #4ade80; margin-right: 6px; }
.camstate.rec::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #ef4444; margin-right: 6px; }
.ring { position: absolute; right: 12px; top: 12px; width: 40px; height: 40px; opacity: 0; transition: opacity 0.2s; }
.ring.on { opacity: 1; }
.ring circle { fill: none; stroke-width: 4; }
.ring circle:first-child { stroke: rgba(255, 255, 255, 0.25); }
#stillArc { stroke: #4ade80; stroke-dasharray: 100.5; stroke-dashoffset: 100.5; transform: rotate(-90deg); transform-origin: center; }
.countdown {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 96px; font-weight: 800; color: #fff;
  background: rgba(0, 0, 0, 0.35);
}

.transcript {
  min-height: 84px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 22px; font-weight: 700;
  word-break: break-word;
}
.transcript .placeholder { color: var(--muted); font-size: 15px; font-weight: 500; }
.transcript .letters { color: var(--warn); }

.cands { display: flex; flex-direction: column; gap: 6px; min-height: 32px; }
.cand { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; font-weight: 600; }
.cand .bar { grid-column: 1 / -1; height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
.cand .bar i { display: block; height: 100%; background: var(--accent); }
.cand.rej .bar i { background: var(--muted); }
.cand .d { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.cands .empty { color: var(--muted); font-size: 14px; }

.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 8px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg input:checked + span { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

.letters { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.letter {
  position: relative;
  font: inherit; font-weight: 800; font-size: 17px;
  padding: 10px 0; border-radius: 10px;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); cursor: pointer;
}
.letter.sel { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.letter .n {
  position: absolute; top: -6px; right: -4px;
  font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; line-height: 18px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink);
}
.letter .n.low { background: var(--warn); }

.status { min-height: 22px; font-weight: 600; }
.status.ok { color: var(--accent); }
.status.warn { color: var(--warn); }
.status.err { color: var(--bad); }

.dict { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.entry {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 8px 8px 14px;
  min-width: 0;
}
.entry .g { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .k { font-size: 12px; color: var(--muted); }
.entry .k.low { color: var(--warn); }
.icon-btn {
  border: 0; background: transparent; color: var(--muted);
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: var(--bg); color: var(--ink); }
.icon-btn.del:hover { color: var(--bad); }
.dict .empty { color: var(--muted); grid-column: 1 / -1; padding: 12px 0; }

@media (max-width: 860px) {
  .grid2, #tab-watch .grid2, #tab-teach .grid2 { grid-template-columns: minmax(0, 1fr); }
  .top { padding-top: 14px; }
  .tabs { width: 100%; }
  .tab-btn { flex: 1; padding: 8px 6px; font-size: 14px; }
}
