:root {
  --accent: #7ec8e3;
  --accent-dark: #4a9ec2;
  --ink: #000000;
  --muted: #000000;
  --border: #000000;
  --bg: #f2f9fc;
  --card-bg: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
}

.site-banner {
  width: 100%;
  padding: 0.5rem 1rem;
  color: var(--ink);
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.page-content {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 0.5rem 1rem 1.5rem;
}

.card {
  width: 100%;
  max-width: 620px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.6rem 1.5rem 1rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.3rem;
}

.card-header h1,
.card-header h2 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: -0.01em;
}

.print-date {
  color: var(--ink);
  font-weight: 400;
  font-size: 0.85rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1 1 calc(25% - 0.3rem);
  min-width: 90px;
  padding: 0.3rem 0.25rem;
  background: var(--bg);
  border-radius: 10px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
}

.stat-label {
  margin-top: 0.15rem;
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-align: center;
}

#show-answers-btn {
  display: block;
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}

#show-answers-btn:hover {
  background: var(--accent-dark);
}

.answers-list {
  margin-top: 0.75rem;
}

.answers-list.hidden {
  display: none;
}

.answers-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-auto-flow: column;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(var(--rows3), auto);
  gap: 0.05rem 0.75rem;
}

.answers-grid li,
.answers-column li {
  padding: 0.05rem 0.4rem;
  font-size: 1.1rem;
}

.answers-grid li.pangram,
.answers-column li.pangram {
  font-weight: 700;
  color: var(--ink);
}

.answers-columns {
  display: none;
}

.answers-column {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}

.word-entry {
  cursor: pointer;
  border-radius: 4px;
}

.word-entry:hover,
.word-entry:focus-visible {
  background: var(--bg);
  text-decoration: underline;
}

@media (max-width: 500px) {
  .answers-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(var(--rows2), auto);
    gap: 0.1rem 3rem;
  }

  .answers-grid li {
    font-size: 1rem;
    padding: 0.05rem 0.25rem;
  }
}

@media (min-width: 900px) {
  .card {
    max-width: 900px;
  }

  .answers-grid {
    display: none;
  }

  .answers-columns {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
  }
}

.len-entry {
  font-weight: 700;
  color: var(--muted);
}

.notice {
  text-align: center;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  background: #e3f2fa;
  color: var(--ink);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.notice.error {
  background: #fde8e8;
  color: var(--ink);
}

.header-links {
  display: flex;
  gap: 0.4rem;
}

.home-links {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.home-btn {
  display: block;
  padding: 0.55rem 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  color: var(--ink);
  background: var(--accent);
  border-radius: 10px;
  text-decoration: none;
  transition: background 0.15s ease;
}

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

.logout-btn {
  flex: none;
  display: inline-block;
  padding: 0.2rem 0.55rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  transition: background 0.15s ease;
}

.logout-btn:hover {
  background: var(--accent);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.login-form label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.login-form input {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}

.password-field {
  position: relative;
  display: flex;
}

.password-field input {
  flex: 1;
  /* Flex items default to min-width: auto, which stops the browser from
     shrinking one below its own intrinsic preferred width -- for a text
     input that's roughly UA-default sized, wider than many phone screens
     leave available once page/card padding is subtracted. Without this, the
     field (and the toggle button glued to its edge) spilled past the right
     side of the screen instead of shrinking to fit. */
  min-width: 0;
  /* room for the toggle so a long password doesn't run underneath it */
  padding-right: 4rem;
}

/* Specific enough to beat `.login-form button` below, which is the big accent
   submit button -- a plain `.password-toggle` would inherit all of that. */
.login-form .password-toggle {
  position: absolute;
  top: 50%;
  right: 0.4rem;
  transform: translateY(-50%);
  margin: 0;
  padding: 0.2rem 0.5rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.login-form .password-toggle:hover {
  background: var(--accent);
}

.login-form .password-toggle:focus-visible {
  outline: 2px solid var(--accent-dark);
  outline-offset: 1px;
}

.login-form button {
  margin-top: 0.4rem;
  padding: 0.55rem 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.login-form button:hover {
  background: var(--accent-dark);
}

#definition-dialog {
  /* fixed, not relative: a <dialog> shown with showModal() normally renders
     in the browser's top layer, pinned to the viewport and out of the page's
     scroll flow. `position: relative` overrode that, leaving the dialog in
     its normal spot in the document (right after the answers list) -- so
     opening it auto-focused an element sitting there, and the page jumped to
     scroll it into view. Fixed + inset/margin reproduces the same
     viewport-centered placement without putting it back in the page flow.
     (Still establishes a containing block for #definition-close below,
     exactly as relative did -- that positioning is unaffected.) */
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(420px, 90vw);
  max-height: 85vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem 1.5rem 1.5rem;
  background: var(--card-bg);
  color: var(--ink);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

#definition-dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

#definition-close {
  position: absolute;
  top: 0.5rem;
  right: 0.65rem;
  border: none;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0.25rem;
}

#definition-close:hover {
  color: var(--ink);
}

.def-word {
  margin: 0 0 0.5rem;
  font-size: 1.3rem;
  font-weight: 700;
}

.def-entry {
  margin-bottom: 0.75rem;
}

.def-entry:last-child {
  margin-bottom: 0;
}

.def-pos {
  margin: 0 0 0.25rem;
  font-style: italic;
  color: var(--muted);
  font-size: 0.9rem;
}

.def-list {
  margin: 0;
  padding-left: 1.2rem;
}

.def-list li {
  margin-bottom: 0.25rem;
}

.def-error {
  color: var(--ink);
}

.def-mw-link {
  display: inline-block;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--accent-dark);
}
