/* ===== Theme Variables ===== */
:root {
  --bg-body: #f0f2f5;
  --bg-card: #ffffff;
  --bg-card-hover: #e8eaed;
  --bg-input: #f0f2f5;
  --bg-modal: #ffffff;
  --bg-panel: #ffffff;
  --text-primary: #333333;
  --text-secondary: #888888;
  --text-muted: #aaaaaa;
  --text-heading: #b8940c;
  --text-white: #333333;
  --accent: #d4a800;
  --accent-hover: #b8940c;
  --border-subtle: #e0e0e0;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --overlay: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] {
  --bg-body: #1a1a2e;
  --bg-card: rgba(255, 255, 255, 0.05);
  --bg-card-hover: rgba(255, 255, 255, 0.1);
  --bg-input: rgba(255, 255, 255, 0.1);
  --bg-modal: #1a1a2e;
  --bg-panel: #1a1a2e;
  --text-primary: #d1d0c5;
  --text-secondary: #888888;
  --text-muted: #666666;
  --text-heading: #e2b714;
  --text-white: #ffffff;
  --accent: #e2b714;
  --accent-hover: #f0c818;
  --border-subtle: rgba(226, 183, 20, 0.2);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  --overlay: rgba(0, 0, 0, 0.8);
}

/* ===== Reset ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: var(--bg-body);
  color: var(--text-primary);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.3s ease, color 0.3s ease;
}

.container, .game-container {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
  flex: 1;
}

/* ===== Header ===== */
.header {
  text-align: center;
  margin-bottom: 40px;
  position: relative;
}

.logo {
  font-size: 2.5rem;
  color: var(--accent);
  margin-bottom: 10px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
}

/* ===== Theme Toggle & Settings ===== */
.header-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
}

.theme-toggle,
.settings-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 4px;
  line-height: 1;
}

.theme-toggle:hover,
.settings-btn:hover {
  transform: scale(1.15);
}

.settings-btn {
  color: var(--text-secondary);
}

.settings-btn:hover {
  color: var(--accent);
  transform: scale(1.15) rotate(30deg);
}

/* ===== Language Section ===== */
.language-section h2, .article-section h2, .ranking-section h2 {
  text-align: center;
  margin-bottom: 30px;
  color: var(--accent);
  font-size: 1.5rem;
}

.language-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.language-card {
  background: var(--bg-card);
  border-radius: 15px;
  padding: 30px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid transparent;
  box-shadow: var(--shadow);
}

.language-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  transform: translateY(-5px);
}

.lang-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 15px;
}

.lang-name {
  font-size: 1.5rem;
  font-weight: bold;
  display: block;
  margin-bottom: 10px;
}

.article-count {
  color: var(--text-secondary);
}

/* ===== Article Section ===== */
.back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1rem;
  cursor: pointer;
  margin-bottom: 20px;
  padding: 10px 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.back-btn:hover {
  text-decoration: underline;
}

.article-list {
  display: grid;
  gap: 20px;
}

.article-card {
  background: var(--bg-card);
  border-radius: 15px;
  padding: 25px;
  transition: all 0.3s ease;
  box-shadow: var(--shadow);
}

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

.article-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.article-header h3 {
  color: var(--text-primary);
  font-size: 1.3rem;
}

.badge {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: bold;
}

.badge.easy {
  background: #28a745;
  color: #fff;
}

.badge.medium {
  background: #ffc107;
  color: #000;
}

.badge.hard {
  background: #dc3545;
  color: #fff;
}

.badge.lang {
  background: rgba(0, 206, 209, 0.15);
  color: #009ea0;
}

[data-theme="dark"] .badge.lang {
  background: rgba(0, 206, 209, 0.2);
  color: #00ced1;
}

.badge-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.article-author {
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.article-preview {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 15px;
}

.article-stats {
  display: flex;
  gap: 20px;
  color: var(--text-secondary);
  margin-bottom: 15px;
}

.article-actions {
  display: flex;
  gap: 10px;
}

/* ===== Buttons ===== */
.btn-primary, .btn-secondary {
  flex: 1;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-primary {
  background: var(--accent);
  color: #000;
}

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

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
}

[data-theme="dark"] .btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

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

[data-theme="dark"] .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ===== Ranking Section ===== */
.ranking-header {
  display: grid;
  grid-template-columns: 60px 1fr 60px 80px 60px 100px;
  gap: 10px;
  padding: 15px;
  background: var(--bg-input);
  border-radius: 10px;
  font-weight: bold;
  color: var(--accent);
  margin-bottom: 10px;
}

.ranking-item {
  display: grid;
  grid-template-columns: 60px 1fr 60px 80px 60px 100px;
  gap: 10px;
  padding: 15px;
  background: var(--bg-card);
  border-radius: 10px;
  margin-bottom: 10px;
  align-items: center;
  box-shadow: var(--shadow);
}

.ranking-item.top-1 {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.15), transparent);
  border-left: 4px solid #ffd700;
}

.ranking-item.top-2 {
  background: linear-gradient(135deg, rgba(192, 192, 192, 0.15), transparent);
  border-left: 4px solid #c0c0c0;
}

.ranking-item.top-3 {
  background: linear-gradient(135deg, rgba(205, 127, 50, 0.15), transparent);
  border-left: 4px solid #cd7f32;
}

.rank {
  font-size: 1.2rem;
}

.empty-state {
  text-align: center;
  padding: 50px;
  color: var(--text-secondary);
}

/* ===== Game Page ===== */
.game-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 30px;
}

.game-header h1 {
  color: var(--accent);
  font-size: 1.5rem;
}

.game-stats {
  display: flex;
  justify-content: space-around;
  background: var(--bg-card);
  border-radius: 15px;
  padding: 20px;
  margin-bottom: 30px;
  box-shadow: var(--shadow);
}

.stat-item {
  text-align: center;
}

.stat-item span {
  display: block;
  font-size: 2rem;
  color: var(--accent);
  font-weight: bold;
}

.stat-item p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ===== Description Area ===== */
.description-area {
  background: rgba(0, 206, 209, 0.06);
  border-left: 3px solid #00ced1;
  border-radius: 10px;
  padding: 20px 25px;
  margin-bottom: 25px;
}

[data-theme="dark"] .description-area {
  background: rgba(0, 206, 209, 0.08);
}

.description-area h3 {
  color: #009ea0;
  font-size: 0.95rem;
  margin-bottom: 10px;
}

[data-theme="dark"] .description-area h3 {
  color: #00ced1;
}

.description-area p {
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 1.7;
}

/* ===== Typing Area ===== */
.typing-area {
  background: var(--bg-card);
  border-radius: 15px;
  padding: 30px;
  margin-bottom: 30px;
  box-shadow: var(--shadow);
}

.text-display {
  font-size: 1.5rem;
  line-height: 2;
  margin-bottom: 20px;
  min-height: 100px;
  max-height: 240px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  scroll-behavior: smooth;
}

.text-display span {
  transition: all 0.1s ease;
}

.text-display .current {
  background: var(--accent);
  color: #000;
  border-radius: 3px;
  animation: blink 1s infinite;
}

.text-display .shake {
  animation: shake 0.3s ease-in-out;
}

.text-display .completed {
  color: #28a745;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0.5; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.typing-area input {
  width: 100%;
  padding: 15px;
  font-size: 1.2rem;
  background: var(--bg-input);
  border: 2px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-primary);
  outline: none;
  transition: all 0.3s ease;
}

.typing-area input:focus {
  border-color: var(--accent);
}

.typing-area input::placeholder {
  color: var(--text-muted);
}

.game-controls {
  display: flex;
  justify-content: center;
}

.game-controls button {
  padding: 15px 50px;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--overlay);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg-modal);
  border-radius: 20px;
  padding: 40px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow);
}

.modal-content h2 {
  color: var(--accent);
  margin-bottom: 30px;
}

.result-stats {
  display: flex;
  justify-content: space-around;
  margin-bottom: 30px;
}

.result-stats div span {
  display: block;
  font-size: 2rem;
  color: var(--accent);
  font-weight: bold;
}

.result-stats div p {
  color: var(--text-secondary);
}

.modal-content input {
  width: 100%;
  padding: 15px;
  font-size: 1rem;
  background: var(--bg-input);
  border: 2px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-primary);
  outline: none;
  margin-bottom: 20px;
}

.modal-content input:focus {
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions button {
  flex: 1;
}

/* ===== Settings Panel ===== */
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  height: 100%;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-subtle);
  z-index: 1001;
  overflow-y: auto;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] .settings-panel {
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
}

.settings-content {
  padding: 30px;
}

.settings-content h3 {
  color: var(--accent);
  margin-bottom: 25px;
  font-size: 1.3rem;
}

.settings-content h4 {
  color: var(--text-primary);
  margin-bottom: 10px;
}

.settings-desc {
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.6;
  margin-bottom: 15px;
}

.settings-desc a {
  color: var(--accent);
}

.settings-content input {
  width: 100%;
  padding: 12px;
  font-size: 0.95rem;
  background: var(--bg-input);
  border: 2px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-primary);
  outline: none;
  margin-bottom: 10px;
}

.settings-content input:focus {
  border-color: var(--accent);
}

/* ===== Gist Status ===== */
.gist-status {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: bold;
  display: inline-block;
  margin-bottom: 15px;
}

.gist-status.synced {
  background: rgba(40, 167, 69, 0.15);
  color: #28a745;
}

.gist-status.unsynced {
  background: var(--bg-input);
  color: var(--text-secondary);
}

.gist-status.error {
  background: rgba(220, 53, 69, 0.15);
  color: #dc3545;
}

.sync-message {
  padding: 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-top: 10px;
}

.sync-message.success {
  background: rgba(40, 167, 69, 0.1);
  color: #28a745;
}

.sync-message.error {
  background: rgba(220, 53, 69, 0.1);
  color: #dc3545;
}

/* ===== Mode Selector ===== */
.mode-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.mode-card {
  background: var(--bg-card);
  border: 2px solid var(--border-subtle);
  border-radius: 12px;
  padding: 25px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: var(--shadow);
}

.mode-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  transform: translateY(-3px);
}

.mode-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 12px;
}

.mode-name {
  color: var(--accent);
  font-size: 1.2rem;
  font-weight: bold;
  display: block;
  margin-bottom: 8px;
}

.mode-desc {
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.4;
}

/* ===== Mode Badge ===== */
.mode-badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: bold;
  margin-left: auto;
  white-space: nowrap;
}

.mode-badge.timed {
  background: rgba(255, 193, 7, 0.2);
  color: #b8960a;
}

[data-theme="dark"] .mode-badge.timed {
  color: #ffc107;
}

.mode-badge.endless {
  background: rgba(0, 206, 209, 0.15);
  color: #009ea0;
}

[data-theme="dark"] .mode-badge.endless {
  background: rgba(0, 206, 209, 0.2);
  color: #00ced1;
}

/* ===== Footer ===== */
.site-footer {
  text-align: center;
  padding: 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.site-footer a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.2s ease;
}

.site-footer a:hover {
  color: var(--accent);
}

.site-footer svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .container, .game-container {
    padding: 10px;
  }

  .header {
    margin-bottom: 20px;
  }

  .logo {
    font-size: 1.8rem;
  }

  .subtitle {
    font-size: 0.9rem;
  }

  .header-actions {
    top: 5px;
    right: 5px;
    gap: 4px;
  }

  .theme-toggle,
  .settings-btn {
    font-size: 1.1rem;
  }

  .language-grid {
    grid-template-columns: 1fr;
  }

  .language-card {
    padding: 20px;
  }

  .lang-icon {
    font-size: 2.5rem;
  }

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

  .ranking-header, .ranking-item {
    grid-template-columns: 40px 1fr 50px 60px 50px 80px;
    font-size: 0.8rem;
  }

  .game-stats {
    padding: 12px;
    gap: 5px;
  }

  .stat-item span {
    font-size: 1.4rem;
  }

  .stat-item p {
    font-size: 0.75rem;
  }

  .game-header {
    flex-wrap: wrap;
    gap: 10px;
  }

  .game-header h1 {
    font-size: 1.2rem;
    flex-basis: 100%;
    order: -1;
  }

  .game-header .back-btn {
    font-size: 0.9rem;
  }

  .mode-badge {
    font-size: 0.7rem;
    padding: 3px 10px;
  }

  .typing-area {
    padding: 15px;
  }

  .text-display {
    font-size: 1.15rem;
    line-height: 1.8;
    max-height: 160px;
  }

  .typing-area input {
    padding: 12px;
    font-size: 1.1rem;
  }

  .game-controls button {
    padding: 12px 30px;
    width: 100%;
  }

  .settings-panel {
    width: 100%;
  }

  .settings-content {
    padding: 20px;
  }

  .mode-options {
    grid-template-columns: 1fr;
  }

  .description-area {
    padding: 15px;
  }

  .modal-content {
    padding: 25px;
    margin: 10px;
  }

  .result-stats {
    gap: 10px;
  }

  .result-stats div span {
    font-size: 1.5rem;
  }

  .site-footer {
    gap: 16px;
    padding: 20px 10px;
  }

  .site-footer a {
    font-size: 0.8rem;
  }
}
