:root {
  color-scheme: dark;
  --bg: #000000;
  --bg-2: #0a0a0a;
  --surface: #111111;
  --surface-2: #1a1a1a;
  --surface-hover: #232323;
  --border: #2a2a2a;
  --border-soft: rgba(255, 255, 255, 0.08);
  --text: #ffffff;
  --text-muted: #8a8a8a;
  --text-dim: #5c5c5c;
  --danger: #e5484d;
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  overflow: hidden;
}

button, input, textarea {
  font-family: inherit;
  color: inherit;
}

button { cursor: pointer; }

.screen {
  display: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}
.screen.active { display: block; }

/* ---------- Background decoration ---------- */
.bg-blobs {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  background:
    radial-gradient(circle at 50% 0%, rgba(255,255,255,0.06), transparent 55%),
    radial-gradient(circle at 100% 100%, rgba(255,255,255,0.04), transparent 50%);
}
.bg-blobs span { display: none; }

/* ---------- Game & Keypad shared card ---------- */
#screen-game, #screen-keypad {
  display: none;
  align-items: center;
  justify-content: center;
}
#screen-game.active, #screen-keypad.active { display: flex; }

.game-card, .keypad-card {
  position: relative;
  z-index: 1;
  width: 92%;
  max-width: 400px;
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: 20px;
  padding: 40px 30px;
  text-align: center;
}

.brand { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 22px; }
.brand-mark { width: 9px; height: 9px; background: var(--text); transform: rotate(45deg); flex-shrink: 0; }
.brand-title {
  font-size: 15px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.game-progress { display: flex; justify-content: center; gap: 10px; margin-bottom: 14px; }
.game-progress .dot {
  width: 9px; height: 9px; border-radius: 50%;
  border: 1px solid var(--text-dim); background: transparent;
  transition: all .25s ease;
}
.game-progress .dot.filled { background: var(--text); border-color: var(--text); }

.game-mode-badge {
  display: inline-block;
  background: transparent;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 14px;
}

.game-question {
  font-size: 22px;
  line-height: 1.45;
  font-weight: 600;
  letter-spacing: -0.01em;
  min-height: 64px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 22px;
}

.game-form { display: flex; flex-direction: column; gap: 12px; }

.game-input {
  width: 100%;
  padding: 15px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  outline: none;
  text-align: center;
  transition: border-color .15s ease;
}
.game-input:focus { border-color: var(--text); }

.btn {
  border: none;
  border-radius: 12px;
  padding: 15px 18px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: transform .15s ease, opacity .15s ease, background .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--text); color: #000; }
.btn-primary:hover { opacity: 0.85; }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(229,72,77,0.4); }
.btn-danger:hover { background: rgba(229,72,77,0.08); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); }

.game-feedback { min-height: 22px; margin-top: 14px; font-size: 13px; font-weight: 600; letter-spacing: 0.02em; }
.game-feedback.ok { color: var(--text); }
.game-feedback.err { color: var(--text-muted); }

.game-stats { display: flex; justify-content: space-between; margin-top: 20px; font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }

/* ---------- Keypad ---------- */
.keypad-hint { color: var(--text-dim); font-size: 12px; margin: -8px 0 22px; text-transform: uppercase; letter-spacing: 0.06em; }
.keypad-dots { display: flex; justify-content: center; gap: 16px; margin-bottom: 14px; }
.keypad-dots span {
  width: 10px; height: 10px; border-radius: 50%;
  border: 1px solid var(--text-dim);
  transition: all .2s ease;
}
.keypad-dots span.filled { background: var(--text); border-color: var(--text); transform: scale(1.15); }
.keypad-card.shake { animation: shake .4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
.keypad-error { min-height: 18px; color: var(--text-muted); font-size: 12px; margin-bottom: 14px; }
.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.keypad-grid button {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
  transition: background .12s ease, transform .1s ease, color .12s ease;
}
.keypad-grid button:active { transform: scale(0.92); background: var(--text); color: #000; }
.keypad-grid button.keypad-alt { font-size: 14px; color: var(--text-dim); background: transparent; border-color: transparent; }
.keypad-grid button.keypad-alt:active { background: var(--surface-2); color: var(--text); }

/* ---------- App shell ---------- */
#screen-app { display: none; }
#screen-app.active { display: block; }

.app-shell { display: flex; height: 100vh; width: 100%; }

.sidebar {
  width: 360px;
  min-width: 300px;
  background: var(--bg);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--border-soft);
}

.me { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 14.5px; }

.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px;
  flex-shrink: 0;
  background-size: cover; background-position: center;
  border: 1px solid var(--border-soft);
}
.avatar.small { width: 30px; height: 30px; font-size: 11px; }
.avatar.large { width: 76px; height: 76px; font-size: 24px; position: relative; }

.sidebar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  transition: background .15s ease, border-color .15s ease;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--text-dim); }

.search-box { padding: 12px 18px; border-bottom: 1px solid var(--border-soft); }
.search-box input {
  width: 100%; padding: 11px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); outline: none;
  letter-spacing: 0.05em;
}
.search-box input:focus { border-color: var(--text); }
.search-result { margin-top: 8px; }
.search-result-empty { color: var(--text-dim); font-size: 12.5px; padding: 6px 2px; }

.chat-list { flex: 1; overflow-y: auto; }
.empty-hint { color: var(--text-dim); text-align: center; padding: 28px 20px; font-size: 13px; line-height: 1.6; }

.chat-item {
  display: flex; align-items: center; gap: 13px;
  padding: 13px 18px; border-bottom: 1px solid var(--border-soft);
  transition: background .15s ease;
}
.chat-item:hover { background: var(--surface); }
.chat-item.active { background: var(--surface-2); }
.chat-item-texts { flex: 1; min-width: 0; }
.chat-item-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.chat-item-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 10.5px; color: var(--text-dim); flex-shrink: 0; }
.chat-item-last { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-width: 0;
  position: relative;
}

.chat-placeholder {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-dim); gap: 12px; text-align: center; padding: 24px;
  font-size: 13.5px;
}
.placeholder-emoji { font-size: 40px; filter: grayscale(1); opacity: 0.6; }

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
}
.chat-header-left { display: flex; align-items: center; gap: 13px; min-width: 0; cursor: pointer; }
.chat-header-texts { min-width: 0; }
.chat-header-name { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-sub { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }
.chat-header-actions { display: flex; gap: 6px; }
.back-btn { display: none; }

.messages-list { flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 10px; }

.msg { max-width: 68%; padding: 11px 14px; border-radius: 14px; font-size: 14.5px; line-height: 1.45; position: relative; cursor: default; }
.msg.me { align-self: flex-end; background: #fff; color: #000; border-bottom-right-radius: 3px; cursor: pointer; }
.msg.other { align-self: flex-start; background: var(--surface-2); color: var(--text); border-bottom-left-radius: 3px; }
.msg.system {
  align-self: center; background: transparent; color: var(--text-dim); font-size: 11.5px;
  max-width: 90%; text-align: center; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 4px 0;
}
.msg-sender { font-size: 12px; font-weight: 700; opacity: 0.6; margin-bottom: 4px; }
.msg-time { font-size: 10px; opacity: 0.5; margin-top: 5px; text-align: right; display: flex; justify-content: flex-end; align-items: center; gap: 4px; }
.msg img.msg-photo { max-width: 100%; border-radius: 10px; display: block; margin-top: 4px; cursor: pointer; }

.msg-ticks { font-size: 11px; opacity: 0.45; }
.msg-ticks.read { opacity: 1; font-weight: 700; }

.voice-msg { display: flex; align-items: center; gap: 10px; min-width: 230px; }
.voice-play {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid currentColor;
  background: transparent; color: inherit; font-size: 13px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.voice-wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 28px; cursor: pointer; }
.voice-wave .bar { flex: 1; min-width: 2px; max-width: 3px; background: currentColor; opacity: 0.3; border-radius: 2px; transition: opacity .15s ease; }
.voice-wave .bar.played { opacity: 1; }
.voice-time { font-size: 11px; opacity: 0.7; min-width: 66px; text-align: right; flex-shrink: 0; white-space: nowrap; }

.chat-input-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 18px; border-top: 1px solid var(--border-soft); background: var(--bg);
}
.chat-input-bar input[type="text"] {
  flex: 1; padding: 12px 16px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface); outline: none;
}
.chat-input-bar input[type="text"]:focus { border-color: var(--text-dim); }
.round-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border);
  background: transparent; display: flex; align-items: center; justify-content: center; font-size: 17px; flex-shrink: 0;
  transition: background .15s ease;
}
.round-btn:hover { background: var(--surface-2); }
.round-btn.recording { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(229,72,77,0.5);} 50% { box-shadow: 0 0 0 8px rgba(229,72,77,0);} }
.round-btn.send { background: #fff; color: #000; border: none; }
.round-btn.send:hover { opacity: 0.85; background: #fff; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal {
  width: 100%; max-width: 420px; max-height: 85vh; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--border-soft); border-radius: 18px;
  padding: 24px;
}
.modal h3 { margin: 0 0 18px; font-size: 15px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; color: var(--text-muted); }
.modal .field { margin-bottom: 14px; }
.modal .field label { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.06em; }
.modal input[type="text"], .modal input[type="search"] {
  width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); outline: none;
}
.modal input:focus { border-color: var(--text-dim); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }

.photo-picker { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.photo-picker .avatar { cursor: pointer; background: var(--surface-2); border: 1px dashed var(--border); }
.photo-picker input[type="file"] { display: none; }

.member-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--border-soft); }
.member-row:last-child { border-bottom: none; }
.member-row-name { flex: 1; font-size: 13.5px; }
.member-row input[type="checkbox"] { width: 17px; height: 17px; accent-color: #fff; }
.member-remove { background: none; border: none; color: var(--danger); font-size: 15px; cursor: pointer; }
.role-tag { font-size: 10px; color: var(--text-dim); border: 1px solid var(--border); padding: 2px 9px; border-radius: 10px; text-transform: uppercase; letter-spacing: 0.04em; }
.role-tag.read-yes { color: var(--text); border-color: var(--text-dim); }

/* ---------- Call overlay ---------- */
.call-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: #000;
  color: white; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
.call-remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.call-local-video {
  position: absolute; bottom: 110px; right: 20px; width: 110px; height: 150px;
  border-radius: 12px; object-fit: cover; background: #111; border: 1px solid rgba(255,255,255,0.2); z-index: 2;
}
.call-info { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.call-name { font-size: 20px; font-weight: 600; }
.call-status { font-size: 13px; color: rgba(255,255,255,0.55); text-transform: uppercase; letter-spacing: 0.06em; }
.call-controls { position: relative; z-index: 2; display: flex; gap: 20px; margin-top: 24px; }
.call-btn {
  width: 58px; height: 58px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.25); font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.06); color: white;
}
.call-btn.accept { background: #fff; color: #000; border-color: #fff; }
.call-btn.reject, .call-btn.end { background: var(--danger); border-color: var(--danger); }
.call-btn.active-toggle.on { background: #fff; color: #000; }

.hidden { display: none !important; }

.toast-stack { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--bg-2); border: 1px solid var(--border-soft); padding: 12px 16px; border-radius: 10px;
  font-size: 12.5px; box-shadow: 0 12px 30px rgba(0,0,0,0.5); max-width: 280px;
  animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: translateY(0);} }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .sidebar { width: 100%; min-width: 0; position: absolute; inset: 0; z-index: 2; }
  .chat-main { position: absolute; inset: 0; z-index: 3; transform: translateX(100%); transition: transform .2s ease; }
  #screen-app.chat-open .chat-main { transform: translateX(0); }
  #screen-app.chat-open .sidebar { display: none; }
  .back-btn { display: flex; }
  .msg { max-width: 82%; }
  .call-local-video { width: 88px; height: 120px; bottom: 130px; }
}
