/*
 * Simple R2 Share · Tactical HUD theme (docs/superpowers/specs/2026-10-27-ui-theme-design.md).
 * Written against the markup contract at the top of src/html.ts and the
 * README classes from src/readme.ts. Dark only; no font size below 16px.
 */

/* ===== Chakra Petch (self-hosted, latin only; copied by scripts/build-fonts.mjs) ===== */
@font-face {
  font-family: "Chakra Petch";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/ChakraPetch-SemiBold.latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Chakra Petch";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/ChakraPetch-Bold.latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ===== Tokens (UI spec §3) ===== */
:root {
  color-scheme: dark;

  --bg: #070b10;
  --grid: #2fd6e808;
  --surface: #0c131a;
  --surface-hero: #0a1118;
  --line: #1b2935;
  --fg: #dce6ec;
  --muted: #84a0b0;
  --accent: #2fd6e8;
  --accent-ink: #04121a;
  --hover: #2fd6e80f;
  --link: #6fe4f0;
  --focus: #ffc24a;
  --ok: #3ee08f;
  --danger: #ff5c6c;
  --code-bg: #0f1a23;

  --font-display: "Chakra Petch", "Jim Mono TC", monospace;
  --font-content: "Jim Mono TC", monospace;

  --text-base: 16px;
  --text-body: 18px;
  --text-lg: 20px;
  --text-xl: 24px;
  --text-2xl: 28px;
  --text-title: clamp(32px, 6vw, 48px);
  --text-hero: clamp(64px, 14vw, 120px);
  --tracking-label: 0.08em;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;

  --layout-max: 960px;
  --gutter-left: max(16px, env(safe-area-inset-left, 0px));
  --gutter-right: max(16px, env(safe-area-inset-right, 0px));
  --chamfer-panel: 14px;
  --chamfer-button: 10px;
  --bracket: 14px;
  --tap: 44px;
  --duration: 150ms;

  /* Tree geometry: row inline padding, caret size and the gap between row parts. */
  --row-pad: var(--space-2);
  --caret: 10px;
  --row-gap: var(--space-2);
  --row-line: 26px;
  --indent: 22px;
  --tree-pad: var(--space-2);
  --panel-pad: var(--space-4);
}

@media (max-width: 560px) {
  :root {
    --chamfer-panel: 10px;
    --row-pad: var(--space-1);
    --indent: 12px;
    --tree-pad: 6px;
    --panel-pad: var(--space-3);
  }
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  padding: 0 var(--gutter-right) env(safe-area-inset-bottom, 0px) var(--gutter-left);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--fg);
  font-family: var(--font-content);
  font-size: var(--text-base);
  font-weight: 400;
  line-height: 1.6;
  font-variant-ligatures: none;
  overflow-wrap: anywhere;
}

/* Ligatures only where code is shown (UI spec §3.2). */
pre,
code {
  font-variant-ligatures: contextual;
}

::selection {
  background: #2fd6e840;
  color: var(--fg);
}

a {
  color: inherit;
}

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

/* The 0×0 icon sprite must not take part in layout. */
svg.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  flex: none;
  width: 16px;
  height: 16px;
}

/* Single 960px column: top bar, main, footer. */
.topbar,
.main,
.footer {
  width: 100%;
  max-width: var(--layout-max);
  margin-inline: auto;
}

/* ===== Top bar (§5.1) ===== */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding-block: var(--space-4);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.12em;
  white-space: nowrap;
}

/*
 * Jim Mono TC's CJK glyphs sit about 0.03em higher on the shared baseline than
 * Chakra Petch capitals, which center on the logo glyph; move them down to
 * match. Browsers paint text on whole pixels, so 0.05em (1px at --text-lg)
 * lands closest. Relative positioning leaves the line box alone.
 */
.brand__cjk {
  position: relative;
  top: 0.05em;
}

/* BRAND_URL turns the brand into a link; it keeps the plain brand look. */
a.brand {
  color: inherit;
  text-decoration: none;
  transition: color var(--duration) ease;
}

.brand__glyph {
  width: 22px;
  height: 22px;
  color: var(--accent);
}

.sync {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  color: var(--muted);
  letter-spacing: var(--tracking-label);
}

.sync__dot {
  flex: none;
  width: 8px;
  height: 8px;
  background: var(--ok);
}

/* ===== Main ===== */
.main {
  display: grid;
  gap: var(--space-6);
  padding-block: var(--space-7) var(--space-8);
}

.main > * {
  min-width: 0;
}

/* ===== Hero (§5.2) with corner brackets ===== */
.hero {
  position: relative;
  display: grid;
  gap: var(--space-3);
  padding: var(--space-6);
  background: var(--surface-hero);
  border: 1px solid var(--line);
}

.hero::before,
.hero::after {
  content: "";
  position: absolute;
  width: var(--bracket);
  height: var(--bracket);
  border: 0 solid var(--accent);
  pointer-events: none;
}

.hero::before {
  top: -1px;
  left: -1px;
  border-top-width: 2px;
  border-left-width: 2px;
}

.hero::after {
  right: -1px;
  bottom: -1px;
  border-right-width: 2px;
  border-bottom-width: 2px;
}

.hero__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-title);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.02em;
}

.hero__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3) var(--space-6);
}

.stats {
  margin: 0;
  color: var(--muted);
  letter-spacing: var(--tracking-label);
}

.stats b {
  color: var(--fg);
  font-weight: 700;
}

/* ===== Chamfered shapes =====
 * Drawn on pseudo-elements so the host is never clipped: focus outlines and
 * content stay visible. --c is the chamfer size; "ring" is a 1px outline that
 * follows the cut corners (outer path, then the inner path as an even-odd hole;
 * 0.41px = √2 − 1 keeps the diagonal 1px thick). */
.panel,
.button {
  position: relative;
  isolation: isolate;
}

.panel::before,
.panel::after,
.button::before,
.button::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.panel::before,
.button::before {
  clip-path: polygon(var(--c) 0, 100% 0, 100% calc(100% - var(--c)), calc(100% - var(--c)) 100%, 0 100%, 0 var(--c));
}

.panel::after,
.button::after {
  clip-path: polygon(
    evenodd,
    var(--c) 0, 100% 0, 100% calc(100% - var(--c)), calc(100% - var(--c)) 100%, 0 100%, 0 var(--c), var(--c) 0,
    calc(var(--c) + 0.41px) 1px, 1px calc(var(--c) + 0.41px), 1px calc(100% - 1px),
    calc(100% - var(--c) - 0.41px) calc(100% - 1px), calc(100% - 1px) calc(100% - var(--c) - 0.41px),
    calc(100% - 1px) 1px, calc(var(--c) + 0.41px) 1px
  );
}

/* ===== Button (§6) ===== */
.button {
  --c: var(--chamfer-button);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  min-height: var(--tap);
  padding: 10px 22px;
  color: var(--accent);
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.06em;
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--duration) ease;
}

.button::before {
  background-color: transparent;
  transition: background-color var(--duration) ease;
}

.button::after {
  background-color: var(--accent);
}

.button:active {
  transform: translateY(1px);
}

/* ===== Panels (§5.3, §5.4) ===== */
.panel {
  --c: var(--chamfer-panel);
}

.panel::before {
  background: var(--surface);
}

.panel::after {
  background: var(--line);
}

.panel__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) var(--panel-pad) var(--space-3) calc(var(--panel-pad) + var(--space-1));
  border-bottom: 1px solid var(--line);
}

.panel__title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0;
  font-size: var(--text-base);
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: var(--tracking-label);
}

.panel__title::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  background: var(--accent);
}

.panel__aside {
  color: var(--muted);
  letter-spacing: var(--tracking-label);
}

.panel__empty {
  margin: 0;
  padding: var(--space-6) var(--panel-pad) var(--space-6) calc(var(--panel-pad) + var(--space-1));
  color: var(--muted);
}

/* ===== Tree ===== */
.tree,
.tree ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.tree {
  padding: var(--tree-pad);
}

/* Child level: dashed guide under the parent's caret, --indent per level. */
.tree ul {
  margin-left: calc(var(--row-pad) + var(--caret) / 2);
  padding-left: calc(var(--indent) - var(--row-pad) - var(--caret) / 2 - 1px);
  border-left: 1px dashed var(--line);
}

.tree details {
  margin: 0;
}

/* Rows align to the first text line, so icons and sizes stay on the first
 * line of a wrapped name; the block padding makes a one-line row exactly
 * --tap tall. */
.row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--row-gap);
  min-height: var(--tap);
  padding: calc((var(--tap) - var(--row-line)) / 2) var(--row-pad);
  line-height: var(--row-line);
  transition: background-color var(--duration) ease;
}

/* Files have no caret: indent by the caret plus its gap so the icons line up. */
.row--file {
  padding-left: calc(var(--row-pad) + var(--caret) + var(--row-gap));
}

summary.row {
  cursor: pointer;
  list-style: none;
}

summary.row::-webkit-details-marker {
  display: none;
}

summary.row::marker {
  content: "";
}

.row .icon {
  margin-top: calc((var(--row-line) - 16px) / 2);
}

.row .row__caret {
  width: var(--caret);
  height: var(--caret);
  margin-top: calc((var(--row-line) - var(--caret)) / 2);
  color: var(--accent);
  transition: transform var(--duration) ease;
}

details[open] > summary > .row__caret {
  transform: rotate(90deg);
}

.row--folder .row__icon {
  color: var(--accent);
}

.row--file .row__icon {
  color: var(--muted);
}

.row__name {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.row--folder .row__name {
  font-weight: 700;
}

a.row__name {
  color: var(--fg);
  text-decoration: none;
  text-underline-offset: 3px;
  transition: color var(--duration) ease;
}

/* The whole file row is the link's hit area (≥ 44px tall). */
a.row__name::after {
  content: "";
  position: absolute;
  inset: 0;
}

.row__meta {
  flex: none;
  padding-left: var(--space-3);
  color: var(--muted);
  white-space: nowrap;
}

/* Focus ring on the whole file row instead of the link text. */
@supports selector(:has(a)) {
  .row--file:has(a.row__name:focus-visible) {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
  }

  a.row__name:focus-visible {
    outline: none;
  }
}

/* ===== README (§5.4) ===== */
.readme {
  padding: var(--space-5) var(--panel-pad) var(--space-6) calc(var(--panel-pad) + var(--space-1));
  font-size: var(--text-body);
  line-height: 1.8;
}

.readme > * {
  max-width: 80ch;
}

.readme > :first-child {
  margin-top: 0;
}

.readme > :last-child {
  margin-bottom: 0;
}

.readme p,
.readme ul,
.readme ol,
.readme pre,
.readme blockquote,
.readme .table-scroll,
.readme hr {
  margin: 0 0 var(--space-4);
}

.readme h3,
.readme h4,
.readme h5,
.readme h6 {
  margin: var(--space-7) 0 var(--space-3);
  font-family: var(--font-content);
  font-weight: 700;
  line-height: 1.4;
}

.readme .md-h1 {
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--line);
  font-size: var(--text-2xl);
}

.readme .md-h2 {
  font-size: var(--text-xl);
}

.readme .md-h3,
.readme .md-h4,
.readme .md-h5,
.readme .md-h6 {
  font-size: var(--text-lg);
}

.readme a,
.footer a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color var(--duration) ease;
}

.readme code {
  padding: 0 6px;
  background: var(--code-bg);
  font-family: var(--font-content);
  font-size: var(--text-base);
}

.readme pre {
  overflow-x: auto;
  padding: var(--space-4);
  background: var(--code-bg);
  border-left: 2px solid var(--accent);
  font-size: var(--text-base);
  line-height: 1.6;
  overflow-wrap: normal;
}

.readme pre code {
  padding: 0;
  background: none;
  white-space: pre;
}

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

.readme table {
  border-collapse: collapse;
  font-size: var(--text-base);
  line-height: 1.6;
  overflow-wrap: normal;
}

/* A minimum cell width makes narrow screens scroll the table instead of
 * breaking every word. */
.readme th,
.readme td {
  min-width: 14ch;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.readme th {
  background: var(--surface-hero);
  font-weight: 700;
}

.readme img {
  max-width: 100%;
  height: auto;
}

.readme blockquote {
  padding-left: var(--space-4);
  border-left: 2px solid var(--line);
  color: var(--muted);
}

.readme ul,
.readme ol {
  padding-left: 2em;
}

.readme li + li,
.readme li > ul,
.readme li > ol {
  margin-top: var(--space-1);
}

.readme li > ul,
.readme li > ol {
  margin-bottom: 0;
}

.readme hr {
  height: 0;
  border: 0;
  border-top: 1px solid var(--line);
}

/* Links and images removed by the URL policy: plain text, no href. */
.unavailable {
  color: var(--muted);
  text-decoration: underline dotted;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  cursor: help;
}

/* ===== Status pages (§7.2) ===== */
.hero--status {
  gap: var(--space-2);
  padding-block: var(--space-7);
}

.status__code {
  font-family: var(--font-display);
  font-size: var(--text-hero);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.04em;
}

.status__code--404 {
  color: var(--accent);
}

.status__code--error {
  color: var(--danger);
}

.status__title {
  margin: var(--space-3) 0 0;
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.3;
}

.status__text {
  max-width: 60ch;
  margin: 0;
  color: var(--muted);
  font-size: var(--text-body);
  line-height: 1.8;
}

/* ===== Footer (§5.5) ===== */
.footer {
  padding-block: var(--space-5) var(--space-7);
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
}

/* ===== Hover (pointer devices only, so touch taps leave no stuck state) ===== */
@media (hover: hover) {
  .button:hover {
    color: var(--accent-ink);
  }

  .button:hover::before {
    background-color: var(--accent);
  }

  .row:hover {
    background-color: var(--hover);
  }

  .row--file:hover a.row__name {
    color: var(--accent);
    text-decoration: underline;
  }

  a.brand:hover {
    color: var(--accent);
  }

  .readme a:hover,
  .footer a:hover {
    text-decoration-thickness: 2px;
  }
}

/* ===== Narrow screens (§9) ===== */
@media (max-width: 560px) {
  .hero {
    padding: var(--space-4);
  }

  .hero__bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .readme {
    padding-block: var(--space-4) var(--space-5);
  }
}

/* ===== Reduced motion (§6) ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
