:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --border: #dde3ea;
  --text: #1c2430;
  --text-dim: #6b7684;
  --accent: #2f5fdb;
  --accent-dim: #e8edfc;
  --good: #1e8e5a;
  --good-bg: #e6f4ec;
  --bad: #d93025;
  --bad-bg: #fbe9e7;
}

* { box-sizing: border-box; }

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

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }
.dim { color: var(--text-dim); font-weight: 400; }

/* ---------- topbar ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9em 1.5em;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1em; letter-spacing: 0.02em; }
.call-meta {
  display: flex;
  align-items: center;
  gap: 0.5em;
  font-size: 0.85em;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.rec-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--bad);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ---------- screens ---------- */
.screen {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3em 1.5em;
}
#screen-intro, #screen-end { align-items: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(20, 30, 50, 0.06);
}

.intro-card {
  max-width: 480px;
  padding: 2.5em;
  text-align: left;
}
.intro-card h1 { margin-top: 0; font-size: 1.4em; }
.intro-card p { color: var(--text-dim); line-height: 1.5; }

.rules { list-style: none; margin: 1.5em 0; padding: 0; }
.rules li {
  display: flex;
  justify-content: space-between;
  gap: 1em;
  padding: 0.55em 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92em;
}
.rules li:last-child { border-bottom: none; }
.rules strong { white-space: nowrap; }
.rules strong.good { color: var(--good); }
.rules strong.bad { color: var(--bad); }

.btn-primary {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.75em 1.6em;
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  margin-top: 0.5em;
}
.btn-primary:hover { background: #2450c0; }
.btn-primary:disabled { background: var(--text-dim); cursor: default; }

/* ---------- video row ---------- */
#screen-game { flex-direction: column; align-items: stretch; padding: 1.5em 1.5em 3em; }

.video-row {
  display: flex;
  gap: 1em;
  max-width: 1100px;
  margin: 0 auto 1.2em;
  width: 100%;
}
.tile {
  flex: 1;
  background: #1b2330;
  border-radius: 10px;
  height: 110px;
  position: relative;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.avatar {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -55%);
  width: 46px; height: 46px;
  border-radius: 50%;
  background: #3a4657;
}
.you-avatar { background: #2f5fdb; }
.tile-label {
  position: relative;
  z-index: 1;
  background: rgba(0,0,0,0.45);
  color: #fff;
  font-size: 0.78em;
  padding: 0.3em 0.6em;
  margin: 0.5em;
  border-radius: 4px;
}
.tile-label .dim { color: #c7cddb; }
.mic-muted { color: var(--bad); }

/* ---------- game layout ---------- */
.game-main {
  display: flex;
  gap: 1.2em;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  align-items: flex-start;
}
.game-primary { flex: 1; min-width: 0; }

.hud {
  display: flex;
  align-items: center;
  gap: 1.5em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1em 1.4em;
  margin-bottom: 1em;
}
.hud-label { font-size: 0.75em; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.score-value { font-size: 1.8em; font-weight: 700; font-variant-numeric: tabular-nums; }
.score-value.negative { color: var(--bad); }

.meter-block { flex: 1; }
.meter {
  height: 8px;
  background: var(--bad-bg);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.meter-fill {
  height: 100%;
  width: 9%;
  background: linear-gradient(90deg, var(--bad), var(--accent), var(--good));
  transition: width 0.4s ease;
}
.meter-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72em;
  color: var(--text-dim);
  margin-top: 0.3em;
}

.timer-block { position: relative; width: 46px; height: 46px; flex-shrink: 0; }
.timer-ring { width: 46px; height: 46px; transform: rotate(-90deg); }
.timer-ring-bg { fill: none; stroke: var(--border); stroke-width: 3; }
.timer-ring-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear, stroke 0.3s ease;
}
.timer-ring-fg.urgent { stroke: var(--bad); }
.timer-value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.question-card { padding: 2em 2.2em; }
.question-category {
  display: inline-block;
  font-size: 0.72em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 0.25em 0.6em;
  border-radius: 4px;
  margin-bottom: 0.9em;
}
.question-prompt {
  font-size: 1.2em;
  line-height: 1.5;
  margin-bottom: 1.6em;
}

.answer-numeric { display: flex; gap: 0.7em; }
.answer-numeric input {
  flex: 1;
  padding: 0.7em 0.9em;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1em;
  font-family: inherit;
}
.answer-numeric input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.answer-numeric .btn-primary { width: auto; margin-top: 0; }

.answer-mcq { display: flex; flex-direction: column; gap: 0.6em; }
.mcq-option {
  text-align: left;
  padding: 0.75em 1em;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95em;
  line-height: 1.4;
}
.mcq-option:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-dim); }
.mcq-option:disabled { cursor: default; }
.mcq-option.correct { border-color: var(--good); background: var(--good-bg); }
.mcq-option.incorrect { border-color: var(--bad); background: var(--bad-bg); }

.feedback {
  margin-top: 1.4em;
  padding: 0.9em 1.1em;
  border-radius: 6px;
  font-size: 0.9em;
  line-height: 1.5;
}
.feedback.good { background: var(--good-bg); color: #145c3b; }
.feedback.bad { background: var(--bad-bg); color: #8f241a; }
.feedback.neutral { background: var(--accent-dim); color: #1d3f96; }

/* ---------- sidebar chat ---------- */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  max-height: 480px;
}
.sidebar-header {
  padding: 0.9em 1.1em;
  border-bottom: 1px solid var(--border);
  font-size: 0.85em;
  font-weight: 600;
}
.chat-feed {
  flex: 1;
  overflow-y: auto;
  padding: 0.8em 1.1em;
  display: flex;
  flex-direction: column;
  gap: 0.6em;
}
.chat-row {
  display: flex;
  flex-direction: column;
  gap: 0.2em;
  background: var(--accent-dim);
  border-radius: 12px;
  border-bottom-left-radius: 3px;
  padding: 0.5em 0.75em;
  animation: bubble-in 0.22s ease;
  max-width: 92%;
  align-self: flex-start;
}
.chat-meta { font-size: 0.68em; color: var(--text-dim); }
.chat-text { font-size: 0.85em; line-height: 1.45; }

.chat-row.typing {
  background: transparent;
  padding: 0.3em 0.75em;
}
.typing-dots { display: inline-flex; align-items: center; gap: 4px; }
.typing-dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: typing-bounce 1s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- end screen ---------- */
.end-stats {
  margin: 1.5em 0;
  border-top: 1px solid var(--border);
  padding-top: 1em;
}
.end-stats div {
  display: flex;
  justify-content: space-between;
  padding: 0.4em 0;
  font-size: 0.92em;
}
.end-stats span { color: var(--text-dim); }

#end-card-lose { text-align: center; }
#lose-status { color: var(--text-dim); font-size: 1.05em; }

/* ---------- mail toast ---------- */
.mail-toast {
  position: fixed;
  right: 1.5em;
  bottom: 1.5em;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.8em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(20, 30, 50, 0.18);
  padding: 0.9em 1.1em;
  max-width: 300px;
  cursor: pointer;
  transform: translateY(20px) scale(0.97);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.35s ease;
}
.mail-toast.show { transform: translateY(0) scale(1); opacity: 1; }
.mail-toast:hover { border-color: var(--accent); }

.mail-icon {
  flex-shrink: 0;
  width: 34px; height: 26px;
  background: var(--accent);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}
.mail-icon-flap {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, transparent 49%, var(--surface) 50%) top left / 50% 50% no-repeat,
    linear-gradient(45deg, transparent 49%, var(--surface) 50%) top right / 50% 50% no-repeat;
  opacity: 0.35;
}
.mail-toast-from { font-size: 0.82em; font-weight: 700; }
.mail-toast-subject { font-size: 0.78em; color: var(--text-dim); margin-top: 0.15em; }

/* ---------- mail modal ---------- */
.mail-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10, 16, 28, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5em;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.mail-modal-overlay.show { opacity: 1; }
.mail-modal-overlay.hidden { display: none; }

.mail-modal {
  background: var(--surface);
  border-radius: 10px;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(10, 16, 28, 0.35);
  transform: translateY(10px) scale(0.98);
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.mail-modal-overlay.show .mail-modal { transform: translateY(0) scale(1); }

.mail-modal-toolbar {
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.8em 1em;
  border-bottom: 1px solid var(--border);
}
.mail-modal-dot { width: 10px; height: 10px; border-radius: 50%; }
.mail-modal-dot.red { background: #ff5f57; }
.mail-modal-dot.yellow { background: #febc2e; }
.mail-modal-dot.green { background: #28c840; }
.mail-modal-title {
  flex: 1;
  text-align: center;
  font-size: 0.85em;
  font-weight: 600;
  color: var(--text-dim);
}
.mail-modal-close {
  background: none;
  border: none;
  font-size: 1.1em;
  line-height: 1;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.1em 0.3em;
}
.mail-modal-close:hover { color: var(--text); }

.mail-modal-headers {
  padding: 1em 1.4em;
  border-bottom: 1px solid var(--border);
  font-size: 0.82em;
}
.mail-modal-headers div { padding: 0.15em 0; }
.mail-modal-headers span {
  display: inline-block;
  width: 4.5em;
  color: var(--text-dim);
}

.mail-modal-body {
  padding: 1.3em 1.4em;
  font-size: 0.92em;
  line-height: 1.65;
}
.mail-modal-body p { margin: 0 0 1em; white-space: pre-line; }
.mail-modal-body p:last-child { margin-bottom: 0; }

.mail-modal-footer {
  padding: 1em 1.4em 1.4em;
  border-top: 1px solid var(--border);
}

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .game-main { flex-direction: column; }
  .sidebar { width: 100%; max-height: 260px; }
  .video-row { display: none; }
}
@media (max-width: 480px) {
  .mail-toast { left: 1em; right: 1em; max-width: none; }
}
