/* Interlinked — "editorial minimal": the original's paper-and-serif soul,
   stripped to one accent, one typographic signature, and generous whitespace. */

:root {
  --bg: #f9f6ef;          /* 60% — flat paper */
  --ink: #22201b;         /* 30% — near-black ink */
  --accent: #b0532c;      /* 10% — terracotta, used sparingly */
  --accent-ink: #8a3e1f;
  --correct: #3c8d5d;     /* semantic only: win states */
  --wrong: #b04a3c;       /* semantic only: error text */
  --gold: #c9a227;        /* the locked anchor box */
  --blue: #3b6fd6;        /* reveal mode */
  --muted: #8a8172;
  --faint: #b5ac9b;
  --card: #fffefb;
  --border: #e3dcc9;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(34, 32, 27, 0.08);
  --shadow-drag: 0 6px 14px rgba(34, 32, 27, 0.16), 0 16px 32px rgba(34, 32, 27, 0.12);
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--serif);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Intro screens: landing, then how to play ---------- */

#landing,
#howto {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  overflow-y: auto;
  transition: opacity 0.4s ease;
}

#howto { display: none; } /* shown when Play is pressed */

#landing.gone,
#howto.gone { opacity: 0; pointer-events: none; }

.howto-wrap {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.9rem;
  width: 100%;
  max-width: 33rem;
  margin: auto;
}

.howto-box {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 1.6rem 1.8rem 1.7rem;
  box-shadow: var(--shadow);
}

.howto-box h2 {
  margin: 0 0 1rem;
  font-family: var(--sans);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-align: center;
}

.rules {
  margin: 0;
  padding-left: 1.4rem;
  font-family: var(--sans);
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--ink);
}

.rules li { margin-bottom: 0.65rem; }
.rules li:last-child { margin-bottom: 0; }
.rules li::marker { color: var(--muted); font-weight: 700; }

#continue-btn {
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 700;
  padding: 0.85rem 1.5rem;
  border-radius: 12px;
  border: 1.5px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

#continue-btn:hover { opacity: 0.85; }
#continue-btn:active { transform: translateY(1px); }

.landing-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 30rem;
}

.wordmark {
  margin: 0;
  font-family: var(--sans);
  font-size: 3.3rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.05;
  color: var(--ink);
}


.landing-sub {
  margin: 1rem 0 0;
  font-family: var(--serif);
  font-size: 1.25rem;
  line-height: 1.5;
  color: var(--ink);
}

#play-btn {
  margin-top: 2rem;
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 600;
  padding: 0.75rem 3rem;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

#play-btn:hover { opacity: 0.85; }
#play-btn:active { transform: translateY(1px); }

.landing-meta {
  margin: 1.8rem 0 0;
  font-family: var(--sans);
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--muted);
}

.landing-meta strong { color: var(--ink); }

/* ---------- Archive calendar ---------- */

.link-btn {
  margin-top: 1rem;
  background: none;
  border: none;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  border-radius: 8px;
}

.link-btn:hover { color: var(--ink); background: rgba(34, 32, 27, 0.05); }

.calendar {
  margin-top: 0.6rem;
  width: 18rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem 0.9rem 0.9rem;
  font-family: var(--sans);
  box-shadow: var(--shadow);
}

.calendar.hidden { display: none; }

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 0.88rem;
  margin-bottom: 0.5rem;
}

.cal-nav {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.4rem;
  border-radius: 6px;
}

.cal-nav:hover { color: var(--ink); background: rgba(34, 32, 27, 0.06); }

.cal-dow, .cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.cal-dow span {
  text-align: center;
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--faint);
  padding-bottom: 0.2rem;
}

.cal-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-family: inherit;
  border: none;
  background: none;
  color: var(--faint);
  border-radius: 7px;
}

.cal-cell.blank { visibility: hidden; }

/* A day with a playable puzzle */
.cal-cell.has {
  color: var(--ink);
  font-weight: 700;
  background: rgba(34, 32, 27, 0.06);
  cursor: pointer;
}

.cal-cell.has:hover { background: var(--ink); color: var(--bg); }

.cal-cell.today { box-shadow: inset 0 0 0 1.5px var(--accent); }
.cal-cell.sel { background: var(--ink); color: var(--bg); }

.cal-note {
  margin: 0.6rem 0 0;
  text-align: center;
  font-size: 0.7rem;
  color: var(--faint);
}

@media (max-width: 480px) {
  .wordmark { font-size: 2.2rem; }
  .landing-sub { font-size: 1.1rem; }
}

/* ---------- Masthead: typography is the signature ---------- */

header {
  text-align: center;
  padding: 2.4rem 1rem 1.4rem;
}

h1 {
  margin: 0;
  font-size: 2.6rem;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  text-indent: 0.24em; /* optically recenter the letter-spaced title */
}

h1::after {
  content: "";
  display: block;
  width: min(24rem, 75%);
  margin: 0.7rem auto 0;
  border-top: 3px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  height: 3px;
}

.tagline {
  margin: 1rem auto 0;
  color: var(--muted);
  max-width: 34rem;
  font-size: 0.95rem;
  line-height: 1.55;
}

.puzzle-meta {
  margin: 0.4rem 0 1.6rem;
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
}

/* Plain text stats — no boxes competing with the cards */
.scoreboard {
  display: flex;
  justify-content: center;
  font-family: var(--sans);
  font-size: 0.88rem;
}

.stat {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 1.1rem;
  background: var(--card);
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

main {
  flex: 1;
  max-width: 76rem;
  margin: 0 auto;
  padding: 0.6rem 1rem 2rem;
  width: 100%;
}

/* ---------- Board & slots ---------- */

/* The table the cards sit on: semi-transparent, blends with the paper */
.board {
  display: flex;
  justify-content: center;
  gap: 1.1rem;
  flex-wrap: nowrap;
  width: fit-content;
  margin: 1.8rem auto 1.4rem;
  padding: 1.2rem 1.4rem 1.5rem;
  background: rgba(34, 32, 27, 0.045);
  border: 1px solid rgba(34, 32, 27, 0.07);
  border-radius: 22px;
}

/* Each card's placeholder well — revealed when its card is lifted */
.well { position: relative; border-radius: var(--radius); }

.well::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1.5px dashed var(--faint);
  background: rgba(34, 32, 27, 0.05);
  border-radius: inherit;
}

.well .card-shell { position: relative; z-index: 1; }

.slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
}

.slot-label {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}

/* A box confirmed in its correct spot by the latest guess */
.slot.correct .slot-label { color: var(--correct); font-weight: 700; }
.slot.correct .card-face {
  border: 2.5px solid var(--correct);
  box-shadow: 0 0 0 2.5px var(--correct);
}

.card-shell.bounce { animation: bounce 0.6s cubic-bezier(0.28, 0.84, 0.42, 1); }

/* Wrong-position "nope" vibration */
.card-shell.shake { animation: shake 0.45s ease; }

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

@keyframes bounce {
  0%   { transform: translateY(0); }
  30%  { transform: translateY(-16px); }
  55%  { transform: translateY(0); }
  72%  { transform: translateY(-7px); }
  88%  { transform: translateY(0); }
  100% { transform: translateY(0); }
}

/* The locked anchor box: golden */
.slot.anchor .slot-label { color: var(--gold); font-weight: 700; }

.slot.anchor .card-shell { cursor: default; }
.slot.anchor .card-face { border: 2.5px solid var(--gold); }

/* ---------- Cards ---------- */

.card-shell {
  /* Sized so all five cards always fit on one row (incl. board padding) */
  width: clamp(150px, calc((100vw - 12rem) / 5), 215px);
  /* Height = a square picture area plus the title bar, so the 2x2 reveal
     quadrants come out square. */
  aspect-ratio: 6 / 7;
  perspective: 1000px;
  cursor: grab;
  border-radius: var(--radius);
  transition: transform 0.18s ease, opacity 0.15s ease;
  touch-action: none; /* pointer-drag needs to own touch gestures on cards */
}

.slot:not(.anchor) .card-shell:hover { transform: translateY(-3px); }
.slot:not(.anchor) .card-shell:active { cursor: grabbing; }

/* The card being dragged leaves an empty gap that slides with the live order */
.card-shell.placeholder { opacity: 0; }

/* The card in flight, following the cursor */
.drag-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  margin: 0;
  transform: rotate(2deg) scale(1.04);
}

.drag-ghost .card-face { box-shadow: var(--shadow-drag); }

body.is-dragging { user-select: none; cursor: grabbing; }
body.is-dragging .card-shell { cursor: grabbing; }

.card {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4, 0.1, 0.2, 1);
}

.card.flipped { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--card);
  box-shadow: var(--shadow);
}

.card-face.back { transform: rotateY(180deg); }

.card-image-wrap {
  flex: 1;
  overflow: hidden;
  background: #efe9db;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

/* Each picture quadrant shows its quarter of the image once revealed.
   Quadrant divisions are invisible unless you're in reveal mode. */
.quad {
  position: relative;
  background-size: 200% 200%;
  background-repeat: no-repeat;
  transition: transform 0.12s ease;
}

.quad[data-q="0"] { background-position: 0% 0%; }
.quad[data-q="1"] { background-position: 100% 0%; }
.quad[data-q="2"] { background-position: 0% 100%; }
.quad[data-q="3"] { background-position: 100% 100%; }

/* Reveal mode: cards get a blue outline; hovering a covered quadrant lifts it */
.board.reveal-mode .card-face {
  box-shadow: 0 0 0 2.5px var(--blue), var(--shadow);
}

.board.reveal-mode .quad:not(.revealed) { cursor: pointer; }

.board.reveal-mode .quad:not(.revealed):hover {
  background-color: rgba(59, 111, 214, 0.14);
  box-shadow: inset 0 0 0 2px var(--blue);
  transform: scale(1.06);
  z-index: 2;
}

.card-title-bar {
  padding: 0.45rem 0.5rem;
  font-family: var(--sans);
  font-size: 0.82rem;
  text-align: center;
  border-top: 1px solid var(--border);
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-title-bar .known {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 0.9rem;
}

/* Hangman-style hidden title */
.hangman {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.15rem 0.55rem;
}

.hm-word { display: flex; gap: 3px; }

.hm-letter,
.hm-char {
  display: inline-block;
  width: 0.72em;
  height: 1.3em;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
}

.hm-letter { border-bottom: 2px solid var(--faint); transition: color 0.2s ease, border-color 0.2s ease; }
.hm-letter:not(:empty) { border-bottom-color: var(--accent); color: var(--accent-ink); }

/* Out-of-guesses reveal: each letter pops in, left to right */
.hm-letter.fill-in { animation: letterPop 0.45s ease; }

@keyframes letterPop {
  0%   { transform: scale(0.4); opacity: 0; }
  60%  { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* A finished title: plain black letters, same metrics as the blanks so
   nothing shifts when a card goes from hidden to solved. */
.hangman.solved .hm-letter {
  background: none;
  border-bottom: none;
  color: var(--ink);
  text-transform: uppercase;
}

/* While a title is auto-filling after a loss it already uses the solved
   styling, so keep the not-yet-filled blanks underlined. */
.hangman.filling .hm-letter:empty { border-bottom: 2px solid var(--faint); }

.card-desc {
  flex: 1;
  padding: 0.7rem 0.75rem;
  font-size: 0.82rem;
  line-height: 1.55;
  overflow-y: auto;
}

/* ---------- Controls ---------- */

.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-top: 1.2rem;
  font-family: var(--sans);
}

#guess-form { display: flex; gap: 0.5rem; }

#guess-input {
  font-family: var(--sans);
  font-size: 1rem;
  padding: 0.6rem 1.05rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  width: 19rem;
  background: var(--card);
  color: var(--ink);
}

#guess-input::placeholder { color: var(--faint); }

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

button {
  font-family: var(--sans);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.6rem 1.35rem;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

button:hover { opacity: 0.82; }
button:active { transform: translateY(1px); }

button:disabled {
  background: var(--border);
  border-color: var(--border);
  color: var(--muted);
  cursor: default;
}

button.secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--border);
}

button.secondary:hover { opacity: 1; border-color: var(--ink); }

#reveal-count {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-weight: 700;
  margin-left: 0.15em;
}

/* Reveal mode active — the button reads as "on" */
#reveal-btn.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

#reveal-btn.active:hover { opacity: 0.9; }
#reveal-btn.active #reveal-count { color: rgba(255, 255, 255, 0.85); }

/* Out of reveals: flash the bar red */
#reveal-btn.flash-red { animation: flashRed 0.6s ease; }
#reveal-btn.flash-red #reveal-count { color: #fff; }

@keyframes flashRed {
  0%, 55% { background: var(--wrong); border-color: var(--wrong); color: #fff; }
  100% { background: transparent; border-color: var(--border); color: var(--ink); }
}

/* ---------- Profile button & modal ---------- */

#profile-btn {
  /* absolute, not fixed — it sits at the top of the page and scrolls away */
  position: absolute;
  top: 1rem;
  right: 1.2rem;
  z-index: 1500;
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#profile-btn:hover { border-color: var(--ink); opacity: 1; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 2500;
  background: rgba(34, 32, 27, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal.hidden { display: none; }

.modal-box {
  position: relative;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 1.8rem 1.9rem 1.6rem;
  width: 100%;
  max-width: 25rem;
  text-align: center;
  font-family: var(--sans);
  box-shadow: var(--shadow-drag);
}

.modal-box h2 {
  margin: 0 0 0.6rem;
  font-family: var(--sans);
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.7rem;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  cursor: pointer;
  box-shadow: none;
}

.modal-close:hover { background: none; color: var(--ink); opacity: 1; }

.modal-note { margin: 0 0 1rem; font-size: 0.88rem; color: var(--muted); }

.modal-fineprint {
  margin: 1rem 0 0;
  font-size: 0.72rem;
  color: var(--faint);
}

#signin-form { display: flex; gap: 0.5rem; justify-content: center; }

#email-input {
  flex: 1;
  font-family: var(--sans);
  font-size: 0.95rem;
  padding: 0.55rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
  min-width: 0;
}

#email-input:focus { outline: none; border-color: var(--ink); }

/* Whether stats are local or synced to an account */
.sync-tag {
  margin: 0.15rem 0 0;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 700;
}

.modal-rule {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0 0 1rem;
}

.modal-status {
  margin: 0.7rem 0 0;
  font-size: 0.8rem;
  min-height: 1.1rem;
  color: var(--muted);
}

.modal-status.ok { color: var(--correct); font-weight: 600; }
.modal-status.bad { color: var(--wrong); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.9rem 0.5rem;
  margin: 1.3rem 0 1.4rem;
}

.stat-grid div { display: flex; flex-direction: column; gap: 0.15rem; }

.stat-grid span {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat-grid small {
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Messages ---------- */

.message {
  text-align: center;
  min-height: 2rem;
  font-family: var(--sans);
  font-size: 0.92rem;
  margin: 1.1rem 0 0;
  color: var(--muted);
}

.message.good { color: var(--correct); font-weight: 600; }
.message.bad { color: var(--wrong); }

/* ---------- Win banner ---------- */

.win-banner {
  margin: 1.6rem auto;
  max-width: 34rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem 1.6rem 1.5rem;
  text-align: center;
  font-family: var(--sans);
  box-shadow: var(--shadow);
}

.win-banner h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.15rem;
  line-height: 1.6;
  color: var(--correct);
}

/* Same banner, shown after running out of guesses */
.win-banner.lost { border-top-color: var(--muted); }
.win-banner.lost h2 { color: var(--ink); }

#win-explanation {
  margin: 0.8rem 0 0;
  font-size: 0.88rem;
  line-height: 1.65;
  text-align: left;
  color: var(--ink);
}

.win-meta {
  margin: 0.9rem 0 0;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.hidden { display: none; }

/* ---------- Footer ---------- */

footer {
  text-align: center;
  font-size: 0.72rem;
  color: var(--faint);
  padding: 1.2rem 1rem 1.6rem;
  font-family: var(--sans);
}

footer a { color: var(--muted); }

/* Cards shrink to keep five on one row, so the description text scales with
   them — otherwise it starts scrolling inside the card. */
@media (max-width: 1150px) {
  .card-desc { font-size: 0.68rem; line-height: 1.42; padding: 0.5rem 0.55rem; }
}

@media (max-width: 950px) {
  .card-desc { font-size: 0.65rem; line-height: 1.4; padding: 0.45rem 0.5rem; }
}

@media (max-width: 700px) {
  h1 { font-size: 1.8rem; }
  #guess-input { width: 12rem; }
  .card-desc { font-size: 0.6rem; line-height: 1.35; }
}
