/* Adder's Connections — shared styles for the landing page and the board.
 *
 * Dark by default with a warm-paper light theme; the four difficulty colours
 * (teal / apricot / periwinkle / orchid) are deliberately not the NYT set.
 */

:root {
  color-scheme: dark;

  --level-0: #45c4a8;
  --level-1: #f0a05a;
  --level-2: #7c8cf8;
  --level-3: #b57be8;

  --bg: #13111c;
  --bg-glow-a: #2b2150;
  --bg-glow-b: #123a41;
  --surface: #1d1a29;
  --surface-2: #262236;
  --tile: #2f2a41;
  --tile-hover: #3a3450;
  /* Selection inverts the tile so it can never be mistaken for a solved row. */
  --tile-selected: #f1ecff;
  --tile-selected-ink: #17131f;
  --ink: #f2eeff;
  --ink-dim: #b3aacd;
  --ink-faint: #7d7597;
  --line: #37314c;
  --band-ink: #14111e;
  --shadow: 0 2px 0 rgba(0, 0, 0, 0.45), 0 8px 22px rgba(0, 0, 0, 0.3);

  --display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif;

  --tile-h: clamp(62px, 15.5vw, 86px);
  --gap: clamp(6px, 1.6vw, 10px);
  --radius: 12px;
}

:root[data-theme="light"] {
  color-scheme: light;

  --level-0: #21a189;
  --level-1: #e08b3c;
  --level-2: #6373e6;
  --level-3: #9d5cd6;

  --bg: #f6f1e6;
  --bg-glow-a: #e8dcc6;
  --bg-glow-b: #d9e7e2;
  --surface: #fffaf1;
  --surface-2: #f1e9da;
  --tile: #ece3d2;
  --tile-hover: #e2d7c1;
  --tile-selected: #2c2438;
  --tile-selected-ink: #f8f3e8;
  --ink: #241f18;
  --ink-dim: #5f574a;
  --ink-faint: #8c8474;
  --line: #ddd1ba;
  --band-ink: #17140f;
  --shadow: 0 2px 0 rgba(120, 100, 70, 0.18), 0 8px 20px rgba(120, 100, 70, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  position: relative;
  overflow-x: hidden;
}

/* Slow-drifting aurora wash + faint grain: the page's main signature. */
body::before {
  content: "";
  position: fixed;
  inset: -30vmax;
  z-index: -2;
  background: radial-gradient(38vmax 38vmax at 22% 18%, var(--bg-glow-a), transparent 62%),
    radial-gradient(42vmax 42vmax at 82% 78%, var(--bg-glow-b), transparent 62%);
  opacity: 0.75;
  animation: drift 34s ease-in-out infinite alternate;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

@keyframes drift {
  from {
    transform: translate3d(-2%, -1%, 0) scale(1);
  }
  to {
    transform: translate3d(3%, 2%, 0) scale(1.08);
  }
}

.wrap {
  width: min(660px, 100% - 2rem);
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem) 0 3rem;
}

/* ------------------------------------------------------------- site head */

.site-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 0.5rem;
}

.mark {
  width: 34px;
  height: 34px;
  flex: none;
  color: var(--level-0);
}

.site-name {
  font-family: var(--display);
  font-size: clamp(1.35rem, 4.4vw, 1.9rem);
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
  line-height: 1.1;
}

.site-name .amp {
  font-style: italic;
  color: var(--level-1);
}

.head-spacer {
  flex: 1;
}

.icon-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-dim);
  border-radius: 999px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s, transform 0.15s;
}

.icon-btn:hover {
  color: var(--ink);
  border-color: var(--ink-faint);
  transform: translateY(-1px);
}

.rule {
  height: 2px;
  border: 0;
  margin: 0.4rem 0 1.4rem;
  background: linear-gradient(
    90deg,
    var(--level-0),
    var(--level-1),
    var(--level-2),
    var(--level-3)
  );
  opacity: 0.85;
  border-radius: 2px;
}

/* ---------------------------------------------------------- puzzle head */

.puzzle-head {
  text-align: center;
  margin-bottom: 1.25rem;
}

.puzzle-title {
  font-family: var(--display);
  font-size: clamp(1.7rem, 6vw, 2.6rem);
  margin: 0 0 0.2rem;
  line-height: 1.05;
  letter-spacing: -0.01em;
}

.puzzle-date {
  margin: 0;
  color: var(--ink-faint);
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.instruction {
  margin: 1rem 0 0.9rem;
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.95rem;
}

/* ---------------------------------------------------------------- board */

#board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: var(--tile-h);
  gap: var(--gap);
  margin: 0 auto;
}

.tile {
  position: relative;
  border: 0;
  border-radius: var(--radius);
  background: var(--tile);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 700;
  font-size: clamp(0.72rem, 2.9vw, 1rem);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0.25rem;
  display: grid;
  place-items: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 2px 0 rgba(0, 0, 0, 0.35);
  transition: background 0.15s, transform 0.12s, box-shadow 0.12s, color 0.15s;
  overflow: hidden;
}

:root[data-theme="light"] .tile {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 2px 0 rgba(150, 130, 95, 0.35);
}

.tile:hover:not(:disabled) {
  background: var(--tile-hover);
}

.tile:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.tile:focus-visible {
  outline: 3px solid var(--level-2);
  outline-offset: 2px;
}

.tile.selected {
  background: var(--tile-selected);
  color: var(--tile-selected-ink);
  transform: translateY(2px);
  box-shadow: inset 0 0 0 2px var(--tile-selected), 0 0 0 2px var(--level-2);
}

.tile.selected:hover:not(:disabled) {
  background: var(--tile-selected);
}

.tile:disabled {
  cursor: default;
}

.tile-text {
  display: block;
  text-align: center;
  line-height: 1.1;
  word-break: break-word;
  hyphens: auto;
}

.tile-text.len-long {
  font-size: 0.92em;
  letter-spacing: 0.01em;
}

.tile-text.len-xlong {
  font-size: 0.8em;
  letter-spacing: 0;
}

/* ---------------------------------------------------------------- bands */

.band {
  grid-column: 1 / -1;
  border-radius: var(--radius);
  display: grid;
  place-content: center;
  text-align: center;
  padding: 0.35rem 0.6rem;
  color: var(--band-ink);
  position: relative;
  overflow: hidden;
}

.band.level-0 {
  background: var(--level-0);
}
.band.level-1 {
  background: var(--level-1);
}
.band.level-2 {
  background: var(--level-2);
}
.band.level-3 {
  background: var(--level-3);
}

.band-name {
  margin: 0;
  font-weight: 800;
  font-size: clamp(0.75rem, 2.8vw, 0.95rem);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.band-words {
  margin: 0.2rem 0 0;
  font-size: clamp(0.78rem, 3vw, 1rem);
  letter-spacing: 0.02em;
}

.band-sheen {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    transparent 35%,
    rgba(255, 255, 255, 0.55) 50%,
    transparent 65%
  );
  transform: translateX(-120%);
  pointer-events: none;
}

.band-enter {
  animation: band-pop 420ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.band-enter .band-sheen {
  animation: sheen 700ms ease-out 120ms;
}

@keyframes band-pop {
  from {
    opacity: 0;
    transform: scale(0.94);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes sheen {
  to {
    transform: translateX(120%);
  }
}

/* ----------------------------------------------------------- animations */

.tile.bounce {
  animation: bounce 320ms ease;
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(2px);
  }
  45% {
    transform: translateY(-12px);
  }
}

.tile.shake {
  animation: shake 400ms ease;
}

@keyframes shake {
  10%,
  50%,
  90% {
    transform: translate(-6px, 2px);
  }
  30%,
  70% {
    transform: translate(6px, 2px);
  }
}

/* ------------------------------------------------------ status & controls */

.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin: 1.15rem 0 0.9rem;
  color: var(--ink-dim);
  font-size: 0.9rem;
  min-height: 1.6rem;
}

#mistake-dots {
  display: inline-flex;
  gap: 0.42rem;
}

.dot {
  width: 13px;
  height: 13px;
  background: var(--ink-dim);
  transform: rotate(45deg);
  border-radius: 3px;
  transition: background 0.3s, opacity 0.3s, transform 0.3s;
}

.dot.spent {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--line);
  opacity: 0.6;
  transform: rotate(45deg) scale(0.72);
}

#controls {
  display: flex;
  justify-content: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

#controls.hidden {
  display: none;
}

.btn {
  font-family: var(--sans);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.62rem 1.15rem;
  border-radius: 999px;
  border: 1.5px solid var(--ink-faint);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.12s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--ink);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 3px solid var(--level-2);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.38;
  cursor: default;
}

.btn-primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.btn-primary:hover:not(:disabled) {
  background: var(--level-0);
  border-color: var(--level-0);
  color: var(--band-ink);
}

.btn-quiet {
  border-color: transparent;
  color: var(--ink-dim);
  text-decoration: none;
  display: inline-grid;
  place-items: center;
}

/* ---------------------------------------------------------------- toast */

.toast-slot {
  height: 2.1rem;
  display: grid;
  place-items: center;
  margin-top: 0.1rem;
}

#toast {
  background: var(--ink);
  color: var(--bg);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ------------------------------------------------------------ end panel */

#end-panel {
  margin-top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.4rem 1.2rem;
  text-align: center;
  box-shadow: var(--shadow);
  animation: rise 400ms ease;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

.end-title {
  font-family: var(--display);
  font-size: 1.7rem;
  margin: 0 0 0.25rem;
}

.end-sub {
  margin: 0 0 0.9rem;
  color: var(--ink-dim);
  font-size: 0.95rem;
}

.share-grid {
  font-size: 1.35rem;
  line-height: 1.35;
  margin: 0 0 1.1rem;
  font-family: var(--sans);
  letter-spacing: 0.08em;
}

.end-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* --------------------------------------------------------------- how-to */

.howto {
  margin: 1.8rem auto 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  padding: 0.2rem 1rem;
}

.howto summary {
  cursor: pointer;
  padding: 0.75rem 0;
  font-weight: 600;
  color: var(--ink-dim);
  list-style: none;
}

.howto summary::-webkit-details-marker {
  display: none;
}

.howto summary::before {
  content: "▸ ";
  color: var(--level-1);
}

.howto[open] summary::before {
  content: "▾ ";
}

.howto ul {
  margin: 0 0 1rem;
  padding-left: 1.1rem;
  color: var(--ink-dim);
  font-size: 0.92rem;
  line-height: 1.65;
}

.legend {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0 0 1rem;
  font-size: 0.82rem;
  color: var(--ink-dim);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  width: 13px;
  height: 13px;
  border-radius: 4px;
  display: inline-block;
}

.swatch.level-0 {
  background: var(--level-0);
}
.swatch.level-1 {
  background: var(--level-1);
}
.swatch.level-2 {
  background: var(--level-2);
}
.swatch.level-3 {
  background: var(--level-3);
}

/* --------------------------------------------------------- landing page */

.puzzle-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.85rem;
}

.puzzle-card .card-link {
  display: block;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.05rem 1.15rem 1.1rem;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.16s, border-color 0.16s;
}

.puzzle-card .card-link:hover,
.puzzle-card .card-link:focus-visible {
  transform: translateY(-2px);
  border-color: var(--ink-faint);
}

.card-swatches {
  display: flex;
  gap: 4px;
  margin-bottom: 0.55rem;
}

.card-title {
  display: block;
  font-family: var(--display);
  font-size: 1.35rem;
  line-height: 1.2;
}

.card-date {
  display: block;
  color: var(--ink-faint);
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-top: 0.25rem;
}

.card-status {
  display: block;
  margin-top: 0.6rem;
  font-size: 0.82rem;
  color: var(--ink-faint);
  letter-spacing: 0.05em;
}

/* An untouched puzzle has no status line and shouldn't reserve space for one. */
.card-status:empty {
  display: none;
}

.card-status.done {
  color: var(--level-0);
}

.puzzle-card.empty {
  color: var(--ink-dim);
  padding: 1rem;
  border: 1px dashed var(--line);
  border-radius: 14px;
}

/* ---------------------------------------------------------------- misc */

.crumbs {
  margin-bottom: 0.9rem;
  font-size: 0.86rem;
}

.crumbs a {
  color: var(--ink-faint);
  text-decoration: none;
}

.crumbs a:hover {
  color: var(--ink);
}

.site-foot {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-size: 0.8rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-foot a {
  color: var(--ink-faint);
}

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

@media (max-width: 380px) {
  .band-words {
    font-size: 0.74rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  body::before {
    animation: none;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
