/* ═══════════════════════════════════════════════════
   SEMIOTICA — Mobile-First · WCAG 2.2 AA Compliant
   ═══════════════════════════════════════════════════ */

/* ── LIGHT (default) ──
   Contrast checks (text on --bg #f2f1ec):
   --text     #1a1a1a  → 15.4:1 ✓
   --text-sec #484842  → 6.5:1  ✓
   --text-dim #706e64  → 4.5:1  ✓ (AA minimum)
*/
body.light {
  --bg: #f2f1ec; --surface: #ffffff; --card: #ffffff;
  --card-hover: #f7f7f2; --border: #d6d4cc; --border-light: #c2c0b8;
  --text: #1a1a1a; --text-sec: #484842; --text-dim: #706e64;
  --green: #0a6e44; --green-bg: rgba(10,110,68,.06); --green-border: rgba(10,110,68,.22);
  --red: #b52a1c; --red-bg: rgba(181,42,28,.05); --red-border: rgba(181,42,28,.2);
  --accent: #4338ca;
  --shadow: rgba(0,0,0,.07);
  --sheet-bg: #ffffff;
  --col-precursors: #4a5568; --col-saussure: #1d4ed8;
  --col-peirce: #b52a1c; --col-hjelmslev: #6d28d9; --col-eco: #0a6e44;
  --dia-text: #1a1a1a; --dia-sec: #484842; --dia-dim: #706e64; --dia-bg: #f2f1ec; --dia-card: #eae9e3;
}

/* ── DARK ──
   Contrast checks (text on --bg #0e1018):
   --text     #e4e6ec  → 14.8:1 ✓
   --text-sec #a4a8b8  → 7.6:1  ✓
   --text-dim #808498  → 4.6:1  ✓ (AA minimum)
*/
body.dark {
  --bg: #0e1018; --surface: #161820; --card: #1c1f2a;
  --card-hover: #24273a; --border: #2c3044; --border-light: #3a3f55;
  --text: #e4e6ec; --text-sec: #a4a8b8; --text-dim: #808498;
  --green: #34d399; --green-bg: rgba(52,211,153,.07); --green-border: rgba(52,211,153,.22);
  --red: #f87171; --red-bg: rgba(248,113,113,.07); --red-border: rgba(248,113,113,.2);
  --accent: #a5b4fc;
  --shadow: rgba(0,0,0,.3);
  --sheet-bg: #161820;
  --col-precursors: #94a3b8; --col-saussure: #60a5fa;
  --col-peirce: #f87171; --col-hjelmslev: #a78bfa; --col-eco: #34d399;
  --dia-text: #e4e6ec; --dia-sec: #a4a8b8; --dia-dim: #808498; --dia-bg: #1c1f2a; --dia-card: #1c1f2a;
}

* { margin:0; padding:0; box-sizing:border-box; }
html { height:100%; -webkit-text-size-adjust:100%; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  min-height:100%; transition: background .25s, color .25s;
  -webkit-font-smoothing: antialiased;
}

/* ── TOPBAR ── */
#topbar {
  position: sticky; top:0; z-index:80;
  background: var(--surface); border-bottom: 1px solid var(--border);
  transition: background .25s;
}
#topbar-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; gap: 10px;
}

/* Brand + tagline aligned on baseline */
#brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
#brand h1 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 18px; font-weight: 700; letter-spacing: 0.06em;
  white-space: nowrap; flex-shrink: 0;
}
.tagline {
  font-size: 11px; color: var(--text-dim); font-style: italic;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: none; /* shown on desktop */
}

.toolbar { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
#search-box {
  width: 0; padding: 6px 0; opacity: 0;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font-size: 13px;
  font-family: inherit; outline: none;
  transition: width .25s, opacity .25s, padding .25s;
}
#search-box.open, #search-box { /* desktop override below */ }
#search-box:focus { border-color: var(--accent); }
#search-box::placeholder { color: var(--text-dim); }

.tb-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--text-sec); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s; font-family: inherit; font-size: 12px; font-weight: 700;
}
.tb-btn:hover, .tb-btn.active { border-color: var(--accent); color: var(--accent); }
.tb-btn svg { flex-shrink: 0; }
#lang-btn { width: auto; padding: 0 10px; font-size: 11px; letter-spacing: .03em; }

/* ── FILTERS ── */
#filters {
  display: flex; gap: 5px; padding: 6px 16px;
  overflow-x: auto; scrollbar-width: none;
  border-top: 1px solid var(--border);
}
#filters::-webkit-scrollbar { display: none; }
.f-btn {
  padding: 4px 12px; border-radius: 99px; border: 1px solid var(--border);
  background: transparent; color: var(--text-dim); font-size: 11px; font-weight: 600;
  cursor: pointer; white-space: nowrap; font-family: inherit; transition: all .15s;
}
.f-btn:hover { border-color: var(--text-sec); color: var(--text-sec); }
.f-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── AUTHOR TABS (mobile) ── */
#author-tabs {
  display: flex; gap: 0; overflow-x: auto; scrollbar-width: none;
  border-top: 1px solid var(--border);
}
#author-tabs::-webkit-scrollbar { display: none; }
.a-tab {
  flex: 1 0 auto; padding: 8px 14px; border: none; background: transparent;
  font-size: 12px; font-weight: 700; cursor: pointer;
  border-bottom: 3px solid transparent; transition: all .15s;
  font-family: inherit; color: var(--text-dim); white-space: nowrap;
}
.a-tab.active { border-bottom-color: var(--_c); color: var(--_c); }
.a-tab:hover { color: var(--text-sec); }

/* ── MAIN ── */
#main { padding: 12px 12px 100px; }
#columns-wrap { position: relative; }
#columns { display: flex; flex-direction: column; gap: 0; }

.col { display: none; }
.col.visible { display: block; }
.col-header { padding: 12px 4px 8px; margin-bottom: 4px; border-bottom: 2px solid var(--_c); display: flex; align-items: center; gap: 10px; }
.col-avatar {
  width: 38px; height: 38px; border-radius: 50%; object-fit: cover;
  border: 2px solid var(--_c); flex-shrink: 0;
  filter: grayscale(100%); opacity: 0.85; transition: filter .2s, opacity .2s;
}
.col-avatar-init {
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--_c) 12%, var(--bg));
  color: var(--_c); font-family: 'Cormorant Garamond', serif;
  font-size: 18px; font-weight: 700; filter: none; opacity: 1;
}
.col-header:hover .col-avatar { filter: grayscale(0%); opacity: 1; }
.col-header-text { min-width: 0; }
.col-header h2 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 20px; font-weight: 700; color: var(--_c); line-height: 1.1;
}
.col-years { font-size: 13px; font-weight: 400; color: var(--text-dim); white-space: nowrap; }
.col-header .col-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── CARDS ── */
.card {
  padding: 10px 12px; margin-bottom: 6px;
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: 8px; cursor: pointer; transition: all .2s;
  border-left: 3px solid var(--_c);
}
.card:hover { background: var(--card-hover); }
.card:active { transform: scale(.99); }
.card.selected {
  border-color: var(--_c);
  background: color-mix(in srgb, var(--_c) 6%, var(--card));
  box-shadow: 0 2px 12px var(--shadow);
}
.card.conn-agree { background: var(--green-bg); border-color: var(--green-border); border-left-color: var(--green); }
.card.conn-disagree { background: var(--red-bg); border-color: var(--red-border); border-left-color: var(--red); }
.card.dimmed { opacity: 0.12; pointer-events: none; transform: translateZ(0); }
.card-tag { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--_c); margin-bottom: 3px; }
.card-text { font-size: 13px; font-weight: 500; line-height: 1.4; color: var(--text); }

/* ── SVG LINES ── */
#lines-svg { display: none; }

/* ── BOTTOM SHEET (non-blocking) ── */
#sheet-overlay { display: none; }
#sheet {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--sheet-bg); border-radius: 14px 14px 0 0;
  box-shadow: 0 -2px 20px var(--shadow);
  max-height: 42vh; transform: translateY(100%);
  transition: transform .3s cubic-bezier(.32,.72,.24,1), background .25s;
  display: flex; flex-direction: column;
}
#sheet.open { transform: translateY(0); }
#sheet-handle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px 4px; flex-shrink: 0; min-height: 32px;
}
#sheet-handle span { width: 32px; height: 4px; border-radius: 2px; background: var(--border-light); }
#sheet-close-btn {
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--card);
  color: var(--text-dim); font-size: 15px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s; flex-shrink: 0; line-height: 1;
}
#sheet-close-btn:hover { color: var(--text); border-color: var(--accent); }
#sheet-scroll { overflow-y: auto; padding: 0 20px 28px; -webkit-overflow-scrolling: touch; }
#main.sheet-open { padding-bottom: 46vh; }

#s-author { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
#s-tag { display: inline-block; font-size: 10px; font-weight: 600; padding: 3px 10px; border-radius: 99px; margin-bottom: 10px; }
#s-text { font-family: 'Cormorant Garamond', serif; font-size: 19px; font-weight: 600; line-height: 1.4; color: var(--text); margin-bottom: 14px; }
#s-diagram { margin: 0 -4px 14px; padding: 14px; background: var(--dia-bg); border: 1px solid var(--border); border-radius: 10px; display: flex; justify-content: center; overflow-x: auto; }
#s-diagram:empty { display: none; margin:0; padding:0; }
#s-diagram svg { max-height: 200px; width: auto; flex-shrink: 0; }
#s-body { font-size: 14px; color: var(--text-sec); line-height: 1.75; }
#s-body b { color: var(--text); font-weight: 600; }
#s-conns-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); margin-top: 16px; margin-bottom: 6px; }
#s-conns-label:empty { display: none; }
#s-conns { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px; border-radius: 8px; font-size: 12px; font-weight: 600;
  cursor: pointer; border: 1px solid; background: none; font-family: inherit; transition: all .15s;
}
.chip:active { transform: scale(.97); }
.chip.agree { border-color: var(--green-border); color: var(--green); }
.chip.disagree { border-color: var(--red-border); color: var(--red); }
.chip .c-sign { font-size: 14px; line-height: 1; }
.chip .c-author { opacity: .7; font-size: 11px; }

/* ── INFO PANEL ── */
#info-panel {
  position: fixed; inset: 0; z-index: 200;
  background: var(--surface); overflow-y: auto;
  transform: translateX(100%); transition: transform .35s cubic-bezier(.32,.72,.24,1), background .25s;
}
#info-panel.open { transform: translateX(0); }
.info-close {
  position: fixed; top: 12px; right: 12px; z-index: 210;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--border);
  color: var(--text-sec); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.info-close:hover { color: var(--text); border-color: var(--accent); }
.info-body { max-width: 640px; margin: 0 auto; padding: 48px 20px 60px; }
.info-body h2 { font-family: 'Cormorant Garamond', serif; font-size: 28px; font-weight: 700; letter-spacing: .04em; }
.info-sub { font-size: 14px; color: var(--text-dim); margin-bottom: 2px; }
.info-tagline { font-size: 12px; color: var(--text-dim); font-style: italic; margin-bottom: 28px; }
.info-body h3 { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); margin: 28px 0 10px; padding-bottom: 5px; border-bottom: 1px solid var(--border); }
.info-body p { font-size: 14px; color: var(--text-sec); line-height: 1.7; margin-bottom: 8px; }
.info-body a { color: var(--accent); text-decoration: none; }
.info-body a:hover { text-decoration: underline; }
.info-body strong { color: var(--text); }
.refs { display: flex; flex-direction: column; gap: 6px; }
.ref { padding: 8px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 1px; transition: background .25s; }
.ref-a { font-size: 12px; font-weight: 700; color: var(--text); }
.ref em { font-size: 12px; color: var(--accent); }
.ref span:last-child { font-size: 11px; color: var(--text-dim); }
.info-credits { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--border); }
.info-credits p { font-size: 13px; margin-bottom: 4px; }
.copy { font-size: 11px; color: var(--text-dim); margin-top: 10px; }
.info-privacy { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
.info-privacy p { font-size: 12px; color: var(--text-dim); line-height: 1.6; }

/* ══════════════ DESKTOP ══════════════ */
@media (min-width: 768px) {
  .tagline { display: inline; }
  #search-box { width: 160px; padding: 6px 10px; opacity: 1; }
  #author-tabs { display: none; }
  #main { padding: 16px 16px 80px; }
  #columns { flex-direction: row; gap: 16px; overflow-x: auto; scrollbar-width: thin; padding-bottom: 8px; }
  .col { display: block !important; min-width: 340px; flex: 0 0 340px; }
  .col-header { position: sticky; top: 0; z-index: 5; background: var(--bg); }
  #lines-svg { display: block; position: absolute; top: 0; left: 0; pointer-events: none; z-index: 6; }
  #sheet { max-width: 780px; left: 50%; transform: translateX(-50%) translateY(100%); border-radius: 14px 14px 0 0; max-height: 45vh; }
  #sheet.open { transform: translateX(-50%) translateY(0); }
  #sheet-scroll { padding: 0 28px 32px; }
  #main.sheet-open { padding-bottom: 48vh; }
}
@media (min-width: 1100px) {
  .col { min-width: 360px; flex: 0 0 360px; }
}
