@font-face {
  font-family: "Franklin";
  src: url("/fonts/libre-franklin-latin.woff2") format("woff2");
  font-weight: 400 800;
  font-display: swap;
}

:root {
  --ink: #121212;
  --paper: #fff;
  --muted: #5a594e;
  --line: #dfdfdf;

  /* Wordle */
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --tile-empty: #d3d6da;
  --tile-filled: #878a8c;
  --key: #d3d6da;

  /* Connections */
  --card: #efefe6;
  --card-selected: #5a594e;
  --yellow: #f9df6d;
  --green: #a0c35a;
  --blue: #b0c4ef;
  --purple: #ba81c5;

  /* Strands */
  --theme-blue: #aedfee;
  --spangram: #f8cd05;
  --selecting: #dbd8c5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Franklin", "Libre Franklin", "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }

/* Top bar and game picker */
.topbar {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 52px;
  border-bottom: 1px solid var(--line);
}
.topbar .home {
  font: 700 22px/1 Georgia, "Times New Roman", serif;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  max-width: 520px;
  margin: 12px auto 4px;
  padding: 0 12px;
}
.pick {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  font-size: 13px;
  font-weight: 600;
}
.pick img { width: 32px; height: 32px; }
.pick[aria-current="true"] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.pick:disabled { color: #9a9a9a; background: #f7f7f7; }
.pick:disabled img { filter: grayscale(1); opacity: 0.4; }
.pick .badge { position: absolute; top: 4px; right: 6px; font-size: 12px; }
.pick.solved .badge { color: var(--correct); font-weight: 800; }

#game { padding: 12px 12px 40px; }

/* Shared pill buttons (Connections style) */
.pill {
  height: 48px;
  padding: 0 18px;
  border: 1px solid var(--ink);
  border-radius: 32px;
  background: var(--paper);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}
.pill:disabled { color: #8b8b8b; border-color: #979797; }
.pill.dark { background: var(--ink); border-color: var(--ink); color: #fff; }

.next { text-align: center; margin: 28px auto 0; }
.next p { font-weight: 700; font-size: 18px; margin: 0 0 12px; }

/* Toasts */
.toasts {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 13px 16px;
  border-radius: 4px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  transition: opacity 0.3s;
}
.toast.fade { opacity: 0; }

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

/* ---------- Strands ---------- */
.strands { max-width: 360px; margin: 0 auto; text-align: center; }
.strands .theme {
  width: min(315px, 100%);
  margin: 8px auto 0;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.strands .theme .label {
  height: 24px;
  padding-top: 4px;
  border-radius: 7px 7px 0 0;
  background: var(--theme-blue);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.96px;
  text-transform: uppercase;
}
.strands .theme .clue { padding: 14px 8px 16px; font-size: 24px; font-weight: 700; }
.strands .count { margin: 18px 0 4px; font-size: 16px; font-weight: 500; color: #2a2a2a; }
.strands .word {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  font-size: 30px;
  font-weight: 600;
  text-transform: uppercase;
}
.strands .word.found { color: #2a7f9e; }
.strands .word.spangram {
  width: fit-content;
  margin: 0 auto;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--spangram);
  font-size: 24px;
}
.strands .board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-auto-rows: 44px;
  gap: 10px;
  width: min(324px, 100%);
  margin: 8px auto 20px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.strands .lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.strands .lines polyline { fill: none; stroke-width: 12; stroke-linecap: round; stroke-linejoin: round; }
.strands .lines .selected { stroke: var(--selecting); }
.strands .lines .theme { stroke: var(--theme-blue); }
.strands .lines .spangram { stroke: var(--spangram); }
.strands .cell {
  position: relative;
  z-index: 1;
  justify-self: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 100%;
  background: transparent;
  font-size: 26px;
  font-weight: 500;
}
.strands .cell.selected { background: var(--selecting); }
.strands .cell.found { background: var(--theme-blue); }
.strands .cell.spangram { background: var(--spangram); }
.strands .cell.hinted { outline: 2px dashed var(--ink); outline-offset: -2px; }
.strands .hint {
  position: relative;
  overflow: hidden;
  width: 148px;
  height: 46px;
  border: 2px solid var(--ink);
  border-radius: 100px;
  background: #fff;
  font-size: 20px;
  font-weight: 600;
  isolation: isolate;
}
.strands .hint::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  z-index: -1;
  width: var(--fill, 0%);
  background: #efefef;
  transition: width 0.3s;
}
.strands .hint:disabled { border-color: #c6c6c6; color: #8b8b8b; }
.strands .hint:not(:disabled) { background: var(--selecting); }

/* ---------- Wordle ---------- */
.wordle { display: flex; flex-direction: column; align-items: center; }
.wordle .board { display: grid; grid-template-rows: repeat(6, 1fr); gap: 5px; padding: 10px; }
.wordle .row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.wordle .tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  border: 2px solid var(--tile-empty);
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
}
.wordle .tile[data-state="tbd"] { border-color: var(--tile-filled); }
.wordle .tile[data-state="correct"],
.wordle .tile[data-state="present"],
.wordle .tile[data-state="absent"] { border: 0; color: #fff; }
.wordle .tile[data-state="correct"] { background: var(--correct); }
.wordle .tile[data-state="present"] { background: var(--present); }
.wordle .tile[data-state="absent"] { background: var(--absent); }
@keyframes pop { from { transform: scale(0.8); opacity: 0; } 40% { transform: scale(1.1); opacity: 1; } }
.wordle .tile.pop { animation: pop 0.1s; }
@keyframes flip-in { from { transform: rotateX(0); } to { transform: rotateX(-90deg); } }
@keyframes flip-out { from { transform: rotateX(-90deg); } to { transform: rotateX(0); } }
.wordle .tile.flip-in { animation: flip-in 175ms ease-in forwards; }
.wordle .tile.flip-out { animation: flip-out 175ms ease-in; }
@keyframes bounce {
  0%, 20% { transform: translateY(0); }
  40% { transform: translateY(-30px); }
  50% { transform: translateY(5px); }
  60% { transform: translateY(-15px); }
  80% { transform: translateY(2px); }
  100% { transform: translateY(0); }
}
.wordle .tile.bounce { animation: bounce 1s; }
.wordle .retry { margin: 4px 0 12px; }
.wordle .keyboard { width: 100%; max-width: 500px; margin-top: 12px; user-select: none; }
.wordle .keys { display: flex; margin: 0 auto 8px; touch-action: manipulation; }
.wordle .spacer { flex: 0.5; }
.wordle .key {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  height: 58px;
  margin-right: 6px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: var(--key);
  color: #1a1a1b;
  font-size: 20px;
  font-weight: 700;
  text-transform: uppercase;
}
.wordle .key:last-child { margin-right: 0; }
.wordle .key.wide { flex: 1.5; font-size: 12px; }
.wordle .key[data-state="correct"] { background: var(--correct); color: #fff; }
.wordle .key[data-state="present"] { background: var(--present); color: #fff; }
.wordle .key[data-state="absent"] { background: var(--absent); color: #fff; }

/* ---------- Connections ---------- */
.connections { max-width: 624px; margin: 0 auto; text-align: center; }
.connections .subtitle { margin: 12px 0 20px; font-size: 18px; font-weight: 400; }
.connections .grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.connections .card {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 80px;
  padding: 0 4px;
  border: 0;
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
  text-transform: uppercase;
  word-break: break-word;
  user-select: none;
  transition: background 0.15s, color 0.15s;
}
.connections .card.long { font-size: 15px; }
.connections .card.selected { background: var(--card-selected); color: #f8f8f8; }
@keyframes hop { 50% { transform: translateY(-6px); } }
.connections .card.hop { animation: hop 0.25s; }
.connections .solved {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 80px;
  border-radius: 6px;
  text-transform: uppercase;
}
.connections .solved.reveal { animation: pop 0.35s; }
.connections .solved h3 { margin: 0 0 2px; font-size: 20px; font-weight: 700; }
.connections .solved p { margin: 0; font-size: 20px; font-weight: 400; }
.connections .solved.yellow { background: var(--yellow); }
.connections .solved.green { background: var(--green); }
.connections .solved.blue { background: var(--blue); }
.connections .solved.purple { background: var(--purple); }
.connections .mistakes { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 24px 0; font-size: 16px; }
.connections .dots { display: inline-flex; gap: 10px; }
.connections .dot { width: 16px; height: 16px; border-radius: 50%; background: var(--card-selected); transition: transform 0.3s, opacity 0.3s; }
.connections .dot.used { transform: scale(0); opacity: 0; }
.connections .controls { display: flex; justify-content: center; gap: 8px; }
.connections .retry { margin-top: 24px; }

@media (max-width: 520px) {
  .connections .grid { gap: 6px; }
  .connections .card { height: 72px; font-size: 16px; }
  .connections .card.long { font-size: 12px; }
  .connections .solved h3, .connections .solved p { font-size: 16px; }
  .wordle .tile { width: 52px; height: 52px; font-size: 28px; }
}

/* ---------- Final ---------- */
.final { max-width: 480px; margin: 0 auto; text-align: center; }
.final h2 { margin: 24px 0 8px; font-size: 28px; }
.final .cmd {
  display: inline-block;
  margin: 8px 0 24px;
  padding: 12px 18px;
  border-radius: 8px;
  background: #121212;
  color: #7CFC9A;
  font: 16px/1.4 ui-monospace, "SF Mono", Menlo, monospace;
  text-align: left;
}
.final .cmd code::before { content: "$ "; color: #8b8b8b; }
.final .flag { display: flex; gap: 8px; justify-content: center; }
.final .flag input {
  flex: 1;
  max-width: 320px;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  font: 16px ui-monospace, "SF Mono", Menlo, monospace;
}
.final .victory .big { font-size: 28px; font-weight: 800; margin: 16px 0 8px; }
