@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;600;700;800&display=swap');

/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-0: #0b1220;
  --bg-1: #0f1a2f;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --border-soft: rgba(255, 255, 255, 0.5);
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.18);
  --text: #1d2433;
  --muted: rgba(29, 36, 51, 0.72);

  --primary-1: #667eea;
  --primary-2: #764ba2;
  --danger: #dc3545;
  --warning: #ffc107;
  --success: #28a745;

  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 12px;
  --focus: 0 0 0 4px rgba(102, 126, 234, 0.26);
}

body {
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: radial-gradient(1200px 700px at 12% 10%, rgba(102, 126, 234, 0.28), transparent 55%),
              radial-gradient(900px 600px at 85% 30%, rgba(118, 75, 162, 0.26), transparent 58%),
              linear-gradient(180deg, var(--bg-0), var(--bg-1));
  min-height: 100vh;
  color: rgba(255, 255, 255, 0.92);
  line-height: 1.5;
}

.container {
  max-width: 920px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Header */
.header {
  text-align: center;
  padding: 14px 0;
  color: rgba(255, 255, 255, 0.96);
}

.header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-shadow: 0 10px 22px rgba(0, 0, 0, 0.25);
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-md);
  backdrop-filter: blur(10px);
}

.game-info {
  display: flex;
  gap: 20px;
  font-size: 1.1rem;
  font-weight: 600;
}

.score-display, .question-counter {
  background: rgba(255, 255, 255, 0.16);
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

/* Main Content */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  color: var(--text);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.card h2 {
  color: var(--primary-1);
  margin-bottom: 16px;
  font-size: 1.5rem;
}

.info-card {
  background: rgba(255, 255, 255, 0.95);
}

.info-card h3 {
  color: var(--primary-2);
  margin-bottom: 12px;
  font-size: 1.2rem;
}

.rules-list {
  list-style: none;
  padding-left: 0;
}

.rules-list li {
  padding: 8px 0;
  padding-left: 24px;
  position: relative;
}

.rules-list li:before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--primary-1);
  font-weight: bold;
}

/* Forms */
.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-weight: 600;
  color: rgba(29, 36, 51, 0.86);
}

.form-group input {
  padding: 12px 16px;
  border: 1px solid rgba(29, 36, 51, 0.14);
  border-radius: 12px;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.96);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.05s ease;
}

.form-group input:focus {
  outline: none;
  border-color: rgba(102, 126, 234, 0.65);
  box-shadow: var(--focus);
}

.form-group small {
  color: var(--muted);
  font-size: 0.85rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 26px;
  border: none;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-1) 0%, var(--primary-2) 100%);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
  background: #6c757d;
  color: white;
}

.btn-outline {
  background: transparent;
  border: 2px solid rgba(102, 126, 234, 0.55);
  color: rgba(29, 36, 51, 0.92);
}

.btn-large {
  font-size: 1.2rem;
  padding: 16px 32px;
}

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

.btn:focus-visible,
.option-btn:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

/* Message */
.message {
  margin-top: 16px;
  padding: 12px;
  border-radius: 12px;
  text-align: center;
  font-weight: 500;
}

.message.error {
  background: rgba(220, 53, 69, 0.12);
  color: #8f1e2b;
  border: 1px solid rgba(220, 53, 69, 0.18);
}

.message.success {
  background: rgba(40, 167, 69, 0.12);
  color: #186c2c;
  border: 1px solid rgba(40, 167, 69, 0.18);
}

/* Game Area */
.loading {
  text-align: center;
  padding: 40px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 1.2rem;
}

.hidden {
  display: none !important;
}

.game-area {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  color: var(--text);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

/* Timer */
.timer-container {
  margin-bottom: 24px;
}

.timer-bar {
  height: 8px;
  background: var(--primary-1);
  border-radius: 4px;
  transition: width 1s linear;
}

.timer-bar.timer-warning {
  background: var(--warning);
}

.timer-bar.timer-critical {
  background: var(--danger);
}

.timer-text {
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-1);
  margin-top: 8px;
}

/* Question */
.question-card {
  margin-bottom: 24px;
}

.question-text {
  color: rgba(29, 36, 51, 0.92);
  font-size: 1.3rem;
  line-height: 1.6;
}

/* Options */
.options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.option-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: rgba(248, 249, 250, 0.92);
  border: 1px solid rgba(29, 36, 51, 0.14);
  border-radius: 12px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
  text-align: left;
}

.option-btn:hover:not(:disabled) {
  background: rgba(233, 236, 239, 0.9);
  border-color: rgba(102, 126, 234, 0.6);
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(19, 23, 33, 0.08);
}

.option-btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.option-btn.correct {
  background: rgba(40, 167, 69, 0.12);
  border-color: rgba(40, 167, 69, 0.45);
}

.option-btn.wrong {
  background: rgba(220, 53, 69, 0.12);
  border-color: rgba(220, 53, 69, 0.45);
}

.option-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary-1), var(--primary-2));
  color: white;
  border-radius: 50%;
  font-weight: 700;
  flex-shrink: 0;
}

.option-text {
  flex: 1;
  font-weight: 500;
}

/* Result Area */
.result-area {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  color: var(--text);
  padding: 40px 24px;
  text-align: center;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.result-card {
  max-width: 400px;
  margin: 0 auto;
}

.result-card h2 {
  font-size: 2rem;
  margin-bottom: 16px;
}

.result-card p {
  font-size: 1.2rem;
  color: #666;
  margin-bottom: 24px;
}

.result-card-large {
  max-width: 500px;
  margin: 0 auto;
}

.score-summary {
  display: flex;
  justify-content: space-around;
  margin: 32px 0;
  padding: 24px;
  background: #f8f9fa;
  border-radius: 12px;
}

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

.score-label {
  display: block;
  color: #888;
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.score-value {
  display: block;
  color: var(--primary-1);
  font-size: 2rem;
  font-weight: 700;
}

/* Player Form */
.player-form {
  margin-top: 32px;
}

.player-form h3 {
  text-align: center;
  color: var(--primary-2);
  margin-bottom: 24px;
}

/* Rank Result */
.rank-result {
  text-align: center;
}

.rank-result h3 {
  color: var(--primary-2);
  margin-bottom: 24px;
}

.rank-display {
  margin: 32px 0;
}

.rank-number {
  display: inline-block;
  font-size: 4rem;
  font-weight: 700;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.rank-result p {
  color: #666;
  margin-bottom: 24px;
  font-size: 1.2rem;
}

.rank-result .btn {
  margin: 8px;
}

/* Leaderboard */
.leaderboard-card {
  max-width: 500px;
  margin: 0 auto;
}

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

.leaderboard-header h2 {
  margin-bottom: 0;
}

.last-updated {
  font-size: 0.85rem;
  color: #888;
}

.leaderboard-content {
  animation: fadeIn 0.3s;
}

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

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.leaderboard-entry {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: #f8f9fa;
  border-radius: 12px;
  transition: all 0.2s;
}

.leaderboard-entry.top-1 {
  background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
  transform: scale(1.02);
}

.leaderboard-entry.top-2 {
  background: linear-gradient(135deg, #c0c0c0 0%, #e8e8e8 100%);
}

.leaderboard-entry.top-3 {
  background: linear-gradient(135deg, #cd7f32 0%, #e8a862 100%);
}

.rank {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary-1), var(--primary-2));
  color: white;
  border-radius: 50%;
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.leaderboard-entry.top-1 .rank {
  background: #b8860b;
}

.leaderboard-entry.top-2 .rank {
  background: #808080;
}

.leaderboard-entry.top-3 .rank {
  background: #a0522d;
}

.player-info {
  flex: 1;
}

.player-name {
  font-weight: 600;
  font-size: 1.1rem;
  color: #333;
}

.score-info {
  text-align: right;
}

.score {
  font-weight: 700;
  color: var(--primary-1);
  font-size: 1.2rem;
}

.time {
  font-size: 0.9rem;
  color: #888;
}

.leaderboard-actions {
  margin-top: 24px;
  text-align: center;
}

.empty-leaderboard {
  text-align: center;
  padding: 40px;
  color: #888;
}

.empty-leaderboard p {
  font-size: 1.2rem;
  margin-bottom: 24px;
}

/* Footer */
.footer {
  text-align: center;
  padding: 20px 0;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.9rem;
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}

/* Responsive */
@media (min-width: 768px) {
  .container {
    max-width: 800px;
  }

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

  .header h1 {
    font-size: 2.5rem;
  }
}

@media (max-width: 768px) {
  .container {
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
  }

  .header {
    padding: 16px 0;
  }

  .header h1 {
    font-size: 1.75rem;
    line-height: 1.2;
  }

  .game-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 12px 16px;
  }

  .game-info {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    font-size: 0.95rem;
  }

  .score-display,
  .question-counter {
    width: 100%;
    text-align: center;
  }

  .card,
  .game-area,
  .result-area {
    padding: 18px;
    border-radius: 14px;
  }

  .card h2 {
    font-size: 1.25rem;
  }

  .question-text {
    font-size: 1.1rem;
  }

  .option-btn {
    padding: 14px 16px;
    gap: 12px;
  }

  .option-label {
    width: 34px;
    height: 34px;
    font-size: 0.95rem;
  }

  .timer-text {
    font-size: 1.6rem;
  }

  .score-summary {
    flex-direction: column;
    gap: 16px;
    padding: 18px;
  }

  .result-card h2 {
    font-size: 1.6rem;
  }

  .result-card p {
    font-size: 1rem;
  }

  .rank-number {
    font-size: 3rem;
  }

  .leaderboard-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .leaderboard-entry {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .score-info {
    text-align: left;
  }

  .player-name {
    font-size: 1rem;
  }

  .score {
    font-size: 1.05rem;
  }

  .btn {
    width: 100%;
  }

  .btn-group .btn,
  .leaderboard-actions .btn,
  .empty-leaderboard .btn,
  .player-form .btn {
    width: 100%;
    margin: 0;
  }

  .leaderboard-actions,
  .empty-leaderboard,
  .player-form {
    text-align: center;
  }

  .footer {
    font-size: 0.8rem;
    padding: 16px 0;
  }
}

@media (max-width: 480px) {
  .container {
    padding: calc(10px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom));
  }

  .header h1 {
    font-size: 1.45rem;
  }

  .card,
  .game-area,
  .result-area {
    padding: 14px;
  }

  .card h2 {
    font-size: 1.1rem;
  }

  .form-group input {
    padding: 11px 14px;
  }

  .option-btn {
    padding: 12px;
    font-size: 1rem;
  }

  .option-label {
    width: 30px;
    height: 30px;
    font-size: 0.9rem;
  }

  .timer-text {
    font-size: 1.35rem;
  }

  .score-summary {
    padding: 14px;
  }

  .rank-number {
    font-size: 2.5rem;
  }

  .leaderboard-entry {
    padding: 14px;
  }

  .footer {
    font-size: 0.75rem;
  }
}
