*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f4ff;
  --card: #ffffff;
  --primary: #4f6ef7;
  --primary-dark: #3a56d4;
  --secondary: #e8ecff;
  --user-bg: #4f6ef7;
  --user-text: #ffffff;
  --comp-bg: #f1f1f1;
  --comp-text: #333;
  --text: #1a1a2e;
  --muted: #6b7280;
  --error: #e53e3e;
  --skip-bg: #fef3c7;
  --skip-text: #92400e;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(79, 110, 247, 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #e8ecff 0%, #f5f0ff 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  color: var(--text);
}

/* --- Screens --- */
.screen { display: none; width: 100%; max-width: 600px; }
.screen.active { display: block; }

/* --- Setup Screen --- */
.setup-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 48px 40px;
  text-align: center;
}

.setup-card h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--primary);
  margin-bottom: 8px;
}

.subtitle {
  color: var(--muted);
  font-size: 1rem;
  margin-bottom: 36px;
  line-height: 1.5;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
  text-align: left;
}

select {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  font-size: 1rem;
  color: var(--text);
  background: white;
  margin-bottom: 24px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
}

select:focus { outline: none; border-color: var(--primary); }

/* --- Buttons --- */
.btn {
  display: inline-block;
  padding: 12px 32px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

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

.btn-primary {
  background: var(--primary);
  color: white;
  width: 100%;
}

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

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

.btn-secondary:hover { background: #dde3ff; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  width: 100%;
  margin-top: 8px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-ghost:hover { color: var(--primary); }

.btn-hint-skip {
  background: var(--skip-bg);
  color: var(--skip-text);
  font-size: 0.9rem;
  font-weight: 700;
  padding: 8px 20px;
  border: 2px dashed #f59e0b;
}

.btn-hint-skip:hover { background: #fde68a; }

/* --- Home button in game header --- */
.home-btn {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.home-btn:hover { background: rgba(255,255,255,0.35); }

/* --- Game Screen --- */
.game-wrap {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.game-header {
  background: var(--primary);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-center {
  flex: 1;
  text-align: center;
}

.category-label {
  font-size: 0.75rem;
  opacity: 0.8;
}

.category-name {
  font-size: 1rem;
  font-weight: 700;
}

.letter-badge {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: white;
  color: var(--primary);
  font-size: 1.8rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* --- Alphabet row --- */
.alphabet-row {
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
}

.alpha-chip {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: #9ca3af;
  background: #e5e7eb;
}

.alpha-chip.done {
  background: #d1fae5;
  color: #065f46;
}

.alpha-chip.skipped {
  background: #fef3c7;
  color: #92400e;
}

.alpha-chip.current {
  background: var(--primary);
  color: white;
}

/* --- Word history --- */
.word-history {
  padding: 16px 20px;
  min-height: 200px;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  animation: fadeIn 0.2s ease;
}

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

.history-row.computer {
  background: var(--comp-bg);
  color: var(--comp-text);
  align-self: flex-start;
  max-width: 72%;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.history-row.user {
  background: var(--user-bg);
  color: var(--user-text);
  align-self: flex-end;
  max-width: 72%;
  flex-direction: row-reverse;
}

.history-row.suggestion-note {
  background: #f0fdf4;
  color: #166534;
  border: 1px dashed #86efac;
}

.history-row.skipped-row {
  background: #fef9ec;
  color: #92400e;
  align-self: flex-end;
  max-width: 72%;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  border: 1px dashed #fde68a;
}

.history-row.skipped-row .h-meta {
  flex-direction: row-reverse;
}

.h-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.h-letter {
  font-size: 0.7rem;
  font-weight: 800;
  opacity: 0.6;
  letter-spacing: 0.05em;
}

.h-word {
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
}

.h-who {
  font-size: 0.75rem;
  opacity: 0.7;
}

/* Wikipedia image on computer bubbles */
.word-img {
  display: none;
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 6px;
}

.word-img.loaded {
  display: block;
  animation: fadeIn 0.3s ease;
}

/* --- Turn indicator / input --- */
.turn-section {
  padding: 16px 20px;
  border-top: 1px solid #e5e7eb;
}

.turn-indicator {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 10px;
  min-height: 20px;
}

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

.input-row input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  font-size: 1rem;
  color: var(--text);
}

.input-row input:focus {
  outline: none;
  border-color: var(--primary);
}

.error-msg {
  color: var(--error);
  font-size: 0.85rem;
  margin-top: 8px;
}

.hint-text {
  color: #7c3aed;
  font-size: 0.85rem;
  margin-top: 8px;
}

.hidden { display: none !important; }

.action-row {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid #e5e7eb;
  align-items: center;
}

/* --- End Screen --- */
.end-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 48px 40px;
  text-align: center;
}

.trophy {
  font-size: 3.5rem;
  margin-bottom: 16px;
}

.end-card h2 {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.end-category-label {
  color: var(--muted);
  margin-bottom: 24px;
}

.final-list {
  text-align: left;
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.final-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 6px;
}

.final-row.user     { background: #eff4ff; }
.final-row.computer { background: #f9fafb; }
.final-row.skipped  { background: #fef9ec; color: #92400e; border: 1px dashed #fde68a; }

.f-letter {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--muted);
  width: 16px;
}

.f-word { flex: 1; font-weight: 600; }
.f-who  { font-size: 0.75rem; color: var(--muted); }

.end-actions {
  display: flex;
  gap: 12px;
}

.end-actions .btn { flex: 1; }

/* --- Inline Word Suggestion (end screen) --- */
.suggest-section {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 20px;
  text-align: left;
}

.suggest-prompt {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.sug-input-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.sug-input-row input {
  width: 100%;
  padding: 9px 13px;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.95rem;
  color: var(--text);
}

.sug-input-row input:focus {
  outline: none;
  border-color: var(--primary);
}

.sug-actions {
  display: flex;
  gap: 8px;
}

/* Inline suggest link inside error message */
.suggest-link {
  color: var(--primary);
  font-size: 0.85rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

.suggest-link:hover { color: var(--primary-dark); }

/* Site footer */
.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 8px;
  font-size: 0.82rem;
}

.site-footer a {
  color: var(--muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--primary);
  text-decoration: underline;
}

.success-msg {
  color: #065f46;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 4px 0;
}

@media (max-width: 480px) {
  .setup-card, .end-card { padding: 32px 20px; }
  .setup-card h1 { font-size: 1.8rem; }
  .game-header { padding: 12px 16px; }
  .letter-badge { width: 48px; height: 48px; font-size: 1.5rem; }
  .end-actions { flex-direction: column; }
}
