/*
 * site.css: aImmaOS reading showcase for Gabriel.
 * Tokens are taken verbatim from the Handhold DESIGN.md published on Refero
 * (source URL recorded in docs/design/DESIGN.md),
 * recorded in docs/design/DESIGN.md with the documented deviations.
 * Plain CSS, no build step. No external URLs anywhere in this file.
 */

/* ---------- Self-hosted fonts (Latin subsets, served from this origin) ---------- */

@font-face {
  font-family: "Cormorant Garamond";
  src: url("../fonts/cormorant-garamond-300.woff2") format("woff2");
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "EB Garamond";
  src: url("../fonts/eb-garamond-400.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url("../fonts/inter-400.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens (verbatim from Handhold DESIGN.md, plus two derived roles) ---------- */

:root {
  /* Handhold colour tokens, verbatim */
  --paper: #f2f1ed;          /* Paper Cream: page canvas */
  --surface: #ffffff;        /* Pure White: card surface, button text on ink */
  --ink: #000000;            /* Ink Black: all text, borders, filled actions */
  --line: #dbd7cd;           /* Warm Border: hairlines, marked-word wash */

  /* Handhold type families. Serif = display (Cormorant 300 is its named fallback
     for bureauSerif 200). Inter = interface. EB Garamond = reading body, see docs. */
  --font-display: "Cormorant Garamond", "EB Garamond", Georgia, serif;
  --font-text: "EB Garamond", Georgia, "Times New Roman", serif;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  --page-max: 1200px;        /* Handhold: page max width */
  --measure: 68ch;           /* long-form measure, inside the 45 to 75 range */
  --radius-card: 24px;       /* Handhold: cards 24 to 32px */
  --radius-node: 24px;
}

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

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 1.125rem;          /* 18px on phones */
  line-height: 1.62;
  font-synthesis: none;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  hyphens: auto;
  -webkit-font-smoothing: antialiased;
  /* Landscape notches: keep content clear of the side insets (0px on a plain phone). */
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

@media (min-width: 720px) {
  body {
    font-size: 1.1875rem;       /* 19px on tablets and desktop */
  }
}

p {
  margin: 0 0 1.1em;
  max-width: var(--measure);
  text-wrap: pretty;
}

a {
  color: var(--ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  border-radius: 4px;
}

img,
svg {
  display: block;
  max-width: 100%;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0.75rem;
  z-index: 10;
  background: var(--ink);
  color: var(--surface);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  text-decoration: none;
}

.skip-link:focus {
  left: 1rem;
}

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

.wrap {
  max-width: var(--page-max);
  margin-inline: auto;
  padding-inline: clamp(1.25rem, 5vw, 3rem);
}

/* ---------- Labels, kickers, tags ---------- */

.kicker,
.tag,
th,
.ui {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1.4;
}

.kicker {
  margin: 0 0 1rem;
}

.tag {
  display: inline-block;
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  margin: 0 0 0.6rem;
}

/* ---------- Headings ---------- */

h1,
h2,
h3 {
  text-wrap: balance;
}

h1 {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(2.75rem, 7.6vw, 6rem);
  line-height: 1;
  letter-spacing: -0.03em;
  margin: 0 0 1.5rem;
  max-width: 14ch;
}

h2 {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(2.1rem, 4.6vw, 3.5rem);
  line-height: 1;
  letter-spacing: -0.03em;
  margin: 0 0 1.25rem;
  max-width: 18ch;
}

h3 {
  font-family: var(--font-text);
  font-weight: 400;
  font-size: clamp(1.3rem, 2.4vw, 1.55rem);
  line-height: 1.25;
  margin: 2.2rem 0 0.6rem;
  max-width: var(--measure);
}

strong {
  font-weight: 600;
}

/* ---------- Page structure ---------- */

.site-header {
  /* Top bar clears the status bar or notch. Without a notch the inset is 0px,
     so the padding is exactly the original 1.5rem. */
  padding-top: calc(1.5rem + env(safe-area-inset-top, 0px));
  padding-bottom: 0;
}

.site-header .wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-header a {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-decoration: none;
}

.s {
  padding-block: clamp(3.5rem, 8vw, 6.5rem);
  border-top: 1px solid var(--line);
}

.hero {
  border-top: 0;
  padding-top: clamp(2.5rem, 7vw, 5rem);
}

.sec-body > * + * {
  margin-top: 0;
}

.lead {
  font-size: clamp(1.3rem, 2.4vw, 1.6rem);
  line-height: 1.5;
  max-width: 44ch;
}

/* Contents list */

.contents ol {
  list-style: none;
  padding: 0;
  margin: 1.5rem 0 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  border-top: 1px solid var(--ink);
  max-width: var(--measure);
}

.contents li {
  border-bottom: 1px solid var(--line);
}

.contents a {
  display: flex;
  gap: 1rem;
  padding: 0.8rem 0;
  text-decoration: none;
  font-size: 1.05rem;
  min-height: 44px;
  align-items: baseline;
}

.contents a:hover {
  text-decoration: underline;
}

.contents .num {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  min-width: 2ch;
}

@media (min-width: 720px) {
  .contents ol {
    grid-template-columns: 1fr 1fr;
    column-gap: 2.5rem;
  }
}

/* Two-column section layout on wide screens: label left, content right */

@media (min-width: 960px) {
  .s:not(.hero) > .wrap {
    display: grid;
    grid-template-columns: 15rem minmax(0, 1fr);
    column-gap: 4rem;
    align-items: start;
  }

  .s .sec-head {
    position: sticky;
    top: 2rem;
  }

  .s .sec-head h2 {
    font-size: clamp(2.2rem, 3.2vw, 3rem);
  }
}

/* ---------- Lists ---------- */

ol.steps,
ul.plain {
  padding-left: 1.25rem;
  max-width: var(--measure);
}

ol.steps li,
ul.plain li {
  margin-bottom: 0.7rem;
  padding-left: 0.3rem;
}

ul.plain {
  list-style: none;
  padding-left: 0;
}

/* ---------- Tables (stacked on phones) ---------- */

.table-wrap {
  margin: 1.5rem 0 2rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
  line-height: 1.5;
}

th,
td {
  text-align: left;
  vertical-align: top;
  padding: 0.9rem 0.75rem;
}

th {
  border-bottom: 1px solid var(--ink);
}

td {
  border-bottom: 1px solid var(--line);
}

td strong {
  font-weight: 600;
}

@media (max-width: 719px) {
  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  tr {
    border-bottom: 1px solid var(--ink);
    padding-block: 1rem;
  }

  td {
    border: 0;
    padding: 0.3rem 0;
  }

  td::before {
    content: attr(data-label);
    display: block;
    font-family: var(--font-ui);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 0.15rem;
  }
}

/* ---------- Architecture figure (proposal section 2, as HTML/CSS) ---------- */

.arch-figure {
  margin: 2rem 0 2.5rem;
}

.arch {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas:
    "edge"
    "site"
    "app"
    "gate"
    "pay"
    "core"
    "media";
  gap: 1.4rem;
  max-width: 980px;
}

.node {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--ink);
  border-radius: var(--radius-node);
  padding: 1rem 1.15rem;
}

.node h4 {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 1.5rem;
  line-height: 1.1;
  margin: 0 0 0.35rem;
}

.node p {
  font-family: var(--font-ui);
  font-size: 0.86rem;
  line-height: 1.5;
  margin: 0;
  max-width: none;
}

.node .role {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

.node.gate {
  background: var(--ink);
  color: var(--surface);
}

.node.gate p,
.node.gate .role {
  color: var(--surface);
}

.node.keep::after,
.node.down::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -1.4rem;
  width: 1px;
  height: 1.4rem;
  background: var(--ink);
}

.arch-figure figcaption {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  line-height: 1.5;
  margin-top: 1.6rem;
  max-width: var(--measure);
}

@media (min-width: 900px) {
  .arch {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-areas:
      "edge edge edge edge edge edge"
      "site site site app app app"
      "gate gate gate gate gate gate"
      "pay pay core core media media";
    gap: 1.6rem 1rem;
  }

  .node.gate {
    grid-area: gate;
  }

  .node.down.site::after,
  .node.down.app::after {
    bottom: -1.6rem;
    height: 1.6rem;
  }
}

.arch .edge { grid-area: edge; }
.arch .site { grid-area: site; }
.arch .app { grid-area: app; }
.arch .gate { grid-area: gate; }
.arch .pay { grid-area: pay; }
.arch .core { grid-area: core; }
.arch .media { grid-area: media; }

/* ---------- Demo ---------- */

.demo {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: clamp(1.25rem, 4vw, 2.5rem);
  margin: 2.5rem 0 1rem;
  max-width: 100%;
}

.demo-status {
  font-family: var(--font-ui);
  font-size: 0.86rem;
  line-height: 1.5;
  margin: 0 0 1.5rem;
  max-width: none;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.demo h3 {
  margin-top: 2.2rem;
}

.demo h3:first-of-type {
  margin-top: 0;
}

.story-head .kicker {
  margin-bottom: 0.5rem;
}

.story-title {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(2.2rem, 5vw, 3.2rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
  margin: 0;
  max-width: none;
}

.story-title-en {
  font-family: var(--font-text);
  font-style: normal;
  font-size: 1rem;
  margin: 0.4rem 0 1.4rem;
  max-width: none;
}

.audio-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin: 0 0 1.5rem;
}

.audio-time {
  font-family: var(--font-ui);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
  margin-left: 0.4rem;
  max-width: none;
}

.passage {
  font-size: clamp(1.15rem, 2.3vw, 1.35rem);
  line-height: 1.8;
  max-width: var(--measure);
}

.passage p {
  max-width: none;
  margin-bottom: 1rem;
}

/* Marked words: the wash is decorative, the text is the same ink, and the
   control is a real button, so the meaning is reachable by keyboard. */

button.word {
  font: inherit;
  color: var(--ink);
  background: var(--line);
  border: 0;
  border-radius: 4px;
  padding: 0 0.16em;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

button.word:hover {
  text-decoration-thickness: 2px;
}

button.word[aria-expanded="true"] {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}

.meaning {
  margin: 1.5rem 0 0;
  border-top: 1px solid var(--ink);
  padding-top: 1.1rem;
  max-width: none;
}

.meaning[hidden] {
  display: none;
}

.meaning dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1.1rem;
  margin: 0;
  font-size: 1rem;
}

.meaning dt {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding-top: 0.2rem;
}

.meaning dd {
  margin: 0;
}

.meaning .meaning-word {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 300;
  line-height: 1.1;
  margin: 0 0 0.5rem;
}

.meaning .meaning-word-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.meaning-hint {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  line-height: 1.5;
  margin: 0.6rem 0 0;
  max-width: none;
}

.hint {
  font-family: var(--font-ui);
  font-size: 0.82rem;
  line-height: 1.5;
  margin: 0.9rem 0 0;
  max-width: none;
}

.progress-block {
  margin: 2rem 0 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.progress-text {
  font-family: var(--font-ui);
  font-size: 0.86rem;
  margin: 0 0 0.6rem;
  max-width: none;
}

.progress {
  height: 8px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--ink);
  border-radius: 999px;
}

.btn {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  line-height: 1.2;
  min-height: 44px;
  padding: 0.6rem 1.15rem;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.btn:hover {
  background: var(--paper);
}

.btn[aria-pressed="true"],
.btn.primary {
  background: var(--ink);
  color: var(--surface);
}

.btn.primary:hover {
  background: var(--ink);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.flash-block,
.quiz-block {
  margin-top: 2.2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.card-btn {
  display: block;
  width: 100%;
  min-height: 9.5rem;
  margin: 0.5rem 0 0.9rem;
  padding: 1.25rem;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 24px;
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(2rem, 6vw, 2.8rem);
  line-height: 1.1;
  text-align: center;
  cursor: pointer;
}

.card-btn .card-side {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0.6rem;
}

.card-example {
  font-style: italic;
  font-size: 1.05rem;
  min-height: 3.2em;
}

.card-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.card-count {
  font-family: var(--font-ui);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.question {
  border: 0;
  margin: 0 0 1.8rem;
  padding: 0;
  min-width: 0;
}

.question legend {
  font-family: var(--font-text);
  font-size: 1.1rem;
  line-height: 1.45;
  padding: 0;
  margin-bottom: 0.7rem;
  max-width: var(--measure);
}

.options {
  display: grid;
  gap: 0.5rem;
}

.option {
  font-family: var(--font-text);
  font-size: 1.05rem;
  line-height: 1.35;
  text-align: left;
  min-height: 44px;
  padding: 0.7rem 1rem;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 24px;
  cursor: pointer;
}

.option:hover {
  background: var(--paper);
}

.option[aria-pressed="true"] {
  background: var(--ink);
  color: var(--surface);
}

.feedback {
  font-size: 1rem;
  margin: 0.7rem 0 0;
  max-width: var(--measure);
}

.feedback:empty {
  display: none;
}

.storage-note {
  font-family: var(--font-ui);
  font-size: 0.82rem;
  margin: 1.2rem 0 0;
  max-width: none;
}

.storage-note:empty {
  display: none;
}

/* ---------- Footer and 404 ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  padding-top: 2.5rem;
  /* Bottom clears the home indicator on phones with one. */
  padding-bottom: calc(3rem + env(safe-area-inset-bottom, 0px));
}

.site-footer p {
  font-family: var(--font-ui);
  font-size: 0.86rem;
  line-height: 1.55;
  margin: 0 0 0.5rem;
  max-width: none;
}

.not-found {
  padding-block: clamp(4rem, 14vw, 9rem);
}

.not-found h1 {
  font-size: clamp(2.6rem, 8vw, 5rem);
}

/* ---------- Motion and print ---------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .progress span {
    transition: width 0.4s ease;
  }

  .card-btn {
    transition: transform 0.25s ease;
  }

  .card-btn:active {
    transform: scale(0.99);
  }
}

@media print {
  body {
    background: #ffffff;
    font-size: 11pt;
  }

  .skip-link,
  .site-header nav,
  .demo,
  .arch-figure .node::after {
    display: none !important;
  }

  .s {
    break-inside: auto;
  }

  a[href^="#"]::after {
    content: "";
  }
}
