/* Apple-inspired design system matching main interface */
:root {
  --bg: #F5F5F7;
  --text: #1D1D1F;
  --muted: #6E6E73;
  --accent: #0A84FF;
  --accent-2: #64D2FF;
  --surface: #FFFFFF;
  --surface-2: rgba(255, 255, 255, 0.72);
  --border: rgba(0, 0, 0, 0.12);
  --radius: 14px;
  --shadow-1: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-2: 0 10px 30px rgba(0,0,0,0.12);
  --transition: 200ms ease;

  /* Stemma-specific colors */
  --family-a: #FF6B6B;
  --family-b: #4ECDC4;
  --family-c: #45B7D1;
  --family-d: #96CEB4;
  --family-e: #FFEAA7;
  --family-f: #DDA0DD;
  --family-g: #98D8C8;
}

/* Explicit theme overrides */
[data-theme="light"] {
  --bg: #F5F5F7;
  --text: #1D1D1F;
  --muted: #8E8E93;
  --surface: #FFFFFF;
  --surface-2: rgba(255, 255, 255, 0.72);
  --border: rgba(0, 0, 0, 0.1);
  --shadow-1: 0 1px 2px rgba(0,0,0,0.1);
  --shadow-2: 0 10px 30px rgba(0,0,0,0.15);
  --accent: #0A84FF;
}

[data-theme="dark"] {
  --bg: #1C1C1E;
  --text: #F5F5F7;
  --muted: #A1A1A6;
  --surface: #2C2C2E;
  --surface-2: rgba(44,44,46,0.72);
  --border: rgba(255, 255, 255, 0.14);
  --shadow-1: 0 1px 2px rgba(0,0,0,0.6);
  --shadow-2: 0 10px 30px rgba(0,0,0,0.5);
  --accent: #0A84FF;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1C1C1E;
    --text: #F5F5F7;
    --muted: #A1A1A6;
    --surface: #2C2C2E;
    --surface-2: rgba(44,44,46,0.72);
    --border: rgba(255, 255, 255, 0.14);
    --shadow-1: 0 1px 2px rgba(0,0,0,0.6);
    --shadow-2: 0 10px 30px rgba(0,0,0,0.5);
  }
}

body {
    font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
    margin: 0;
    padding: 20px;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

header {
    text-align: center;
    margin-bottom: 40px;
    padding-bottom: 24px;
}

h1 {
    color: var(--text);
    margin-bottom: 8px;
    font-weight: 700;
    font-size: 2.2rem;
    letter-spacing: -0.02em;
}

header p {
    color: var(--muted);
    margin-bottom: 24px;
    font-size: 0.98rem;
}

nav {
    margin-top: 16px;
}

.nav-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    display: inline-block;
}

.nav-link:hover {
    background: rgba(10,132,255,0.1);
}

main {
    max-width: 1200px;
    margin: 0 auto;
}

#family-roots-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.family-root {
    background: var(--surface-2);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    backdrop-filter: blur(16px) saturate(180%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow-1);
    position: relative;
    overflow: hidden;
}

.family-root::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--accent);
    transition: width var(--transition);
}

.family-root:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-2);
    border-color: rgba(10,132,255,0.35);
}

.family-root.active {
    border-color: var(--accent);
    box-shadow: var(--shadow-2);
}

.family-root.active::before {
    width: 6px;
}

.family-root h2 {
    margin: 0 0 12px 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}

.family-root p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--muted);
    line-height: 1.4;
}

/* Family-specific accent colors */
.family-root[data-family-id="A_Classical"]::before { background: var(--family-a); }
.family-root[data-family-id="B_LongSoak"]::before { background: var(--family-b); }
.family-root[data-family-id="C_Modern"]::before { background: var(--family-c); }
.family-root[data-family-id="D_SaltWaterBoil"]::before { background: var(--family-d); }
.family-root[data-family-id="E_Meta"]::before { background: var(--family-e); }
.family-root[data-family-id="F_Anomalous"]::before { background: var(--family-f); }
.family-root[data-family-id="G_Cepak"]::before { background: var(--family-g); }

.witness-group {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 20px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.hidden {
    display: none;
}

.witness-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-1);
    transition: all var(--transition);
    position: relative;
}

.witness-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-2);
    border-color: rgba(10,132,255,0.35);
}

.witness-card h3 {
    margin: 0 0 16px 0;
    color: var(--text);
    font-weight: 600;
    font-size: 1.1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}

.witness-card p {
    margin: 0 0 12px 0;
    font-size: 0.9rem;
    line-height: 1.4;
    color: var(--text);
}

.witness-card strong {
    color: var(--text);
    font-weight: 600;
}

.witness-card details {
    margin-top: 16px;
}

.witness-card summary {
    cursor: pointer;
    font-weight: 500;
    color: var(--accent);
    padding: 8px 0;
    border-top: 1px solid var(--border);
    user-select: none;
}

.witness-card summary:hover {
    color: var(--accent-2);
}

.witness-card pre {
    background: rgba(0,0,0,0.04);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.8rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    line-height: 1.4;
    margin-top: 8px;
    max-height: 400px;
    overflow-y: auto;
}

/* Responsive design */
@media (max-width: 900px) {
    #family-roots-container {
        grid-template-columns: 1fr;
    }

    .witness-group {
        grid-template-columns: 1fr;
    }

    body {
        padding: 16px;
    }
}

/* Theme toggle button */
.nav-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    margin-left: 8px;
    position: relative;
    z-index: 10;
}

.nav-btn:hover {
    border-color: var(--accent);
    background: rgba(10, 132, 255, 0.1);
}

/* Position theme toggle in top right */
nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}