/* ═══════════════════════════════════════════════════════════════
   Koher UI System v4.1
   Canonical CSS for all Koher tool frontends.

   Usage:
     <body class="k" data-theme="coherence">

   Fonts (load before this stylesheet):
     Fraunces, Source Serif 4, IBM Plex Sans, IBM Plex Mono

   Source of truth: ui-system/koher-ui.css
   Reference: ui-system/reference.html
   ═══════════════════════════════════════════════════════════════ */


/* ── Reset ──────────────────────────────────────────────────────── */

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

html {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  scrollbar-width: none;
}
html::-webkit-scrollbar { display: none; }


/* ── Base tokens ────────────────────────────────────────────────── */

.k {
  /* Accent — default terracotta (Koher identity) */
  --accent: #C75B39;
  --accent-hover: #B04D2E;
  --accent-bg: rgba(199, 91, 57, 0.12);

  /* Dark surfaces */
  --bg: #2D3127;
  --border-dark: #4A4543;

  /* Light surfaces */
  --surface: #F7F3ED;
  --surface-border: #D8D0C8;
  --surface-inner: #EFEBE4;

  /* Ink — text on light backgrounds */
  --ink: #2D3436;
  --ink2: #4A4A48;
  --ink3: #6b6560;

  /* Light — text on dark backgrounds */
  --light: #F7F3ED;
  --light2: #9A8F85;
  --light3: #6b6560;

  /* Score system */
  --score-track: #D5D5D5;
  --score-fill: #B2A898;

  /* Three-state system */
  --state-solid: #3D7A4A;
  --state-examine: #A0823B;

  /* Typography stacks */
  --font-display: 'Fraunces', serif;
  --font-body: 'Source Serif 4', serif;
  --font-label: 'IBM Plex Sans', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;

  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.7;
  color: var(--light);
  background: var(--bg);
}

.k a { color: var(--accent); text-decoration: none; }
.k a:hover { text-decoration: underline; }
.k input, .k textarea { font-family: inherit; color: inherit; }
.k button { font: inherit; }


/* ── Typography ─────────────────────────────────────────────────── */

.k-title {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 400;
  line-height: 1.2;
}

.k-sub {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink3);
}

.k-tagline {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 14px;
  line-height: 1.5;
}

.k-lbl {
  font-family: var(--font-label);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* Label colour adapts to surface */
.k-lbl { color: var(--light2); }
.k-card .k-lbl { color: var(--ink3); }


/* ── Container ──────────────────────────────────────────────────── */

.k-container { max-width: 720px; margin: 0 auto; }


/* ── Header ─────────────────────────────────────────────────────── */

.k-header {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 16px 24px;
  background: rgba(45, 49, 39, 0.97);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-dark);
}

.k-header-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Tool identity: logo + name as one unit (left) */
.k-tool-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.k-tool-identity:hover { text-decoration: none; }

.k-tool-logo {
  height: 22px;
  width: auto;
  display: block;
}

.k-tool-name {
  font-family: var(--font-label);
  font-weight: 500;
  font-size: 15px;
  color: var(--light);
  letter-spacing: -0.01em;
}

/* Right section */
.k-header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.k-header-user {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--light2);
}

.k-header-link {
  font-family: var(--font-label);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--light3);
  transition: color 0.2s;
}
.k-header-link:hover { color: var(--light2); text-decoration: none; }

/* KOHER wordmark in header */
.k-wordmark {
  font-family: var(--font-label);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--light3);
  text-decoration: none;
  transition: color 0.2s;
}
.k-wordmark:hover { color: var(--light2); text-decoration: none; }


/* ── Gate (registration) ────────────────────────────────────────── */

.k-gate {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 70vh;
  padding: 40px 24px;
}

.k-gate-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 48px 40px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  color: var(--ink);
}

.k-gate-card .k-title { margin-bottom: 8px; }
.k-gate-card .k-sub { margin-bottom: 28px; }


/* ── Forms ───────────────────────────────────────────────────────── */

.k-form-group {
  text-align: left;
  margin-bottom: 16px;
}

.k-form-label {
  font-family: var(--font-label);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink3);
  margin-bottom: 6px;
  display: block;
}

.k-form-input {
  width: 100%;
  padding: 12px 16px;
  font-family: var(--font-label);
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 4px;
}
.k-form-input:focus {
  outline: none;
  border-color: var(--accent);
}


/* ── Buttons ─────────────────────────────────────────────────────── */

.k-btn-primary {
  font-family: var(--font-label);
  font-size: 15px;
  font-weight: 500;
  padding: 14px 32px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-block;
  text-align: center;
  background: var(--accent);
  color: #fff;
}
.k-btn-primary:hover { background: var(--accent-hover); text-decoration: none; }
.k-btn-primary:disabled {
  background: var(--border-dark);
  color: var(--light3);
  cursor: default;
}

.k-btn-outline {
  font-family: var(--font-label);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 24px;
  border: 1px solid var(--surface-border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  background: transparent;
  color: var(--ink3);
}
.k-btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.k-btn-ghost {
  font-family: var(--font-label);
  font-size: 13px;
  background: none;
  border: none;
  color: var(--light2);
  cursor: pointer;
  padding: 4px 10px;
}
.k-btn-ghost:hover { color: var(--light); }


/* ── Card ────────────────────────────────────────────────────────── */

.k-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 32px;
  color: var(--ink);
}


/* ── Echo (user input display) ───────────────────────────────────── */

.k-echo {
  border: 1px solid var(--surface-border);
  border-radius: 4px;
  padding: 16px 20px;
  font-family: var(--font-body);
  font-style: italic;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink2);
  margin-bottom: 20px;
}


/* ── Verdict ─────────────────────────────────────────────────────── */

.k-verdict { margin-bottom: 20px; }

.k-verdict-heading {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  margin-bottom: 8px;
}


/* ── Scores ──────────────────────────────────────────────────────── */

.k-scores {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.k-score {
  display: flex;
  align-items: center;
  gap: 12px;
}

.k-score-dim {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink3);
  width: 120px;
  flex-shrink: 0;
  text-align: right;
}

.k-score-bar {
  flex: 1;
  height: 6px;
  background: var(--score-track);
  border-radius: 3px;
  overflow: hidden;
}

.k-score-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--score-fill);
  transition: width 0.4s ease;
}

.k-score-fill-accent {
  background: var(--accent);
}

.k-score-val {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink2);
  width: 40px;
  flex-shrink: 0;
}


/* ── Narrative ───────────────────────────────────────────────────── */

.k-narrative {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
}

.k-narrative-bar {
  width: 4px;
  flex-shrink: 0;
  background: var(--accent);
  border-radius: 2px;
  margin-right: 20px;
}

.k-narrative-body {
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.8;
  color: var(--ink);
  flex: 1;
  min-width: 0;
}

.k-narrative-body p { margin-bottom: 12px; }
.k-narrative-body p:last-child { margin-bottom: 0; }
.k-narrative-body p:first-child { font-weight: 600; }


/* ── Chips ────────────────────────────────────────────────────────── */

.k-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.k-chip {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 10px;
  background: white;
  border: 1px solid var(--surface-border);
  border-radius: 3.5px;
  color: var(--ink2);
}

.k-chip-accent {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}


/* ── Behind the Curtain ──────────────────────────────────────────── */

.k-curtain-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 24px;
  margin-top: 28px;
  border-top: 1px solid #E4DDD5;
  cursor: pointer;
  user-select: none;
}

.k-curtain-text {
  font-family: var(--font-label);
  font-size: 13px;
  color: var(--ink3);
}

/* Toggle pill — 31×17px, rx 8.5 per wireframe */
.k-pill {
  width: 31px;
  height: 17px;
  border-radius: 8.5px;
  border: 1px solid var(--surface-border);
  background: var(--surface-inner);
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}

.k-pill-dot {
  position: absolute;
  top: 2.5px;
  left: 3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface-border);
  transition: transform 0.2s, background 0.2s;
}

.k-curtain-row[aria-expanded="true"] .k-pill {
  background: var(--accent);
  border-color: var(--accent);
}

.k-curtain-row[aria-expanded="true"] .k-pill-dot {
  transform: translateX(13px);
  background: #fff;
}


/* ── Pipeline (Q/R/L layers) ─────────────────────────────────────── */

.k-pipeline {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.4s ease, opacity 0.3s ease;
}

.k-pipeline.open {
  max-height: 2000px;
  opacity: 1;
}

.k-pipeline-head {
  font-family: var(--font-label);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink3);
  margin: 20px 0 16px;
}

.k-layer {
  display: flex;
  gap: 16px;
  padding: 16px 0;
  position: relative;
}

.k-layer + .k-layer { border-top: 1px solid #E4DDD5; }

/* Circled Q/R/L marker */
.k-layer-mark {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--ink3);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-label);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink3);
}

/* Vertical connector line between markers */
.k-layer:not(:last-child) .k-layer-mark::after {
  content: '';
  position: absolute;
  left: 12px;
  top: 44px;
  width: 1.5px;
  height: calc(100% - 44px);
  background: #E4DDD5;
}

.k-layer-body {
  flex: 1;
  min-width: 0;
}

.k-layer-name {
  font-family: var(--font-label);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 3px;
}

.k-layer-desc {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 14px;
  color: var(--ink3);
  line-height: 1.6;
  margin-bottom: 10px;
}


/* ── Loading ─────────────────────────────────────────────────────── */

.k-loading {
  text-align: center;
}

.k-loading-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--light3);
  margin-bottom: 12px;
}

.k-loading-bar {
  width: 200px;
  height: 2px;
  background: var(--border-dark);
  overflow: hidden;
  position: relative;
  margin: 0 auto;
}

.k-loading-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 28%;
  background: var(--accent);
  animation: k-sweep 1.6s ease-in-out infinite;
}

@keyframes k-sweep {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(460%); }
}

/* Skeleton placeholders */
.k-skel {
  background: linear-gradient(90deg, var(--surface-inner) 25%, var(--surface) 50%, var(--surface-inner) 75%);
  background-size: 200% 100%;
  animation: k-shimmer 1.5s infinite;
  border-radius: 4px;
}

@keyframes k-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}


/* ── Error ────────────────────────────────────────────────────────── */

.k-error {
  border-left: 3px solid #C75B39;
  background: rgba(199, 91, 57, 0.06);
  padding: 14px 18px;
  text-align: left;
  font-family: var(--font-label);
  font-size: 13px;
  color: var(--ink2);
  line-height: 1.5;
  border-radius: 0 4px 4px 0;
}

.k-error strong { color: #C75B39; font-weight: 500; }

/* Notice (informational, accent-coloured) */
.k-notice {
  border-left: 3px solid var(--accent);
  background: var(--accent-bg);
  padding: 14px 18px;
  text-align: left;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink2);
  line-height: 1.6;
  border-radius: 0 4px 4px 0;
}

.k-notice strong { color: var(--accent); font-weight: 600; }


/* ── Three-state symbols ─────────────────────────────────────────── */

.k-state-solid {
  color: var(--state-solid);
}
.k-state-solid::before { content: '●'; }

.k-state-examine {
  color: var(--state-examine);
}
.k-state-examine::before { content: '◐'; }

.k-state-attention {
  color: var(--accent);
}
.k-state-attention::before { content: '○'; }


/* ── Footer ──────────────────────────────────────────────────────── */

.k-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-dark);
  text-align: center;
}

.k-footer-mark {
  display: inline-block;
  margin-bottom: 6px;
}
.k-footer-mark:hover { text-decoration: none; }

.k-footer-tagline {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 12px;
  color: var(--light3);
  margin-bottom: 4px;
}

.k-footer-link {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--light2);
}
.k-footer-link:hover { color: var(--light); text-decoration: none; }


/* ── Themes ──────────────────────────────────────────────────────── */

/* Coherence — Teal */
[data-theme="coherence"] {
  --accent: #3B82A0;
  --accent-hover: #2E6A84;
  --accent-bg: rgba(59, 130, 160, 0.12);
}

/* Play Shape — Gold */
[data-theme="playshape"] {
  --accent: #A0823B;
  --accent-hover: #8A6F30;
  --accent-bg: rgba(160, 130, 59, 0.12);
}

/* Fragment Mapper — Deep blue */
[data-theme="fragment"] {
  --accent: #4A6FA5;
  --accent-hover: #3D5E8E;
  --accent-bg: rgba(74, 111, 165, 0.12);
}

/* Koher Garden — Forest green */
[data-theme="garden"] {
  --accent: #3D7A4A;
  --accent-hover: #326440;
  --accent-bg: rgba(61, 122, 74, 0.12);
}


/* ── Responsive ──────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .k-gate-card { padding: 32px 24px; }
  .k-card { padding: 24px; }
  .k-title { font-size: 24px; }
  .k-score-dim { width: 90px; font-size: 10px; }
}
