/* The Dotlace look: velvet plum, gold thread, ivory laces.
   Change a colour here and it changes everywhere. */

:root {
  color-scheme: dark;

  /* Surfaces */
  --velvet: #17102a;      /* page */
  --velvet-glow: #2f1d52; /* soft light at the top of the page */
  --panel: #231839;       /* cards and the board */
  --panel-edge: #47346b;

  /* Text */
  --ivory: #f7f0e3;
  --muted: #bbaed2;

  /* Accents */
  --gold: #f4be55;
  --emerald: #12875f;
  --emerald-light: #5fdcae;
  --ruby: #d9304f;
  --ruby-light: #ff8a9e;
  --lilac: #c49bff;

  /* One colour per loop, so separate loops are easy to tell apart. */
  --loop-0: var(--gold);
  --loop-1: #4fd1d9;
  --loop-2: #ff8a6b;
  --loop-3: var(--lilac);
  --loop-4: #8be28b;
  --loop-5: #ff7eb6;

  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(120% 480px at 50% 0, var(--velvet-glow), transparent) no-repeat,
    var(--velvet);
  color: var(--ivory);
  font-family: var(--sans);
  line-height: 1.45;
}

header,
main {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 16px;
}

main {
  padding-bottom: 32px;
}

/* The hidden attribute must win over any display rule below. */
[hidden] {
  display: none !important;
}

a {
  color: inherit;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sound-toggle {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 20px 0 12px;
  font-family: var(--serif);
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand a {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.error {
  padding: 12px;
  border: 1px solid var(--ruby-light);
  border-radius: 12px;
  color: var(--ruby-light);
}

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

.tagline {
  margin: 0 0 8px;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 1.15rem;
}

.new-here {
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid var(--lilac);
  border-radius: 14px;
  background: var(--panel);
}

.new-here p {
  margin: 4px 0 12px;
  color: var(--muted);
}

.new-here .button {
  width: 100%;
}

.today-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 2px 12px;
  margin-top: 16px;
  padding: 16px 18px;
  border-radius: 14px;
  background: var(--gold);
  color: var(--velvet);
  text-decoration: none;
}

.today-card small {
  grid-column: 1 / -1;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.today-card strong {
  font-family: var(--serif);
  font-size: 1.7rem;
  line-height: 1.15;
}

.today-card span {
  font-weight: 700;
  text-transform: capitalize;
}

.today-card em {
  grid-column: 1 / -1;
  margin-top: 4px;
  font-size: 0.9rem;
  font-style: normal;
  font-weight: 600;
}

.mark {
  margin-right: 6px;
  color: var(--gold);
}

.mark:empty {
  display: none;
}

.menu-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

/* ---- past puzzles -------------------------------------------------------- */

.archive-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.archive-list a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--panel-edge);
  border-left: 3px solid var(--accent);
  border-radius: 12px;
  background: var(--panel);
  font-weight: 600;
  text-decoration: none;
}

.archive-list small {
  color: var(--accent);
  font-weight: 600;
  text-transform: capitalize;
}

.level-easy { --accent: var(--emerald-light); }
.level-medium { --accent: var(--gold); }
.level-hard { --accent: var(--ruby-light); }

.menu-group {
  --accent: var(--gold);
}

.group-tutorial { --accent: var(--lilac); }
.group-easy { --accent: var(--emerald-light); }
.group-medium { --accent: var(--gold); }
.group-hard { --accent: var(--ruby-light); }

.menu-group h2 {
  margin: 28px 0 12px;
  color: var(--accent);
  font-family: var(--serif);
  font-size: 1.3rem;
}

.menu-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.menu-list a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-height: 52px;
  padding: 14px;
  border: 1px solid var(--panel-edge);
  border-left: 3px solid var(--accent);
  border-radius: 12px;
  background: var(--panel);
  font-weight: 600;
  text-decoration: none;
}

.menu-list small {
  color: var(--muted);
  font-weight: 400;
  white-space: nowrap;
}

@media (hover: hover) {
  .menu-list a:hover {
    border-color: var(--accent);
  }
}

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

.back {
  display: inline-block;
  padding: 4px 0;
  color: var(--muted);
  text-decoration: none;
}

.puzzle-title {
  margin: 4px 0;
  font-family: var(--serif);
  font-size: 1.5rem;
}

.how-to {
  margin: 4px 0 14px;
  color: var(--muted);
  font-size: 0.95rem;
}

/* The lesson panel. Its height is held so the board doesn't jump as the text
   changes from step to step. */
.coach {
  min-height: 8.9em;
  margin: 4px 0 12px;
  padding: 10px 14px;
  border: 1px solid var(--panel-edge);
  border-left: 3px solid var(--lilac);
  border-radius: 12px;
  background: var(--panel);
}

.coach small {
  color: var(--lilac);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.coach p {
  margin: 4px 0 0;
}

.coach.nudge {
  animation: nudge 0.35s ease-in-out;
}

@keyframes nudge {
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat {
  padding: 8px 14px;
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  background: var(--panel);
}

.stat strong {
  display: block;
  font-family: var(--serif);
  font-size: 1.5rem;
  line-height: 1.2;
  white-space: nowrap; /* "25 of 25" stays on one line on small phones */
}

.stat span {
  color: var(--muted);
  font-size: 0.85rem;
}

.stat.good {
  border-color: var(--emerald-light);
}

.stat.good strong {
  color: var(--emerald-light);
}

.message {
  min-height: 28px; /* stops the board jumping when a message appears */
  margin: 10px 0;
  color: var(--ruby-light);
  font-weight: 600;
}

.message.solved {
  color: var(--gold);
  font-family: var(--serif);
  font-size: 1.1rem;
}

#board {
  display: block;
  width: 100%;
  height: auto;
  max-height: 85vh;
  margin: 0 auto;
  touch-action: manipulation; /* no double-tap zoom while lacing quickly */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.frame {
  fill: var(--panel);
  stroke: var(--panel-edge);
  stroke-width: 0.04;
}

.loop,
.loop-glow {
  fill: none;
  stroke-linejoin: round;
}

.loop {
  stroke-width: 0.11;
}

.loop-glow {
  stroke-width: 0.32;
  stroke-opacity: 0.16;
}

.colour-0 { stroke: var(--loop-0); }
.colour-1 { stroke: var(--loop-1); }
.colour-2 { stroke: var(--loop-2); }
.colour-3 { stroke: var(--loop-3); }
.colour-4 { stroke: var(--loop-4); }
.colour-5 { stroke: var(--loop-5); }

.lace {
  stroke: var(--ivory);
  stroke-width: 0.2;
  stroke-linecap: round;
}

.plain-dot {
  fill: var(--ivory);
}

.clue-dot {
  stroke-width: 0.06;
}

.clue-text {
  font-size: 62px; /* game.js shrinks this to fit the board */
  font-weight: 700;
  text-anchor: middle;
  fill: var(--ivory);
}

/* A clue has three states: not enough laces yet, exact, or too many.
   "Too many" also gets a broken ring, so it doesn't rely on colour alone. */
.clue-under .clue-dot { fill: var(--velvet); stroke: var(--muted); }

.clue-ok .clue-dot { fill: var(--emerald); stroke: var(--emerald-light); }

.clue-over .clue-dot {
  fill: var(--ruby);
  stroke: var(--ivory);
  stroke-dasharray: 0.16 0.1;
}

/* Lesson hints: a glowing lace to tap, and rings around dots. Taps pass
   straight through them to the gap underneath. */
.hint-lace,
.hint-dot {
  pointer-events: none;
  animation: hint-glow 1.1s ease-in-out infinite alternate;
}

.hint-lace {
  stroke: var(--lilac);
  stroke-width: 0.26;
  stroke-linecap: round;
}

.hint-dot {
  fill: none;
  stroke: var(--lilac);
  stroke-width: 0.07;
}

@keyframes hint-glow {
  from { opacity: 0.35; }
  to { opacity: 1; }
}

/* Tap areas: invisible until hovered or reached with the keyboard. */
.gap {
  fill: transparent;
  cursor: pointer;
  outline: none;
}

.gap:focus-visible {
  fill: rgba(244, 190, 85, 0.22);
}

@media (hover: hover) {
  .gap:hover {
    fill: rgba(244, 190, 85, 0.12);
  }
}

#board.solved .gap {
  cursor: default;
  fill: transparent;
}

#board.solved .loop-glow {
  stroke-opacity: 0.4;
  animation: thread-glow 1.8s ease-in-out infinite alternate;
}

@keyframes thread-glow {
  to { stroke-opacity: 0.15; }
}

/* ---- the solved moment (see celebrate.js) ------------------------------- */

/* The finished line dims, so the needle can redraw it in bright gold. */
.celebrating .loop {
  stroke-opacity: 0.3;
}

/* pathLength="1" makes the loop's length 1, so a dash of 1 is the whole line
   and moving the offset from 1 to 0 draws it from start to finish. */
.loop-trace,
.loop-needle {
  fill: none;
  stroke-linecap: round;
  animation: trace var(--trace-time) linear both;
}

.loop-trace {
  stroke: var(--gold);
  stroke-width: 0.15;
  stroke-dasharray: 1 1;
}

/* One tiny dash, the same length as a dot, riding at the head of the line. */
.loop-needle {
  stroke: var(--ivory);
  stroke-width: 0.3;
  stroke-dasharray: 0.004 0.996;
}

@keyframes trace {
  from { stroke-dashoffset: 1; }
  to { stroke-dashoffset: 0; }
}

/* A number lights up as the needle passes. --delay is set in celebrate.js. */
.celebrating .clue-ok {
  transform-box: fill-box;
  transform-origin: center;
  animation: clue-pop 0.5s ease-out var(--delay, 0ms) both;
}

.celebrating .clue-ok .clue-dot {
  animation: clue-flash 0.6s ease-out var(--delay, 0ms) both;
}

@keyframes clue-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

@keyframes clue-flash {
  0% { fill: var(--emerald); }
  35% { fill: var(--gold); }
  100% { fill: var(--emerald); }
}

/* Holding the praise back until the loop closes makes it the payoff.
   1.6s matches TRACE_MILLISECONDS in celebrate.js. */
.message.solved {
  animation: praise-in 0.5s ease-out 1.6s both;
}

@keyframes praise-in {
  from { opacity: 0; transform: translateY(6px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

/* The loop closes: the board tightens like a pulled thread. */
.finale #board {
  animation: pulled-tight 0.55s ease-out;
}

@keyframes pulled-tight {
  0% { transform: scale(1); }
  30% { transform: scale(0.965); }
  65% { transform: scale(1.012); }
  100% { transform: scale(1); }
}

.board-wrap {
  position: relative;
  margin: 0 auto;
}

/* The gold seal that stamps down on the corner of the board. */
.seal {
  display: none;
  position: absolute;
  top: -22px;
  right: 8px;
  width: 74px;
  height: 74px;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--velvet);
  border-radius: 50%;
  outline: 4px solid var(--gold);
  background: var(--gold);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  color: var(--velvet);
  font-family: var(--serif);
  font-size: 0.95rem;
  font-style: italic;
  font-weight: 700;
  pointer-events: none;
  transform: rotate(-12deg);
}

/* Gold for a Perfect Lace, ivory for Clean, lilac for Laced. */
.seal-clean {
  outline-color: var(--ivory);
  background: var(--ivory);
}

.seal-laced {
  outline-color: var(--lilac);
  background: var(--lilac);
}

.streak-note {
  margin: 12px 0 0;
  color: var(--gold);
  font-weight: 600;
  text-align: center;
}

.finale .seal {
  display: flex;
  animation: stamp 0.4s cubic-bezier(0.3, 1.5, 0.5, 1) 0.15s both;
}

@keyframes stamp {
  /* 1.3 keeps it inside the screen. Bigger makes the page scroll sideways. */
  from { opacity: 0; transform: rotate(-12deg) scale(1.3); }
  to { opacity: 1; transform: rotate(-12deg) scale(1); }
}

/* The burst floats above the page and never catches a tap. */
#confetti {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.burst-piece {
  position: absolute;
  opacity: 0;
  animation: burst-fly var(--time) cubic-bezier(0.15, 0.6, 0.4, 1) var(--wait) forwards;
}

/* The pieces are the game's own parts: dots, loops and laces. */
.burst-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
}

.burst-ring {
  width: 15px;
  height: 15px;
  border: 2.5px solid currentColor;
  border-radius: 50%;
}

.burst-thread {
  width: 3px;
  height: 20px;
  border-radius: 2px;
  background: currentColor;
}

.burst-gold { color: var(--gold); }
.burst-ivory { color: var(--ivory); }
.burst-lilac { color: var(--lilac); }
.burst-aqua { color: var(--loop-1); }

/* Up and out quickly, then a slow drift down as it fades. */
@keyframes burst-fly {
  0% {
    opacity: 1;
    transform: translate(0, 0) rotate(0deg) scale(0.4);
  }
  35% {
    opacity: 1;
    transform: translate(var(--x), var(--y)) rotate(var(--spin)) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--x), calc(var(--y) + 320px)) rotate(calc(var(--spin) * 2)) scale(1);
  }
}

/* Players whose device asks for less motion see the result without movement. */
@media (prefers-reduced-motion: reduce) {
  #board.solved .loop-glow,
  .hint-lace,
  .hint-dot,
  .coach.nudge,
  .celebrating .clue-ok,
  .celebrating .clue-ok .clue-dot,
  .message.solved,
  .finale #board,
  .finale .seal {
    animation: none;
  }
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 48px;
  padding: 8px 24px;
  border: 1px solid var(--gold);
  border-radius: 12px;
  background: transparent;
  color: var(--gold);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.button.primary {
  background: var(--gold);
  color: var(--velvet);
}

/* A button that looks like a link, for "How to play" and Close. */
.link-button {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--lilac);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

/* ---- How to play --------------------------------------------------------- */

.help {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 16px 18px 20px;
  border: 1px solid var(--panel-edge);
  border-radius: 16px;
  background: var(--velvet);
  color: var(--ivory);
  overscroll-behavior: contain;
}

.help::backdrop {
  background: rgba(10, 6, 20, 0.75);
}

.help-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.help h2 {
  margin: 0;
  outline: none; /* the window puts focus here, so no ring appears on Close */
  font-family: var(--serif);
  font-size: 1.5rem;
}

.help h3 {
  margin: 24px 0 6px;
  color: var(--gold);
  font-family: var(--serif);
  font-size: 1.15rem;
}

.help p {
  margin: 6px 0;
}

.help-goal {
  padding: 12px 14px;
  border-left: 3px solid var(--gold);
  border-radius: 10px;
  background: var(--panel);
}

.help-board {
  display: block;
  width: 100%;
  max-width: 260px;
  height: auto;
  margin: 8px auto;
}

.help-legend {
  display: grid;
  gap: 6px;
  margin: 8px 0;
  padding: 0;
  list-style: none;
}

.help-legend li {
  display: flex;
  align-items: center;
  gap: 10px;
}

.legend-dot {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
}

.legend-under { background: var(--velvet); border: 2px solid var(--muted); }
.legend-ok { background: var(--emerald); border: 2px solid var(--emerald-light); }
.legend-over { background: var(--ruby); border: 2px dashed var(--ivory); }

.help-tips {
  display: grid;
  gap: 8px;
  margin: 6px 0;
  padding-left: 22px;
}

.help .button {
  display: flex;
  width: 100%;
  margin-top: 20px;
}

.button.share {
  flex-basis: 100%;
}

/* Shown only when the browser can't share or copy by itself. */
.share-box {
  margin-top: 12px;
}

.share-box label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.share-box textarea {
  display: block;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ivory);
  font: inherit;
  font-size: 16px; /* smaller text makes iPhones zoom in on the box */
  resize: none;
}
