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

:root {
  --green:      #4ade80;
  --correct-bg: #166534;
  --wrong-bg:   #374151;
  --bg:         #111827;
  --surface:    #1f2937;
  --border:     #374151;
  --text:       #f9fafb;
  --muted:      #9ca3af;
  --accent:     #4ade80;
  --radius:     8px;
  --header-h:   56px;
  --infobox-header-bg: #1e3a5f;
  --section-bg: #243447;
  --row-alt:    rgba(255,255,255,0.03);
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-center { text-align: center; flex: 1; }
.header-right  { width: 36px; }

h1 {
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: 4px;
  text-transform: uppercase;
}

.ball { font-size: 1.1rem; }

.icon-btn {
  width: 36px; height: 36px;
  background: var(--border);
  border: none;
  border-radius: 50%;
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.icon-btn:hover { background: #4b5563; }

/* ── Main ── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 12px 48px;
  gap: 20px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

/* ── Player Card ── */
.player-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.card-puzzle-info {
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 1px;
  text-align: center;
  padding: 10px 16px 0;
}

/* ── Wikipedia Infobox ── */
.wiki-infobox {
  border: 1px solid #2d4a6e;
  border-radius: 8px;
  margin: 12px 14px 0;
  overflow: hidden;
}

/* Infobox header */
.infobox-header {
  background: var(--infobox-header-bg);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 2px solid var(--accent);
}

.player-avatar {
  width: 52px;
  height: 52px;
  background: rgba(255,255,255,0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: rgba(255,255,255,0.5);
}

.player-avatar svg {
  width: 32px;
  height: 32px;
}

.infobox-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.5px;
}

.infobox-subtitle {
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 600;
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Bio info table */
.info-table {
  width: 100%;
  border-collapse: collapse;
  border-bottom: 1px solid var(--border);
}

.info-table tr {
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.info-table tr:last-child {
  border-bottom: none;
}

.info-table tr:nth-child(even) {
  background: var(--row-alt);
}

.info-table th {
  padding: 9px 14px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  width: 38%;
  white-space: nowrap;
}

.info-table td {
  padding: 9px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

/* Career sections */
.career-section {
  border-top: 1px solid var(--border);
}

.career-title {
  background: var(--section-bg);
  padding: 7px 14px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.career-table {
  width: 100%;
  border-collapse: collapse;
}

.career-table thead tr {
  background: rgba(255,255,255,0.04);
}

.career-table th {
  padding: 6px 14px;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  white-space: nowrap;
}

.career-table th:nth-child(3),
.career-table th:nth-child(4) {
  text-align: right;
  width: 36px;
}

.career-table td {
  padding: 7px 14px;
  font-size: 0.83rem;
  color: var(--text);
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: top;
}

.career-table td:nth-child(3),
.career-table td:nth-child(4) {
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.career-table tbody tr:last-child td {
  border-bottom: none;
}

.career-table tbody tr:nth-child(even) td {
  background: var(--row-alt);
}

.career-table .years-col {
  color: var(--muted);
  white-space: nowrap;
  font-size: 0.78rem;
  width: 90px;
}

/* ── Guess history ── */
.guess-history {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 14px 0;
}

.guess-history-item {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

.guess-history-item.correct {
  background: var(--correct-bg);
  color: #bbf7d0;
  border: 1px solid #15803d;
}

.guess-history-item.wrong {
  background: var(--wrong-bg);
  color: #9ca3af;
  border: 1px solid #4b5563;
}

/* ── Input area ── */
.input-area {
  display: flex;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

.search-wrapper {
  position: relative;
  flex: 1;
}

.player-input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}
.player-input:focus { border-color: var(--accent); }
.player-input::placeholder { color: var(--muted); }

/* ── Autocomplete ── */
.autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 200;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.92rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover,
.autocomplete-item.active { background: var(--border); }

.autocomplete-empty {
  padding: 10px 14px;
  color: var(--muted);
  font-size: 0.88rem;
}

/* ── Guess button ── */
.guess-btn {
  padding: 11px 20px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.guess-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.guess-btn:not(:disabled):hover { opacity: 0.85; }
.guess-btn:not(:disabled):active { transform: scale(0.97); }

/* ── Error message ── */
.error-msg {
  color: #f87171;
  font-size: 0.83rem;
  text-align: center;
}

/* ── Result panel ── */
.result-panel {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 20px;
  text-align: center;
}

#result-message {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 10px;
}

.answer-reveal {
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 22px;
}
.answer-reveal strong { color: var(--text); }

.result-actions { margin-bottom: 16px; }

.share-btn {
  padding: 12px 28px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}
.share-btn:hover { opacity: 0.85; }

.share-toast {
  margin: 8px auto 0;
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
}

.next-puzzle-text {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 14px;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 400px;
  width: 100%;
  position: relative;
}

.modal h2 {
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: 14px;
  text-align: center;
}

.modal p {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.55;
}

.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  background: var(--border);
  border: none;
  border-radius: 50%;
  width: 30px; height: 30px;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

.play-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 16px;
}

/* ── Animations ── */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  40%       { transform: translateX(6px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}
.shake { animation: shake 0.35s ease-out; }

/* ── Utility ── */
.hidden { display: none !important; }
