/* =========================================================
   CROSSLINK — visual identity
   Deep plum/violet + warm gold accent. Cards that progressively
   collapse from "clue group" to "solved pill" as you play, then
   transform into a pyramid reveal. Deliberately not styled like
   Wordle, Connections, or either earlier prototype in this folder.
   ========================================================= */

:root {
  --bg: #f8f6fb;
  --surface: #ffffff;
  --ink: #241f2e;
  --ink-soft: #6a6277;
  --border: #e2dcec;
  --primary: #5b3a8e;
  --primary-dark: #422a68;
  /* Fill for filled primary action buttons specifically. Equal to
     --primary in light mode; overridden to --primary-dark in dark mode
     below, where --primary itself is a much lighter purple (needed for
     text-on-background uses like .wordmark) but fails contrast as a
     button fill with white text — see the dark-mode override. */
  --action-bg: var(--primary);
  --accent: #8a5f12;
  --accent-soft: #faf0dc;
  --good: #26764c;
  --good-soft: #e3f5eb;
  --bad: #c2483a;
  --bad-soft: #f8e6e3;
  --shadow: 0 10px 24px -12px rgba(36, 31, 46, 0.25);
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171320;
    --surface: #201a2c;
    --ink: #f1eef7;
    --ink-soft: #a99fbb;
    --border: #372c48;
    --primary: #9a78d1;
    --primary-dark: #7a5bb0;
    /* --primary (#9a78d1) with white text is only ~3.5:1 — fails WCAG AA
       (4.5:1) for normal-size button text. --primary-dark (#7a5bb0)
       with white text measures ~5.3:1, comfortably passing — see
       AUDIT_REPORT / release notes for the full calculation. */
    --action-bg: var(--primary-dark);
    --accent: #e0ac4d;
    --accent-soft: #3a2f1c;
    --good: #4cb37e;
    --good-soft: #1c3327;
    --bad: #e2695a;
    --bad-soft: #3a2420;
    --shadow: 0 10px 28px -12px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  min-height: 100%;
}

body { display: flex; flex-direction: column; min-height: 100vh; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
button:focus-visible, input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.wordmark {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.1em;
  color: var(--primary);
  margin: 0 auto;
}
.iconBtn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 20px;
  line-height: 1;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.iconBtn:hover { background: var(--border); }
.timerDisplay {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 600;
  min-width: 34px;
  text-align: right;
}

/* ---------- layout ---------- */

main#app {
  flex: 1;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 18px 60px;
  display: flex;
  flex-direction: column;
}
.screen { display: none; flex-direction: column; gap: 16px; }
.screen.active { display: flex; }

/* ---------- menu ---------- */

.menuIntro { text-align: center; padding: 6px 0 2px; }
.tagline {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 6px;
}
.subtag { color: var(--ink-soft); margin: 0; font-size: 14.5px; line-height: 1.5; }
.devTag { color: var(--bad); }

/* ---------- home screen ---------- */

.todayCard {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.todayLabel {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  text-transform: uppercase;
}
.todayMeta { display: flex; align-items: center; gap: 8px; }
.parBadge {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 20px;
  background: var(--bg);
  color: var(--ink-soft);
  border: 1px solid var(--border);
}
.streakLine { font-size: 13.5px; font-weight: 700; color: var(--accent); }
.todayProgress { font-size: 13.5px; color: var(--ink-soft); }
.todayResult {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.01em;
}
.todayResult.won { color: var(--good); }
.todayResult.lost { color: var(--bad); }
.comeBackNote { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-soft); }

#recentSection { display: flex; flex-direction: column; gap: 6px; }
.recentList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.recentRow {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 13px;
}
.recentNum { font-weight: 800; color: var(--ink-soft); width: 40px; flex-shrink: 0; }
.recentLabel { font-weight: 800; flex: 1; }
.recentLabel.won { color: var(--good); }
.recentLabel.lost { color: var(--bad); }
.recentPips { font-size: 11px; letter-spacing: 1px; }

.statsGrid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 6px;
}
.statCell { text-align: center; }
.statCell b { display: block; font-size: 16px; color: var(--ink); }
.statCell span { font-size: 9.5px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }

.devModeBtn {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 10px;
  margin: 4px auto 0;
  min-height: 44px;
}

.sectionTitle {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin: 0 2px;
}

.puzzleList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.puzzleItem {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
}
.puzzleItem:active { transform: scale(0.98); }
.puzzleItem .pNum {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.puzzleItem .pMeta { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.puzzleItem .pMeta small { font-weight: 500; color: var(--ink-soft); font-size: 12px; }

.diffBadge {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 20px;
  flex-shrink: 0;
}
.diffBadge.easy { background: var(--good-soft); color: var(--good); }
.diffBadge.medium { background: var(--accent-soft); color: var(--accent); }
.diffBadge.hard { background: var(--bad-soft); color: var(--bad); }

.statusMark { font-size: 16px; flex-shrink: 0; }
.statusMark.won { color: var(--good); }
.statusMark.lost { color: var(--bad); }

/* ---------- game screen ---------- */

.gameHead { display: flex; justify-content: space-between; align-items: baseline; }
.puzzleLabel { font-weight: 800; font-size: 15px; }
.linkBtn {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 4px;
  min-height: 44px;
}

.attemptsRowWrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
}
.attemptsLabel {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}
.attemptsRow { display: flex; gap: 6px; }
.attemptsCount {
  min-width: 26px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.attemptsRow .attemptDot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  transition: background 0.2s ease, transform 0.2s ease;
}
.attemptsRow .attemptDot.lost { background: var(--border); transform: scale(0.85); }

.groups { display: flex; flex-direction: column; gap: 12px; }

.groupCard {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: padding 0.25s ease, background 0.25s ease, border-color 0.25s ease;
}
.groupCard.solved {
  padding: 12px 16px;
  border-color: var(--good);
  background: var(--good-soft);
}
.groupCard.shake { animation: shake 0.35s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.directionLabel {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.clueRow {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.clueChip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 12px;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.answerForm { display: flex; gap: 8px; }
.answerForm input {
  flex: 1;
  min-width: 0;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
}
.answerForm input:focus {
  border-color: var(--primary);
}
.answerForm button {
  padding: 11px 16px;
  border-radius: 12px;
  border: none;
  background: var(--action-bg);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  min-height: 44px;
}
.answerForm button:active { transform: scale(0.96); }

.solvedRow {
  display: flex;
  align-items: center;
  gap: 10px;
}
.solvedCheck {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--good);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  animation: popIn 0.3s ease;
}
@keyframes popIn {
  0% { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.solvedAnswer {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.02em;
  color: var(--good);
}
.solvedClues { margin-left: auto; font-size: 12px; color: var(--ink-soft); text-align: right; }

/* ---------- hints ---------- */

.hintRow { margin-top: 10px; }
.hintBtn {
  background: none;
  border: 1.5px dashed var(--accent);
  color: var(--accent);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 800;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.hintBtn:active { transform: scale(0.96); }
.hintCost {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}
.hintText {
  margin: 0;
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 8px 12px;
  line-height: 1.4;
}

/* ---------- final area (locked / unlock transition / unlocked) ---------- */

.finalLockedNote {
  text-align: center;
  color: var(--ink-soft);
  font-size: 13.5px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 14px;
  margin: 0;
}

.finalUnlockBanner {
  text-align: center;
  background: var(--good-soft);
  border: 1.5px solid var(--good);
  border-radius: var(--radius);
  padding: 22px 16px;
  color: var(--good);
  font-weight: 900;
  font-size: 17px;
  letter-spacing: 0.03em;
  animation: popIn 0.3s ease;
}
.finalUnlockCheck {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--good);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin: 0 auto 10px;
}

.finalArea { display: flex; flex-direction: column; gap: 10px; animation: fadeIn 0.35s ease; }
.finalUnlockedTag {
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--good);
}
.finalHeading {
  text-align: center;
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
  margin-top: -4px;
}
.finalGroupSummary {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.finalAnswerChip {
  background: var(--good-soft);
  color: var(--good);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.02em;
}
.autoClueBlock { text-align: center; }
.autoClueLabel {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  opacity: 0.8;
  margin-bottom: 3px;
}
.finalAutoClue {
  text-align: center;
  font-size: 13px;
  color: var(--ink-soft);
  font-style: italic;
  margin: 0;
  padding: 0 6px;
}
.wide { width: 100%; }

.primaryBtn {
  background: var(--action-bg);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 15px 18px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}
.primaryBtn:active { transform: scale(0.97); }
.primaryBtn:disabled { opacity: 0.5; }

.ghostBtn {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--ink-soft);
  border-radius: 14px;
  padding: 14px;
  font-size: 13.5px;
  font-weight: 700;
}
.ghostBtn:active { transform: scale(0.97); }

/* Fixed-height status area (empty when inactive) directly below the
   attempts bar, so a transient encouragement message appearing or
   fading never shifts the puzzle groups below it. */
.feedback {
  text-align: center;
  min-height: 24px;
  font-weight: 700;
  font-size: 14.5px;
  color: var(--ink-soft);
  opacity: 1;
  transition: opacity 0.6s ease;
}
.feedback.pulse { animation: fadeIn 0.3s ease; }
.feedback.fadeOut { opacity: 0; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- result screen ---------- */

.resultBanner { text-align: center; padding: 10px 0 2px; }
.resultBanner .big {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -0.01em;
}
.resultBanner.win .big { color: var(--good); }
.resultBanner.lose .big { color: var(--ink); font-size: 20px; margin-top: 2px; }
.resultBanner .small { color: var(--ink-soft); font-size: 14px; margin-top: 4px; }
.resultBanner .small.soClose {
  font-size: 22px;
  font-weight: 900;
  color: var(--bad);
  letter-spacing: 0.02em;
}

/* Compact "how did I do" summary — 2-3 short stacked lines directly
   under the verdict, deliberately not a stats-dashboard layout. This
   is the ONLY place attempts/par/hints appear on the result screen. */
.performanceSummary {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
  margin-top: -4px;
}
.performanceLine {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink-soft);
}
.performanceLine.parLine { font-weight: 800; }
.performanceLine.parLine.beat { color: var(--good); }
.performanceLine.parLine.made { color: var(--accent); }
.performanceLine.parLine.over { color: var(--ink-soft); }

.pyramidReveal { display: flex; flex-direction: column; gap: 10px; }
.revealCard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  animation: linkIn 0.3s ease backwards;
}
@keyframes linkIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.revealCard .revealClues { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 4px; }
.revealCard .revealAnswerRow { display: flex; align-items: center; gap: 8px; }
.revealCard .revealAnswer { font-size: 18px; font-weight: 900; color: var(--primary); }
.revealCard .revealTag {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--good-soft);
  color: var(--good);
}
.revealCard .revealTag.wasNotSolved { background: var(--bad-soft); color: var(--bad); }
.revealCard .revealTag.hintTag { background: var(--accent-soft); color: var(--accent); }
.revealCard .revealWhy { margin-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.revealCard .revealLine {
  font-size: 12.5px;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}
.revealCard .revealAnswerRow { flex-wrap: wrap; row-gap: 4px; }

.finalConnection {
  background: var(--accent-soft);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.finalConnection .finalWordLabel {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.85;
}
.finalConnection .finalWord {
  font-size: 26px;
  font-weight: 900;
  color: var(--accent);
  animation: popIn 0.4s ease;
}
.finalConnection p { font-size: 13.5px; color: var(--ink); line-height: 1.55; margin: 8px 0 0; text-align: left; }
.finalHintUsedNote { font-size: 12px; color: var(--accent); font-weight: 700; margin-top: 8px !important; }

.secondaryDetails {
  display: flex;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
}
.secondaryDetails .stat { text-align: center; }
.secondaryDetails .stat b { display: block; font-size: 15px; color: var(--ink); }
.secondaryDetails .stat span { font-size: 10.5px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }

.benchmarkBlock {
  background: repeating-linear-gradient(135deg, var(--accent-soft), var(--accent-soft) 10px, var(--bg) 10px, var(--bg) 20px);
  border: 1.5px dashed var(--accent);
  border-radius: 14px;
  padding: 12px 14px;
  text-align: center;
}
.benchmarkLabel {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.benchmarkValue { font-size: 14px; font-weight: 700; color: var(--ink); margin-top: 4px; }

/* 3. Primary Share action — one full-width button, nothing competing
   next to it. The share-text preview (.shareFallback) stays hidden
   unless both Web Share and clipboard copying genuinely fail. */
.shareBox {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.shareFallbackNote {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin: 0 0 6px;
  text-align: center;
}
.shareText {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13.5px;
  line-height: 1.5;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  color: var(--ink);
}

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

/* ---------- last-attempt hint confirmation (CROSSLink-native modal) ---------- */

.modalOverlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 28, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fadeIn 0.2s ease;
}
.modalCard {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 20px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  animation: popIn 0.2s ease;
}
.modalTitle {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink);
}
.modalDesc {
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.5;
  margin: 8px 0 18px;
}
.modalActions { display: flex; flex-direction: column; gap: 10px; }
.modalActions .primaryBtn, .modalActions .ghostBtn { width: 100%; }

@media (max-width: 380px) {
  .solvedAnswer { font-size: 18px; }
}

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