:root {
  --danger: #B3261E;
  --accent-tint: #DCE7F2;
  --key-idle: #D3D6DA;
  --key-used: #787C7E;
  --key-ink: #1F1D1A;
  --key-ink-used: #FFFFFF;
}

@media (prefers-color-scheme: dark) {
  :root {
    --danger: #F2968E;
    --accent-tint: #243546;
    --key-idle: #818384;
    --key-used: #3A3A3C;
    --key-ink: #FFFFFF;
    --key-ink-used: #FFFFFF;
  }
}

.credit { color: var(--muted); }
.credit cite { font-style: italic; }
.help { margin-top: 0; }

.board {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1rem;
  margin: 1.25rem 0 1rem;
  font-size: 1.35rem;
}

.word { display: inline-flex; gap: 0.2rem; }

.slot {
  appearance: none;
  background: transparent;
  color: inherit;
  font: inherit;
  border: 2px solid transparent;
  border-bottom-color: var(--text);
  border-radius: 0.25rem;
  min-width: 1.7rem;
  min-height: 2.75rem;
  padding: 0.1rem 0.15rem 0.15rem;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: color-mix(in srgb, var(--accent) 25%, transparent);
}
.slot .guess,
.slot .code { pointer-events: none; }

.slot:focus-visible,
.controls button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.slot.is-match { background: var(--accent-tint); }
.slot.is-selected { border-color: var(--accent); }
.slot.is-wrong .guess { color: var(--danger); text-decoration: line-through; }
.slot.is-revealed { border-style: double; border-color: var(--accent); }
.slot.is-conflict .guess { text-decoration: underline dashed; }
.slot.is-wrong.is-conflict .guess { text-decoration: line-through underline dashed; }

.guess {
  min-height: 1.15em;
  font-weight: 650;
  line-height: 1.1;
}

.code {
  font-size: 0.7rem;
  line-height: 1.2;
  color: var(--muted);
}

.mark { align-self: flex-end; padding: 0 0.05rem 0.35rem; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  overflow: visible;
}

.controls button {
  appearance: none;
  position: relative;
  min-height: 2.75rem;
  padding: 0.45rem 1.1rem;
  flex: 0 1 auto;
  min-width: 5.75rem;
  font: inherit;
  font-weight: 650;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid color-mix(in srgb, var(--text) 22%, transparent);
  border-radius: 0.7rem;
  cursor: pointer;
}
.controls button:hover {
  background: color-mix(in srgb, var(--accent-tint) 55%, var(--surface));
}
.controls button:disabled {
  opacity: 0.4;
  cursor: default;
}
.controls button:disabled:hover { background: var(--surface); }

.hint-badge {
  position: absolute;
  top: -0.4rem;
  right: -0.4rem;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  box-shadow: 0 0 0 2px var(--bg);
}

.play-dock {
  margin: 1rem 0 0.75rem;
}
body.puzzle-play.is-solved .play-dock { display: none; }
.play-dock-inner { max-width: 40rem; }
.play-dock .controls { margin-bottom: 0; }

/* Desktop / wide: real keyboard only. The on-screen keys stay in the DOM for phones. */
.keyboard { display: none; }

.key-row {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: stretch;
  gap: 0.35rem;
  min-width: 0;
}
.key {
  appearance: none;
  min-width: 0;
  min-height: 3.5rem;
  padding: 0;
  flex: 1 1 0;
  max-width: 2.7rem;
  border: 0;
  border-radius: 0.3rem;
  background: var(--key-idle);
  color: var(--key-ink);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.key:active { filter: brightness(0.92); }
.key-enter,
.key-backspace {
  flex: 1.55 1 0;
  max-width: 4.1rem;
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.key-backspace {
  font-size: 1.15rem;
  letter-spacing: 0;
  text-transform: none;
}
.key.is-used {
  background: var(--key-used) !important;
  color: var(--key-ink-used) !important;
  text-decoration: none;
  opacity: 1;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #000 18%, transparent);
}
.key:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Phones: Wordle-style bar pinned to the bottom. */
@media (max-width: 40rem) {
  body.puzzle-play {
    --play-dock-space: calc(12.25rem + env(safe-area-inset-bottom, 0px));
    padding-bottom: var(--play-dock-space);
  }
  body.puzzle-play.is-solved {
    --play-dock-space: 0px;
    padding-bottom: 0;
  }

  .play-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    margin: 0;
    padding: 0.5rem 0 calc(0.4rem + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--rule);
  }
  .play-dock-inner {
    max-width: 40rem;
    margin: 0 auto;
    padding: 0 0.5rem;
  }
  .play-dock .controls {
    margin: 0 0.25rem 0.45rem;
    gap: 0.4rem;
  }
  .play-dock .controls button {
    flex: 1 1 0;
    min-width: 0;
    border-radius: 0.55rem;
    font-size: 0.95rem;
  }

  .keyboard {
    display: grid;
    gap: 0.4rem;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0 0.15rem 0.1rem;
    box-sizing: border-box;
    background: transparent;
    border-radius: 0;
  }
}

@media (max-width: 24rem) {
  body.puzzle-play { --play-dock-space: calc(11.5rem + env(safe-area-inset-bottom, 0px)); }
  .key { min-height: 3.15rem; font-size: 0.88rem; }
  .key-enter,
  .key-backspace { font-size: 0.62rem; max-width: 3.5rem; }
  .key-backspace { font-size: 1.05rem; }
  .key-row { gap: 0.25rem; }
  .board { gap: 0.6rem 0.65rem; font-size: 1.15rem; }
  .slot { min-width: 1.4rem; min-height: 2.4rem; }
  .app-nudge .app-store-badge img { width: 118px; }
  .app-nudge p { font-size: 0.78rem; }
}

/* Desktop controls sit with the puzzle, a bit stronger than the page chrome. */
@media (min-width: 40.01rem) {
  .play-dock .controls {
    justify-content: center;
    gap: 0.75rem;
  }
  .play-dock .controls button {
    min-width: 6.5rem;
    min-height: 2.9rem;
    padding: 0.55rem 1.35rem;
    border-radius: 0.75rem;
    box-shadow: 0 1px 0 color-mix(in srgb, var(--text) 8%, transparent);
  }
  .hint-badge {
    top: -0.45rem;
    right: -0.45rem;
    min-width: 1.45rem;
    height: 1.45rem;
    font-size: 0.78rem;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.1rem + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  max-width: min(22rem, calc(100vw - 2rem));
  margin: 0;
  padding: 0.7rem 1.15rem;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 650;
  line-height: 1.25;
  text-align: center;
  box-shadow: 0 10px 28px color-mix(in srgb, var(--text) 28%, transparent);
  transform: translate(-50%, 0.6rem);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.is-on {
  opacity: 1;
  transform: translate(-50%, 0);
}
@media (max-width: 40rem) {
  body.puzzle-play:not(.is-solved) .toast {
    bottom: calc(12.5rem + env(safe-area-inset-bottom, 0px));
  }
}

blockquote {
  margin: 0.5rem 0 1rem;
  font-family: "Newsreader", "Iowan Old Style", Georgia, "Times New Roman", serif;
  font-size: 1.5rem;
  line-height: 1.35;
}

.cta { margin-bottom: 0.75rem; }

.app-nudge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  margin: 1rem 0 0.35rem;
  text-align: center;
}
.app-nudge .app-store-badge { margin: 0; line-height: 0; }
.app-nudge .app-store-badge img { width: 132px; height: auto; }
.app-nudge p {
  margin: 0;
  max-width: 14rem;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

#share {
  display: inline-block;
  margin: 1rem auto 1.25rem;
  padding: 0.55rem 1.15rem;
  border: 1.5px solid var(--text);
  border-radius: 0.55rem;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
#share:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

#share-fallback {
  display: block;
  width: 100%;
  max-width: 22rem;
  margin: 0 auto 1rem;
  padding: 0.6rem;
  font: inherit;
  line-height: 1.4;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--text);
  resize: vertical;
  min-height: 5rem;
  text-align: left;
}

#solved {
  margin: 1.25rem 0 1.5rem;
  text-align: center;
}
#solved h2 {
  margin: 0.35rem 0 0.75rem;
}
#solved h2:focus { outline: none; }
.solved-mark {
  margin: 0;
  color: #1F8A4C;
  font-size: 2.75rem;
  font-weight: 700;
  line-height: 1;
}
@media (prefers-color-scheme: dark) {
  .solved-mark { color: #5DCF8B; }
}
#solved blockquote {
  margin: 0.5rem auto 0.75rem;
  max-width: 28rem;
}
#solved-credit {
  margin: 0 0 1rem;
  color: var(--muted);
}
/* Solved takes the board's place so the quote sits where the player was looking. */
body.is-solved .board,
body.is-solved .help { display: none; }
