:root {
  --ink: #3a3a3c;
  --muted: #626266;
  --paper: #fffdfb;
  --blush: #fff2f4;
  --rose: #c94f6d;
  --rose-dark: #8d304d;
  --gold: #9a7416;
  --correct: #6aaa64;
  --present-color: #c9b458;
  --absent-color: #787c7e;
  --line: #d8d8d8;
  --shadow: 0 18px 50px rgba(58, 58, 60, 0.12);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: #faf9f6;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "DM Sans", sans-serif;
  background:
    radial-gradient(circle at 12% 4%, rgba(106, 170, 100, 0.14), transparent 25rem),
    radial-gradient(circle at 90% 92%, rgba(201, 180, 88, 0.15), transparent 24rem),
    radial-gradient(circle at 82% 8%, rgba(201, 79, 109, 0.09), transparent 18rem),
    #faf9f6;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.topbar {
  min-height: 82px;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 10px;
  width: min(100%, 680px);
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 18px 10px;
}

.home-link,
.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--rose-dark);
  background: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  font-size: 1.7rem;
  font-weight: 600;
  cursor: pointer;
}

.icon-button { font-size: 1rem; }

.brand { text-align: center; }
.brand-kicker,
.eyebrow,
.answer-kicker,
.dialog-kicker {
  display: block;
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.brand h1 {
  margin: 1px 0 0;
  color: var(--rose-dark);
  font: 700 clamp(1.55rem, 6vw, 2rem)/1 "Playfair Display", serif;
}

.brand h1::after {
  content: " ♥";
  color: var(--rose);
  font-size: 0.72em;
}

.game-shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 8px 14px max(24px, env(safe-area-inset-bottom));
}

.daily-heading {
  padding: 8px 8px 16px;
  text-align: center;
}

.daily-heading > p {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.daily-heading h2 {
  margin: 0;
  font: 600 1.12rem/1.3 "Playfair Display", serif;
}

.round-tabs {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 13px;
}

.round-tab {
  width: 43px;
  height: 43px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: var(--paper);
  font-weight: 700;
  cursor: pointer;
  transition: 160ms ease;
}

.round-tab.active {
  border-color: var(--correct);
  color: white;
  background: var(--correct);
  box-shadow: 0 7px 18px rgba(106, 170, 100, 0.25);
}

.round-tab.solved:not(.active) {
  border-color: rgba(106, 170, 100, 0.4);
  color: #477944;
  background: #f0f7ef;
}

.round-tab.solved::after { content: "✓"; }
.round-tab.solved { font-size: 0; }
.round-tab.solved::after { font-size: 0.9rem; }

.puzzle-card {
  border: 1px solid rgba(120, 124, 126, 0.22);
  border-radius: 28px;
  padding: 20px 16px 16px;
  background: rgba(255, 253, 251, 0.96);
  box-shadow: var(--shadow);
}

.round-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 0 3px;
}

.round-heading h2 {
  margin: 2px 0 0;
  font: 700 1.4rem/1.2 "Playfair Display", serif;
}

.attempt-count {
  flex: none;
  color: var(--muted);
  font-size: 0.76rem;
}

.legend {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 15px 0 13px;
  color: var(--muted);
  font-size: 0.67rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.legend-mark {
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border-radius: 5px;
  color: white;
  font-style: normal;
  font-size: 0.65rem;
  font-weight: 700;
}

.exact { background: var(--correct); }
.present { background: var(--present-color); color: #29291f; }
.absent { background: var(--absent-color); }

.board-scroll {
  max-height: min(330px, 39vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.board {
  display: grid;
  gap: 7px;
  justify-content: center;
  padding: 2px 0 6px;
}

.word-row {
  display: grid;
  grid-template-columns: repeat(5, min(13vw, 58px));
  gap: 7px;
}

.word-row.clue-row {
  margin-bottom: 7px;
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--line);
}

.tile {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 2px solid #d3d6da;
  border-radius: 10px;
  color: var(--ink);
  background: white;
  font-size: clamp(1.2rem, 6vw, 1.75rem);
  font-weight: 800;
  text-transform: uppercase;
}

.tile.exact,
.tile.absent {
  border-color: transparent;
  color: white;
}

.tile.present {
  border-color: transparent;
  color: #29291f;
}

.tile.exact,
.key.exact { background: var(--correct); }

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

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

.tile.exact::after,
.tile.present::after,
.tile.absent::after {
  position: absolute;
  right: 4px;
  bottom: 1px;
  font-size: 0.55rem;
  opacity: 0.82;
}

.tile.exact::after { content: "✓"; }
.tile.present::after { content: "↔"; }
.tile.absent::after { content: "×"; }

.tile.fresh {
  border-color: #878a8c;
  animation: pop 120ms ease;
}

.tile.filled {
  border-color: #878a8c;
}

.word-row.reveal .tile { animation: reveal 420ms ease both; }
.word-row.reveal .tile:nth-child(2) { animation-delay: 80ms; }
.word-row.reveal .tile:nth-child(3) { animation-delay: 160ms; }
.word-row.reveal .tile:nth-child(4) { animation-delay: 240ms; }
.word-row.reveal .tile:nth-child(5) { animation-delay: 320ms; }

.status {
  min-height: 22px;
  margin: 8px 0 5px;
  color: var(--rose-dark);
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
}

.answer-card {
  margin: 10px 0 16px;
  padding: 18px;
  border: 1px solid rgba(201, 79, 109, 0.24);
  border-radius: 20px;
  text-align: center;
  background: linear-gradient(145deg, #eef7ed, #fff6e0 62%, #fff0f3);
}

.answer-card h3 {
  margin: 2px 0 6px;
  color: var(--rose-dark);
  font: 700 2rem/1 "Playfair Display", serif;
  letter-spacing: 0.08em;
}

.definition {
  margin: 0;
  color: var(--muted);
  font-size: 0.83rem;
}

blockquote {
  margin: 13px 0 16px;
  color: var(--ink);
  font: 600 1rem/1.45 "Playfair Display", serif;
}

.next-button {
  min-height: 44px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  color: white;
  background: var(--rose);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(201, 79, 109, 0.24);
}

.keyboard {
  display: grid;
  gap: 6px;
  margin-top: 8px;
  touch-action: manipulation;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key {
  min-width: 0;
  height: 48px;
  flex: 1;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: #d3d6da;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}

.key.wide { flex: 1.55; font-size: 0.68rem; }
.key.exact, .key.absent { color: white; }
.key.present { color: #29291f; }
.key.exact,
.key.present,
.key.absent { position: relative; }

.key.exact::after,
.key.present::after,
.key.absent::after {
  position: absolute;
  right: 3px;
  bottom: 1px;
  font-size: 0.48rem;
  opacity: 0.86;
}

.key.exact::after { content: "✓"; }
.key.present::after { content: "↔"; }
.key.absent::after { content: "×"; }
.keyboard.disabled { opacity: 0.48; pointer-events: none; }

.help-dialog {
  width: min(calc(100% - 28px), 460px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  padding: 28px;
  border: 0;
  border-radius: 26px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 24px 80px rgba(52, 37, 49, 0.28);
}

.help-dialog::backdrop {
  background: rgba(52, 37, 49, 0.48);
  backdrop-filter: blur(4px);
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 14px;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-size: 1.8rem;
  cursor: pointer;
}

.help-dialog h2 {
  margin: 5px 0 10px;
  font: 700 1.8rem/1.1 "Playfair Display", serif;
}

.help-dialog p,
.help-dialog li {
  color: var(--muted);
  line-height: 1.5;
}

.help-dialog ul { padding-left: 20px; }

.help-example {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  margin: 18px 0;
}

.help-example .tile { font-size: 1.1rem; }

.celebration {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 20;
}

.confetti {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  animation: fall 1700ms ease-in forwards;
}

@keyframes pop {
  50% { transform: scale(1.08); }
}

@keyframes reveal {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

@keyframes fall {
  to { transform: translate3d(var(--drift), 110vh, 0) rotate(680deg); }
}

@media (max-width: 390px) {
  .puzzle-card { padding-inline: 10px; }
  .word-row { gap: 5px; }
  .legend { gap: 7px; }
  .key-row { gap: 3px; }
  .key { height: 44px; font-size: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
  }
}
