:root {
  /* Sampled directly from a real Wordle board screenshot (dark theme). */
  --green: #538d4e; /* correct  */
  --present: #b59f3b; /* present  */
  --absent: #3a3a3c; /* absent   */
  --tile-border: #3a3a3c; /* empty tile outline */
  --key-border: #565758; /* typed, not yet scored */
  --bg: #121213; /* matches the real Wordle board background */
  --card: #121213;
  --line: #2c2c2e;
  --text: #f5f5f5;
  --muted: #8a8f95;
  --link: #c2c7cc;
  --win: #6ac46a;
  --radius: 18px;
  --tile: 3.7rem;
  --tile-gap: 0.32rem;
  --col-gap: 1.4rem;
  --font: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

/* Author display rules (e.g. .row { display: grid }) otherwise beat the
   hidden attribute, leaving "hidden" elements visible. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

a:hover {
  color: var(--text);
}

/* Main play area fills the viewport and centres its content vertically,
   the way real Wordle lets the board float in the middle of the page. */
.app {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2.5rem 1rem;
}

.card {
  width: 100%;
  max-width: 1060px;
}

.hero {
  text-align: center;
  margin-bottom: 1.5rem;
}

.hero h1 {
  font-size: clamp(1.8rem, 6vw, 2.7rem);
  margin: 0;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.tagline {
  color: var(--muted);
  margin: 0.4rem 0 0;
  font-style: italic;
  font-size: 0.95rem;
}

.play {
  display: flex;
  flex-direction: column;
  gap: var(--tile-gap);
}

/* The shared three-column grid: the centre (tiles) column is the anchor, so
   the boxes stay centred on the page while labels hang left and content right. */
.row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: var(--col-gap);
}

.lead {
  justify-self: end;
  text-align: right;
  color: var(--muted);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.aside {
  justify-self: start; /* everything right of the tiles aligns to one line */
  min-width: 0;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* ---------- tiles ---------- */
.stage {
  position: relative;
}

.ghost-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  background: transparent;
  font-size: 16px; /* stops iOS zoom on focus */
  cursor: text;
}

.tiles {
  display: flex;
  gap: var(--tile-gap);
}

.tile {
  width: var(--tile);
  height: var(--tile);
  display: grid;
  place-items: center;
  font-size: 1.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text);
  border: 2px solid var(--tile-border);
  background: transparent;
  user-select: none;
}

/* Only the focused row highlights and blinks its next tile, so a row that
   isn't the typing target doesn't look like it's waiting for input. */
.tiles.focused .tile.active {
  border-color: var(--muted);
  animation: caret 1.1s steps(1) infinite;
}

@keyframes caret {
  50% {
    border-color: var(--tile-border);
  }
}

/* Typed but not yet scored (the Word / Opener rows): lighter outline, no fill. */
.tile.filled {
  border-color: var(--key-border);
  animation: pop 0.12s ease;
}

/* Scored tiles are solid blocks — border matches the fill so there's no ring. */
.tile.correct {
  background: var(--green);
  border-color: var(--green);
}

.tile.present {
  background: var(--present);
  border-color: var(--present);
}

.tile.absent {
  background: var(--absent);
  border-color: var(--absent);
}

@keyframes pop {
  from {
    transform: scale(0.85);
  }
}

/* ---------- opener / random button ---------- */
.random-btn {
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--win);
  background: transparent;
  border: 1.5px solid var(--green);
  border-radius: 999px;
  padding: 0.5rem 1.3rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.random-btn:hover {
  background: rgba(83, 141, 78, 0.18);
}

/* Subtle link shown in place of the hidden opener row. */
.opener-toggle {
  align-self: center;
  margin: 0.35rem 0;
  background: none;
  border: none;
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.9rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.opener-toggle:hover {
  color: var(--text);
}

/* Subtle, so it doesn't compete with the green Random pill. */
.reset-btn {
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  border: 1.5px solid var(--key-border);
  border-radius: 999px;
  padding: 0.5rem 1.3rem;
  cursor: pointer;
  transition:
    color 0.15s ease,
    border-color 0.15s ease;
}

.reset-btn:hover {
  color: var(--text);
  border-color: var(--muted);
}

/* ---------- divider / error ---------- */
.divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 1.1rem 0 1.3rem;
  width: 100%;
}

.error {
  color: #ff6b6b;
  font-size: 0.9rem;
  margin: 0;
  text-align: center;
}

.shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  10%,
  90% {
    transform: translateX(-2px);
  }
  30%,
  70% {
    transform: translateX(4px);
  }
  50% {
    transform: translateX(-6px);
  }
}

/* ---------- board ---------- */
.board {
  display: flex;
  flex-direction: column;
  gap: var(--tile-gap);
}

.count {
  color: var(--muted);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.definition {
  color: #d8dadc;
  font-size: 0.82rem;
  line-height: 1.35;
  font-style: italic;
  margin: 0;
  max-width: 32rem;
}

.definition em {
  color: var(--muted);
  font-style: normal;
}

.definition.muted {
  color: var(--muted);
}

/* Board rows: count left, tiles centre, definition right. The info button is
   only used on narrow screens. */
.row.guess .definition {
  justify-self: start;
}

.row.empty {
  display: flex;
  justify-content: center;
}

.info-btn {
  display: none; /* desktop shows the definition inline; no icon needed */
  align-items: center;
  justify-self: start;
  padding: 0.3rem;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.info-btn:hover {
  color: var(--text);
}

.verdict-band {
  text-align: center;
  color: var(--win);
  font-weight: 700;
  font-size: 1.3rem;
  padding: 0.4rem 0;
}

.verdict-band.lose {
  color: var(--present);
}

.tile.dim {
  opacity: 0.4;
}

/* ---------- footer pinned to the bottom of the page ---------- */
.attribution {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
  padding: 1.5rem 1rem 1.75rem;
}

.attribution p {
  margin: 0.2rem 0;
}

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  :root {
    --tile: 2.75rem;
    --tile-gap: 0.28rem;
  }
  .hero h1 {
    letter-spacing: 0.06em;
  }
  .play {
    gap: 0.9rem;
  }

  /* Input rows stack: label on top, tiles centred, Random below. */
  .row.io-row {
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas:
      "lbl   lbl   lbl"
      "tiles tiles tiles"
      "act   act   act";
    row-gap: 0.4rem;
    justify-items: center;
  }
  .row.io-row .lead {
    grid-area: lbl;
    justify-self: center;
    color: var(--text);
    font-size: 0.95rem;
  }
  .row.io-row .stage {
    grid-area: tiles;
  }
  .row.io-row .aside {
    grid-area: act;
    justify-self: center;
  }

  /* Board rows: count caption above the tiles, info icon beside them, and the
     definition tucked into a tap-to-expand panel underneath. */
  .row.guess {
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas:
      ".     tiles info"
      "cnt   cnt   cnt"
      "det   det   det";
    row-gap: 0.15rem;
    column-gap: 0.4rem;
  }
  .row.guess .lead {
    grid-area: cnt;
    justify-self: center;
  }
  .row.guess .tiles {
    grid-area: tiles;
  }
  .row.guess .info-btn {
    grid-area: info;
    display: inline-flex;
  }
  .row.guess .definition {
    grid-area: det;
    display: none;
    justify-self: stretch;
    text-align: center;
    max-width: none;
    font-size: 0.8rem;
    padding: 0.1rem 0.5rem 0.4rem;
  }
  .row.guess.open .definition {
    display: block;
  }

  .verdict-band {
    font-size: 1.1rem;
  }
}

@media (max-width: 380px) {
  :root {
    --tile: 2.3rem;
    --tile-gap: 0.24rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .shake {
    animation: none !important;
  }
}
