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

:root {
  --bg: #1a0a00;
  --surface: #2a1500;
  --border: #4a2e00;
  --text: #f5f0e8;
  --text-muted: #a89070;
  --gold: #c9a84c;
  --gold-dark: #9a7530;
  --radius: 8px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, 'Times New Roman', serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 2rem 1.25rem 4rem;
}

#app {
  width: 100%;
  max-width: 660px;
}

/* ── Header ── */

header {
  text-align: center;
  margin-bottom: 2.5rem;
}

#header-row {
  display: flex;
  align-items: center;
  border-bottom: 2px solid var(--gold);
  padding-bottom: 1rem;
  margin-bottom: 0.75rem;
}

h1 { flex: 0 0 auto; text-align: center; }

.hdr-side { flex: 1; }
.hdr-left { display: flex; justify-content: flex-start; }
.hdr-right { display: flex; justify-content: flex-end; }

#stats-btn, #archive-link {
  background: transparent;
  border: 1px solid var(--gold);
  color: var(--gold);
  border-radius: var(--radius);
  padding: 0.25rem 0.6rem;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

#stats-btn:hover, #archive-link:hover { background: var(--gold); color: var(--bg); }

#archive-banner {
  display: flex;
  justify-content: center;
  margin-top: 0.4rem;
}

#back-to-today {
  background: transparent;
  border: none;
  color: var(--gold);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

#back-to-today:hover { color: var(--text); }

h1 {
  font-size: clamp(1.75rem, 6vw, 2.75rem);
  color: var(--gold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0;
  line-height: 1.1;
  white-space: nowrap;
}

#date-display {
  color: var(--text-muted);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.9rem;
  margin-bottom: 0.6rem;
}

#score-stars {
  font-size: 1.5rem;
  min-height: 1.75rem;
  letter-spacing: 0.1em;
}

/* ── Clue cards ── */

#clues-container {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  margin-bottom: 2rem;
}

.clue-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius);
  padding: 1rem 1.375rem;
  animation: none;
}

.clue-card.new {
  animation: slideIn 0.4s ease-out;
}

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

.clue-label {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--gold);
  margin-bottom: 0.35rem;
}

.clue-value {
  font-size: 1.15rem;
  line-height: 1.4;
}

/* ── Feedback ── */

#feedback-message {
  min-height: 1.5rem;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 1.25rem;
  transition: color 0.2s;
}

#feedback-message.error { color: #e07070; }
#feedback-message.success { color: #70c070; }

/* ── Input section ── */

#input-section {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

#guess-row {
  display: flex;
  gap: 0.625rem;
  align-items: stretch;
}

#autocomplete-wrapper {
  position: relative;
  flex: 1;
  min-width: 0;
}

#guess-input {
  width: 100%;
  height: 100%;
  min-height: 3rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}

#guess-input:focus { border-color: var(--gold); }

#guess-input.shake {
  animation: shake 0.35s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-8px); }
  40%       { transform: translateX(8px); }
  60%       { transform: translateX(-5px); }
  80%       { transform: translateX(5px); }
}

#autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 220px;
  overflow-y: auto;
  z-index: 100;
  display: none;
  -webkit-overflow-scrolling: touch;
}

#autocomplete-dropdown.open { display: block; }

.autocomplete-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border);
  min-height: 44px;
  display: flex;
  align-items: center;
}

.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover, .autocomplete-item.active {
  background: var(--border);
  color: var(--gold);
}

#submit-btn {
  flex-shrink: 0;
  padding: 0.75rem 1.5rem;
  min-height: 3rem;
  background: var(--gold);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

#submit-btn:hover { background: var(--gold-dark); }
#submit-btn:disabled { background: var(--border); color: var(--text-muted); cursor: default; }

#guesses-remaining {
  text-align: center;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── End section ── */

#end-section {
  text-align: center;
  padding: 2rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

#end-message {
  font-size: clamp(1rem, 4vw, 1.25rem);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

#end-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

#share-btn, #leaderboard-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.8rem 1.5rem;
  min-height: 48px;
  border-radius: var(--radius);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  text-decoration: none;
}

#share-btn {
  background: transparent;
  border: 2px solid var(--gold);
  color: var(--gold);
}

#share-btn:hover { background: var(--gold); color: var(--bg); }

#leaderboard-btn {
  background: var(--gold);
  border: 2px solid var(--gold);
  color: var(--bg);
}

#leaderboard-btn:hover { background: var(--gold-dark); border-color: var(--gold-dark); }

/* ── Name modal ── */

#name-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#name-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

#name-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
  width: min(90vw, 380px);
  text-align: center;
}

#name-content h2 {
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--gold);
  margin-bottom: 0.6rem;
}

#name-content p {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

#name-error {
  color: #e07070;
  margin-top: -0.75rem;
}

#name-input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 1rem;
  margin-bottom: 1rem;
  outline: none;
  -webkit-appearance: none;
}

#name-input:focus { border-color: var(--gold); }

.name-buttons { display: flex; gap: 0.75rem; }

#name-submit {
  flex: 1;
  padding: 0.75rem;
  background: var(--gold);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}

#name-submit:hover { background: var(--gold-dark); }
#name-submit:disabled { background: var(--border); color: var(--text-muted); cursor: default; }

#name-skip {
  padding: 0.75rem 1rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.95rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

#name-skip:hover { border-color: var(--text-muted); color: var(--text); }

#share-confirm {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.85rem;
  color: #70c070;
  margin-bottom: 1rem;
}

#countdown-timer {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 1.25rem;
}

/* ── Stats modal ── */

#stats-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#stats-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

#stats-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.75rem 1.75rem;
  width: min(90vw, 420px);
  text-align: center;
}

#stats-content h2 {
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--gold);
  margin-bottom: 1.25rem;
}

#stats-content h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--gold);
  margin: 1.25rem 0 0.75rem;
}

#stats-close {
  position: absolute;
  top: 0.75rem;
  right: 0.875rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

#stats-close:hover { color: var(--text); }

#stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.stat-box span {
  font-size: 2rem;
  font-weight: 700;
  color: var(--gold);
  line-height: 1;
}

.stat-box label {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.dist-label {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.85rem;
  color: var(--text-muted);
  width: 0.75rem;
  text-align: right;
  flex-shrink: 0;
}

.dist-bar-wrap {
  flex: 1;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  height: 1.4rem;
}

.dist-bar {
  height: 100%;
  background: var(--border);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.4rem;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 1.5rem;
  transition: width 0.4s ease;
}

.dist-bar.dist-bar-filled {
  background: var(--gold-dark);
  color: var(--text);
}

/* ── No show ── */

#no-show-message {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-family: 'Helvetica Neue', Arial, sans-serif;
}

/* ── Mobile ── */

@media (max-width: 520px) {
  body { padding: 1.25rem 1rem 3rem; }

  header { margin-bottom: 1.5rem; }
  #header-row { padding-bottom: 0.75rem; }
  #header-row { flex-wrap: wrap; row-gap: 0.4rem; }
  h1 { width: 100%; order: -1; white-space: normal; }
  #stats-btn, #archive-link { padding: 0.2rem 0.45rem; font-size: 0.7rem; }

  #clues-container { gap: 0.75rem; margin-bottom: 1.75rem; }

  .clue-card { padding: 0.875rem 1rem; }

  .clue-value { font-size: 1.05rem; }

  /* Stack input and button vertically, both full width */
  #guess-row { flex-direction: column; gap: 0.625rem; }

  #submit-btn {
    width: 100%;
    padding: 0.875rem;
    min-height: 52px;
    font-size: 1.05rem;
  }

  #guess-input { min-height: 52px; font-size: 1rem; }

  #end-section { padding: 1.5rem 1rem; }

  #share-btn { width: 100%; }
}
