/* App shell and components. Every value comes from tokens.css. Class names match the design system's (kd-*). */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--surface-000); color: var(--ink); font-family: var(--font-sans); font-size: 15px; line-height: 22px; }
a { color: var(--coral-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { text-wrap: balance; }
:where(a, button, input, select, textarea):focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* FocusOnNavigate moves focus to the page heading for screen readers; it is not an interactive target. */
h1:focus { outline: none; }
@media (prefers-reduced-motion: no-preference) {
  .kd-btn, .kd-nav { transition: background-color 150ms ease-out, color 150ms ease-out; }
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Shell: nav + main; on phones the nav becomes a bottom tab bar. */
.kd-shell { max-width: 1440px; margin: 0 auto; display: flex; min-height: 100vh; }
.kd-sidebar { flex: 0 0 var(--nav-width); position: sticky; top: 0; height: 100vh; align-self: flex-start; overflow-y: auto; padding: 28px 20px; display: flex; flex-direction: column; gap: 28px; border-right: 1px solid var(--border); }
.kd-sidebar-links { display: flex; flex-direction: column; gap: var(--space-1); }
.kd-sidebar-foot { margin-top: auto; padding: 14px; border-radius: var(--radius-lg); background: var(--surface-100); display: flex; flex-direction: column; gap: 6px; }
.kd-main { flex: 1 1 auto; min-width: 0; padding: 28px max(16px, 32px) 48px; }
.kd-page { max-width: var(--feed-width); display: flex; flex-direction: column; gap: var(--space-6); }
.kd-page-wide { max-width: 960px; }
.kd-page-head h1 { margin: 0; font-family: var(--font-display); font-size: 30px; line-height: 36px; font-weight: 700; letter-spacing: -0.02em; }
.kd-page-head p { margin: 4px 0 0; color: var(--ink-muted); }
.kd-page-head h1 .kd-badge { vertical-align: middle; margin-left: var(--space-2); }
.kd-label { font-size: 11px; line-height: 14px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
.kd-small { font-size: 13px; line-height: 18px; color: var(--ink-muted); }
/* A button or action row placed straight into a column keeps its own width. */
.kd-page > .kd-btn, .kd-card > .kd-btn, .kd-card > .kd-actions, .kd-profile-text > .kd-btn { align-self: flex-start; }

@media (max-width: 600px) {
  .kd-shell { flex-direction: column; }
  .kd-sidebar { position: fixed; inset: auto 0 0 0; height: auto; overflow: visible; z-index: 10; flex-direction: row; padding: 0 0 env(safe-area-inset-bottom, 0px); gap: 0; border-right: 0; border-top: 1px solid var(--border); background: var(--surface-100); }
  .kd-sidebar > .kd-logo, .kd-sidebar-foot { display: none; }
  .kd-sidebar-links { flex-direction: row; flex: 1; gap: 0; }
  .kd-sidebar-links .kd-nav { flex: 1; flex-direction: column; justify-content: center; gap: 2px; min-height: 60px; padding: 6px 0; font-size: 11px; border-radius: 0; }
  .kd-main { padding: 20px 16px 96px; }
}

/* Logo */
.kd-logo { display: inline-flex; align-items: center; gap: var(--space-3); color: var(--ink); }
.kd-logo:hover { text-decoration: none; }
.kd-logo-tile { width: 40px; height: 40px; border-radius: var(--radius-lg); display: inline-block; }
.kd-logo-word { font-family: var(--font-display); font-size: 22px; line-height: 28px; font-weight: 700; letter-spacing: -0.01em; }

/* Nav item */
.kd-nav { display: flex; align-items: center; gap: var(--space-3); padding: 10px 12px; min-height: var(--touch-min); border-radius: var(--radius-md); color: var(--ink-subtle); }
.kd-nav:hover { background: var(--surface-100); color: var(--ink); text-decoration: none; }
.kd-nav.active { background: var(--surface-200); color: var(--ink); font-weight: 600; }

/* Buttons */
.kd-btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: var(--touch-min); padding: 0 18px; border-radius: var(--radius-lg); border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; }
.kd-btn:hover { text-decoration: none; }
.kd-btn-primary { background: var(--coral); color: var(--on-coral); }
.kd-btn-secondary { background: transparent; color: var(--ink); border-color: var(--border-control); }
.kd-btn-secondary:hover { background: var(--surface-200); }
.kd-btn-ghost { background: transparent; color: var(--ink-subtle); }
.kd-btn-ghost:hover { background: var(--surface-200); color: var(--ink); }
.kd-btn-danger { background: var(--danger-bg); color: var(--danger-ink); }
.kd-btn-sm { min-height: 36px; padding: 0 12px; border-radius: var(--radius-md); font-size: 13px; }
.kd-btn[disabled] { opacity: 0.45; cursor: not-allowed; }

/* Badges */
/* inline-block, not flex, so ::first-letter can capitalise raw values such as "active". Badges hold text only. */
.kd-badge { display: inline-block; vertical-align: middle; padding: 3px 9px; border-radius: var(--radius-sm); font-size: 12px; line-height: 16px; font-weight: 600; white-space: nowrap; }
.kd-badge::first-letter { text-transform: uppercase; }
.kd-badge-admin { background: var(--ai-bg); color: var(--ai-ink); }
.kd-badge-guest { background: var(--guest-bg); color: var(--guest-ink); }
.kd-badge-success { background: var(--success-bg); color: var(--success-ink); }
.kd-badge-neutral { background: var(--surface-200); color: var(--ink-subtle); }
.kd-dot { width: 8px; height: 8px; border-radius: var(--radius-round); background: var(--success); display: inline-block; }

/* Card */
.kd-card { background: var(--surface-100); border: 1px solid var(--border); border-radius: var(--radius-xl); padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); }
/* The card's gap spaces its children, so they carry no margins of their own. */
.kd-card > :is(p, ul, ol) { margin: 0; }
.kd-card h2 { margin: 0; font-family: var(--font-display); font-size: 17px; line-height: 24px; font-weight: 600; }
.kd-danger-card { border-color: var(--danger-ink); }

/* Empty state */
.kd-empty { padding: var(--space-12) var(--space-6); text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.kd-empty h2 { margin: 0; font-family: var(--font-display); font-size: 17px; line-height: 24px; font-weight: 600; }
.kd-empty p { margin: 0; max-width: 420px; color: var(--ink-muted); }

/* Forms */
.kd-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kd-field label { font-size: 13px; line-height: 18px; color: var(--ink-muted); }
.kd-field input, .kd-field select { min-height: var(--touch-min); padding: 0 12px; border-radius: var(--radius-md); border: 1px solid var(--border-control); background: var(--surface-000); color: var(--ink); font: inherit; }
.kd-form-row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; }
.kd-form-row .kd-field { flex: 1 1 200px; }
.kd-error { color: var(--danger-ink); background: var(--danger-bg); padding: 10px 12px; border-radius: var(--radius-md); font-size: 14px; }

/* Table */
/* position: relative contains visually-hidden headers, which would otherwise widen the page on phones. */
.kd-table-wrap { overflow-x: auto; position: relative; }
.kd-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.kd-table th { text-align: left; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.kd-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.kd-mono { font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums; }

/* Sign-in */
.kd-auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.kd-auth-card { width: 100%; max-width: 420px; background: var(--surface-100); border: 1px solid var(--border); border-radius: var(--radius-xl); padding: var(--space-8); display: flex; flex-direction: column; gap: var(--space-5); }
.kd-auth-card h1 { margin: 0; font-family: var(--font-display); font-size: 30px; line-height: 36px; font-weight: 700; letter-spacing: -0.02em; }
.kd-auth-card p { margin: 0; color: var(--ink-muted); }
.kd-divider { display: flex; align-items: center; gap: var(--space-3); color: var(--ink-muted); font-size: 12px; }
.kd-divider::before, .kd-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* Loading */
.kd-loading { min-height: 100vh; display: flex; align-items: center; justify-content: center; color: var(--ink-muted); }

#blazor-error-ui { background: var(--danger-bg); color: var(--danger-ink); bottom: 0; display: none; left: 0; padding: 0.6rem 1.25rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

/* Avatars (design system: KinAvatar) */
.kd-avatar { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; border-radius: var(--radius-round); color: var(--kin-ink); font-weight: 700; object-fit: cover; object-position: center 20%; }
.kd-avatar-xs { width: 28px; height: 28px; font-size: 11px; }
.kd-avatar-sm { width: 34px; height: 34px; font-size: 12px; }
.kd-avatar-md { width: 42px; height: 42px; font-size: 14px; }
.kd-avatar-lg { width: 56px; height: 56px; font-size: 18px; }
.kd-avatar-xl { width: 152px; height: 152px; font-size: 44px; font-family: var(--font-display); }
.kd-tint-peach { background: var(--kin-peach); } .kd-tint-lilac { background: var(--kin-lilac); }
.kd-tint-mint { background: var(--kin-mint); } .kd-tint-honey { background: var(--kin-honey); }
.kd-badge-ai { background: var(--ai-bg); color: var(--ai-ink); font-size: 10px; line-height: 12px; padding: 2px 6px; letter-spacing: 0.05em; font-weight: 700; vertical-align: middle; }
.kd-badge-warning { background: var(--surface-200); color: var(--warning); }
.kd-badge-danger { background: var(--danger-bg); color: var(--danger-ink); }

/* Feed & post card (design system: PostCard) */
.kd-feed { display: flex; flex-direction: column; gap: var(--space-6); }
.kd-post { background: var(--surface-100); border: 1px solid var(--border); border-radius: var(--radius-xl); overflow: hidden; }
.kd-post-head { display: flex; align-items: center; gap: var(--space-3); padding: 14px var(--space-4); }
.kd-post-who { display: flex; align-items: center; gap: var(--space-3); color: var(--ink); min-width: 0; }
.kd-post-who:hover { text-decoration: none; }
.kd-post-who-text { display: flex; flex-direction: column; min-width: 0; }
.kd-post-name { font-weight: 600; }
.kd-post-meta { font-size: 13px; line-height: 18px; color: var(--ink-muted); }
.kd-photo { display: block; aspect-ratio: 4 / 5; background: var(--photo-placeholder); max-width: 100%; }
.kd-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kd-post-body { padding: 14px var(--space-4) 18px; display: flex; flex-direction: column; gap: 6px; }
.kd-post-caption { margin: 0; white-space: pre-line; }
.kd-post-tags { margin: 0; color: var(--coral-text); font-size: 14px; }
.kd-load-more { align-self: center; }
/* New posts landed while reading (docs/features/live-updates.md § The feed). Sticks to the top of the viewport. */
.kd-page > .kd-new-posts { position: sticky; top: var(--space-4); z-index: 5; align-self: center; margin-bottom: calc(-1 * var(--space-6)); box-shadow: var(--shadow-float); border-radius: 999px; }
.kd-end { text-align: center; }

/* Kin index */
.kd-kin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--space-4); }
.kd-kin-card { display: flex; gap: var(--space-4); padding: var(--space-5); background: var(--surface-100); border: 1px solid var(--border); border-radius: var(--radius-xl); color: var(--ink); }
.kd-kin-card:hover { background: var(--surface-200); text-decoration: none; }
.kd-kin-card-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kd-kin-card-bio { font-size: 14px; color: var(--ink-subtle); }

/* Comments (design system: Comment). People get a rounded square, never a Kin's circle. */
.kd-post-comments { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; min-height: var(--touch-min); color: var(--ink-subtle); font-size: 14px; }
.kd-post-comments:hover { color: var(--ink); text-decoration: none; }
.kd-comments { border-top: 1px solid var(--border); padding-top: var(--space-3); display: flex; flex-direction: column; gap: var(--space-3); }
.kd-comment-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.kd-comment { display: flex; gap: var(--space-3); align-items: flex-start; }
.kd-comment-replies { padding-left: calc(34px + var(--space-3)); }
.kd-person-avatar { border-radius: var(--radius-md); background: var(--surface-300); color: var(--ink); }
.kd-comment-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.kd-comment-head { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--space-2); }
.kd-comment-name { font-weight: 600; color: var(--ink); }
.kd-comment-text { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
.kd-comment-to { color: var(--coral-text); }
.kd-comment-actions { display: flex; flex-wrap: wrap; gap: var(--space-1); margin-left: -12px; }
.kd-comment-placeholder { margin: 0; font-style: italic; }
.kd-comment-reason { margin: 0; overflow-wrap: anywhere; }
.kd-queue-comment .kd-draft-text p { margin: 0; overflow-wrap: anywhere; }
.kd-comment-form { display: flex; flex-direction: column; gap: var(--space-2); }
.kd-comment-replying { margin: 0; display: flex; align-items: center; gap: var(--space-2); }

/* Profile */
.kd-profile { display: flex; flex-wrap: wrap; gap: var(--space-8); align-items: center; }
.kd-profile-text { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.kd-profile-title { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.kd-profile-title h1 { margin: 0; font-family: var(--font-display); font-size: 30px; line-height: 36px; font-weight: 700; letter-spacing: -0.02em; }
.kd-profile-text p { margin: 0; }
.kd-profile-bio { max-width: 520px; }
.kd-profile-stats { display: flex; flex-wrap: wrap; gap: 0 var(--space-5); }
.kd-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.kd-chip { display: inline-flex; align-items: center; min-height: 30px; padding: 0 12px; border-radius: var(--radius-pill); background: var(--surface-200); font-size: 14px; }
button.kd-chip { border: 1px solid transparent; color: var(--ink); font: inherit; font-size: 14px; cursor: pointer; }
button.kd-chip:hover { border-color: var(--border-control); }
.kd-chip-on, button.kd-chip-on { background: var(--ink); color: var(--surface-000); }
.kd-ref-messages { margin: 0; padding-left: var(--space-5); font-size: 13px; line-height: 18px; color: var(--ink-muted); display: flex; flex-direction: column; gap: 4px; overflow-wrap: anywhere; }
.kd-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.kd-grid-tile { display: block; aspect-ratio: 4 / 5; border-radius: var(--radius-sm); overflow: hidden; background: var(--photo-placeholder); }
.kd-grid-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Post view */
.kd-back { align-self: flex-start; color: var(--ink-subtle); min-height: var(--touch-min); display: inline-flex; align-items: center; }
.kd-postview { display: flex; flex-wrap: wrap; background: var(--surface-100); border: 1px solid var(--border); border-radius: var(--radius-xl); overflow: clip; }
.kd-postview-photo { align-self: flex-start; flex: 1 1 380px; min-width: 0; aspect-ratio: 4 / 5; background: var(--photo-placeholder); max-width: 100%; }
/* Side by side (wide enough that the columns don't wrap), the photo stays in view beside the long text column. clip, not hidden, on the card keeps sticky working. */
@media (min-width: 1100px) { .kd-postview-photo { position: sticky; top: 0; } }
.kd-postview-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kd-postview-side { flex: 1 1 320px; min-width: 0; padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-3); }
.kd-postview-side h2, .kd-making h2 { margin: var(--space-2) 0 0; font-family: var(--font-display); font-size: 17px; line-height: 24px; font-weight: 600; }
.kd-making { border-top: 1px solid var(--border); padding-top: var(--space-3); display: flex; flex-direction: column; gap: var(--space-3); }
.kd-timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.kd-timeline li { display: flex; flex-direction: column; gap: 2px; padding-left: var(--space-4); border-left: 2px solid var(--surface-300); font-size: 14px; }
.kd-timeline-stage { font-size: 11px; line-height: 14px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--violet); }
.kd-details summary { cursor: pointer; color: var(--ink-subtle); min-height: var(--touch-min); display: flex; align-items: center; }
pre.kd-code { white-space: pre-wrap; word-break: break-word; background: var(--surface-000); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-3); margin: 0; }

/* Admin */
.kd-admin-tabs { display: flex; flex-wrap: wrap; gap: 22px; border-bottom: 1px solid var(--border); }
.kd-admin-tab { min-height: var(--touch-min); display: inline-flex; align-items: center; color: var(--ink-muted); font-weight: 600; border-bottom: 2px solid transparent; }
.kd-admin-tab:hover { color: var(--ink); text-decoration: none; }
.kd-admin-tab.active { color: var(--ink); border-bottom-color: var(--coral); }
.kd-cell-actions { text-align: right; white-space: nowrap; }
@media (max-width: 600px) {
  /* One row that scrolls sideways, rather than tabs wrapping onto a second line. */
  .kd-admin-tabs { flex-wrap: nowrap; gap: 18px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
  .kd-admin-tab { flex-shrink: 0; }
}
.kd-banner { margin: 0; padding: 10px 14px; border-radius: var(--radius-md); background: var(--surface-200); color: var(--ink); }
.kd-card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: var(--space-3); }
.kd-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.kd-stat { padding: var(--space-3); border-radius: var(--radius-lg); background: var(--surface-200); }
.kd-stat-value { font-family: var(--font-display); font-size: 22px; line-height: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kd-stat-label { font-size: 12px; line-height: 16px; color: var(--ink-muted); }
a.kd-stat-link { color: var(--ink); text-decoration: none; }
a.kd-stat-link:hover { background: var(--surface-300); }
a.kd-stat-link .kd-stat-label { color: var(--coral-text); }
.kd-table-kin { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--ink); font-weight: 600; }
.kd-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.kd-editor-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: var(--space-4); }
.kd-form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-3); }
.kd-field textarea { padding: 10px 12px; border-radius: var(--radius-md); border: 1px solid var(--border-control); background: var(--surface-000); color: var(--ink); font: inherit; resize: vertical; }
textarea.kd-code { font-family: var(--font-mono); font-size: 13px; line-height: 19px; }
.kd-drafts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.kd-draft { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
.kd-draft:last-child { border-bottom: 0; }
.kd-draft-thumb { width: 64px; aspect-ratio: 4 / 5; border-radius: var(--radius-sm); object-fit: cover; background: var(--photo-placeholder); flex-shrink: 0; display: block; }
.kd-draft-text { flex: 1 1 240px; min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.kd-draft-links { display: flex; gap: var(--space-4); font-size: 13px; }
.kd-activity-reason { min-width: 240px; }
@media (max-width: 600px) { .kd-activity-reason { min-width: 0; } }

/* Kin import */
.kd-select { min-height: var(--touch-min); padding: 0 12px; border-radius: var(--radius-md); border: 1px solid var(--border-control); background: var(--surface-000); color: var(--ink); font: inherit; }
.kd-import-image { width: 100%; max-width: 280px; aspect-ratio: 4 / 5; object-fit: cover; border-radius: var(--radius-md); background: var(--photo-placeholder); display: block; }
.kd-import-layout { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: var(--space-4); align-items: start; }
.kd-import-layout pre.kd-code { max-height: 220px; overflow: auto; }
@media (max-width: 720px) { .kd-import-layout { grid-template-columns: minmax(0, 1fr); } }

/* Kin portraits */
.kd-portraits { display: flex; flex-wrap: wrap; gap: var(--space-4); margin-bottom: var(--space-3); }
.kd-portrait { margin: 0; width: 152px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-muted); }
.kd-portrait img, .kd-portrait-empty { width: 152px; height: 152px; border-radius: var(--radius-sm); object-fit: cover; background: var(--photo-placeholder); display: block; }
.kd-portrait-empty { display: flex; align-items: center; justify-content: center; text-align: center; border: 1px dashed var(--border-control); color: var(--ink-subtle); }
.kd-portrait img.kd-portrait-whole { object-fit: contain; }
.kd-import-layout .kd-portraits { gap: var(--space-3); }
/* The native file input, with its button drawn like a small secondary button. */
.kd-field input[type=file] { min-height: auto; padding: 8px; border-style: dashed; color: var(--ink-subtle); cursor: pointer; }
.kd-field input[type=file]::file-selector-button { margin-right: var(--space-3); min-height: 36px; padding: 0 12px; border-radius: var(--radius-md); border: 1px solid var(--border-control); background: transparent; color: var(--ink); font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; }
.kd-field input[type=file]::file-selector-button:hover { background: var(--surface-200); }
.kd-choice { border: 0; padding: 0; margin: 0 0 var(--space-3); display: flex; flex-wrap: wrap; gap: 6px var(--space-4); font-size: 14px; }
.kd-choice legend { width: 100%; padding: 0; margin-bottom: 4px; font-size: 13px; color: var(--ink-muted); }
.kd-choice label { display: inline-flex; align-items: center; gap: 6px; }

/* Tables that become one card per row on phones (opt in with kd-table-stack; each td carries data-label). */
@media (max-width: 600px) {
  .kd-table-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .kd-table-stack, .kd-table-stack tbody, .kd-table-stack tr { display: block; }
  .kd-table-stack tr { padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
  .kd-table-stack tr:last-child { border-bottom: 0; }
  .kd-table-stack td { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-2); padding: 2px 0; border: 0; text-align: left; }
  .kd-table-stack td::before { content: attr(data-label); flex: 0 0 96px; font-family: var(--font-sans); font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
  .kd-table-stack td:first-child { padding-bottom: var(--space-2); }
  .kd-table-stack td:first-child::before, .kd-table-stack td[data-label=""]::before { content: none; }
  .kd-table-stack td:empty { display: none; }
}

/* Profile header on phones: a smaller face beside the name and handle; the rest runs full width below. */
@media (max-width: 600px) {
  .kd-profile { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: var(--space-2) var(--space-4); align-items: center; }
  .kd-profile > .kd-avatar { grid-row: span 2; width: 88px; height: 88px; font-size: 28px; }
  .kd-profile-text { display: contents; }
  .kd-profile-text > :nth-child(n+3) { grid-column: 1 / -1; }
  .kd-profile-text > :nth-child(3) { margin-top: var(--space-2); }
  .kd-profile-text > .kd-btn { justify-self: start; }
  .kd-profile-title h1 { font-size: 24px; line-height: 30px; }
}

/* Kin editor save bar: stays at the bottom of the viewport while the long form scrolls. */
.kd-savebar { position: sticky; bottom: var(--space-4); z-index: 5; display: flex; align-items: center; justify-content: flex-end; gap: var(--space-4); padding: var(--space-3) var(--space-3) var(--space-3) var(--space-5); border-radius: var(--radius-xl); border: 1px solid var(--border); background: var(--surface-100); box-shadow: var(--shadow-float); }
.kd-savebar-status { margin-right: auto; font-size: 14px; color: var(--ink-muted); }
.kd-savebar-dirty .kd-savebar-status { color: var(--ink); font-weight: 600; }
.kd-savebar-dirty .kd-savebar-status::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: var(--space-2); border-radius: var(--radius-round); background: var(--coral); vertical-align: middle; }
@media (max-width: 600px) { .kd-savebar { bottom: calc(68px + env(safe-area-inset-bottom, 0px)); } }

/* Likes (social interactions 1b): the count beside the comment count, and "Liked by" on a post. */
.kd-post-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--space-4); }
.kd-post-likes { display: inline-flex; align-items: center; gap: 6px; min-height: var(--touch-min); color: var(--ink-subtle); font-size: 14px; }
.kd-liked-by { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: 14px; color: var(--ink-subtle); }
.kd-liked-by-faces { display: inline-flex; }
.kd-liked-by-faces .kd-avatar + .kd-avatar { margin-left: -8px; box-shadow: 0 0 0 2px var(--surface-100); }

/* Kin editor: browse sessions and their decisions. */
.kd-sessions, .kd-decisions { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.kd-session { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3) 0; border-bottom: 1px solid var(--border); min-width: 0; }
.kd-session:last-child { border-bottom: 0; }
.kd-session-head, .kd-decision-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--space-2); min-width: 0; }
.kd-session-error { margin: 0; color: var(--danger-ink); overflow-wrap: anywhere; }
.kd-decisions { gap: var(--space-3); padding-left: var(--space-4); border-left: 2px solid var(--surface-300); }
.kd-decision { display: flex; flex-direction: column; gap: 2px; font-size: 14px; min-width: 0; }
.kd-decision-text, .kd-decision-reason { overflow-wrap: anywhere; }

/* Reference library: the Kin editor's library card and the import page's face picker */
.kd-library-group { flex-direction: column; flex-wrap: nowrap; gap: var(--space-2); }
.kd-library-option { display: flex !important; align-items: flex-start; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid var(--border); min-width: 0; }
.kd-library-option:last-child { border-bottom: 0; }
.kd-library-option input { margin-top: 3px; flex-shrink: 0; }
.kd-library-thumb { width: 44px; aspect-ratio: 4 / 5; border-radius: var(--radius-sm); object-fit: cover; background: var(--photo-placeholder); flex-shrink: 0; }
.kd-library-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.kd-library-unavailable { opacity: 0.75; }
.kd-face-library { flex-direction: column; flex-wrap: nowrap; }
.kd-face-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--space-2); }
.kd-face { display: flex; flex-direction: column; gap: 4px; padding: 4px; border-radius: var(--radius-md); border: 2px solid transparent; background: var(--surface-200); color: var(--ink); font: inherit; font-size: 12px; line-height: 16px; cursor: pointer; text-align: left; min-width: 0; }
.kd-face img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; border-radius: var(--radius-sm); display: block; }
.kd-face span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kd-face-on { border-color: var(--ink); }

/* Admin → Settings: which deployment secrets are set. */
.kd-secrets { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.kd-secrets li { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.kd-secrets li:first-child { border-top: 0; }
.kd-secret-name { display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow-wrap: anywhere; }

/* Import review: the consistency baseline renders (docs/features/kin-import.md §4). */
.kd-baseline { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 720px; gap: var(--space-4); }
.kd-baseline-render { margin: 0; display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.kd-baseline-render img, .kd-baseline-render .kd-portrait-empty { width: 100%; height: auto; aspect-ratio: 4 / 5; object-fit: cover; border-radius: var(--radius-md); background: var(--surface-200); }
.kd-baseline-render figcaption { display: flex; flex-direction: column; gap: 2px; overflow-wrap: anywhere; }
.kd-baseline-score { font-weight: 600; }
@media (max-width: 600px) { .kd-baseline { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kd-baseline-low, .kd-baseline-error { color: var(--warning); }

/* Profile counts that open the follower and following lists (docs/features/social-interactions.md §7). */
.kd-profile-stat-link { color: inherit; }
.kd-profile-stat-link:hover { text-decoration: underline; }
.kd-follow-list { list-style: none; margin: var(--space-4) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.kd-follow-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); background: var(--surface-100); border: 1px solid var(--border); border-radius: var(--radius-lg); color: var(--ink); min-width: 0; }
.kd-follow-row:hover { background: var(--surface-200); text-decoration: none; }
.kd-follow-row .kd-kin-card-text { flex: 1; }
.kd-follow-since { flex-shrink: 0; }

/* Kin editor → Memory (docs/features/kin-memory-and-relationships.md §4) */
.kd-facts { list-style: none; margin: 0 0 var(--space-3); padding: 0; }
.kd-fact { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-2) 0; border-bottom: 1px solid var(--border); min-width: 0; }
.kd-fact:last-child { border-bottom: 0; }
.kd-fact-text { flex: 1 1 16rem; min-width: 0; overflow-wrap: anywhere; }
.kd-fact-text .kd-small { margin-left: var(--space-2); }
.kd-fact > input, .kd-fact-add input { flex: 1 1 16rem; min-width: 0; }
.kd-fact-add { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin-bottom: var(--space-4); }
.kd-pin-fact { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-3) 0; }
.kd-fact input, .kd-fact-add input { min-height: var(--touch-min); padding: 0 12px; border-radius: var(--radius-md); border: 1px solid var(--border-control); background: var(--surface-000); color: var(--ink); font: inherit; }
.kd-arc-form { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-2) 0 var(--space-4); }
.kd-arc-form .kd-btn { align-self: flex-start; }

/* Relationships: the Kin editor card and the ecosystem graph (docs/features/kin-memory-and-relationships.md §4).
   Hue says the sign (warm blue, cold red); a solid line is the strong stance, a dashed one the mild one, so colour is never alone. */
.kd-relationship { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3) 0; border-bottom: 1px solid var(--border); min-width: 0; }
.kd-relationship:last-child { border-bottom: 0; }
.kd-relationship-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
.kd-relationship-head .kd-btn { margin-left: auto; }
.kd-relationship-note { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); padding-left: var(--space-4); }
.kd-relationship-note input, .kd-relationship .kd-fact-add input { flex: 1 1 16rem; min-width: 0; min-height: var(--touch-min); padding: 0 12px; border-radius: var(--radius-md); border: 1px solid var(--border-control); background: var(--surface-000); color: var(--ink); font: inherit; }
.kd-relationship-edit { margin-top: var(--space-2); }
.kd-relationship > .kd-btn { align-self: flex-start; }
.kd-stance { font-size: 13px; font-weight: 600; color: var(--ink); padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border-control); }
.kd-stance-friend, .kd-stance-friendly { border-color: var(--stance-warm); }
.kd-stance-cool, .kd-stance-rival { border-color: var(--stance-cold); }
.kd-stance-cool, .kd-stance-friendly { border-style: dashed; }
.kd-graph { display: block; width: 100%; max-width: 560px; height: auto; margin: 0 auto; }
.kd-graph-legend { list-style: none; margin: 0 0 var(--space-3); padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); font-size: 13px; color: var(--ink-subtle); }
.kd-graph-legend li { display: inline-flex; align-items: center; gap: var(--space-2); }
.kd-edge { stroke-width: 2; stroke-linecap: round; }
.kd-edge-friend, .kd-edge-rival { stroke-width: 2.5; }
.kd-edge-friendly, .kd-edge-cool { stroke-dasharray: 5 4; }
.kd-edge-friend, .kd-edge-friendly { stroke: var(--stance-warm); }
.kd-edge-cool, .kd-edge-rival { stroke: var(--stance-cold); }
.kd-arrow-friend, .kd-arrow-friendly { fill: var(--stance-warm); }
.kd-arrow-cool, .kd-arrow-rival { fill: var(--stance-cold); }
.kd-edge-hit { stroke: transparent; stroke-width: 14; pointer-events: stroke; }
.kd-edge-hit:hover { stroke: color-mix(in srgb, var(--ink) 10%, transparent); }
.kd-node circle { stroke: var(--surface-100); stroke-width: 2; }
.kd-node-initials { fill: var(--kin-ink); font-size: 14px; font-weight: 700; pointer-events: none; }
.kd-node-name { fill: var(--ink); font-size: 15px; font-weight: 600; }
.kd-node a:focus-visible circle { stroke: var(--focus); stroke-width: 3; }
.kd-itinerary { display: flex; flex-direction: column; gap: var(--space-2); }
.kd-itinerary-leg { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) auto; gap: var(--space-2); align-items: end; }
@media (max-width: 640px) { .kd-itinerary-leg { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .kd-itinerary-leg > .kd-field:first-child { grid-column: 1 / -1; } }
