/* ============================================================
   WORD GUESSING GAME — STYLESHEET
   ============================================================ */

/* ── Game Container ────────────────────────────────────────── */
.form_container {
  background-color: #ffffff;
  border: 1px solid var(--border-medium);
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
  max-width: 500px;
  margin: 2rem auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.game-header h2 {
  color: var(--accent-primary);
  border-bottom: 2px solid var(--accent-primary);
  display: inline-block;
  font-size: 1.4rem;
  margin-bottom: 0;
  padding-bottom: 0.2rem;
}

#game_intro {
  font-size: 0.85rem;
  opacity: 0.7;
}

/* ── Notifications — fixed height, no layout shift ──────────── */
#notifications {
  min-height: 1.5em;
  line-height: 1.5em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
  font-style: italic;
  color: var(--status-error, #d33333);
  margin: 0;
  padding: 0;
}

.success-msg {
  color: var(--status-success, #28a745);
}
.error-msg {
  color: var(--status-error, #d33333);
}

/* ── Word Board ─────────────────────────────────────────────── */
#current_word {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 5px;
  list-style: none;
  padding: 1rem 0;
  width: 100%;
  font-weight: bold;
  letter-spacing: 5px;
  font-size: 1.5rem;
}

#current_word li {
  background-color: var(--bg-body);
  border: 2px solid var(--accent-primary);
  border-radius: 4px;
  border-bottom: 3px solid var(--border-medium);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
  box-shadow: 2px 2px 0 rgba(44, 62, 80, 0.2);
  text-transform: uppercase;
  width: 32px;
  height: 42px;
  font-weight: bold;
  font-size: 1.4rem;
}

.word-display-field {
  display: block !important;
  text-align: center;
  padding: 2rem 0;
  border-bottom: 2px solid #f1f3f5;
}

/* ── Form Layout ────────────────────────────────────────────── */
.formField {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 20px;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid #f1f3f5;
}

.formField:last-of-type {
  border-bottom: none;
}

.formField label {
  font-weight: 600;
  color: #495057;
  font-size: 0.9rem;
}

/* ── Inputs & Buttons ───────────────────────────────────────── */
#guess_letter {
  width: 50px;
  padding: 10px;
  text-align: center;
  font-size: 1.2rem;
  font-weight: bold;
  border: 2px solid var(--border-medium);
  border-radius: 4px;
  transition: border-color 0.2s;
}

#guess_letter:focus {
  border-color: var(--accent-primary);
  outline: none;
}

#guess_count {
  width: 60px;
  background: #e9ecef;
  border: 1px solid #ced4da;
  padding: 5px;
  text-align: center;
  font-family: monospace;
  font-weight: bold;
  border-radius: 4px;
}

.submitField {
  padding: 1.5rem 0;
  text-align: center;
}

#guess_button {
  background-color: var(--bg-header);
  color: #ffffff;
  border: none;
  padding: 0.8rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#guess_button:hover {
  background-color: var(--bg-footer);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* ── Guess History Pills ────────────────────────────────────── */
#guesses {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 5px;
  padding: 5px 0;
  margin: 0;
  list-style: none;
  scrollbar-width: none;
}

#guesses::-webkit-scrollbar {
  display: none;
}

#guesses li {
  background: var(--bg-tag, #e3f2fd);
  color: var(--accent-tag, #1976d2);
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.85rem;
  font-family: "Roboto Mono", monospace;
  font-weight: bold;
  flex-shrink: 0;
  border: 1px solid var(--border-tag, #bbdefb);
}

/* ── Alphabet Grid ──────────────────────────────────────────── */
.alphabet-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
  background: #ebf3f9;
  padding: 8px;
  border-radius: 8px;
}

.letter-btn {
  aspect-ratio: 1 / 1.2;
  padding: 0;
  font-size: 1.1rem;
  font-weight: bold;
  border: 1px solid #ced4da;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
  transition:
    transform 0.1s,
    background 0.1s;
  cursor: pointer;
}

.letter-btn:active {
  transform: translateY(2px);
  box-shadow: none;
  background: #dee2e6;
}

.letter-btn.selected {
  background: var(--bg-header);
  color: #fff;
  border-color: var(--bg-header);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.letter-btn:disabled {
  background: #e9ecef;
  color: #adb5bd;
  box-shadow: none;
  border-color: transparent;
  cursor: not-allowed;
}

/* ── Game Metrics ───────────────────────────────────────────── */
#game_metrics {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 15px;
  padding: 10px;
  background: var(--bg-subtle, #f5f7fa);
  border-radius: 8px;
  margin: 10px 0;
}

.formField.metric_group,
#game_metrics .formField {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

#game_metrics .label {
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

#game_metrics #guess_count {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  background: #fff;
  font-family: "Roboto Mono", monospace;
  font-size: 1.1rem;
  text-align: center;
  color: var(--text-main);
}

/* ── Game Container ─────────────────────────────────────────── */
#game_container {
  max-width: 500px;
  margin: 2rem auto;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  padding: 20px;
  overflow: hidden;
}

/* ── Splash / Login ─────────────────────────────────────────── */
#user_info_container {
  display: flex;
}

#splash_screen {
  border: none;
  box-shadow: none;
  padding: 0;
}

#game_form {
  display: none;
}

/* ── Game Footer ────────────────────────────────────────────── */
.game-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border-top: 1px solid #eee;
  font-size: 0.9rem;
}

/* ============================================================
   SCOREBOARD OVERLAY
   JS toggles display: none <-> flex — that is preserved.
   Layout & visual design is a complete rewrite.
   ============================================================ */
#scoreboard {
  display: none; /* JS switches this to 'flex' */
  position: fixed;
  inset: 0;
  z-index: 9999;
  justify-content: center;
  align-items: flex-end; /* bottom-sheet on mobile */
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

/* ── Sheet card ─────────────────────────────────────────────── */
#scoreboard > div {
  background: #ffffff;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 500px;
  overflow: hidden;

  /* Reset the default shared grid — scoreboard card is its own layout */
  display: flex !important;
  flex-direction: column;
  gap: 0;
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.15);
  animation: sb-rise 0.3s cubic-bezier(0.34, 1.1, 0.64, 1) both;
}

@keyframes sb-rise {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* Drag handle strip */
#scoreboard > div::before {
  content: "";
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.35);
  margin: 12px auto 0;
  order: -2;
  flex-shrink: 0;
}

/* ── Dark header band ───────────────────────────────────────── */
#scoreboard > div > div:first-child {
  /* Override shared row rules completely */
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  justify-content: flex-start !important;
  gap: 3px !important;
  padding: 14px 20px 16px !important;
  border-bottom: none !important;

  background: var(--bg-header, #2c3e50);
  order: -1;
}

#scoreboard > div > div:first-child > div:first-child {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
}

#scoreboard > div > div:first-child > div:last-child {
  /* This is the "Total words completed" label — repurpose as heading */
  font-size: 1.2rem;
  font-weight: 600;
  color: #ffffff;
}

/* ── Stat rows → 2-col card grid ────────────────────────────── */
/*
  The HTML has 4 stat rows + 1 button row inside #scoreboard > div.
  We target rows 2–5 (nth-child 2–5) and float them into a grid.
  Rows 2–5 = total words, incorrect guesses, avg guesses, avg time.
  Row 6 = the button row (play again / quit).
*/

/* Wrapper grid — we can't add a real wrapper div, so we use
   a CSS grid hack on the parent to re-layout children 2–5     */
#scoreboard > div {
  /* Already flex column — override with grid so we can span rows */
  display: grid !important;
  grid-template-areas:
    "handle"
    "header"
    "cards"
    "buttons";
  grid-template-rows: auto auto 1fr auto;
}

#scoreboard > div::before {
  grid-area: handle;
}
#scoreboard > div > div:nth-child(1) {
  grid-area: header;
}
#scoreboard > div > div:nth-child(5) {
  grid-area: buttons;
}

/* Rows 2–4 sit in the "cards" area — we need a sub-grid.
   Since we can't wrap them in HTML, we absolutely position a
   pseudo element background and use negative-margin columns.
   Simpler: just style each stat row as a half-width card
   and let them wrap. */

#scoreboard > div > div:nth-child(n + 2):nth-child(-n + 4) {
  /* Stat card styling */
  margin: 0;
  padding: 14px 16px !important;
  border-bottom: none !important;

  /* Stack label over value */
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  justify-content: flex-start !important;
  gap: 4px !important;

  background: var(--bg-subtle, #f5f7fa);
}

/* Put 2 cards per row by making each exactly half the container.
   We use a flex row on the parent for rows 2-4.
   Since this is a grid parent we rely on the grid column trick: */
#scoreboard > div > div:nth-child(2) {
  grid-column: 1;
  border-right: 5px solid #fff;
  border-bottom: 5px solid #fff !important;
}
#scoreboard > div > div:nth-child(3) {
  grid-column: 2;
  border-bottom: 5px solid #fff !important;
}
#scoreboard > div > div:nth-child(4) {
  grid-column: 1 / -1; /* avg guesses — full width row */
}

/* Adjust grid columns for the card pairing */
#scoreboard > div {
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "handle  handle"
    "header  header"
    "c1      c2"
    "c3      c3"
    "buttons buttons";
}

#scoreboard > div > div:nth-child(1) {
  grid-area: header;
}
#scoreboard > div > div:nth-child(2) {
  grid-area: c1;
}
#scoreboard > div > div:nth-child(3) {
  grid-area: c2;
}
#scoreboard > div > div:nth-child(4) {
  grid-area: c3;
}
#scoreboard > div > div:nth-child(5) {
  grid-area: buttons;
}

/* Gaps between cards via borders acting as gutters */
#scoreboard > div > div:nth-child(2),
#scoreboard > div > div:nth-child(3),
#scoreboard > div > div:nth-child(4) {
  border: none !important;
  outline: 4px solid #ffffff; /* gutter colour */
}

/* ── Stat text inside each card ─────────────────────────────── */
/* First child = the label text, second child = the value span  */
#scoreboard > div > div:nth-child(n + 2):nth-child(-n + 4) > div:first-child {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted, #6c757d);
}

/* The value spans (id=total_*, id=average_*) */
#scoreboard [id^="total_"],
#scoreboard [id^="average_"] {
  font-size: 2rem;
  font-weight: 700;
  font-family: "Roboto Mono", monospace;
  color: var(--accent-primary, #2c3e50);
  /* Remove the badge pill look from before */
  background: none;
  padding: 0;
  border-radius: 0;
  min-width: 0;
  text-align: left;
  line-height: 1;
}

/* ── Button row ─────────────────────────────────────────────── */
#scoreboard > div > div:nth-child(5) {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: 10px !important;
  padding: 12px 16px 28px !important;
  border-top: 1px solid var(--border-subtle, #e9ecef) !important;
  border-bottom: none !important;
  background: #ffffff;
}

#scoreboard #play_again,
#scoreboard #quit_game {
  padding: 13px 0;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition:
    opacity 0.15s,
    transform 0.1s;
}

#scoreboard #play_again {
  flex: 1;
  background: var(--bg-header, #2c3e50);
  color: #ffffff;
}

#scoreboard #quit_game {
  width: 90px;
  background: var(--bg-hover, #e9ecef);
  color: var(--text-main, #212529);
}

#scoreboard #play_again:hover {
  opacity: 0.85;
}
#scoreboard #quit_game:hover {
  opacity: 0.75;
}

/* ── Desktop: centred modal ─────────────────────────────────── */
@media (min-width: 601px) {
  #scoreboard {
    align-items: center;
  }

  #scoreboard > div {
    border-radius: 16px;
    max-width: 420px;
    animation: sb-pop 0.25s cubic-bezier(0.34, 1.1, 0.64, 1) both;
  }

  @keyframes sb-pop {
    from {
      transform: scale(0.92);
      opacity: 0;
    }
    to {
      transform: scale(1);
      opacity: 1;
    }
  }

  #scoreboard > div > div:nth-child(5) {
    padding-bottom: 20px !important;
  }
}

/* ── Mobile overrides ───────────────────────────────────────── */
@media (max-width: 600px) {
  .form_container {
    padding: 1rem;
    margin: 0.5rem;
  }

  #game_container {
    top: 0;
    left: 0;
    position: fixed;
    z-index: 1000;
  }

  #site-header,
  footer,
  #guesses,
  #guess_letter_container {
    display: none;
    position: absolute;
    z-index: -9999;
  }
}
