:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --line: #2a2f3a;
  --text: #eef0f4;
  --muted: #8a92a3;
  --accent: #4f8cff;
  --accent-2: #7aa7ff;
  --good: #3ecf8e;
  --warn: #f5b041;
  --bad: #ff6b6b;
  --me: #2b4a86;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-t);
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { font: inherit; color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); }

.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px 4px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.logo {
  display: inline-grid; place-items: center; width: 64px; height: 64px; border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6); font-weight: 800; font-size: 24px; color: #fff;
}
.logo.small { width: 30px; height: 30px; border-radius: 9px; font-size: 12px; }
.stats { color: var(--muted); font-size: 13px; text-align: right; }

.tabs { display: flex; gap: 4px; padding: 6px 16px; }
.tab { flex: 1; padding: 8px 0; border-radius: 10px; color: var(--muted); font-weight: 600; font-size: 14px; }
.tab.active { background: var(--panel-2); color: var(--text); }

.tab-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.controls { padding: 6px 16px 8px; display: flex; flex-direction: column; gap: 10px; }
.seg { display: flex; background: var(--panel); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; padding: 8px 0; border-radius: 10px; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--accent); color: #fff; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 6px 12px; border-radius: 999px; background: var(--panel); color: var(--muted); font-size: 14px; border: 1px solid var(--line); }
.chip.active { color: var(--text); border-color: var(--accent); background: rgba(79, 140, 255, .15); }

.chat { flex: 1; overflow-y: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }
.empty { margin: auto 0; color: var(--text); background: var(--panel); border-radius: var(--radius); padding: 14px 16px; font-size: 15px; }
.empty p { margin: 6px 0; }

.msg { max-width: 86%; padding: 10px 13px; border-radius: 16px; position: relative; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--me); border-bottom-right-radius: 5px; }
.msg.tutor { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 5px; }
.msg .play { margin-left: 6px; font-size: 14px; opacity: .8; }
.msg.pending { opacity: .6; font-style: italic; }
.note { align-self: flex-start; max-width: 86%; background: rgba(245, 176, 65, .1); border: 1px solid rgba(245, 176, 65, .35); border-radius: 12px; padding: 8px 12px; font-size: 14px; }
.note .better { color: var(--good); font-weight: 600; }
.note .words { color: var(--accent-2); margin-top: 4px; }

.dock { padding: 8px 16px calc(10px + var(--safe-b)); background: linear-gradient(transparent, var(--bg) 30%); display: flex; flex-direction: column; gap: 8px; }
.bar { display: flex; gap: 10px; align-items: center; }
.bar input { flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; outline: none; }
.mic { flex: none; width: 64px; height: 64px; border-radius: 50%; background: var(--accent); font-size: 26px; box-shadow: 0 6px 20px rgba(79, 140, 255, .35); transition: transform .15s; }
.mic.rec { background: var(--bad); animation: pulse 1.2s infinite; }
.mic.busy { background: var(--panel-2); box-shadow: none; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.live-status { flex: 1; color: var(--muted); font-size: 15px; }
.live-status.on { color: var(--good); }

.btn { padding: 12px 16px; border-radius: 14px; font-weight: 600; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.ghost { color: var(--muted); border: 1px solid var(--line); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }

.review { margin: 0 16px 10px; background: var(--panel); border-radius: var(--radius); padding: 14px 16px; max-height: 55vh; overflow-y: auto; }
.review h3 { margin: 0 0 6px; }
.review .score { font-size: 28px; font-weight: 800; color: var(--good); }
.review ul { padding-left: 18px; margin: 6px 0; }
.review li { margin: 6px 0; }
.review .wrong { color: var(--bad); text-decoration: line-through; }
.review .right { color: var(--good); }

.list { flex: 1; overflow-y: auto; padding: 8px 16px calc(16px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--panel); border-radius: 12px; padding: 10px 14px; }
.item .en { font-weight: 600; }
.item .ru { color: var(--muted); }
.item .date { color: var(--muted); font-size: 13px; }

.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 12px; line-height: 18px; }

.deck { padding: 6px 16px 8px; display: flex; flex-direction: column; gap: 10px; }
.deck-stats { display: flex; justify-content: space-around; background: var(--panel); border-radius: var(--radius); padding: 12px 8px; text-align: center; font-size: 13px; }
.deck-stats .big { font-size: 26px; font-weight: 800; }
.card-row { display: flex; gap: 12px; align-items: center; background: var(--panel); border-radius: 12px; padding: 10px 12px; }
.card-row img, .card-row .ph { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; flex: none; background: var(--panel-2); display: grid; place-items: center; font-weight: 700; color: var(--muted); }
.card-row .txt { flex: 1; min-width: 0; }
.card-row .en { font-weight: 600; }
.card-row .ru { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-row .when { color: var(--muted); font-size: 12px; flex: none; }
.card-row .when.due { color: var(--warn); }

.overlay.study { display: flex; flex-direction: column; place-items: stretch; padding: calc(12px + var(--safe-t)) 16px calc(16px + var(--safe-b)); }
.study-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.flash { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; overflow-y: auto; }
.f-img { width: min(60vw, 240px); height: min(60vw, 240px); object-fit: cover; border-radius: 20px; }
.f-en { font-size: 32px; font-weight: 800; }
.f-back { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; width: 100%; }
.f-ru { font-size: 22px; font-weight: 700; color: var(--good); }
.f-meaning { color: var(--text); }
.f-example { color: var(--accent-2); font-style: italic; }
.study-actions { padding-top: 10px; }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rate button { padding: 10px 4px; border-radius: 12px; font-weight: 700; font-size: 14px; display: flex; flex-direction: column; gap: 2px; }
.rate small { font-weight: 400; font-size: 11px; opacity: .85; }
.rate .r1 { background: rgba(255, 107, 107, .2); color: var(--bad); }
.rate .r2 { background: rgba(245, 176, 65, .2); color: var(--warn); }
.rate .r3 { background: rgba(62, 207, 142, .2); color: var(--good); }
.rate .r4 { background: rgba(79, 140, 255, .25); color: var(--accent-2); }

.overlay.editor { align-items: start; overflow-y: auto; padding-top: calc(16px + var(--safe-t)); }
.editor-card { width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 10px; }
.editor-card input:not([type=file]) { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; outline: none; }
.editor-card .bar input { width: auto; }
.ed-img { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.ed-img img { width: 180px; height: 180px; object-fit: cover; border-radius: 16px; }
.ed-img-btns { display: flex; gap: 8px; }
.ed-img-btns .btn { white-space: nowrap; padding: 10px 14px; }

.overlay { position: fixed; inset: 0; background: var(--bg); z-index: 10; display: grid; place-items: center; padding: 24px; }
.card { background: var(--panel); border-radius: 20px; padding: 24px; }
.login-card { width: 100%; max-width: 360px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.login-card h1 { margin: 4px 0 0; font-size: 22px; }
.login-card input { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none; }
