/*
 * styles.css
 * Book-matched design tokens, components and quiet motion. Loaded by every built page. From the accepted prototype
 * (task 002), refined to the mist-blue cover and local Montserrat family for task 010.
 * Contrast pairs are checked by scripts/check-contrast.mjs; keep that list in step with the colors used here.
 */

@import url("./fonts/fonts.css");

/* ---------- Tokens (light default; dark follows the system setting) ---------- */
:root {
  color-scheme: light;
  --color-page: #edf4f7;
  --color-surface: #f8fbfd;
  --color-soft: #dce8ee;
  --color-text: #132f3a;
  --color-muted: #405e6d;
  --color-accent: #234c60;
  --color-accent-hover: #153747;
  --color-on-accent: #f8fbfd;
  --color-border: #607b8a;
  --color-focus: #1d4d65;
  --shadow-card: 0 8px 24px rgb(16 35 31 / 5%);
  --shadow-dialog: 0 24px 80px rgb(0 0 0 / 28%);
  --font-body: "Montserrat", "Segoe UI", system-ui, sans-serif;
  --font-display: "Montserrat", "Segoe UI", system-ui, sans-serif;
  --font-mono: Consolas, monospace;
  --text-xs: 0.8125rem;
  --text-sm: 0.9375rem;
  --text-base: 1rem;
  --text-lg: 1.1875rem;
  --text-xl: 1.5rem;
  --text-title: clamp(2rem, 4.8vw, 3.5rem);
  --leading-body: 1.6;
  --leading-heading: 1.25;
  --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;
  --radius-control: 0.3rem;
  --radius-card: 0.55rem;
  --border-width: 1px;
  --focus-width: 3px;
  --focus-offset: 3px;
  --measure: 62ch;
  --page-width: 60rem;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --color-page: #091c25;
    --color-surface: #102a36;
    --color-soft: #193744;
    --color-text: #e7f1f5;
    --color-muted: #a6c1cd;
    --color-accent: #b1d8eb;
    --color-accent-hover: #d4eaf5;
    --color-on-accent: #102a36;
    --color-border: #6a8c9e;
    --color-focus: #b1d8eb;
    --shadow-card: 0 8px 24px rgb(0 0 0 / 12%);
    --shadow-dialog: 0 24px 80px rgb(0 0 0 / 45%);
  }
}

/* ---------- Base ---------- */
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--color-page);
  color: var(--color-text);
  font: var(--text-base) / var(--leading-body) var(--font-body);
  overflow-wrap: anywhere;
}
button {
  font: inherit;
}
a {
  color: var(--color-accent);
  text-underline-offset: 0.22em;
}
a:hover {
  color: var(--color-accent-hover);
}
:where(a, button):focus-visible {
  outline: var(--focus-width) solid var(--color-focus);
  outline-offset: var(--focus-offset);
}
h1,
h2,
h3,
h4,
h5,
h6 {
  text-wrap: balance;
  text-transform: uppercase;
  overflow-wrap: anywhere;
  font-family: var(--font-display);
  font-weight: 300;
  line-height: 1.2;
  letter-spacing: 0.055em;
}
h1 {
  font-size: var(--text-title);
  line-height: var(--leading-heading);
  letter-spacing: 0.07em;
  margin: 0 0 var(--space-5);
}
h2 {
  font-size: var(--text-xl);
  margin: var(--space-7) 0 var(--space-4);
}
h3 {
  font-size: var(--text-lg);
  margin: var(--space-5) 0 var(--space-2);
}
p,
li {
  max-width: var(--measure);
}
code {
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
}
pre {
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: var(--space-4);
  background: var(--color-soft);
  border-radius: var(--radius-control);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table-scroll {
  overflow-x: auto;
}
th,
td {
  text-align: left;
  vertical-align: top;
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border-width) solid var(--color-border);
}
img {
  max-width: 100%;
  height: auto;
}
.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-4);
  z-index: 10;
  padding: var(--space-3);
  transform: translateY(-180%);
  background: var(--color-surface);
}
.skip-link:focus {
  transform: translateY(0);
}
.page {
  max-width: var(--page-width);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

/* ---------- Header and navigation ---------- */
.site-header {
  padding-block: var(--space-5);
  border-bottom: var(--border-width) solid var(--color-border);
}
.identity {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: min(10.5rem, 100%);
  min-height: 3.25rem;
  max-width: 100%;
  text-decoration: none;
}
.monogram {
  display: grid;
  place-items: center;
  width: 2.75rem;
  min-width: 44px;
  min-height: 44px;
  white-space: nowrap;
  line-height: 1;
  flex-shrink: 0;
  height: 2.75rem;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-control);
  font-family: var(--font-display);
  font-size: var(--text-lg);
}
.identity strong {
  color: var(--color-text);
  font-weight: 500;
}
nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin-top: var(--space-4);
}
nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: var(--text-sm);
  min-width: 44px;
  padding-inline: var(--space-2);
  transform-origin: center;
}
nav a[aria-current] {
  font-weight: 600;
  text-decoration-thickness: 2px;
}
main {
  padding-block: var(--space-7);
}

/* ---------- Cards ---------- */
.eyebrow {
  color: var(--color-accent);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.card {
  padding: var(--space-5);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}
.card-stack {
  display: grid;
  gap: var(--space-3);
  padding: 0;
  list-style: none;
}
.card-stack > li {
  max-width: none;
}
.proof-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2) var(--space-4);
  text-decoration: none;
}
.proof-card strong {
  color: var(--color-text);
  font-size: var(--text-lg);
  font-weight: 500;
}
.proof-card .card-note {
  color: var(--color-muted);
  font-size: var(--text-sm);
  grid-column: 1;
}
.proof-card .arrow {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: center;
  font-size: var(--text-xl);
}
.proof-card:hover {
  border-color: var(--color-accent);
}
.work-card h3 {
  margin: var(--space-3) 0 0;
  font: 300 var(--text-lg) / 1.4 var(--font-display);
  letter-spacing: 0.04em;
}
.work-card .tagline {
  color: var(--color-muted);
  font-size: var(--text-sm);
  margin: var(--space-1) 0 0;
}
.work-card .description {
  margin: var(--space-4) 0 0;
}
.link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--space-5);
}
.text-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-weight: 500;
  min-width: 44px;
  max-width: 100%;
}
.muted {
  color: var(--color-muted);
  font-size: var(--text-sm);
}
.soft-panel {
  margin-top: var(--space-6);
  padding: var(--space-5);
  background: var(--color-soft);
  border-radius: var(--radius-card);
}
.soft-panel h2 {
  margin-top: 0;
}
.placeholder {
  padding: var(--space-4);
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-control);
  color: var(--color-muted);
}

/* ---------- Buttons ---------- */
.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-5);
}
.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 46px;
  min-width: 44px;
  max-width: 100%;
  white-space: nowrap;
  padding: var(--space-3) var(--space-4);
  border: var(--border-width) solid var(--color-accent);
  border-radius: var(--radius-control);
  color: var(--color-on-accent);
  background: var(--color-accent);
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.button:hover {
  color: var(--color-on-accent);
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}
.button.secondary {
  color: var(--color-accent);
  border-color: var(--color-border);
  background: var(--color-surface);
}
.button.secondary:hover {
  color: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}
.button:disabled {
  color: var(--color-muted);
  background: var(--color-surface);
  border-color: var(--color-border);
  cursor: not-allowed;
}
[hidden] {
  display: none !important;
}

/* ---------- Footer ---------- */
.site-footer {
  padding-block: var(--space-6);
  border-top: var(--border-width) solid var(--color-border);
}
.site-footer h2 {
  margin-top: 0;
  font-size: var(--text-lg);
}
.site-footer .footer-note {
  color: var(--color-muted);
  font-size: var(--text-xs);
  margin-top: var(--space-5);
}

/* ---------- Updates dialog ---------- */
dialog {
  width: min(34rem, calc(100% - 2rem));
  max-height: calc(100dvh - 2rem);
  margin: auto;
  padding: var(--space-5);
  overflow-y: auto;
  overflow-wrap: anywhere;
  color: var(--color-text);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-dialog);
}
dialog::backdrop {
  background: rgb(0 0 0 / 62%);
}
.dialog-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  flex-wrap: wrap;
  gap: var(--space-3);
  /* Close stays reachable while long text scrolls on a phone (Trial by Fire v2, chaos tester). */
  position: sticky;
  top: calc(-1 * var(--space-5));
  z-index: 1;
  padding-top: var(--space-5);
  margin-top: calc(-1 * var(--space-5));
  background: var(--color-surface);
}
.dialog-heading h2 {
  margin: 0;
}

/* ---------- Small screens, motion, forced colors ---------- */
@media (max-width: 480px) {
  .page {
    padding-inline: var(--space-4);
  }
  .card,
  .soft-panel {
    padding: var(--space-4);
  }
  main {
    padding-block: var(--space-6);
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}
@media (prefers-reduced-motion: reduce) {
  nav a,
  .card,
  dialog {
    transform: none !important;
  }
  .js .reveal {
    translate: none !important;
  }
}
@media (forced-colors: active) {
  .button,
  .card,
  dialog {
    border-color: ButtonText;
  }
  :where(a, button):focus-visible {
    outline-color: Highlight;
  }
}

/* ---------- Book, screenshots and centered header (tasks 011 and 013) ---------- */
b,
strong,
th {
  font-weight: 600;
}
/* Equal outer tracks keep the title centered even though the controls differ in width. */
.header-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: var(--space-4);
}
.header-row > * {
  min-width: 0;
}
.site-title {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: 0.16em;
  text-align: center;
  text-transform: uppercase;
}
.updates-trigger {
  justify-self: end;
  font-size: var(--text-sm);
  letter-spacing: 0.04em;
  width: max-content;
  min-width: 7rem;
}
/* Reading pages retain their measure; only the portfolio needs room for four cards. */
main.page:has(.work-grid) {
  max-width: 84rem;
}
.work-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-5);
  padding: 0;
  list-style: none;
}
.work-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: none;
  padding: var(--space-4);
}
.work-card .description {
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}
.work-card .link-row {
  margin-top: auto;
  gap: 0 var(--space-3);
}
@media (min-width: 40rem) {
  .work-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (min-width: 60rem) {
  .work-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (min-width: 80rem) {
  .work-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
@media (max-width: 44rem) {
  /* Let whole controls wrap at enlarged text sizes instead of squeezing their labels. */
  .header-row {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: var(--space-3);
  }
  .header-row > .identity,
  .updates-trigger {
    flex-shrink: 0;
  }
  .site-title {
    order: -1;
    flex-basis: 100%;
  }
}
.shot {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0 0 var(--space-5);
  padding: var(--space-2);
  overflow: hidden;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-control);
  background: var(--color-page);
  color: var(--color-text);
  cursor: zoom-in;
}
.shot img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 8 / 5;
  object-fit: contain;
}
.shot:hover,
.shot:focus-visible {
  border-color: var(--color-accent);
}
.book-card {
  display: grid;
  grid-template-columns: minmax(6rem, 9rem) minmax(0, 1fr);
  align-items: center;
  gap: var(--space-6);
  margin-block: var(--space-7);
  padding: var(--space-5);
  background: var(--color-soft);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-card);
}
.book-card > * {
  min-width: 0;
}
.book-cover {
  display: block;
  margin: 0;
  max-width: 100%;
}
.book-cover img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 480 / 766;
  box-shadow: var(--shadow-card);
}
.book-card :is(h2, h3) {
  margin-top: 0;
  font-size: var(--text-xl);
}
.book-card p:last-child {
  margin-bottom: 0;
}
dialog#updates {
  width: min(42rem, calc(100% - 2rem));
  padding: clamp(1rem, 4vw, 2.5rem);
  border-top: 4px solid var(--color-accent);
}
.updates-dialog .dialog-heading {
  align-items: center;
  padding-bottom: var(--space-4);
  border-bottom: var(--border-width) solid var(--color-border);
}
.updates-dialog .dialog-heading h2 {
  flex: 1 1 12rem;
  font-size: clamp(1.5rem, 4vw, 2rem);
}
.updates-dialog .example-badge {
  display: inline-block;
  margin: var(--space-5) 0 var(--space-2);
  padding: var(--space-1) var(--space-3);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-control);
  color: var(--color-accent);
  background: var(--color-soft);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.updates-dialog h3 {
  padding-top: var(--space-4);
  border-top: var(--border-width) solid var(--color-border);
}
.updates-dialog li + li {
  margin-top: var(--space-3);
}
.updates-dialog :is(p, li) > a {
  display: inline-flex;
  align-items: center;
  min-width: 44px;
  min-height: 44px;
  max-width: 100%;
}
.lightbox {
  width: min(74rem, calc(100% - 2rem));
}
#lightbox-details {
  max-width: var(--measure);
  margin: var(--space-5) auto 0;
  padding-top: var(--space-5);
  border-top: var(--border-width) solid var(--color-border);
}
.lightbox .dialog-heading {
  margin-bottom: var(--space-5);
}
.lightbox :is(h2, h3) {
  min-width: 0;
  max-width: 100%;
  font-size: var(--text-lg);
}
.lightbox img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100dvh - 11rem);
  margin-inline: auto;
  object-fit: contain;
  background: var(--color-page);
}

@media (max-width: 480px) {
  .book-card {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-5);
    padding: var(--space-4);
  }
  .book-cover {
    width: min(8rem, 100%);
  }
  .book-card :is(h2, h3) {
    font-size: var(--text-lg);
  }
}

/* Motion uses transforms so content never pushes its neighbors around.
 * Reveals remain opaque and readable even if their observer does not run.
 */
@media (prefers-reduced-motion: no-preference) {
  main {
    animation: page-arrive 280ms ease-out;
  }
  nav a {
    transition:
      transform 160ms ease-out,
      color 160ms ease-out;
  }
  nav a:is(:hover, :focus-visible) {
    transform: scale(1.06);
  }
  .card {
    transition:
      transform 180ms ease-out,
      box-shadow 180ms ease-out,
      border-color 180ms ease-out;
  }
  .button,
  .shot {
    transition:
      background-color 160ms ease-out,
      border-color 160ms ease-out;
  }
  dialog[open] {
    animation: dialog-arrive 220ms ease-out;
  }
  dialog[open]::backdrop {
    animation: backdrop-arrive 220ms ease-out;
  }
  .js .reveal {
    translate: 0 10px;
    transition: translate 320ms ease-out;
  }
  .js .reveal.is-visible,
  .js .reveal:focus-within {
    translate: 0 0;
  }
}
@media (prefers-reduced-motion: no-preference) and (hover: hover) {
  .card:hover {
    transform: translateY(-3px);
    border-color: var(--color-accent);
  }
}
@keyframes page-arrive {
  from {
    opacity: 0.98;
  }
  to {
    opacity: 1;
  }
}
@keyframes dialog-arrive {
  from {
    opacity: 0.98;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes backdrop-arrive {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Reserve the opener's box while app.js enables it; avoid a jump on first paint. */
#updates-button[hidden] {
  display: inline-flex !important;
  visibility: hidden;
  pointer-events: none;
}
main :is(p, li) > a:not(.button):not(.proof-card):not(.text-link) {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  min-width: 44px;
  max-width: 100%;
}
