/* Palette. Light is warm paper and ink; dark is charcoal with soft bone ink.
   --cell is an empty square, --fill a filled one, --mark the x on a marked one,
   --dim the opacity of a clue that is already satisfied. */
:root {
  --paper: #fbf8f2;
  --ink: #2b2a27;
  --muted: #8a867c;
  --line: #ddd6c8;
  --cell: #ffffff;
  --fill: #2b2a27;
  --mark: #b9b3a6;
  --dim: 0.28;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light dark;
}

/* Dark mode follows the system setting. */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171614;
    --ink: #ebe6db;
    --muted: #8f897d;
    --line: #34322e;
    --cell: #211f1c;
    --fill: #e4dccb;
    --mark: #57534b;
    --dim: 0.32;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  transition: background-color 0.4s ease, color 0.4s ease;
}

main {
  max-width: 28rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
  text-align: center;
}

h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.1;
}

.meta, .timer, .status {
  color: var(--muted);
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  margin: 0.4rem 0;
  font-variant-numeric: tabular-nums;
}

.timer { font-size: 1rem; }

.status {
  color: var(--ink);
  font-size: 1.1rem;
  min-height: 1.5em;
}

.status:not(:empty) { animation: rise 0.45s var(--ease) var(--reveal-total, 0ms) both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* The grid: clues sit above the columns and left of the rows. It always fits
   the screen width, so a 10x10 Sunday works on a 390px phone. */
.board {
  display: grid;
  gap: 2px;
  margin: 1rem auto 0.5rem;
  width: 100%;
  max-width: 26rem;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  font-size: clamp(0.6rem, 2.4vw, 0.85rem);
  transition: gap 0.4s var(--ease) var(--reveal-total, 0ms);
}

.clue {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  transition: opacity 0.35s ease, color 0.35s ease;
}

.clue.done { opacity: var(--dim); }

.clue.col {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 0.25rem;
  line-height: 1.25;
}

.clue.row {
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  padding-right: 0.35rem;
  gap: 0.3rem;
}

.cell {
  min-width: 0;
  aspect-ratio: 1;
  background: var(--cell);
  border: 1px solid var(--line);
  border-radius: 3px;
  cursor: pointer;
  transition:
    background-color 0.12s ease,
    border-color 0.12s ease,
    border-radius 0.4s var(--ease),
    transform 0.12s var(--ease);
}

.cell[data-state='filled'] {
  background: var(--fill);
  border-color: var(--fill);
  transform: scale(0.92);
}

.cell[data-state='marked'] {
  background: var(--paper);
  position: relative;
}

.cell[data-state='marked']::before,
.cell[data-state='marked']::after {
  content: '';
  position: absolute;
  left: 22%;
  right: 22%;
  top: 50%;
  height: 1.5px;
  background: var(--mark);
  transform: rotate(45deg);
  transition: opacity 0.3s ease;
}

.cell[data-state='marked']::after { transform: rotate(-45deg); }

/* The reveal (site/js/fx.js): each row settles in turn, then the gridlines
   melt away and the filled squares close up into one picture. */
.board.revealed { gap: 0; }

.board.revealed .clue { opacity: var(--dim); }

.board.revealed .cell {
  cursor: default;
  border-color: transparent;
  border-radius: 0;
  transition:
    background-color 0.4s ease var(--row-delay, 0ms),
    border-color 0.4s ease var(--row-delay, 0ms),
    border-radius 0.4s var(--ease) var(--row-delay, 0ms);
}

.board.revealed .cell:not([data-state='filled']) { background: var(--paper); }

.board.revealed .cell[data-state='marked']::before,
.board.revealed .cell[data-state='marked']::after { opacity: 0; }

.board.revealed .cell[data-state='filled'] {
  transform: none;
  animation: settle 0.42s var(--ease) var(--row-delay, 0ms) both;
}

@keyframes settle {
  0% { transform: scale(0.92); }
  45% { transform: scale(0.7); }
  100% { transform: none; }
}

/* Share (site/js/share-ui.js): appears once the picture is solved. */
.share {
  margin-top: 0.75rem;
  padding: 0.5rem 1.4rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--paper);
  background: var(--ink);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  animation: rise 0.45s var(--ease) var(--reveal-total, 0ms) both;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  margin: 0;
  padding: 0.45rem 1rem;
  color: var(--paper);
  background: var(--ink);
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  transform: translate(-50%, 6px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s var(--ease);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Stats: the header icon opens a native dialog sheet with the history. */
header { position: relative; }

.icon {
  position: absolute;
  top: 0.2rem;
  right: 0;
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  color: var(--ink);
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.icon:hover { background: var(--line); }

#stats-button { top: 0; }

.sheet {
  width: min(22rem, calc(100vw - 2rem));
  padding: 1rem 1.25rem 1.25rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 1rem;
  text-align: left;
}

.sheet::backdrop { background: rgb(0 0 0 / 0.35); }

.sheet header { display: flex; align-items: center; justify-content: space-between; }

.sheet h2 {
  margin: 0.4rem 0 0.2rem;
  font-size: 1.05rem;
  font-weight: 600;
}

#stats-close { position: static; }

.stat {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}

.stat strong { font-variant-numeric: tabular-nums; }

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

.chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 6.5rem;
  margin-top: 0.5rem;
}

.bar {
  flex: 1;
  height: 4%;
  background: var(--line);
  border-radius: 3px 3px 0 0;
}

.bar.solved { background: var(--fill); }

/* Archive: the header icon left of stats, then a calendar per month. */
#archive-button { right: 2.75rem; }

#archive-close { position: static; }

.archive { width: min(22rem, calc(100vw - 2rem)); max-height: 80vh; overflow: auto; }

.month + .month { margin-top: 1rem; }

.month h3 {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.weekday { color: var(--muted); font-size: 0.7rem; text-align: center; }

.day {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 0;
  color: var(--ink);
  font: inherit;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  background: var(--cell);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.day small { font-size: 0.6rem; line-height: 1; color: var(--muted); }

.day.solved { background: var(--line); }

.day:hover, .day:focus-visible { border-color: var(--ink); }

/* Reduced motion: no waves, pops or fades; the finished picture just appears. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
