:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1a1a1b;
  --muted: #787c7e;
  --border: #d3d6da;
  --tile-empty: #ffffff;
  --tile-border: #878a8c;
  --accent: #538d4e;
  --wrong: #b3261e;
  --key-bg: #d3d6da;
  --modal-bg: #ffffff;
  --overlay: rgba(0, 0, 0, 0.5);
  --surface: #ffffff;
  --surface-border: rgba(20, 20, 20, 0.06);
  --shadow: 0 1px 2px rgba(16, 24, 32, 0.04), 0 16px 32px -16px rgba(16, 24, 32, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121213;
    --fg: #ffffff;
    --muted: #818384;
    --border: #3a3a3c;
    --tile-empty: #121213;
    --tile-border: #565758;
    --accent: #538d4e;
    --wrong: #ff6b6b;
    --key-bg: #818384;
    --modal-bg: #1a1a1b;
    --overlay: rgba(0, 0, 0, 0.7);
    --surface: #1e1e21;
    --surface-border: rgba(255, 255, 255, 0.08);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 32px -16px rgba(0, 0, 0, 0.6);
  }
}

/* Viewing "Yesterday" swaps the accent from green to a light purple, so
   every accent-colored element (tiles, buttons, borders, toggle) makes the
   different mode obvious at a glance without needing extra copy. */
body.yesterday-mode {
  --accent: #7c5cbf;
}

@media (prefers-color-scheme: dark) {
  body.yesterday-mode {
    --accent: #a78bfa;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  padding-bottom: calc(108px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--fg);
  font-family: "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

@media (min-width: 700px) {
  .topbar {
    padding-left: 36px;
    padding-right: 36px;
  }
}

@media (min-width: 1100px) {
  .topbar {
    padding-left: 72px;
    padding-right: 72px;
  }
}

.topbar h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.topbar h1 span {
  color: var(--accent);
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--key-bg);
  border: none;
  color: var(--fg);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.pill-btn:hover {
  background: var(--accent);
  color: #fff;
}

.pill-icon {
  display: inline-flex;
  line-height: 1;
}

.pill-icon svg {
  width: 16px;
  height: 16px;
}

.subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  font-size: 0.9rem;
  color: var(--muted);
}

.lives {
  display: flex;
  gap: 4px;
  font-size: 1.1rem;
}

.day-toggle {
  display: flex;
  gap: 2px;
  background: var(--key-bg);
  border-radius: 999px;
  padding: 2px;
}

.day-toggle button {
  border: none;
  background: transparent;
  color: var(--fg);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.day-toggle button.active {
  background: var(--accent);
  color: #fff;
}

.day-toggle button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.lives .heart.lost {
  opacity: 0.25;
  filter: grayscale(1);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 560px);
  justify-content: center;
  gap: 16px;
  max-width: 1180px;
  margin: 0 auto;
}

.game-column {
  grid-column: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

/* The game is always the visual center: it sits in a fixed-width middle
   column, flanked by an equal-width sidebar column and an empty spacer
   column so the game itself never drifts off-center as the sidebar
   appears/disappears. */
@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(220px, 300px) minmax(0, 560px) minmax(220px, 300px);
    align-items: start;
    gap: 32px;
  }

  .game-column {
    grid-column: 2;
    grid-row: 1;
    margin: 0;
  }

  .sidebar {
    grid-column: 1;
    grid-row: 1;
    justify-self: end;
    position: sticky;
    top: calc(64px + 24px);
  }
}

main {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 0 16px;
}

@media (min-width: 900px) {
  .sidebar {
    max-width: 300px;
    padding: 0;
  }
}

.sidebar-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
  border-radius: 20px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.sidebar-bio {
  margin: 0;
  font-size: 0.87rem;
  line-height: 1.6;
  color: var(--muted);
}

.sidebar-bio strong {
  color: var(--fg);
}

.sidebar-badge {
  align-self: flex-start;
  background: var(--key-bg);
  color: var(--fg);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 6px 12px;
  border-radius: 999px;
}

.sidebar-btn {
  display: block;
  text-align: center;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.sidebar-btn.donate-btn {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--accent) 70%, transparent);
}

.sidebar-btn.donate-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px -8px color-mix(in srgb, var(--accent) 75%, transparent);
}

.sidebar-btn.projects-btn {
  background: transparent;
  border-color: var(--surface-border);
  color: var(--fg);
}

.sidebar-btn.projects-btn:hover {
  border-color: var(--accent);
}

.sidebar-btn.coming-soon {
  opacity: 0.6;
  cursor: default;
  transform: none;
}

.chain {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chain-step {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.chain-step.given { background: rgba(83, 141, 78, 0.08); }
.chain-step.solved { background: rgba(83, 141, 78, 0.12); }
.chain-step.failed { background: rgba(179, 38, 30, 0.10); }
.chain-step.active { border-color: var(--accent); border-width: 2px; }
.chain-step.locked { opacity: 0.55; }

.step-index {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tile {
  width: 38px;
  height: 38px;
  border: 2px solid var(--tile-border);
  background: var(--tile-empty);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  border-radius: 4px;
  text-transform: uppercase;
}

.tile.filled {
  border-color: var(--accent);
}

.tile.solved-tile {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tile.failed-tile {
  background: var(--wrong);
  border-color: var(--wrong);
  color: #fff;
}

.link-phrase {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

.hint-prompt {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-style: italic;
  padding: 4px 0;
}

.hint-prompt-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  border: 2px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  font-style: normal;
}

.locked-placeholder {
  display: flex;
  align-items: center;
  padding: 4px 0;
}

.locked-icon {
  font-size: 1rem;
  opacity: 0.6;
}

.wrong-guesses {
  font-size: 0.8rem;
  color: var(--wrong);
}

/* Floating, iOS-style compose bar: pinned to the bottom of the viewport so
   it's always reachable, with a frosted-glass background like an iMessage
   toolbar. Centered under the game column at every width. */
.guess-bar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px calc(22px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--surface-border);
}

@supports not (backdrop-filter: blur(1px)) {
  .guess-bar {
    background: var(--bg);
  }
}

.guess-bar .message {
  min-height: 1.2em;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
}

.guess-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

#guessInput {
  flex: 1;
  min-width: 0;
  padding: 11px 16px;
  font-size: 1rem;
  border: 1px solid var(--surface-border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg);
  text-transform: uppercase;
}

#guessInput::placeholder {
  text-transform: none;
  color: var(--muted);
}

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

.send-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.send-btn svg {
  width: 18px;
  height: 18px;
}

.send-btn:active {
  transform: scale(0.92);
}

.send-btn:disabled {
  background: var(--key-bg);
  color: var(--muted);
  cursor: not-allowed;
}

#shareBtn {
  padding: 10px 18px;
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--modal-bg);
  color: var(--fg);
  border-radius: 10px;
  padding: 24px;
  max-width: 440px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--fg);
}

.modal h2 {
  margin-top: 0;
}

.modal .example {
  font-weight: 700;
  letter-spacing: 0.05em;
}

.modal ul {
  padding-left: 20px;
}

/* Help modal */

.help-section {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

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

.help-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--key-bg);
  color: var(--accent);
}

.help-icon svg {
  width: 17px;
  height: 17px;
}

.help-body {
  flex: 1;
  min-width: 0;
}

.help-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.help-caption {
  font-size: 0.85rem;
  color: var(--muted);
}

.chain-demo {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.chain-chip {
  background: var(--key-bg);
  border-radius: 6px;
  padding: 4px 8px;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.03em;
}

.chain-arrow {
  color: var(--muted);
}

.hint-demo {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hint-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mini-tiles {
  display: flex;
  gap: 3px;
}

.mini-tile {
  width: 22px;
  height: 22px;
  border: 2px solid var(--tile-border);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
}

.mini-tile.filled {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.hint-caption {
  font-size: 0.8rem;
  color: var(--muted);
}

.help-footer {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  margin-bottom: 0;
  margin-top: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 12px;
  text-align: center;
}

.stat-box .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
}

.stat-box .stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
}

.end-score {
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
}

.already-played-note {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--key-bg);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 10px 0 0;
}

.end-recap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 12px 0;
  font-size: 0.9rem;
}

.end-recap .recap-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.share-text {
  background: var(--key-bg);
  color: var(--fg);
  padding: 10px;
  border-radius: 6px;
  white-space: pre-wrap;
  font-size: 0.9rem;
}

.next-puzzle {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 420px) {
  .tile { width: 32px; height: 32px; font-size: 1rem; }
  .topbar h1 { font-size: 1.3rem; }
  .pill-label { display: none; }
  .pill-btn { padding: 7px 10px; }
  .pill-icon svg { width: 18px; height: 18px; }
}
