/* Folio Design System — Components */

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

* {
  margin: 0;
}

/* ── Base ── */
html {
  font-family: var(--fo-font-body);
  font-size: var(--fo-text-base);
  line-height: var(--fo-leading);
  color: var(--fo-color-ink);
  background: var(--fo-color-paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
}

/* ── Typography ── */
h1, h2, h3, h4 {
  line-height: 1.2;
  color: var(--fo-color-ink);
  text-wrap: balance;
}

h1 { font-size: var(--fo-text-2xl); margin-bottom: var(--fo-space-md); }
h2 { font-size: var(--fo-text-xl); margin-bottom: var(--fo-space-md); }
h3 { font-size: var(--fo-text-lg); margin-bottom: var(--fo-space-sm); }
h4 { font-size: var(--fo-text-base); font-weight: 600; margin-bottom: var(--fo-space-sm); }

p, li, blockquote, figcaption, td, th {
  text-wrap: pretty;
}

p {
  margin-bottom: var(--fo-space-md);
  color: var(--fo-color-ink);
}

small {
  font-size: var(--fo-text-sm);
  color: var(--fo-color-ink-muted);
}

a {
  color: var(--fo-color-accent-sky-400);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

strong { font-weight: 600; }

code {
  font-family: var(--fo-font-mono);
  font-size: 0.9em;
  background: var(--fo-color-paper-raised);
  padding: 0.15em 0.4em;
  border-radius: var(--fo-radius-sm);
}

pre {
  font-family: var(--fo-font-mono);
  font-size: var(--fo-text-sm);
  background: var(--fo-color-paper-raised);
  padding: var(--fo-space-md);
  border-radius: var(--fo-radius-md);
  overflow-x: auto;
  margin-bottom: var(--fo-space-md);
}

pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

blockquote {
  border-left: 3px solid var(--fo-color-border);
  padding-left: var(--fo-space-md);
  color: var(--fo-color-ink-muted);
  margin-bottom: var(--fo-space-md);
}

hr {
  border: none;
  border-top: 1px solid var(--fo-color-border-muted);
  margin: var(--fo-space-lg) 0;
}

mark {
  background: var(--fo-color-accent-honey-50);
  color: inherit;
  padding: 0.1em 0.2em;
  border-radius: 2px;
}

del {
  background: var(--fo-color-accent-coral-50);
  color: var(--fo-color-accent-coral-700);
  text-decoration: line-through;
}

ins {
  background: var(--fo-color-accent-sage-50);
  color: var(--fo-color-accent-sage-700);
  text-decoration: none;
}

kbd {
  font-family: var(--fo-font-mono);
  font-size: 0.85em;
  background: var(--fo-color-paper-raised);
  border: 1px solid var(--fo-color-border);
  border-bottom-width: 2px;
  padding: 0.15em 0.4em;
  border-radius: var(--fo-radius-sm);
}

ul, ol {
  padding-left: var(--fo-space-lg);
  margin-bottom: var(--fo-space-md);
}

li + li {
  margin-top: var(--fo-space-xs);
}

figure {
  margin: 0 0 var(--fo-space-md);
}

figcaption {
  font-size: var(--fo-text-sm);
  color: var(--fo-color-ink-muted);
  margin-top: var(--fo-space-xs);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ── Layout ── */
main {
  max-width: 64rem;
  margin-inline: auto;
  padding: var(--fo-space-lg) var(--fo-space-md);
}

nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 64rem;
  margin-inline: auto;
  padding: var(--fo-space-sm) var(--fo-space-md);
  gap: var(--fo-space-md);
}

nav ul {
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--fo-space-md);
  padding: 0;
  margin: 0;
}

nav li {
  margin: 0;
}

nav a {
  color: var(--fo-color-ink-muted);
  text-decoration: none;
  font-size: var(--fo-text-sm);
}

nav a:hover,
nav a[aria-current="page"] {
  color: var(--fo-color-ink);
}

header {
  margin-bottom: var(--fo-space-lg);
}

footer {
  margin-top: var(--fo-space-xl);
  padding: var(--fo-space-md) 0;
  color: var(--fo-color-ink-muted);
  font-size: var(--fo-text-sm);
}

section {
  margin-bottom: var(--fo-space-xl);
}

section > h2:first-child,
section > h3:first-child {
  margin-top: 0;
}

/* article = card */
article {
  background: var(--fo-color-paper-raised);
  border: 1px solid var(--fo-color-border-muted);
  border-radius: var(--fo-radius-lg);
  padding: var(--fo-space-lg);
  box-shadow: var(--fo-shadow-sm);
  margin-bottom: var(--fo-space-md);
}

article > header {
  margin: calc(-1 * var(--fo-space-lg));
  margin-bottom: var(--fo-space-lg);
  padding: var(--fo-space-md) var(--fo-space-lg);
  border-bottom: 1px solid var(--fo-color-border-muted);
  border-radius: var(--fo-radius-lg) var(--fo-radius-lg) 0 0;
}

article > header > :last-child {
  margin-bottom: 0;
}

article > footer {
  margin: calc(-1 * var(--fo-space-lg));
  margin-top: var(--fo-space-lg);
  padding: var(--fo-space-md) var(--fo-space-lg);
  border-top: 1px solid var(--fo-color-border-muted);
  border-radius: 0 0 var(--fo-radius-lg) var(--fo-radius-lg);
}

/* aside = callout */
aside {
  background: var(--fo-color-paper-raised);
  border-left: 3px solid var(--fo-color-accent-sky-400);
  padding: var(--fo-space-md) var(--fo-space-lg);
  border-radius: 0 var(--fo-radius-md) var(--fo-radius-md) 0;
  margin-bottom: var(--fo-space-md);
}

/* details/summary = disclosure */
details {
  border: 1px solid var(--fo-color-border-muted);
  border-radius: var(--fo-radius-md);
  padding: var(--fo-space-sm) var(--fo-space-md);
  margin-bottom: var(--fo-space-md);
}

summary {
  cursor: pointer;
  font-weight: 600;
  padding: var(--fo-space-sm) 0;
}

details[open] summary {
  margin-bottom: var(--fo-space-sm);
}

figure > img {
  border-radius: var(--fo-radius-md);
}

/* ── Forms ── */
input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  line-height: var(--fo-leading);
  color: var(--fo-color-ink);
  background: var(--fo-color-paper);
  border: 1px solid var(--fo-color-border);
  border-radius: var(--fo-radius-md);
  padding: var(--fo-space-sm) var(--fo-space-md);
  width: 100%;
  transition: border-color 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--fo-color-accent-sky-400);
  box-shadow: 0 0 0 2px var(--fo-color-accent-sky-100);
}

input::placeholder, textarea::placeholder {
  color: var(--fo-color-ink-faint);
}

/* Prevent iOS zoom */
@media (max-width: 48rem) {
  input, textarea, select {
    font-size: max(1rem, 16px);
  }
}

input[type="color"] {
  width: 100%;
  height: 2.5rem;
  padding: var(--fo-space-xs);
  cursor: pointer;
}

input[type="range"] {
  padding: 0;
  border: none;
  background: transparent;
}

input[type="range"]:focus {
  box-shadow: none;
}

label {
  display: block;
  font-size: var(--fo-text-sm);
  font-weight: 500;
  color: var(--fo-color-ink-sub);
  margin-bottom: var(--fo-space-md);
}

label > input,
label > textarea,
label > select {
  margin-top: var(--fo-space-xs);
}

fieldset {
  border: 1px solid var(--fo-color-border-muted);
  border-radius: var(--fo-radius-md);
  padding: var(--fo-space-md);
  margin-bottom: var(--fo-space-md);
}

legend {
  font-family: var(--fo-font-label);
  font-size: var(--fo-text-sm);
  font-weight: 500;
  letter-spacing: 0.03em;
  padding: 0 var(--fo-space-xs);
}

/* ── Buttons ── */
button, [role="button"] {
  font-family: var(--fo-font-body);
  font-size: var(--fo-text-sm);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
  color: var(--fo-color-btn-text, var(--fo-color-paper));
  background: var(--fo-color-btn, var(--fo-color-ink));
  border: 1.5px solid transparent;
  border-radius: var(--fo-radius-md);
  padding: 0.6rem 1.25rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--fo-space-xs);
  text-decoration: none;
  min-height: 2.75rem;
  transition: opacity 0.15s, background 0.15s;
}

button:hover, [role="button"]:hover {
  opacity: 0.85;
}

button:focus-visible, [role="button"]:focus-visible {
  outline: 2px solid var(--fo-color-ink-muted);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.fo-btn-outline {
  background: transparent;
  color: var(--fo-color-ink);
  border-color: var(--fo-color-border);
}

.fo-btn-outline:hover {
  background: var(--fo-color-paper-raised);
  opacity: 1;
}

.fo-btn-ghost {
  background: transparent;
  color: var(--fo-color-ink-muted);
  border-color: transparent;
}

.fo-btn-ghost:hover {
  color: var(--fo-color-ink);
  background: var(--fo-color-paper-raised);
  opacity: 1;
}

.fo-btn-sm {
  font-size: var(--fo-text-xs);
  padding: 0.35rem 0.75rem;
  border-radius: var(--fo-radius-sm);
  min-height: 2rem;
}

.fo-btn-xs {
  font-size: var(--fo-text-xs);
  padding: 0.15rem 0.4rem;
  border-radius: var(--fo-radius-sm);
  min-height: auto;
  line-height: 1.2;
}

/* Colored buttons */
.fo-btn-sage { background: var(--fo-color-accent-sage-400); color: white; }
.fo-btn-coral { background: var(--fo-color-accent-coral-400); color: white; }
.fo-btn-sky { background: var(--fo-color-accent-sky-400); color: white; }
.fo-btn-honey { background: var(--fo-color-accent-honey-400); color: var(--fo-color-ink); }

/* ── Tables ── */
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--fo-space-md);
  font-size: var(--fo-text-sm);
}

th, td {
  padding: var(--fo-space-sm) var(--fo-space-md);
  text-align: left;
  border-bottom: 1px solid var(--fo-color-border-muted);
}

th {
  font-weight: 600;
  color: var(--fo-color-ink-sub);
  border-bottom-color: var(--fo-color-border);
}

thead th {
  font-family: var(--fo-font-label);
  font-size: var(--fo-text-xs);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ── Chips & Badges ── */
.fo-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--fo-space-xs);
  font-family: var(--fo-font-label);
  font-size: var(--fo-text-xs);
  font-weight: 500;
  padding: 0.2em 0.6em;
  border-radius: var(--fo-radius-full);
  background: var(--fo-color-paper-raised);
  border: 1px solid var(--fo-color-border);
  color: var(--fo-color-ink-muted);
}

.fo-badge {
  display: inline-block;
  font-family: var(--fo-font-label);
  font-size: var(--fo-text-xs);
  font-weight: 600;
  padding: 0.15em 0.5em;
  border-radius: var(--fo-radius-sm);
  line-height: 1;
}

/* ── Dialog ── */
dialog {
  border: none;
  border-radius: var(--fo-radius-lg);
  padding: 0;
  max-width: min(90vw, 36rem);
  width: 100%;
  background: var(--fo-color-paper);
  color: var(--fo-color-ink);
  box-shadow: var(--fo-shadow-md);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

@supports (color: oklch(0 0 0)) {
  dialog::backdrop {
    background: oklch(0 0 0 / 0.4);
  }
}

dialog > article {
  margin: 0;
  border: none;
  box-shadow: none;
  background: transparent;
}

/* ── Toast ── */
.fo-toast {
  position: fixed;
  bottom: var(--fo-space-lg);
  right: var(--fo-space-lg);
  padding: var(--fo-space-sm) var(--fo-space-md);
  border-radius: var(--fo-radius-md);
  font-size: var(--fo-text-sm);
  font-weight: 500;
  color: var(--fo-color-paper);
  background: var(--fo-color-ink);
  box-shadow: var(--fo-shadow-md);
  z-index: 1000;
  animation: fo-toast-in 0.2s ease-out;
}

.fo-toast[data-type="success"] { background: var(--fo-color-accent-sage-400); }
.fo-toast[data-type="warning"] { background: var(--fo-color-accent-honey-400); color: var(--fo-color-ink); }
.fo-toast[data-type="danger"] { background: var(--fo-color-accent-coral-400); }

@keyframes fo-toast-in {
  from { opacity: 0; transform: translateY(0.5rem); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Toggle ── */
.fo-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--fo-space-sm);
  cursor: pointer;
}

.fo-toggle input {
  appearance: none;
  width: 2.75rem;
  height: 1.5rem;
  border-radius: var(--fo-radius-full);
  background: var(--fo-color-border);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  border: none;
  padding: 0;
  flex-shrink: 0;
}

.fo-toggle input::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(1.5rem - 6px);
  height: calc(1.5rem - 6px);
  border-radius: 50%;
  background: var(--fo-color-paper);
  transition: transform 0.15s;
}

.fo-toggle input:checked {
  background: var(--fo-color-accent-sky-400);
}

.fo-toggle input:checked::after {
  transform: translateX(1.25rem);
}

/* ── Tabs ── */
.fo-tabs [role="tablist"] {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--fo-color-border-muted);
  margin-bottom: var(--fo-space-md);
}

.fo-tabs [role="tab"] {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: var(--fo-space-sm) var(--fo-space-md);
  color: var(--fo-color-ink-muted);
  font-size: var(--fo-text-sm);
  font-weight: 500;
  cursor: pointer;
  min-height: auto;
}

.fo-tabs [role="tab"]:hover {
  color: var(--fo-color-ink);
  opacity: 1;
}

.fo-tabs [role="tab"][aria-selected="true"] {
  color: var(--fo-color-ink);
  border-bottom-color: var(--fo-color-ink);
}

.fo-tabs [role="tabpanel"] {
  display: none;
}

.fo-tabs [role="tabpanel"].active {
  display: block;
}

/* ── Label ── */
.fo-label {
  font-family: var(--fo-font-label);
  font-size: var(--fo-text-xs);
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fo-color-ink-muted);
}

/* ── Layout Helpers ── */
.fo-stack {
  display: flex;
  flex-direction: column;
  gap: var(--fo-space-md);
}

.fo-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--fo-space-md);
  align-items: center;
}

/* ── Utility ── */
.fo-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.fo-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Focus ── */
:focus-visible {
  outline: 2px solid var(--fo-color-ink-muted);
  outline-offset: 2px;
}

/* ── Popover ── */
.fo-popover {
  display: none;
  position: absolute;
  z-index: 100;
  background: var(--fo-color-paper-raised);
  border: 1px solid var(--fo-color-border);
  border-radius: var(--fo-radius-lg);
  padding: var(--fo-space-md);
  box-shadow: var(--fo-shadow-md);
  max-width: 18rem;
  width: max-content;
}

.fo-popover[data-placement="above"]::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: var(--fo-popover-arrow-left, 50%);
  transform: translateX(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: var(--fo-color-paper-raised);
  border-right: 1px solid var(--fo-color-border);
  border-bottom: 1px solid var(--fo-color-border);
}

.fo-popover[data-placement="below"]::after {
  content: '';
  position: absolute;
  top: -6px;
  left: var(--fo-popover-arrow-left, 50%);
  transform: translateX(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: var(--fo-color-paper-raised);
  border-left: 1px solid var(--fo-color-border);
  border-top: 1px solid var(--fo-color-border);
}

/* ── Score Display ── */
.fo-score {
  text-align: center;
}

.fo-score-value {
  font-size: var(--fo-text-2xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.fo-score-label {
  font-family: var(--fo-font-label);
  font-size: var(--fo-text-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fo-color-ink-muted);
  margin-top: var(--fo-space-xs);
}

.fo-score-caption {
  font-size: var(--fo-text-sm);
  color: var(--fo-color-ink-muted);
  margin-top: var(--fo-space-xs);
}

/* ── Stat List ── */
.fo-stat-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: var(--fo-text-sm);
}

.fo-stat-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--fo-space-xs) 0;
  margin: 0;
}

.fo-stat-list .fo-stat-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ── Highlight Marks ── */
.fo-mark-honey {
  background: var(--fo-color-accent-honey-200);
  border-radius: 2px;
  padding: 0.05em 0;
}

.fo-mark-coral {
  background: var(--fo-color-accent-coral-200);
  border-radius: 2px;
  padding: 0.05em 0;
}

.fo-mark-sky {
  background: var(--fo-color-accent-sky-200);
  border-radius: 2px;
  padding: 0.05em 0;
}

.fo-mark-sage {
  background: var(--fo-color-accent-sage-200);
  border-radius: 2px;
  padding: 0.05em 0;
}

.fo-mark-wisteria {
  background: var(--fo-color-accent-wisteria-200);
  border-radius: 2px;
  padding: 0.05em 0;
  border-bottom: 1.5px dashed var(--fo-color-accent-wisteria-400);
}

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

/* ── Accessibility: High Contrast ── */
@media (prefers-contrast: more) {
  :root {
    --fo-color-border: var(--fo-color-ink-muted);
    --fo-color-border-muted: var(--fo-color-ink-faint);
  }
}
