/* ===== CSS Variables ===== */
:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --card: #16213e;
  --text: #e8e8e8;
  --muted: #8888aa;
  --accent: #fbbf24;
  --success: #22c55e;
  --danger: #ef4444;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
}

/* ===== Screen Container ===== */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
}

.screen.active {
  display: flex;
}

/* ===== Start Screen ===== */
#screen-start {
  align-items: center;
  justify-content: center;
  gap: 2rem;
  text-align: center;
}

#screen-start h1 {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--danger), var(--success));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#screen-start .subtitle {
  color: var(--muted);
  font-size: 1rem;
}

/* ===== Lobby Screen ===== */
#screen-lobby {
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
}

#screen-lobby .room-info {
  color: var(--muted);
  font-size: 0.9rem;
}

#screen-lobby .player-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 300px;
  overflow-y: auto;
}

#screen-lobby .player-item {
  background: var(--surface);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#screen-lobby .player-item .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

/* ===== Game Screen ===== */
#screen-game {
  align-items: center;
  justify-content: center;
  gap: 2rem;
}

#screen-game .color-word {
  font-size: 5rem;
  font-weight: 900;
  text-align: center;
  line-height: 1.2;
  transition: opacity 0.15s ease;
  max-height: 50vh;
  max-width: min(100%, 50vh);
  align-self: center;
  overflow: hidden;
}

#screen-game .timer-bar-container {
  width: 100%;
  height: 6px;
  background: var(--surface);
  border-radius: 3px;
  overflow: hidden;
}

#screen-game .timer-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 100%;
  transition: width 0.1s linear;
}

#screen-game .question-counter {
  color: var(--muted);
  font-size: 0.9rem;
}

/* ===== Result Screen ===== */
#screen-result {
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  text-align: center;
}

#screen-result .final-score {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent);
}

/* ===== Leaderboard ===== */
.leaderboard {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-radius: 8px;
  font-size: 0.95rem;
}

.leaderboard-item .rank {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.leaderboard-item .rank.gold {
  background: var(--accent);
  color: var(--bg);
}

.leaderboard-item .name {
  flex: 1;
  text-align: left;
}

.leaderboard-item .score {
  font-weight: 700;
  color: var(--accent);
}

/* ===== Status Bar ===== */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.status-bar .connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
}

.status-bar .connection-dot.online {
  background: var(--success);
}

.status-bar .connection-dot.offline {
  background: var(--danger);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 2rem;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  -webkit-appearance: none;
  appearance: none;
}

.btn:active {
  transform: scale(0.97);
}

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

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--muted);
}

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

.btn-block {
  width: 100%;
}

/* ===== Input ===== */
.input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--muted);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

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

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

/* ===== Error Banner ===== */
.error-banner {
  width: 100%;
  padding: 0.75rem 1rem;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--danger);
  border-radius: 8px;
  color: var(--danger);
  font-size: 0.9rem;
  text-align: center;
  display: none;
}

.error-banner.visible {
  display: block;
}

/* ===== Utility ===== */
.text-center {
  text-align: center;
}

.text-muted {
  color: var(--muted);
}

.text-sm {
  font-size: 0.85rem;
}

.mt-auto {
  margin-top: auto;
}

.flex-col {
  display: flex;
  flex-direction: column;
}

.gap-1 {
  gap: 0.5rem;
}

.gap-2 {
  gap: 1rem;
}

/* ===== Divider ===== */
.divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  width: 100%;
}

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

/* ===== Textarea ===== */
.textarea {
  resize: none;
  font-family: monospace;
  font-size: 0.8rem;
}

/* ===== Invite Section ===== */
.invite-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--surface);
  border-radius: 8px;
}

.invite-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.invite-row .input,
.invite-row .textarea {
  flex: 1;
}

.btn-sm {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  white-space: nowrap;
}
