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

html { width: 100%; min-height: 100%; }

body {
    width: 100%;
    min-height: 100vh;
    overflow-x: hidden;
    font-family: Inter, Arial, Helvetica, sans-serif;
    background: #0b0e13;
    color: #f2f5f8;
    transition: background .35s ease, color .35s ease;
}

button, input { font: inherit; }

body.light-theme { background: #eef1f5; color: #171b21; }

.page {
    display: none;
    width: 100%;
    min-height: 100vh;
    padding: 40px;
    animation: pageIn .45s ease;
}

.page.active { display: block; }

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

.welcome-content {
    width: min(700px, 90vw);
    margin: 0 auto;
    text-align: center;
    padding-top: 20vh;
}

#welcomePage {
    display: none;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: radial-gradient(circle at center, rgba(80,130,190,.16), transparent 55%);
}

#welcomePage.active { display: flex; }

.welcome-badge, .eyebrow {
    margin-bottom: 14px;
    font-size: 11px;
    letter-spacing: .22em;
    font-weight: 700;
    opacity: .55;
}

.welcome-content h1 {
    margin-bottom: 18px;
    font-size: clamp(42px, 7vw, 82px);
    line-height: .95;
    letter-spacing: -.05em;
}

.welcome-content p {
    max-width: 560px;
    margin: 0 auto 34px;
    font-size: 17px;
    line-height: 1.7;
    opacity: .65;
}

.primary-button {
    border: 0;
    padding: 15px 34px;
    border-radius: 12px;
    background: #fff;
    color: #101319;
    font-weight: 800;
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease;
}

.primary-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 35px rgba(0,0,0,.25);
}

body.light-theme .primary-button { background: #171b21; color: #fff; }

.page-header {
    width: min(1200px, 100%);
    margin: 0 auto 40px;
    display: flex;
    align-items: center;
    gap: 30px;
}

.page-header h2, .tree-header h2 {
    font-size: clamp(28px, 4vw, 48px);
    letter-spacing: -.035em;
}

.back-button {
    border: 0;
    background: transparent;
    color: inherit;
    opacity: .55;
    cursor: pointer;
    transition: opacity .2s ease, transform .2s ease;
}

.back-button:hover { opacity: 1; transform: translateX(-4px); }

.cards-grid {
    width: min(1200px, 100%);
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 24px;
}

.database-card {
    position: relative;
    overflow: hidden;
    border-radius: 16px;
    background: rgba(255,255,255,.055);
    border: 1px solid rgba(255,255,255,.07);
    cursor: pointer;
    transition: transform .3s ease, background .3s ease, box-shadow .3s ease;
}

.database-card:hover {
    transform: translateY(-6px);
    background: rgba(255,255,255,.085);
    box-shadow: 0 18px 45px rgba(0,0,0,.25);
}

.card-image {
    display: block;
    width: 100%;
    aspect-ratio: 2 / 3;
    object-fit: cover;
}

.card-content { padding: 15px 16px 18px; }
.card-title { font-size: 18px; margin-bottom: 9px; }

.faction-card { text-align: center; }
.faction-card .card-image { aspect-ratio: 1 / 1; }
.faction-card .card-content { padding-bottom: 20px; }

.faction-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.faction-tag {
    padding: 4px 8px;
    border-radius: 20px;
    background: rgba(255,255,255,.08);
    font-size: 10px;
    opacity: .65;
}

body.light-theme .database-card {
    background: rgba(255,255,255,.72);
    border-color: rgba(0,0,0,.07);
}

body.light-theme .database-card:hover { background: #fff; }

.tree-page {
    position: relative;
    padding: 25px 30px 30px;
    overflow: hidden;
}

.tree-header {
    position: relative;
    z-index: 20;
    width: 100%;
    min-height: 70px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 20px;
    margin-bottom: 15px;
}

.tree-title { text-align: center; }
.tree-header .back-button { justify-self: start; }

.settings-button {
    justify-self: end;
    width: 44px;
    height: 44px;
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 50%;
    background: rgba(255,255,255,.055);
    color: inherit;
    font-size: 20px;
    cursor: pointer;
    backdrop-filter: blur(12px);
    transition: transform .25s ease, background .25s ease, border-color .25s ease;
}

.settings-button:hover {
    transform: rotate(30deg);
    background: rgba(255,255,255,.11);
    border-color: rgba(255,255,255,.18);
}

body.light-theme .settings-button {
    border-color: rgba(0,0,0,.08);
    background: rgba(255,255,255,.75);
}

.relationship-tree {
    position: relative;
    width: 100%;
    height: calc(100vh - 130px);
    min-height: 600px;
    overflow: hidden;
    border-radius: 20px;
    background: radial-gradient(circle at center, rgba(255,255,255,.025), transparent 65%);
    touch-action: none;
}

.relationship-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
    z-index: 1;
}

.tree-nodes { position: absolute; inset: 0; z-index: 2; }

.tree-node {
    position: absolute;
    width: 105px;
    transform: translate(-50%, -50%);
    cursor: grab;
    user-select: none;
    touch-action: none;
    will-change: left, top;
    z-index: 5;
}

.tree-node:active { cursor: grabbing; }

.tree-node-image {
    display: block;
    width: 105px;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    border-radius: 10px;
    border: 3px solid transparent;
    box-shadow: 0 10px 30px rgba(0,0,0,.3);
    transition: box-shadow .2s ease, filter .2s ease;
}

.tree-node-name {
    margin-top: 6px;
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    opacity: .8;
}

.tree-node.friend:hover .tree-node-image {
    box-shadow: 0 0 0 3px #8ecbff, 0 0 22px rgba(142,203,255,.55);
}

.tree-node.enemy:hover .tree-node-image {
    box-shadow: 0 0 0 3px #ff9494, 0 0 22px rgba(255,148,148,.55);
}

.tree-node.neutral:hover .tree-node-image {
    box-shadow: 0 0 0 3px #d2d7df, 0 0 22px rgba(210,215,223,.45);
}

.center-node .tree-node-image {
    border-color: transparent;
    box-shadow: 0 10px 30px rgba(0,0,0,.3);
}

.center-node:hover .tree-node-image {
    border-color: transparent;
    box-shadow: 0 0 0 3px #9cffb0, 0 0 25px rgba(156,255,176,.58), 0 12px 35px rgba(0,0,0,.35);
}

.relationship-line {
    stroke-width: 2.5;
    stroke-linecap: round;
    opacity: .65;
    filter: drop-shadow(0 0 4px rgba(255,255,255,.15));
}

.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: min(420px, 90vw);
    height: 100vh;
    padding: 35px;
    z-index: 100;
    overflow-y: auto;
    background: rgba(16,20,27,.94);
    border-left: 1px solid rgba(255,255,255,.08);
    backdrop-filter: blur(20px);
    transform: translateX(105%);
    transition: transform .35s cubic-bezier(.2,.8,.2,1);
}

.side-panel.open { transform: translateX(0); }

body.light-theme .side-panel {
    background: rgba(248,249,251,.96);
    border-left-color: rgba(0,0,0,.08);
}

.panel-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: rgba(255,255,255,.08);
    color: inherit;
    font-size: 25px;
    line-height: 1;
    cursor: pointer;
    transition: transform .2s ease;
}

.panel-close:hover { transform: rotate(90deg); }

.panel-character {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 25px;
}

.panel-character-image {
    width: 75px;
    height: 105px;
    object-fit: cover;
    border-radius: 10px;
}

.panel-character-name { font-size: 21px; font-weight: 800; }

.panel-relation {
    display: inline-block;
    padding: 7px 11px;
    margin-bottom: 18px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .08em;
}

.panel-relation.friend { background: rgba(142,203,255,.15); color: #8ecbff; }
.panel-relation.enemy { background: rgba(255,148,148,.15); color: #ff9494; }
.panel-relation.neutral { background: rgba(210,215,223,.12); color: #d2d7df; }

.panel-description { line-height: 1.75; opacity: .7; margin-bottom: 25px; }

.open-tree-button {
    width: 100%;
    padding: 13px 15px;
    border: 0;
    border-radius: 10px;
    background: rgba(255,255,255,.1);
    color: inherit;
    cursor: pointer;
    transition: background .2s ease, transform .2s ease;
}

.open-tree-button:hover {
    background: rgba(255,255,255,.16);
    transform: translateY(-2px);
}

.character-info-image {
    width: 100%;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    border-radius: 14px;
    margin-bottom: 22px;
}

.character-info-title {
    font-size: 30px;
    margin-bottom: 15px;
}

.character-info-description { line-height: 1.75; opacity: .7; }

.empty-state {
    grid-column: 1 / -1;
    padding: 70px 20px;
    text-align: center;
    opacity: .45;
}

.settings-panel { z-index: 110; }
.settings-content { padding-top: 35px; }
.settings-title { margin-bottom: 35px; font-size: 34px; letter-spacing: -.04em; }

.settings-block {
    width: 95% !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    font-size: 14px;
}

.settings-row strong { opacity: .65; }

.physics-weight-slider {
    width: 100%;
    height: 5px;
    cursor: grab;
    accent-color: #9cffb0;
}

.physics-weight-slider:active { cursor: grabbing; }

.settings-scale {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 10px;
    opacity: .4;
}

.settings-description {
    margin-top: 20px;
    line-height: 1.7;
    font-size: 13px;
    opacity: .55;
}

.theme-setting { margin-top: 18px; }

.theme-toggle {
    width: 44px;
    height: 44px;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 50%;
    background: rgba(255,255,255,.08);
    color: inherit;
    cursor: pointer;
    transition: transform .2s ease, background .2s ease;
}

.theme-toggle:hover {
    transform: scale(1.08);
    background: rgba(255,255,255,.14);
}

body.light-theme .theme-toggle {
    border-color: rgba(0,0,0,.1);
    background: rgba(255,255,255,.7);
}

@media (max-width: 850px) {
    .page { padding: 25px 18px; }

    .tree-header {
        grid-template-columns: auto 1fr auto;
        text-align: left;
    }

    .tree-title { text-align: center; }

    .relationship-tree {
        height: calc(100vh - 170px);
        min-height: 500px;
    }

    .tree-node, .tree-node-image { width: 90px; }
    .tree-node-name { font-size: 10px; }
}

@media (max-width: 550px) {
    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .database-card { border-radius: 12px; }
    .card-content { padding: 11px; }
    .card-title { font-size: 15px; }

    .tree-header {
        grid-template-columns: 1fr auto;
    }

    .tree-title {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .tree-header .back-button {
        grid-column: 1;
        grid-row: 2;
    }

    .settings-button {
        grid-column: 2;
        grid-row: 2;
    }
}

.language-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px;
    background:
        radial-gradient(circle at center, rgba(80,130,190,.16), transparent 55%);
}

.language-selector {
    width: min(760px, 94vw);
    text-align: center;
}

.language-selector h1 {
    margin-bottom: 16px;
    font-size: clamp(38px, 6vw, 64px);
    letter-spacing: -.045em;
}

.language-selector p {
    margin-bottom: 34px;
    opacity: .6;
    line-height: 1.6;
}

.language-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.language-card {
    min-height: 150px;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 16px;
    background: rgba(255,255,255,.055);
    transition: transform .25s ease, background .25s ease, box-shadow .25s ease;
}

.language-card:hover {
    transform: translateY(-6px);
    background: rgba(255,255,255,.09);
    box-shadow: 0 18px 45px rgba(0,0,0,.25);
}

.language-code {
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .14em;
    opacity: .5;
}

.language-name {
    font-size: 17px;
    font-weight: 800;
}

body.light-theme .language-card {
    background: rgba(255,255,255,.72);
    border-color: rgba(0,0,0,.07);
}

.language-button {
    display: block;
    width: 100%;
    margin-top: 14px;
    padding: 13px 15px;
    border-radius: 10px;
    background: rgba(255,255,255,.07);
    border: 1px solid rgba(255,255,255,.07);
    color: inherit;
    text-align: center;
    text-decoration: none;
    font-weight: 700;
    font-size: 13px;
    transition: background .2s ease, transform .2s ease;
}

.language-button:hover {
    background: rgba(255,255,255,.13);
    transform: translateY(-2px);
}

body.light-theme .language-button {
    background: rgba(255,255,255,.72);
    border-color: rgba(0,0,0,.07);
}

@media (max-width: 650px) {
    .language-options {
        grid-template-columns: 1fr;
    }

    .language-card {
        min-height: 105px;
    }
}

.language-page {
    min-height: 100vh;
    width: 100%;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 40px;

    background:
        radial-gradient(
            circle at center,
            rgba(80, 130, 190, 0.16),
            transparent 55%
        );

    color: #f2f5f8;
}

.language-container {
    width: min(900px, 92vw);

    text-align: center;
}

.language-badge {
    margin-bottom: 14px;

    font-size: 11px;
    letter-spacing: 0.22em;
    font-weight: 700;

    opacity: 0.55;
}

.language-title {
    margin-bottom: 18px;

    font-size:
        clamp(42px, 7vw, 76px);

    line-height: 0.95;

    letter-spacing: -0.05em;
}

.language-description {
    max-width: 560px;

    margin:
        0 auto 40px;

    font-size: 17px;

    line-height: 1.7;

    opacity: 0.65;
}

.language-buttons {
    display: grid;

    grid-template-columns:
        repeat(3, 1fr);

    gap: 18px;

    width: min(760px, 100%);

    margin: 0 auto;
}

.language-button {
    min-height: 50px;

    padding: 25px;

    border-radius: 16px;

    border:
        1px solid
        rgba(255,255,255,0.09);

    background:
        rgba(255,255,255,0.055);

    color: #f2f5f8;

    cursor: pointer;

    font-size: 18px;

    font-weight: 700;

    transition:
        transform 0.25s ease,
        background 0.25s ease,
        box-shadow 0.25s ease,
        border-color 0.25s ease;
}

.language-button:hover {
    transform:
        translateY(-6px);

    background:
        rgba(255,255,255,0.10);

    border-color:
        rgba(255,255,255,0.18);

    box-shadow:
        0 18px 45px
        rgba(0,0,0,0.25);
}

.language-button span {
    display: block;

    margin-top: 8px;

    font-size: 12px;

    font-weight: 500;

    opacity: 0.45;
}

body.light-theme .language-page {
    color: #171b21;

    background:
        radial-gradient(
            circle at center,
            rgba(80,130,190,0.12),
            transparent 55%
        );
}

body.light-theme .language-button {
    background:
        rgba(255,255,255,0.72);

    color: #171b21;

    border-color:
        rgba(0,0,0,0.08);
}

body.light-theme .language-button:hover {
    background: white;

    border-color:
        rgba(0,0,0,0.14);
}

@media (max-width: 700px) {

    .language-page {
        padding: 25px 18px;
    }

    .language-buttons {
        grid-template-columns: 1fr;
    }

    .language-button {
        min-height: 90px;
    }
}