/* ==========================================================================
   MicroBin — Apple Human Interface Guidelines design system
   --------------------------------------------------------------------------
   Foundations (developer.apple.com/design/human-interface-guidelines):
   - typography.md  › system fonts, 13 pt macOS body default, hierarchy by
     weight/size, no thin weights for small text.
   - color.md       › one color = one meaning; semantic colors with light and
     dark variants; nothing conveyed by color alone.
   - dark-mode.md   › respect prefers-color-scheme, no app-level toggle;
     4.5:1 minimum contrast.
   - layout.md      › order by importance, align to scan, group related
     items, progressive disclosure, 8pt spacing grid.
   - buttons.md     › 44pt minimum hit region, one prominent action per
     view, press state on every custom button.
   - accessibility.md › visible focus, reduced motion/transparency honored.
   Cross-platform web translation (cross-platform.md): system font stack,
   CSS custom properties stand in for semantic colors.

   Contrast (WCAG, computed from hex — all body text >= 4.5:1):
   Light: label #1D1D1F on #FFFFFF 16.83:1; secondary #6E6E73 5.07:1;
          accent #0071E3 4.70:1; white on accent 4.70:1;
          danger #D70015 5.38:1.
   Dark:  label #F5F5F7 on #1C1C1E 15.63:1; secondary #98989D 5.93:1;
          accent #0A84FF 4.66:1; white on #0071E3 (button fill) 4.70:1;
          danger #FF453A 4.99:1.
   ========================================================================== */

/* ------------------------------------------------------------------ tokens */
:root {
  /* Semantic colors — light */
  --bg: #F5F5F7;               /* system grouped background */
  --bg-card: #FFFFFF;          /* grouped content surface */
  --bg-elevated: #FFFFFF;
  --fill: #E8E8ED;             /* control fill (secondary buttons) */
  --fill-secondary: #F2F2F7;   /* code blocks, wells */
  --label: #1D1D1F;            /* primary text */
  --label-secondary: #6E6E73;  /* secondary text */
  --separator: #D2D2D7;        /* hairlines */
  --separator-opaque: #E5E5EA;
  --accent: #0071E3;           /* system blue — links + primary actions */
  --accent-hover: #0077ED;
  --accent-pressed: #0060C5;
  --accent-soft: rgba(0, 113, 227, 0.10);
  --danger: #D70015;           /* destructive */
  --danger-soft: rgba(215, 0, 21, 0.08);
  --success: #248A3D;
  --focus-ring: rgba(0, 113, 227, 0.35);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --shadow-pop: 0 2px 8px rgba(0, 0, 0, 0.08), 0 16px 32px rgba(0, 0, 0, 0.10);

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro", "Segoe UI", Roboto,
    "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", monospace;

  /* Shape + spacing (8pt grid) */
  --radius-card: 16px;
  --radius-control: 10px;
  --radius-small: 8px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 48px;

  /* Back-compat aliases — older inline styles reference these names */
  --background-body: var(--bg);
  --background: var(--fill-secondary);
  --background-alt: var(--bg-card);
  --text-main: var(--label);
  --text-bright: var(--label);
  --text-muted: var(--label-secondary);
  --links: var(--accent);
  --focus: var(--accent);
  --border: var(--separator);
  --code: var(--label);
  --form-text: var(--label);
  --form-placeholder: var(--label-secondary);
  --button-base: var(--fill);
  --button-hover: var(--separator-opaque);
  --selection: rgba(0, 113, 227, 0.25);
  --highlight: #FFD60A;
  --variable: var(--accent);
  --scrollbar-thumb: #C7C7CC;
  --scrollbar-thumb-hover: #AEAEB2;
  --animation-duration: 0.15s;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-card: #1C1C1E;
    --bg-elevated: #2C2C2E;
    --fill: #2C2C2E;
    --fill-secondary: #1C1C1E;
    --label: #F5F5F7;
    --label-secondary: #98989D;
    --separator: #38383A;
    --separator-opaque: #48484A;
    --accent: #0A84FF;          /* link text on dark */
    --accent-hover: #409CFF;
    --accent-pressed: #0066CC;
    --accent-btn: #0071E3;      /* primary button fill (white text 4.70:1) */
    --accent-soft: rgba(10, 132, 255, 0.16);
    --danger: #FF453A;          /* destructive text on dark */
    --danger-btn: #D70015;      /* destructive fill (white text 5.38:1) */
    --danger-soft: rgba(255, 69, 58, 0.12);
    --success: #30D158;
    --focus-ring: rgba(10, 132, 255, 0.45);
    --shadow-card: none;
    --shadow-pop: 0 2px 8px rgba(0, 0, 0, 0.4), 0 16px 32px rgba(0, 0, 0, 0.5);
    --scrollbar-thumb: #48484A;
    --scrollbar-thumb-hover: #636366;
    --selection: rgba(10, 132, 255, 0.35);
    --highlight: #FFD60A;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-color: var(--scrollbar-thumb) var(--bg);
  scrollbar-width: thin;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--label);
  background: var(--bg);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--selection); }

/* Type scale — macOS text styles, px for the web.
   Display 28/700 · Title 2 22/700 · Title 3 20/600 · Headline 17/600 ·
   Body 16/400 · Callout 15 · Subhead 14 · Footnote 13 · Caption 12 (meta only). */
h1 { font-size: 28px; line-height: 1.25; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 8px; }
h2 { font-size: 22px; line-height: 1.3; font-weight: 700; letter-spacing: -0.01em; margin: 32px 0 8px; }
h3 { font-size: 20px; line-height: 1.35; font-weight: 600; margin: 24px 0 8px; }
h4 { font-size: 17px; line-height: 1.4; font-weight: 600; margin: 24px 0 8px; }
h5, h6 { font-size: 15px; line-height: 1.45; font-weight: 600; margin: 16px 0 8px; }
p { margin: 0 0 16px; }
small { font-size: 13px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
strong, b { font-weight: 600; }
code, kbd, pre, samp { font-family: var(--font-mono); }

/* Visible keyboard focus on desktop (accessibility.md). */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------------------------------------------ layout */
.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}
body.wide .page { max-width: 1024px; }

/* ------------------------------------------------------------------ top bar
   Sticky translucent bar (Liquid Glass: blur belongs on the floating
   functional layer, never in content). Falls back to solid when
   transparency is reduced. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(245, 245, 247, 0.72);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--separator);
}
@media (prefers-color-scheme: dark) {
  .topbar { background: rgba(0, 0, 0, 0.72); }
}
@media (prefers-reduced-transparency: reduce) {
  .topbar { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
body.wide .topbar-inner { max-width: 1024px; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--label);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-logo { height: 28px; width: auto; display: block; border-radius: 6px; }
.brand-name { line-height: 1; }
.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}
.topnav a {
  color: var(--label-secondary);
  font-size: 15px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 8px;
  white-space: nowrap;
}
.topnav a:hover { color: var(--label); background: var(--fill-secondary); text-decoration: none; }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 24px;
  margin-bottom: 24px;
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card-title {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 4px;
}
.card-subtitle {
  font-size: 14px;
  color: var(--label-secondary);
  margin: 0 0 16px;
}

/* ------------------------------------------------------------------ buttons
   buttons.md: 44pt minimum hit region; one prominent action per view;
   style (not size) distinguishes the preferred choice; every custom
   button has a press state. */
button,
input[type="button"],
input[type="reset"],
input[type="submit"],
select {
  cursor: pointer;
  font-family: inherit;
}
button,
input[type="button"],
input[type="reset"],
input[type="submit"] {
  min-height: 44px;
  padding: 0 20px;
  border: none;
  border-radius: var(--radius-control);
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  color: var(--label);
  background: var(--fill);
  transition: background-color var(--animation-duration) linear,
    transform 0.08s ease, box-shadow var(--animation-duration) linear;
}
button:hover,
input[type="button"]:hover,
input[type="reset"]:hover { background: var(--separator-opaque); }
button:active,
input[type="button"]:active,
input[type="reset"]:active { transform: scale(0.98); }
button:disabled,
input[type="submit"]:disabled { opacity: 0.5; cursor: default; transform: none; }

/* Primary action — filled accent. One per view. */
input[type="submit"],
form button,
.btn-primary {
  background: var(--accent);
  color: #FFFFFF;
}
@media (prefers-color-scheme: dark) {
  input[type="submit"],
  form button,
  .btn-primary { background: var(--accent-btn, #0071E3); }
}
input[type="submit"]:hover,
form button:hover,
.btn-primary:hover { background: var(--accent-hover); }
input[type="submit"]:active,
form button:active,
.btn-primary:active { background: var(--accent-pressed); transform: scale(0.98); }

/* Secondary — filled gray. */
.btn-secondary { background: var(--fill); color: var(--label); }
.btn-secondary:hover { background: var(--separator-opaque); }

/* Small buttons (toolbar rows). Still 44px tall on touch. */
.small-button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
  border-radius: var(--radius-small);
}
@media (pointer: coarse) {
  .small-button { min-height: 44px; }
}

/* Destructive text links (delete). Color is never the only signal — the
   word itself says what happens. */
a[href*="/remove/"] { color: var(--danger); }

/* ------------------------------------------------------------------ forms
   entering-data.md / text-fields.md: labels above fields, choices over
   typing, dynamic validation, 44pt controls. */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--label-secondary);
  margin-bottom: 6px;
}
label sup a { color: var(--label-secondary); }
input,
select,
textarea {
  font-family: inherit;
  font-size: 16px;
  color: var(--label);
  background: var(--bg-card);
  border: 1px solid var(--separator);
  border-radius: var(--radius-control);
  outline: none;
  transition: border-color var(--animation-duration) linear,
    box-shadow var(--animation-duration) linear;
}
input,
select { min-height: 44px; padding: 0 12px; }
textarea {
  width: 100%;
  min-height: 200px;
  padding: 16px;
  line-height: 1.6;
  resize: vertical;
}
input::placeholder,
textarea::placeholder { color: var(--label-secondary); opacity: 1; }
input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' height='12' width='20' fill='%236E6E73'%3E%3Cpath d='M10 2c-0.5-0.8-1.5-0.8-2 0L1 9a1 1 0 0 0 0.8 1.6h16.4a1 1 0 0 0 0.8-1.6L10 2z' transform='rotate(180 10 6)'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
@media (prefers-color-scheme: dark) {
  select {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' height='12' width='20' fill='%2398989D'%3E%3Cpath d='M10 2c-0.5-0.8-1.5-0.8-2 0L1 9a1 1 0 0 0 0.8 1.6h16.4a1 1 0 0 0 0.8-1.6L10 2z' transform='rotate(180 10 6)'/%3E%3C/svg%3E");
  }
}
[type="checkbox"],
[type="radio"] { min-height: 0; padding: 0; accent-color: var(--accent); }

/* ------------------------------------------------------------------ tables
   lists-and-tables.md: rows separated by hairlines, no heavy grid;
   44pt rows, metadata in secondary label. */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}
th {
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: var(--label-secondary);
  padding: 8px 12px;
  border-bottom: 1px solid var(--separator);
  white-space: nowrap;
}
td {
  padding: 12px;
  border-bottom: 1px solid var(--separator-opaque);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--fill-secondary); }
td, th { overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ code */
pre {
  background: var(--fill-secondary);
  border: 1px solid var(--separator-opaque);
  border-radius: 12px;
  padding: 16px;
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 16px;
}
pre code {
  background: none;
  padding: 0;
  color: var(--label);
  font-size: inherit;
}
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--fill-secondary);
  border-radius: 6px;
  padding: 2px 6px;
  color: var(--label);
}
blockquote {
  border-left: 3px solid var(--accent);
  margin: 16px 0;
  padding: 8px 16px;
  color: var(--label-secondary);
}
mark { background: var(--highlight); border-radius: 2px; padding: 0 2px; color: #000; }

/* ------------------------------------------------------------------ footer */
footer, .page-footer {
  margin-top: 48px;
  text-align: center;
  font-size: 13px;
  color: var(--label-secondary);
  line-height: 1.6;
}
footer a, .page-footer a { color: var(--label-secondary); text-decoration: underline; }

/* ------------------------------------------------------------------ misc */
hr { border: none; border-top: 1px solid var(--separator); margin: 24px 0; }
img, video { max-width: 100%; height: auto; }
.muted { color: var(--label-secondary); font-size: 14px; }
.hidden { display: none !important; }

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

/* ------------------------------------------------------------------ compact */
@media (max-width: 640px) {
  .page { padding: 16px 16px 32px; }
  .card { padding: 16px; border-radius: 12px; }
  .topnav a { padding: 8px; font-size: 14px; }
  .brand-name { display: none; }
  h1 { font-size: 24px; }
  h2 { font-size: 20px; }
  input[type="submit"], .btn-primary { width: 100%; }
}
