/* ===== RESET & BASE ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0f1117;
  --bg-card: #1a1b23;
  --bg-hover: #252630;
  --text: #e4e4e7;
  --text-muted: #8b8b9e;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --accent-glow: rgba(108, 92, 231, 0.3);
  --success: #00b894;
  --danger: #e17055;
  --warning: #fdcb6e;
  --border: #2d2d3d;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ===== LIGHT THEME ===== */
[data-theme="light"] {
  --bg: #f5f5f7;
  --bg-card: #ffffff;
  --bg-hover: #e8e8ec;
  --text: #1a1a2e;
  --text-muted: #6b6b80;
  --accent: #6c5ce7;
  --accent-light: #5a4bd1;
  --accent-glow: rgba(108, 92, 231, 0.12);
  --success: #00a884;
  --danger: #d63031;
  --warning: #f39c12;
  --border: #d1d1d8;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .loading-overlay {
  background: rgba(245, 245, 247, 0.85);
}

[data-theme="light"] .article-content a:hover {
  color: var(--accent);
}

[data-theme="light"] .btn-primary:hover {
  background: #5a4bd1;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  min-height: 100vh;
  animation: fadeIn 0.3s ease;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--accent-light);
}

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: var(--accent);
  background: var(--bg-card);
}

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #d63031;
}

.btn-small {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

.btn-icon {
  font-size: 1.1em;
}

/* ===== MENU SCREEN ===== */
.menu-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  text-align: center;
}

.logo {
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: -2px;
  margin-bottom: 0.5rem;
}

.accent {
  color: var(--accent);
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.1rem;
  max-width: 400px;
  margin-bottom: 2.5rem;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 320px;
}

.menu-buttons .btn {
  width: 100%;
  padding: 1rem 1.5rem;
  font-size: 1.05rem;
}

/* Custom form */
.custom-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-top: 1.5rem;
  width: 100%;
  max-width: 400px;
  text-align: left;
}

.custom-form h3 {
  margin-bottom: 1rem;
  text-align: center;
}

.form-group {
  margin-bottom: 1rem;
  position: relative;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.form-group input {
  width: 100%;
  padding: 0.7rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.form-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.form-row .btn {
  flex: 1;
}

.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}

.suggestions.visible {
  display: block;
}

.suggestion-item {
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover {
  background: var(--bg-hover);
}

.lang-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.lang-selector select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.3rem 0.6rem;
  font-family: var(--font);
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
}

.menu-bottom-row {
  margin-top: 2rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.hidden {
  display: none !important;
}

/* ===== GAME SCREEN ===== */
.game-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.game-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 200px;
}

.info-item {
  display: flex;
  flex-direction: column;
}

.info-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.info-value {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.target-highlight {
  color: var(--accent-light);
}

.info-arrow {
  color: var(--text-muted);
  font-size: 1.2rem;
}

.game-stats {
  display: flex;
  gap: 1rem;
}

.stat {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--bg);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.stat-value {
  font-weight: 700;
  color: var(--accent-light);
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.game-actions {
  display: flex;
  gap: 0.5rem;
}

/* Breadcrumb */
.breadcrumb {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 2rem;
}

.breadcrumb-item {
  cursor: pointer;
  color: var(--accent-light);
  transition: color 0.15s;
}

.breadcrumb-item:hover {
  color: var(--accent);
  text-decoration: underline;
}

.breadcrumb-item.current {
  color: var(--text);
  cursor: default;
  font-weight: 600;
}

.breadcrumb-separator {
  color: var(--text-muted);
  opacity: 0.5;
}

/* Article layout with TOC sidebar */
.article-layout {
  flex: 1;
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.toc-sidebar {
  width: 240px;
  min-width: 200px;
  padding: 1rem 0 2rem 1rem;
  position: sticky;
  top: 70px;
  align-self: flex-start;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  flex-shrink: 0;
}

.toc-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-size: 0.8rem;
}

.toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-weight: 700;
  font-size: 0.85rem;
}

.toc-toggle {
  background: none;
  border: none;
  color: var(--accent-light);
  cursor: pointer;
  font-size: 0.75rem;
  font-family: var(--font);
  padding: 0;
}

.toc-toggle:hover {
  text-decoration: underline;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-list.collapsed {
  display: none;
}

.toc-list li {
  margin-bottom: 0.2rem;
}

.toc-list a {
  color: var(--accent-light);
  text-decoration: none;
  display: block;
  padding: 0.15rem 0.3rem;
  border-radius: 3px;
  transition: background 0.15s, color 0.15s;
  line-height: 1.4;
  word-break: break-word;
}

.toc-list a:hover {
  background: var(--accent-glow);
  color: var(--text);
}

.toc-list .toc-h3 {
  padding-left: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.toc-list .toc-h3:hover {
  color: var(--text);
}

.toc-num {
  color: var(--text-muted);
  margin-right: 0.3rem;
}

.article-container {
  flex: 1;
  padding: 1.5rem 2rem 3rem;
  max-width: 900px;
  min-width: 0;
  width: 100%;
}

.article-title {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border);
}

.article-content {
  font-size: 0.95rem;
  line-height: 1.8;
}

.article-content p {
  margin-bottom: 0.8rem;
}

.article-content h2, .article-content h3, .article-content h4 {
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.article-content h2 {
  font-size: 1.4rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}

.article-content h3 {
  font-size: 1.15rem;
}

.article-content ul, .article-content ol {
  padding-left: 1.5rem;
  margin-bottom: 0.8rem;
}

.article-content li {
  margin-bottom: 0.3rem;
}

.article-content a {
  color: var(--accent-light);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: all 0.15s;
  cursor: pointer;
}

.article-content a:hover {
  color: #fff;
  border-bottom-color: var(--accent-light);
  background: var(--accent-glow);
  border-radius: 2px;
  padding: 0 2px;
}

.article-content a.target-link {
  background: rgba(0, 184, 148, 0.2);
  color: var(--success);
  font-weight: 600;
  border-bottom-color: var(--success);
  padding: 0 3px;
  border-radius: 3px;
}

.article-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  margin: 0.5rem 0;
}

.article-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
  font-size: 0.85rem;
}

.article-content th, .article-content td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  text-align: left;
}

.article-content th {
  background: var(--bg-hover);
}

.article-content .infobox {
  float: right;
  clear: right;
  margin: 0 0 1rem 1.5rem;
  max-width: 300px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-size: 0.85rem;
}

.article-content .infobox th,
.article-content .infobox td {
  padding: 0.25rem 0.5rem;
}

.article-content .thumb {
  margin: 0.75rem 0;
  max-width: 300px;
}

.article-content .thumb.tright {
  float: right;
  clear: right;
  margin-left: 1.5rem;
}

.article-content .thumb.tleft {
  float: left;
  clear: left;
  margin-right: 1.5rem;
}

.article-content .thumbinner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
}

.article-content .thumbcaption {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  line-height: 1.4;
}

.article-content .sidebar,
.article-content .navbox {
  display: none;
}

/* Loader */
.loader {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
  font-size: 1.1rem;
}

.loader::before {
  content: '';
  display: block;
  width: 40px;
  height: 40px;
  margin: 0 auto 1rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== RESULT SCREEN ===== */
.result-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  text-align: center;
}

.result-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.result-container h2 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.result-message {
  color: var(--text-muted);
  margin-bottom: 2rem;
  max-width: 400px;
}

.result-stats {
  display: flex;
  gap: 2rem;
  margin-bottom: 2rem;
}

.result-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
  min-width: 120px;
}

.result-stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent-light);
}

.result-stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.path-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin: 1rem 0 2rem;
  max-width: 600px;
}

.path-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.path-item.start {
  border-color: var(--success);
  color: var(--success);
}

.path-item.end {
  border-color: var(--accent);
  color: var(--accent-light);
}

.path-arrow {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ===== RESULT: OPPONENT SECTION ===== */
.result-opponent {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
}

.result-opponent h3 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
  color: var(--text-muted);
}

.result-opponent-header {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.ro-name {
  font-weight: 800;
  font-size: 1.1rem;
}

.ro-clicks-badge {
  background: var(--accent);
  color: #fff;
  padding: 0.15rem 0.6rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

.ro-status {
  font-size: 0.85rem;
  font-weight: 700;
}

.ro-status.playing {
  color: var(--accent-light);
}

.ro-status.finished {
  color: #2ecc71;
}

.ro-status.lost {
  color: var(--danger);
}

.ro-path {
  font-size: 0.85rem;
  max-height: 200px;
  overflow-y: auto;
  padding: 0.4rem 0;
}

@keyframes ro-new-article {
  0% { background: var(--accent); color: #fff; }
  100% { background: transparent; color: inherit; }
}

.ro-path .path-item.ro-new {
  animation: ro-new-article 0.8s ease-out;
}

.result-buttons {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.shortest-path-section {
  margin-top: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 600px;
  text-align: center;
}

.shortest-path-section h3 {
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

/* ===== LEADERBOARD SCREEN ===== */
.leaderboard-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 3rem 2rem;
}

.leaderboard-container h2 {
  font-size: 1.8rem;
  margin-bottom: 1.5rem;
}

.leaderboard-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.tab {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 1.2rem;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.tab:hover {
  border-color: var(--accent);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.leaderboard-list {
  width: 100%;
  max-width: 600px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
}

.lb-entry {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  transition: border-color 0.2s;
}

.lb-entry:hover {
  border-color: var(--accent);
}

.lb-rank {
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--text-muted);
  min-width: 2rem;
  text-align: center;
}

.lb-entry:nth-child(1) .lb-rank { color: #ffd700; }
.lb-entry:nth-child(2) .lb-rank { color: #c0c0c0; }
.lb-entry:nth-child(3) .lb-rank { color: #cd7f32; }

.lb-info {
  flex: 1;
  min-width: 0;
}

.lb-route {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.lb-stats {
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
}

.lb-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.lb-stat-value {
  font-weight: 700;
  color: var(--accent-light);
}

.lb-stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ===== AUTH SCREEN ===== */
.auth-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  text-align: center;
}

.auth-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 380px;
  text-align: left;
  margin-top: 1.5rem;
}

.auth-form h3 {
  margin-bottom: 1rem;
  text-align: center;
  font-size: 1.2rem;
}

.auth-error {
  background: rgba(225, 112, 85, 0.15);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--danger);
}

.btn-full {
  width: 100%;
  margin-top: 0.5rem;
}

.auth-switch {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.auth-link {
  color: var(--accent-light);
  text-decoration: none;
  font-weight: 600;
  margin-left: 0.3rem;
}

.auth-link:hover {
  text-decoration: underline;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.5rem 0;
  width: 100%;
  max-width: 380px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ===== LOGIN PROMPT (for offline users) ===== */
.login-prompt {
  margin-bottom: 1rem;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

/* ===== USER BAR (Menu) ===== */
.user-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  margin-bottom: 1.5rem;
  width: 100%;
  max-width: 420px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.user-bar:hover {
  border-color: var(--accent);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
}

.user-avatar {
  font-size: 1.5rem;
}

.user-name {
  font-weight: 700;
  font-size: 0.95rem;
  display: block;
}

.user-rating {
  font-size: 0.8rem;
  color: var(--accent-light);
  font-weight: 600;
}

.user-stats-mini {
  display: flex;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===== MATCHMAKING SCREEN ===== */
.matchmaking-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  text-align: center;
}

.matchmaking-container h2 {
  font-size: 1.8rem;
  margin-bottom: 1.5rem;
}

.spinner-large {
  width: 64px;
  height: 64px;
  border: 5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 1.5rem;
}

.matchmaking-status {
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.matchmaking-players {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  margin-top: 1rem;
}

.mm-player-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  text-align: center;
  min-width: 140px;
}

.mm-player-card .mm-name {
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.mm-player-card .mm-rating {
  font-size: 0.85rem;
  color: var(--accent-light);
}

.mm-vs {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent);
}

/* ===== MATCHMAKING STATE: FOUND ===== */
.mm-player-card.mm-found {
  border-color: #2ecc71;
  box-shadow: 0 0 12px rgba(46, 204, 113, 0.25);
  animation: mm-card-appear 0.4s ease-out;
}

@keyframes mm-card-appear {
  0% { opacity: 0; transform: scale(0.8); }
  100% { opacity: 1; transform: scale(1); }
}

.matchmaking-container h2.match-found-title {
  color: #2ecc71;
  animation: found-glow 1.5s ease-in-out infinite alternate;
}

@keyframes found-glow {
  0% { text-shadow: 0 0 4px rgba(46, 204, 113, 0.2); }
  100% { text-shadow: 0 0 16px rgba(46, 204, 113, 0.5); }
}

/* ===== COUNTDOWN CIRCLE ===== */
.countdown-circle {
  position: relative;
  width: 140px;
  height: 140px;
  margin: 1.5rem auto;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.countdown-circle.visible {
  opacity: 1;
  transform: scale(1);
}

.countdown-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  filter: drop-shadow(0 0 8px rgba(46, 204, 113, 0.4));
}

.countdown-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 5;
  opacity: 0.4;
}

.countdown-progress {
  fill: none;
  stroke: #2ecc71;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 339.292;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear;
  filter: drop-shadow(0 0 3px rgba(46, 204, 113, 0.6));
}

.countdown-number {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 3rem;
  font-weight: 800;
  color: #2ecc71;
  text-shadow: 0 0 12px rgba(46, 204, 113, 0.5);
}

.countdown-number.tick {
  animation: countdown-tick 0.4s ease-out;
}

@keyframes countdown-tick {
  0% { transform: translate(-50%, -50%) scale(1.5); opacity: 0.5; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.countdown-number.go {
  color: #f1c40f;
  text-shadow: 0 0 16px rgba(241, 196, 15, 0.6);
  animation: countdown-go 0.6s ease-out;
}

@keyframes countdown-go {
  0% { transform: translate(-50%, -50%) scale(2); opacity: 0; }
  50% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* ===== URGENCY FLASH ===== */
.urgency-flash {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 9999;
  box-shadow: inset 0 0 0 0 rgba(231, 76, 60, 0);
  transition: box-shadow 0.3s ease;
}

.urgency-flash.flash-active {
  animation: urgency-border-flash 0.8s ease-in-out;
}

@keyframes urgency-border-flash {
  0% { box-shadow: inset 0 0 0 0 rgba(231, 76, 60, 0); }
  25% { box-shadow: inset 0 0 120px 30px rgba(231, 76, 60, 0.45); }
  50% { box-shadow: inset 0 0 80px 20px rgba(231, 76, 60, 0.25); }
  75% { box-shadow: inset 0 0 50px 10px rgba(231, 76, 60, 0.1); }
  100% { box-shadow: inset 0 0 0 0 rgba(231, 76, 60, 0); }
}

/* ===== URGENCY TIMER BADGE ===== */
.urgency-timer {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  color: #fff;
  padding: 0.8rem 2rem;
  border-radius: 0 0 var(--radius) var(--radius);
  font-weight: 800;
  font-size: 1.5rem;
  z-index: 10000;
  box-shadow: 0 4px 20px rgba(231, 76, 60, 0.5);
  animation: urgency-timer-appear 0.3s ease-out;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.urgency-timer .urgency-icon {
  font-size: 1.3rem;
}

.urgency-timer .urgency-seconds {
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
  text-align: center;
  font-size: 1.8rem;
}

.urgency-timer.critical {
  animation: urgency-critical-pulse 0.5s ease-in-out infinite;
  background: linear-gradient(135deg, #c0392b, #922b21);
}

@keyframes urgency-timer-appear {
  0% { opacity: 0; transform: translateX(-50%) translateY(-20px); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes urgency-critical-pulse {
  0%, 100% { opacity: 1; transform: translateX(-50%) scale(1); }
  50% { opacity: 0.85; transform: translateX(-50%) scale(1.08); }
}

/* ===== SPECTATOR PANEL (opponent path tracker) ===== */
.spectator-panel {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 0;
  z-index: 10000;
  width: 420px;
  max-width: 95vw;
  max-height: 50vh;
  box-shadow: 0 4px 30px rgba(0,0,0,0.4);
  animation: spectator-slide-up 0.4s ease-out;
}

@keyframes spectator-slide-up {
  0% { opacity: 0; transform: translateX(-50%) translateY(20px); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.spectator-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  border-radius: var(--radius) var(--radius) 0 0;
}

.spectator-icon { font-size: 1.1rem; }

.spectator-close {
  margin-left: auto;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.3rem;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.spectator-close:hover { opacity: 1; }

.spectator-body {
  padding: 0.8rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  overflow-y: auto;
  max-height: 40vh;
}

.spectator-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.spectator-name {
  font-weight: 800;
  font-size: 1.1rem;
}

.spectator-clicks-badge {
  background: var(--accent);
  color: #fff;
  padding: 0.2rem 0.7rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

.spectator-path {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}

.spectator-path .sp-article {
  background: var(--bg-body);
  border: 1px solid var(--border);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.3s;
}

.spectator-path .sp-article:first-child {
  border-color: var(--accent);
  color: var(--accent);
}

.spectator-path .sp-article:last-child {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 700;
}

.spectator-path .sp-article.sp-new {
  animation: sp-highlight 0.5s ease-out;
}

@keyframes sp-highlight {
  0% { background: var(--accent); color: #fff; transform: scale(1.1); }
  100% { background: var(--bg-body); color: inherit; transform: scale(1); }
}

.spectator-path .sp-arrow {
  color: var(--text-muted);
  font-size: 0.7rem;
}

.spectator-status-msg {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  font-weight: 600;
}

.spectator-status-msg.finished {
  color: #2ecc71;
}

.spectator-status-msg.gave-up {
  color: var(--danger);
}

/* ===== OPPONENT STAT (in-game) ===== */
.opponent-stat {
  background: rgba(225, 112, 85, 0.15);
  border: 1px solid var(--danger);
}

/* ===== RATING CHANGE (result screen) ===== */
.rating-change {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.rating-change-value {
  font-size: 1.5rem;
  font-weight: 800;
}

.rating-change-value.positive {
  color: var(--success);
}

.rating-change-value.negative {
  color: var(--danger);
}

.rating-change-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===== ONLINE LEADERBOARD ===== */
.lb-pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.online-lb-entry {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  transition: border-color 0.2s;
}

.online-lb-entry:hover {
  border-color: var(--accent);
}

.online-lb-entry.is-me {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.online-lb-name {
  flex: 1;
  font-weight: 600;
  font-size: 0.95rem;
}

.online-lb-rating {
  font-weight: 700;
  color: var(--accent-light);
  font-size: 1rem;
}

.online-lb-stats {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== PROFILE SCREEN ===== */
.profile-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 3rem 2rem;
}

.profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.profile-avatar {
  font-size: 3rem;
}

.profile-header h2 {
  font-size: 1.5rem;
}

.profile-rating {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.profile-rating-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent-light);
}

.profile-rating-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.profile-stats {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.profile-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  min-width: 80px;
}

.profile-stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent-light);
}

.profile-stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Rating history chart (simple CSS bars) */
.rating-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 100px;
  width: 100%;
  max-width: 500px;
  margin-bottom: 1.5rem;
  padding: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.rating-bar {
  flex: 1;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  min-width: 4px;
  transition: height 0.3s;
}

.profile-history-list {
  width: 100%;
  max-width: 500px;
}

.history-entry {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.history-rating {
  font-weight: 700;
  min-width: 50px;
  color: var(--accent-light);
}

.history-change {
  font-weight: 600;
  min-width: 45px;
}

.history-change.positive { color: var(--success); }
.history-change.negative { color: var(--danger); }

.history-match {
  flex: 1;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===== BTN ACCENT (online battle) ===== */
.btn-accent {
  background: linear-gradient(135deg, var(--accent), #e17055);
  color: #fff;
  border: none;
  box-shadow: 0 4px 15px rgba(108, 92, 231, 0.4);
}

.btn-accent:hover {
  opacity: 0.9;
  box-shadow: 0 6px 20px rgba(108, 92, 231, 0.5);
}

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 1rem;
}

/* ===== HINT TOAST ===== */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow);
  z-index: 200;
  animation: slideUp 0.3s ease;
  max-width: 90%;
  text-align: center;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .game-header {
    padding: 0.5rem 1rem;
    gap: 0.75rem;
  }

  .game-info {
    order: 1;
    width: 100%;
  }

  .game-stats {
    order: 2;
  }

  .game-actions {
    order: 3;
  }

  .article-container {
    padding: 1rem;
  }

  .logo {
    font-size: 2.5rem;
  }

  .result-stats {
    flex-direction: column;
    gap: 1rem;
  }

  .article-content .infobox,
  .article-content .thumb.tright,
  .article-content .thumb.tleft {
    float: none;
    margin: 1rem auto;
    max-width: 100%;
  }

  .toc-sidebar {
    display: none;
  }

  .article-layout {
    flex-direction: column;
  }

  .user-bar {
    flex-direction: column;
    text-align: center;
  }

  .profile-stats {
    flex-wrap: wrap;
    justify-content: center;
  }

  .matchmaking-players {
    flex-direction: column;
  }

  .mm-vs {
    transform: rotate(90deg);
  }
}
