/* ==========================================================================
   Depart Karl — shared styles (mobile-first).
   Colors, fonts and sizes come from tokens.css.
   ========================================================================== */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  font-size: var(--font-size);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}

/* The crimson puzzle road crossing the page, like on the poster. */
body::before {
  content: "";
  position: fixed;
  left: 50%;
  top: 56%;
  z-index: 0;
  width: 300vmax;
  height: var(--road-width);
  background: url("../img/puzzle-texture.svg") 0 0 / 64px 64px, linear-gradient(var(--road), var(--road));
  box-shadow: 0 5px 0 var(--road-dark), 0 18px 30px rgba(40, 10, 5, 0.25);
  transform: translate(-50%, -50%) rotate(-34deg);
  pointer-events: none;
}
.site-header, main, .site-footer { position: relative; z-index: 1; }

img { max-width: 100%; }
svg.icon { width: 1.25em; height: 1.25em; flex: none; }

h1, h2, h3 { font-family: var(--font-heading); }
h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2.1rem, 7vw, 3.4rem);
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  margin: 0.5rem 0 0.6rem;
}
h2 { font-size: 1.2rem; font-weight: 700; line-height: 1.3; margin: 0 0 0.75rem; }
h3 { font-size: 1.05rem; margin: 1.25rem 0 0.5rem; }

main {
  flex: 1;
  width: 100%;
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.lead { color: var(--muted); font-weight: 500; margin: 0 0 1.25rem; }

/* Home page title: "PUZZLE / the change" */
.hero { margin: 0.5rem 0 0.75rem; }
.hero-eyebrow {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.hero-title { font-size: clamp(3rem, 12vw, 5.5rem); margin: 0.1em 0 0; }
.hero-title span {
  display: block;
  font-size: 0.52em;
  text-transform: none;
  letter-spacing: 0;
}
.muted { color: var(--muted); }
.hint { font-size: 0.875rem; color: var(--muted); margin: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

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

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: var(--radius-small);
  background: var(--accent);
  color: var(--on-accent);
  text-decoration: none;
}
.skip-link:focus { top: 8px; }

/* ---------- Header / navigation ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border-strong);
}

.header-inner {
  max-width: var(--content-w);
  min-height: var(--header-h);
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}

.brand {
  font-family: var(--font-display);
  font-size: 1.5rem;
  line-height: 1;
  text-transform: uppercase;
  color: var(--text);
  text-decoration: none;
}
.brand span { color: var(--accent); }

.site-nav { display: flex; gap: 4px; }
.site-nav a {
  padding: 8px 12px;
  border-radius: 0;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-decoration: none;
}
.site-nav a:hover { color: var(--accent); }
.site-nav a[aria-current="page"] { color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }

.nav-toggle {
  display: none;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

@media (max-width: 720px) {
  .nav-toggle { display: inline-flex; }
  .site-nav { display: none; width: 100%; flex-direction: column; padding-bottom: 12px; }
  .site-nav.open { display: flex; }
  .site-nav a { padding: 12px 4px; border-top: 1px solid var(--border); }
  .site-nav a[aria-current="page"] { box-shadow: inset 3px 0 0 var(--accent); padding-left: 12px; }
}

.site-footer {
  padding: 16px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--bg);
  border-top: 1px solid var(--border-strong);
}
.site-footer p { margin: 0; }
.site-footer .event { margin-bottom: 4px; color: var(--text); font-weight: 600; letter-spacing: 0.04em; }
.site-footer a { color: var(--muted); }

/* ---------- Buttons & form controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
}
.btn:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--border-strong); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover:not(:disabled) { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-small { min-height: 32px; padding: 4px 10px; font-size: 0.75rem; }

/* A <label class="btn"> wrapping a visually hidden file input. */
.file-btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="text"], input[type="email"], input[type="password"], select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input[type="file"] { font: inherit; max-width: 100%; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
}
.toolbar select { width: auto; }
.toolbar .inline { display: inline-flex; align-items: center; gap: 6px; }

.form { display: grid; gap: 14px; max-width: 520px; }
.field { display: grid; gap: 4px; }
.field > span, fieldset legend { font-weight: 600; font-size: 0.925rem; }
fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; }
.radio { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.radio input { margin-top: 5px; }

/* ---------- Cards, notices, loading ---------- */

.card {
  margin: 0 0 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: var(--radius-small);
  background: var(--accent-soft);
  color: var(--accent-soft-text);
}
.notice:empty { display: none; }
.notice-error { background: var(--danger-soft); color: var(--danger); }
.notice-success { background: var(--success-soft); color: var(--success); }

.empty-state {
  padding: 40px 16px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  color: var(--muted);
}
.empty-state.dragover { border-color: var(--accent); background: var(--accent-soft); }

.spinner {
  display: inline-block;
  width: 1.1em;
  height: 1.1em;
  flex: none;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 32px 0; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
  .puzzle-tile, .toast { transition: none !important; }
}

/* ---------- Toasts & dialogs ---------- */

.toast-region {
  position: fixed;
  left: 50%;
  bottom: 16px;
  z-index: 200;
  display: grid;
  gap: 8px;
  width: min(420px, calc(100% - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius-small);
  background: var(--text);
  color: #fff;
  box-shadow: var(--shadow-raised);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast.leaving { opacity: 0; transform: translateY(8px); }

.modal {
  width: min(420px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-raised);
}
.modal::backdrop { background: var(--overlay); }
.modal-body { padding: 20px; }
.modal-body p { margin: 0 0 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* ---------- Puzzle ---------- */

.puzzle { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.puzzle-stats {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--bg);
  display: flex;
  gap: 20px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.puzzle-stats b { color: var(--text); }

.puzzle-board {
  position: relative;
  overflow: hidden;
  background: var(--surface-sunken);
  border-radius: 6px;
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.puzzle-tile {
  position: absolute;
  top: 0;
  left: 0;
  background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
  cursor: grab;
  touch-action: none;
  transition: transform 0.18s ease;
}
.puzzle-tile.selected { z-index: 2; box-shadow: inset 0 0 0 3px var(--accent), inset 0 0 0 5px #fff; }
.puzzle-tile.dragging {
  z-index: 3;
  cursor: grabbing;
  transition: none;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35), inset 0 0 0 2px #fff;
}
.puzzle-board.solved .puzzle-tile { box-shadow: none; cursor: default; }

.puzzle-peek {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.puzzle-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--overlay);
}
.puzzle-overlay .card { max-width: 320px; margin: 0; text-align: center; }
.puzzle-overlay .toolbar { justify-content: center; margin: 12px 0 0; }

/* ---------- Sudoku ---------- */

.sudoku-panel {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  background: var(--sudoku-panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow-raised);
}
.sudoku-panel .toolbar { margin-bottom: 12px; }

.sudoku-stats {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--bg);
  display: flex;
  justify-content: space-between;
  max-width: 480px;
  margin: 0 auto 8px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.sudoku-stats b { color: var(--text); }

.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: #fff;
  border: 2px solid var(--sudoku-box-line);
  user-select: none;
  -webkit-user-select: none;
}

.sudoku-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--sudoku-line);
  border-bottom: 1px solid var(--sudoku-line);
  background: #fff;
  color: var(--sudoku-entry);
  font: inherit;
  font-size: clamp(1.05rem, 5vw, 1.6rem);
  font-weight: 600;
  cursor: pointer;
}
.sudoku-cell:nth-child(9n) { border-right: 0; }
.sudoku-cell:nth-child(n + 73) { border-bottom: 0; }
.sudoku-cell.box-right { border-right: 2px solid var(--sudoku-box-line); }
.sudoku-cell.box-bottom { border-bottom: 2px solid var(--sudoku-box-line); }
.sudoku-cell.given { color: var(--sudoku-given); font-weight: 700; }
.sudoku-cell.peer { background: var(--sudoku-peer); }
.sudoku-cell.same { background: var(--sudoku-same); }
.sudoku-cell.selected { background: var(--sudoku-selected); }
.sudoku-cell.conflict { color: var(--danger); }
.sudoku-cell.wrong { background: var(--sudoku-wrong); }
.sudoku-board.solved .sudoku-cell { background: var(--success-soft); color: var(--success); }

.numpad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  max-width: 480px;
  margin: 12px auto 0;
}
.numpad .btn { min-height: 46px; padding: 0; font-size: 1.2rem; }
.numpad .erase { font-size: 0.95rem; }
@media (min-width: 560px) {
  .numpad { grid-template-columns: repeat(10, 1fr); }
}

.sudoku-message { margin: 12px 0 0; justify-content: center; }

/* ---------- Messages ---------- */

.narrow { max-width: 640px; margin: 0 auto; }

textarea {
  width: 100%;
  min-height: 140px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  resize: vertical;
}

.char-count { margin-top: -8px; text-align: right; font-variant-numeric: tabular-nums; }

.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

.photo-preview { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.photo-preview img { display: block; max-height: 160px; border-radius: var(--radius-small); }

.sent-card { text-align: center; }

.message-list { display: grid; gap: 12px; }

.message-card {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.message-card.unread { border-left: 4px solid var(--accent); }

.message-meta { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); }
.message-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.message-photo {
  justify-self: start;
  padding: 0;
  border: 0;
  border-radius: var(--radius-small);
  overflow: hidden;
  background: var(--surface-sunken);
  cursor: zoom-in;
}
.message-photo img { display: block; max-width: min(260px, 100%); max-height: 200px; object-fit: cover; }

.badge {
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-new { background: var(--accent-soft); color: var(--accent); }

/* Lightbox (full-size photo viewer) */
.lightbox {
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}
.lightbox::backdrop { background: rgba(0, 0, 0, 0.9); }
.lightbox-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 56px 16px 16px;
}
.lightbox img { display: block; max-width: 100%; max-height: calc(100vh - 120px); object-fit: contain; border-radius: 4px; }
.lightbox-caption { margin: 10px 0 0; color: #fff; text-align: center; }
.lightbox-btn {
  position: fixed;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
}
.lightbox-btn:hover { background: rgba(255, 255, 255, 0.28); }
.lightbox-close { top: 12px; right: 12px; }
.lightbox-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.lightbox-next { right: 12px; top: 50%; transform: translateY(-50%); }

/* ---------- Fasicule (flip book) ---------- */

.book-wrap {
  max-width: 1120px;
  margin: 0 auto;
}
.book { margin: 0 auto; }
.book-page {
  overflow: hidden;
  background: var(--surface);
}
.book-page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.book .stf__block { box-shadow: var(--shadow-raised); }

.book-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 18px 0 0;
}
.book-controls .btn { white-space: nowrap; }
.book-count {
  white-space: nowrap;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--bg);
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
