/* ==========================================================================
   P5R Companion — shared design system.
   Loud frame, calm content: the drama lives in titles, headers, buttons and
   feedback; data areas stay level, high-contrast, scannable. Dark-only.
   ========================================================================== */

/* ---- Tokens ------------------------------------------------------------- */

:root {
  /* Owner palette (fixed) */
  --ink: #0d0d0d;
  --blood: #d92323;
  --maroon: #732424;
  --smoke: #7b7b7b;
  --paper: #ffffff;

  /* Derived surfaces — one step, never a rainbow of grays */
  --panel: #131313;
  --panel-2: #1a1a1a;
  --line: #2a2a2a;
  --line-strong: #3d3d3d;
  /* Secondary text that still clears 4.5:1 on --panel */
  --smoke-lift: #8f8f8f;

  /* Type scale — fixed rem, ~1.2 ratio (product register) */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;
  --text-2xl: 2rem;
  --text-title: 2.75rem;

  /* Spacing — 4pt scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;

  /* Motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-swift: cubic-bezier(0.16, 1, 0.3, 1);
  --t-fast: 120ms;
  --t-med: 220ms;
  --t-slow: 380ms;

  /* Signature geometry */
  --slant: -8deg;

  /* Z scale */
  --z-strip: 20;
  --z-panel-backdrop: 30;
  --z-panel: 40;
}

/* ---- Base ---------------------------------------------------------------- */

* { margin: 0; padding: 0; box-sizing: border-box; }

html { color-scheme: dark; }

body {
  background: var(--ink);
  color: var(--paper);
  font-family: "Arsenal", "Segoe UI", sans-serif;
  font-size: var(--text-base);
  /* Light-on-dark compensation: looser leading, whisper of tracking */
  line-height: 1.6;
  letter-spacing: 0.01em;
  font-kerning: normal;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

.wrap {
  width: 100%;
  max-width: 64rem;
  margin-inline: auto;
  padding-inline: var(--space-5);
}

p { max-width: 70ch; text-wrap: pretty; }

a { color: var(--paper); text-decoration-color: var(--blood); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { color: var(--blood); }

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

::selection { background: var(--blood); color: var(--paper); }

.muted { color: var(--smoke-lift); }

/* Screen-reader-only helper */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ---- Halftone band --------------------------------------------------------
   The game's dot-print texture, in pure code. Frame-only: page heads and
   hero bands, never behind working data. */

.halftone {
  position: relative;
  isolation: isolate;
}
.halftone::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(circle, rgba(217, 35, 35, 0.16) 1px, transparent 1.6px);
  background-size: 11px 11px;
  -webkit-mask-image: linear-gradient(105deg, rgba(0,0,0,0.9), transparent 62%);
          mask-image: linear-gradient(105deg, rgba(0,0,0,0.9), transparent 62%);
}

/* ---- Ransom-note title -----------------------------------------------------
   One per page. JS (P5RUI.ransomize) splits the text into letters and deals
   each a cut-out style; these classes are the deck it deals from. */

.ransom {
  font-size: var(--text-title);
  line-height: 1.15;
  font-weight: 700;
  text-transform: uppercase;
  text-wrap: balance;
}
.ransom .word { display: inline-block; white-space: nowrap; margin-right: 0.28em; }
.ransom .word:last-child { margin-right: 0; }
.ransom b {
  display: inline-block;
  font-weight: 700;
  font-style: normal;
  padding: 0.01em 0.09em;
  margin-right: 0.015em;
  font-size: calc(var(--fs, 1) * 1em);
  transform: rotate(var(--rot, 0deg)) translateY(var(--ty, 0));
}
/* The deck: paper/ink/blood cut-outs in three typefaces */
.ransom .r0 { background: var(--paper); color: var(--ink); }
.ransom .r1 { background: var(--blood); color: var(--paper); }
.ransom .r2 { background: var(--ink); color: var(--paper); box-shadow: 0 0 0 2px var(--paper); }
.ransom .r3 { background: var(--paper); color: var(--blood); font-family: "Alfa Slab One", "Arsenal", serif; font-weight: 400; }
.ransom .r4 { background: var(--ink); color: var(--paper); box-shadow: 0 0 0 2px var(--paper); font-family: "Times New Roman", Times, serif; font-style: italic; }
.ransom .r5 { background: var(--blood); color: var(--ink); font-family: "Alfa Slab One", "Arsenal", serif; font-weight: 400; }

/* ---- Page head (the loud frame) ------------------------------------------ */

.page-head {
  padding: var(--space-7) 0 var(--space-6);
  border-bottom: 3px solid var(--blood);
  transform: skewY(-1.2deg);
  transform-origin: left;
  margin-bottom: var(--space-6);
}
.page-head > .wrap { transform: skewY(1.2deg); }
.page-head .tagline {
  color: var(--smoke-lift);
  margin-top: var(--space-3);
  font-size: var(--text-lg);
  font-style: italic;
}

/* ---- Section heading: red slash, no eyebrows ------------------------------ */

.sec-h {
  font-size: var(--text-xl);
  font-weight: 700;
  font-style: italic;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.sec-h::before {
  content: "";
  width: 0.55em;
  height: 1.1em;
  background: var(--blood);
  transform: skewX(var(--slant));
  flex: none;
}

section + section { margin-top: var(--space-8); }

/* ---- Tool strip ------------------------------------------------------------
   The slim shared bar on every tool page: back to menu, tool name,
   completion counter, save badge. Condenses on scroll. */

.tool-strip {
  position: sticky;
  top: 0;
  z-index: var(--z-strip);
  background: var(--ink);
  border-bottom: 2px solid var(--blood);
}
.tool-strip .wrap {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding-block: var(--space-4);
  transition: padding-block var(--t-med) var(--ease-out);
}
.tool-strip.is-condensed .wrap { padding-block: var(--space-2); }

.strip-back {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  font-style: italic;
  text-transform: uppercase;
  font-size: var(--text-sm);
  letter-spacing: 0.06em;
  color: var(--paper);
  text-decoration: none;
  padding: var(--space-1) var(--space-2);
}
.strip-back::before {
  content: "";
  width: 0.55em;
  height: 0.9em;
  background: var(--blood);
  clip-path: polygon(100% 0, 0 50%, 100% 100%);
  transition: transform var(--t-fast) var(--ease-out);
}
.strip-back:hover { color: var(--blood); }
.strip-back:hover::before { transform: translateX(-3px); }

.strip-title {
  font-size: var(--text-lg);
  font-weight: 700;
  font-style: italic;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.strip-spacer { flex: 1; }

/* ---- Completion counter ---------------------------------------------------- */

.counter {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: var(--text-lg);
  white-space: nowrap;
}
.counter .slash {
  color: var(--blood);
  font-style: italic;
  padding-inline: 0.12em;
}
.counter .total { color: var(--smoke-lift); font-weight: 400; }

/* ---- Buttons ---------------------------------------------------------------
   The P5R parallelogram. Outer element carries the slant, inner span
   counter-slants so the label stays level. */

.btn {
  display: inline-block;
  border: none;
  font: inherit;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: var(--text-sm);
  cursor: pointer;
  padding: 0.55em 1.3em;
  transform: skewX(var(--slant));
  background: var(--blood);
  color: var(--paper);
  text-decoration: none;
  transition: background var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out), transform var(--t-fast) var(--ease-out);
}
.btn > span { display: inline-block; transform: skewX(calc(-1 * var(--slant))); }
.btn:hover { background: var(--paper); color: var(--ink); }
.btn:active { transform: skewX(var(--slant)) scale(0.96); }
.btn:disabled {
  background: var(--panel-2);
  color: var(--smoke);
  cursor: not-allowed;
}
.btn:disabled:active { transform: skewX(var(--slant)); }

.btn--ghost {
  background: transparent;
  color: var(--paper);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.btn--ghost:hover {
  background: transparent;
  color: var(--blood);
  box-shadow: inset 0 0 0 1px var(--blood);
}

.btn--sm { font-size: var(--text-xs); padding: 0.45em 1em; }

/* ---- Filter bar & chips ----------------------------------------------------- */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

.chip {
  border: none;
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  padding: 0.4em 0.95em;
  transform: skewX(var(--slant));
  background: transparent;
  color: var(--smoke-lift);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  transition: background var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out), box-shadow var(--t-fast) var(--ease-out);
}
.chip > span { display: inline-block; transform: skewX(calc(-1 * var(--slant))); }
.chip:hover { color: var(--paper); box-shadow: inset 0 0 0 1px var(--paper); }
.chip[aria-pressed="true"] {
  background: var(--blood);
  color: var(--paper);
  box-shadow: none;
}

.field {
  font: inherit;
  font-size: var(--text-sm);
  color: var(--paper);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  padding: 0.5em 0.8em;
  min-width: 12rem;
  transition: border-color var(--t-fast) var(--ease-out);
}
.field::placeholder { color: var(--smoke-lift); opacity: 1; }
.field:focus { border-color: var(--blood); outline: none; }
.field:focus-visible { outline: 2px solid var(--paper); outline-offset: 2px; }

/* ---- Tags (status labels) ---------------------------------------------------- */

.tag {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.2em 0.7em;
  transform: skewX(var(--slant));
  background: var(--panel-2);
  color: var(--smoke-lift);
}
.tag > span { display: inline-block; transform: skewX(calc(-1 * var(--slant))); }
.tag--live { background: var(--blood); color: var(--paper); }

/* ---- Data table (the calm content) ------------------------------------------- */

.table-scroll { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}
.data-table th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--smoke-lift);
  padding: var(--space-2) var(--space-3);
  border-bottom: 2px solid var(--line-strong);
  white-space: nowrap;
}
.data-table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.data-table tbody tr:hover { background: var(--panel); }
.data-table .num { text-align: right; }

/* ---- Checklist row ------------------------------------------------------------ */

.check-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-2);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  -webkit-user-select: none;
          user-select: none;
}
.check-row:hover { background: var(--panel); }

.check-row input[type="checkbox"] {
  appearance: none;
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--smoke);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-content: center;
  transition: border-color var(--t-fast) var(--ease-out), background var(--t-fast) var(--ease-out);
}
.check-row input[type="checkbox"]::before {
  content: "";
  width: 0.65rem;
  height: 0.65rem;
  background: var(--paper);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
  transform: scale(0);
  transition: transform var(--t-fast) var(--ease-swift);
}
.check-row input[type="checkbox"]:checked {
  border-color: var(--blood);
  background: var(--blood);
}
.check-row input[type="checkbox"]:checked::before { transform: scale(1); }
.check-row input[type="checkbox"]:focus-visible { outline: 2px solid var(--paper); outline-offset: 3px; }

.check-label { position: relative; }
.check-label::after {
  content: "";
  position: absolute;
  left: -2%;
  right: -2%;
  top: 52%;
  height: 2px;
  background: var(--blood);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform var(--t-med) var(--ease-swift);
}
.check-row.is-done .check-label { color: var(--smoke-lift); }
.check-row.is-done .check-label::after { transform: scaleX(1); }

/* ---- Save badge ----------------------------------------------------------------- */

.save-badge {
  border: none;
  font: inherit;
  background: transparent;
  color: var(--smoke-lift);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: var(--space-2) var(--space-2);
}
.save-badge:hover { color: var(--paper); }

.save-badge .dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--smoke);
  flex: none;
}
.save-badge[data-state="synced"] .dot { background: var(--smoke); }
.save-badge[data-state="syncing"] .dot {
  background: var(--blood);
  animation: badge-pulse 0.9s var(--ease-out) infinite;
}
.save-badge[data-state="offline"] .dot {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--smoke);
}
.save-badge[data-state="problem"] { color: var(--blood); }
.save-badge[data-state="problem"] .dot { background: var(--blood); }

@keyframes badge-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.45); opacity: 0.55; }
}

/* ---- Save panel (tap the badge) --------------------------------------------------- */

.save-panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-panel-backdrop);
  background: rgba(13, 13, 13, 0.6);
}

.save-panel {
  position: fixed;
  top: 4rem;
  right: var(--space-5);
  z-index: var(--z-panel);
  width: min(22rem, calc(100vw - 2 * var(--space-5)));
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-top: 3px solid var(--blood);
  padding: var(--space-5);
}
.save-panel .panel-close {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  border: none;
  background: transparent;
  color: var(--smoke-lift);
  font: inherit;
  font-size: var(--text-lg);
  line-height: 1;
  cursor: pointer;
  padding: var(--space-2) var(--space-3);
}
.save-panel .panel-close:hover { color: var(--blood); }
.save-panel h2 {
  font-size: var(--text-base);
  font-weight: 700;
  font-style: italic;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-3);
}
.save-panel .panel-status { font-size: var(--text-sm); margin-bottom: var(--space-2); }
.save-panel .panel-time { font-size: var(--text-xs); color: var(--smoke-lift); margin-bottom: var(--space-4); }
.save-panel .panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  border-top: 1px solid var(--line);
  padding-top: var(--space-4);
}
.save-panel .panel-pass { margin-bottom: var(--space-4); display: flex; gap: var(--space-2); flex-wrap: wrap; }
.save-panel .panel-pass .field { flex: 1; min-width: 9rem; }

/* ---- Footer ------------------------------------------------------------------------ */

.site-footer {
  margin-top: var(--space-8);
  border-top: 1px solid var(--line);
  padding: var(--space-5) 0;
  color: var(--smoke-lift);
  font-size: var(--text-sm);
  line-height: 1.7;
}
.site-footer a { color: var(--smoke-lift); }
.site-footer a:hover { color: var(--blood); }

/* ---- Entrance staging ----------------------------------------------------------------
   Content is visible by default; JS only animates FROM offsets when GSAP is
   present and motion is allowed. Nothing is gated on a class. */

/* ---- Mobile ---------------------------------------------------------------------------- */

@media (max-width: 640px) {
  :root { --text-title: 2rem; }
  .wrap { padding-inline: var(--space-4); }
  .page-head { padding: var(--space-6) 0 var(--space-5); }
  .strip-title { font-size: var(--text-base); }
  .counter { font-size: var(--text-base); }
  /* Hide the label visually but keep the link's accessible name */
  .strip-back .strip-back-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .save-panel { right: var(--space-4); }
}

/* ---- Touch ergonomics: one-thumb phone use mid-game ------------------------------------- */

@media (pointer: coarse) {
  .chip,
  .save-badge,
  .btn--sm,
  .panel-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
  }
}

/* ---- Reduced motion --------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
