/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --accent: #e94560;
  --accent2: #0f3460;
  --text: #eaeaea;
  --text-dim: #9a9ab0;
  --correct: #27ae60;
  --wrong: #e74c3c;
  --radius: 12px;
  --transition: 0.2s ease;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.hidden {
  display: none !important;
}

/* ── App shell ─────────────────────────────────────────────────────────────── */
#app {
  width: 100%;
  max-width: 780px;
}

/* ── Card ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 36px 40px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

/* ── Logo / header ─────────────────────────────────────────────────────────── */
.game-logo {
  text-align: center;
  margin-bottom: 32px;
}

.game-logo .logo-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 8px;
}

.game-logo h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}

.game-logo h1 span {
  color: var(--accent);
}

.game-logo .tagline {
  margin-top: 6px;
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* ── Login screen ─────────────────────────────────────────────────────────── */
.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 340px;
  margin: 0 auto;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-field label {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.login-field input[type="text"],
.login-field input[type="password"] {
  width: 100%;
  background: var(--accent2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition);
}

.login-field input:focus {
  border-color: var(--accent);
}

/* ── Connect screen ────────────────────────────────────────────────────────── */
.connect-options {
  display: flex;
  flex-direction: column;
  gap: 24px;
}


.section-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.section-hint {
  font-size: 0.88rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 14px;
}

.input-row {
  display: flex;
  gap: 10px;
}

input[type="text"],
input[type="number"] {
  background: var(--accent2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition);
}

input[type="text"]:focus,
input[type="number"]:focus {
  border-color: var(--accent);
}

input[type="text"] { flex: 1; }

.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.settings-row label {
  color: var(--text-dim);
  font-size: 0.9rem;
  white-space: nowrap;
}

.settings-row input[type="number"] {
  width: 80px;
}

.error-msg {
  color: var(--accent);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin-top: 4px;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 12px 22px;
  transition: opacity var(--transition), transform var(--transition);
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-secondary {
  background: var(--accent2);
  color: var(--text);
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--accent);
}

.btn-full { width: 100%; }

/* ── Quiz screen ───────────────────────────────────────────────────────────── */
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.progress-bar {
  height: 6px;
  background: var(--accent2);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 28px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.question-text {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.5;
  margin-bottom: 24px;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.option-btn {
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
  padding: 16px 14px;
  text-align: left;
  transition: border-color var(--transition), background var(--transition);
}

.option-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(233,69,96,0.08);
}

.option-btn.selected {
  border-color: var(--accent);
  background: rgba(233,69,96,0.18);
  color: #fff;
}

.feedback {
  font-size: 0.95rem;
  font-weight: 600;
  min-height: 1.5em;
  text-align: center;
}

.neutral-text { color: var(--text-dim); }

/* ── Results screen ────────────────────────────────────────────────────────── */
.results-loading {
  text-align: center;
  padding: 40px 0;
  color: var(--text-dim);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--accent2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.sync-banner {
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  padding: 20px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  line-height: 1.3;
}

.agent-connected-label {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 20px;
}

.agent-connected-label span {
  color: var(--text);
  font-weight: 600;
}

.sync-tier-1 { background: rgba(231,76,60,0.12);  color: #e74c3c; }
.sync-tier-2 { background: rgba(230,126,34,0.12); color: #e67e22; }
.sync-tier-3 { background: rgba(52,152,219,0.12); color: #3498db; }
.sync-tier-4 { background: rgba(39,174,96,0.12);  color: #2ecc71; }
.sync-tier-5 { background: rgba(155,89,182,0.15); color: #9b59b6; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.stat-card-highlight {
  border: 1px solid rgba(233,69,96,0.3);
}

.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent);
}

.stat-card .stat-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.breakdown-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.results-table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.results-table th {
  background: var(--accent2);
  color: var(--text-dim);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

.results-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: top;
}

.results-table tr:last-child td { border-bottom: none; }

.row-match { background: rgba(39,174,96,0.06); }
.row-diff  { background: transparent; }

.cell-match { color: #2ecc71; font-weight: 600; }
.cell-diff  { color: var(--text-dim); }

.results-actions {
  margin-top: 28px;
  display: flex;
  justify-content: center;
}

/* ── Notification toast ─────────────────────────────────────────────────────── */
.notification {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid rgba(233,69,96,0.5);
  border-radius: var(--radius);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 1000;
  max-width: 480px;
  width: calc(100% - 40px);
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from { top: -20px; opacity: 0; }
  to   { top: 20px;  opacity: 1; }
}

.notif-dismiss {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
  padding: 0 4px;
  margin-left: auto;
  flex-shrink: 0;
}
.notif-dismiss:hover { color: var(--text); }

/* ── Main menu ───────────────────────────────────────────────────────────────── */
.agent-status-bar {
  text-align: center;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 24px;
}

.agent-status-waiting {
  background: rgba(154,154,176,0.1);
  color: var(--text-dim);
}

.agent-status-ready {
  background: rgba(39,174,96,0.12);
  color: #2ecc71;
}

.main-menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Sub-screen chrome ───────────────────────────────────────────────────────── */
.screen-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
}

.btn-back {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.88rem;
  padding: 0;
  margin-bottom: 16px;
  display: inline-block;
  transition: color var(--transition);
}
.btn-back:hover { color: var(--text); }

/* ── Token section ───────────────────────────────────────────────────────────── */
.token-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.token-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--accent2);
  border-radius: 8px;
  padding: 12px 14px;
  margin-top: 8px;
  overflow: hidden;
}

.token-box code {
  flex: 1;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.82rem;
  color: var(--accent);
  word-break: break-all;
}

.btn-sm {
  padding: 7px 14px;
  font-size: 0.82rem;
  flex-shrink: 0;
}

.simulate-section {
  margin-top: 24px;
  text-align: center;
}

.simulate-label {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

/* ── Agent log ───────────────────────────────────────────────────────────────── */
.log-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.log-entry {
  display: flex;
  gap: 14px;
  align-items: baseline;
  background: var(--surface2);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.88rem;
}

.log-time {
  color: var(--text-dim);
  font-size: 0.78rem;
  flex-shrink: 0;
  font-family: 'Consolas', monospace;
}

.log-msg  { color: var(--text); }

.log-empty {
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
  padding: 20px 0;
}

/* ── Vote-for-agent screen ─────────────────────────────────────────────────── */
.vote-banner {
  background: rgba(230,126,34,0.12);
  color: #e67e22;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 20px;
}

.vote-label {
  font-size: 0.85rem;
  color: #e67e22;
  font-weight: 600;
}

.vote-fill {
  background: #e67e22;
}

.vote-option:hover:not(:disabled) {
  border-color: #e67e22 !important;
  background: rgba(230,126,34,0.1) !important;
}

.row-no-agent { background: rgba(154,154,176,0.04); }

.no-answer {
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.85rem;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 540px) {
  .card {
    padding: 24px 20px;
  }

  .options-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .input-row {
    flex-direction: column;
  }
}
