/* --- 1. Visualization Variables (Inherits from app.css theme logic) --- */
:root {
    /* Default Light Theme Visualization */
    --vis-glass-bg: rgba(255, 255, 255, 0.65);
    --vis-glass-border: rgba(145, 145, 145, 0.6);
    --vis-text-main: #1a1a1a;
    --vis-text-sub: #545c69;
    --vis-highlight-border: #007cf0; /* Primary Blue */
    --vis-highlight-bg: rgba(0, 124, 240, 0.15);
    --vis-highlight-shadow: 0 0 15px rgba(0, 124, 240, 0.2);
    --vis-primary: #545c69;
    --vis-accent: #7928ca;
    --vis-glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
}

/* Dark Mode Override (Applied when body has .dark-mode class) */
body.dark-mode {
    --vis-glass-bg: rgba(255, 255, 255, 0.05);
    --vis-glass-border: rgba(0, 0, 0, 0.15); /* Dark border for contrast on light bg */
    --vis-text-main: #ffffff;
    --vis-text-sub: #b0b0b0;
    --vis-highlight-border: #00d2ff; /* Neon Cyan */
    --vis-highlight-bg: rgba(0, 210, 255, 0.15);
    --vis-highlight-shadow: 0 0 20px rgba(0, 210, 255, 0.4);
    --vis-primary: #b0b0b0;
    --vis-accent: #ff0099; /* Neon Pink */
    --vis-glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.parser-result-node-content {
    --vis-glass-bg: rgba(32, 31, 32, 0.78);
    --vis-glass-border: rgba(229, 226, 227, 0.12);
    --vis-text-main: #f1eff3;
    --vis-text-sub: rgba(229, 226, 227, 0.68);
    --vis-highlight-border: #c0c1ff;
    --vis-highlight-bg: rgba(192, 193, 255, 0.14);
    --vis-highlight-shadow: 0 0 18px rgba(192, 193, 255, 0.22);
    --vis-primary: #c0c1ff;
    --vis-accent: #4edea3;
    --vis-glass-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
}

/* --- 2. Tree Container Layout --- */
.ptv-tree-container {
    display: flex;
    justify-content: center;
    position: relative;
    margin: 40px 0;
    padding: 10px;
    z-index: 1;
}

/* --- 3. Phrase Box (Glassmorphic) --- */
.ptv-phrase {

    border-radius: 12px;
    padding: 10px;
    margin: 5px;
    margin-top: 15px;
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: stretch;
    
    /* Theme Styles */
    background: var(--vis-glass-bg);
    color: var(--vis-text-main);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: var(--vis-glass-shadow);
    transition: background-color 0.3s, border-color 0.3s, box-shadow 0.3s;
}

.parser-result-node-content .ptv-phrase {
    border: 1px solid rgba(229, 226, 227, 0.1);
    background:
        linear-gradient(180deg, rgba(43, 42, 45, 0.92), rgba(28, 27, 29, 0.9)),
        rgba(32, 31, 32, 0.9);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

/* --- 4. Word Box (Glassmorphic) --- */
.ptv-word-box {
    border: 1px solid var(--vis-glass-border);
    border-radius: 8px;
    transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s;
    
    /* Theme Styles */
    background: var(--vis-glass-bg); /* Same glass level or slightly different opacity */
    backdrop-filter: blur(4px);
}

.parser-result-node-content .ptv-word-box {
    border-color: rgba(229, 226, 227, 0.11);
    background: rgba(19, 19, 20, 0.52);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
}

.parser-result-node-content .ptv-tree-container.ptv--horizontal .ptv-word-box,
.parser-result-node-content .ptv-tree-container.ptv--vertical .ptv-word-box {
    background: rgba(19, 19, 20, 0.52);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
}

.ptv-phrase-label {
    position: absolute;
    top: -1.4em;
    left: 0;
    font-weight: 700;
    padding: 0 4px;

    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* --- 5. Highlighting (Neon Effect) --- */
div[data-element-type='table-word'].highlight,
div[data-element-type='tree-leaf'].highlight,
div[xmlns="http://www.w3.org/1999/xhtml"].highlight,
.ptv-phrase.highlight,
.ptv-word-box.highlight {
    border-color: var(--vis-highlight-border) !important;
    background: var(--vis-highlight-bg) !important;
    box-shadow: var(--vis-highlight-shadow) !important;
}

/* --- 6. Typography --- */
.ptv-word {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    color: var(--vis-text-main);
}

.ptv-field {
    font-size: 12px;
    color: var(--vis-text-sub);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Linguistic Tags Color */
.ptv-field.phonetic,
.ptv-field.lemma,
.ptv-field.upos {
    text-align: center;

    font-weight: 500;
}

.ptv-field.phonetics-box {
    margin-bottom: 6px;
}

/* --- 7. Toggles UI (Floating Glass Panel) --- */
.ptv-field-toggles {
    font-family: 'Outfit', sans-serif;
    display: flex;
    flex-wrap: wrap;
    gap: 5px 15px;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px 20px;
    border-radius: 16px;
    justify-content: center;

    /* Theme Styles */
    background: var(--vis-glass-bg);
    border: 1px solid var(--vis-glass-border);
    box-shadow: var(--vis-glass-shadow);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.ptv-field-toggles label {
    cursor: pointer;
    user-select: none;
    font-size: 14px;
    color: var(--vis-text-main);
    display: flex;
    align-items: center;
    gap: 5px;
}

.ptv-field-toggles input[type=checkbox] {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 1px solid var(--vis-glass-border);
    border-radius: 4px;
    outline: none;
    cursor: pointer;
    position: relative;
    background: rgba(0,0,0,0.1);
    transition: all 0.2s;
}

.ptv-field-toggles input[type=checkbox]:checked {
    background: linear-gradient(45deg, var(--vis-primary), #3a7bd5);
    border-color: transparent;
}

.ptv-field-toggles input[type=checkbox]:checked::after {
    content: '\2713';
    display: block;
    color: #fff;
    font-size: 12px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* ======================================================
   HORIZONTAL layout 
   ====================================================== */
.ptv-tree-container.ptv--horizontal .ptv-children-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding-top: 10px;
    flex-direction: row;
    flex: 1 1 0;
}

.ptv-tree-container.ptv--horizontal .ptv-word-box {
    display: block;
    border: none !important;
    border-radius: 8px;
    padding: 8px;
    text-align: center;
    background: var(--vis-glass-bg);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.ptv-tree-container.ptv--horizontal .ptv-word-box>*+* {
    border-left: 0;
    margin-left: 0;
    padding-left: 0;
    padding-top: 4px;
    padding-bottom: 4px;
}

/* Internal Dividers */
.ptv-tree-container.ptv--horizontal .ptv-field.tag-box,
.ptv-tree-container.ptv--horizontal .ptv-field.upos-box,
.ptv-tree-container.ptv--horizontal .ptv-field.meaning-box,
.ptv-tree-container.ptv--horizontal .ptv-field.feats-box,
.ptv-tree-container.ptv--horizontal .ptv-field.deprel-box,
.ptv-tree-container.ptv--horizontal .ptv-field.trans-box,
.ptv-tree-container.ptv--horizontal .ptv-field.type-box,
.ptv-tree-container.ptv--horizontal .ptv-field.function-box {
    font-size: 11px;

    padding-bottom: 5px;
    padding-top: 5px;
    white-space: pre-wrap;
    overflow: visible;
    text-overflow: clip;
    font-weight: 400;
    line-height: 1.4;
}

.ptv-tree-container.ptv--horizontal .ptv-phrase>.ptv-field:first-of-type {
    border-top: none;
    padding-top: 0;
    margin-top: 0;
}

/* ======================================================
   VERTICAL layout
   ====================================================== */
.ptv-tree-container.ptv--vertical .ptv-children-row {
    display: flex;
    flex-direction: column;
    align-items: left;
    gap: 10px;
    padding-top: 10px;
}

.ptv-tree-container.ptv--vertical .ptv-word-box {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0;
    border: 1px solid var(--vis-glass-border);
    border-radius: 8px;
    padding: 8px 10px;
    background: var(--vis-glass-bg);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.ptv-tree-container.ptv--vertical .ptv-word-box>*+* {
    border-left: 1px solid var(--vis-glass-border);
    margin-left: 8px;
    padding-left: 8px;
}

.ptv-tree-container.ptv--vertical .ptv-field.meaning-box,
.ptv-tree-container.ptv--vertical .ptv-field.feats-box,
.ptv-tree-container.ptv--vertical .ptv-field.deprel-box {
    white-space: pre-wrap;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.4;
    font-size: 11px;
    font-weight: 400;
}

.ptv-tree-container.ptv--vertical .ptv-field.trans-box,
.ptv-tree-container.ptv--vertical .ptv-field.type-box,
.ptv-tree-container.ptv--vertical .ptv-field.function-box {
    font-size: 11px;
    border-top: 1px solid var(--vis-glass-border);
    padding-top: 5px;
    margin-top: 5px;
    white-space: pre-wrap;
    overflow: visible;
    text-overflow: clip;
    font-weight: 400;
    line-height: 1.4;
}

.ptv-tree-container.ptv--vertical .ptv-phrase>.ptv-field:first-of-type {
    border-top: none;
    padding-top: 0;
    margin-top: 0;
}

/* ======================================================
   SVG Graph (Dependency / Flowchart)
   ====================================================== */
.graph-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 600px;
    border: none;
    padding: 10px;
}

.graph-container svg {
    width: auto;
    height: auto;
    overflow: visible;
}

/* Center Circle */
.graph-container .center-circle {
    fill: rgba(0, 0, 0, 0.1);
    stroke: var(--vis-accent);
    stroke-width: 2px;
    stroke-dasharray: 6 4;
    transition: stroke 0.2s ease, transform 0.2s ease;
    cursor: pointer;
    transform-origin: center center;
}

body.dark-mode .graph-container .center-circle {
    fill: rgba(255, 255, 255, 0.05);
}

.graph-container .center-circle:hover {
    stroke: var(--vis-primary);
    transform: scale(1.05);
}

/* Satellite Circles */
.graph-container .sat-circle {
    fill: var(--vis-glass-bg);
    stroke: var(--vis-primary);
    stroke-width: 1.5px;
    stroke-dasharray: 5 3;
    transition: transform .12s ease, fill .12s ease;
    cursor: pointer;
}

.graph-container .sat-circle:hover {
    transform: scale(1.06);
    fill: var(--vis-highlight-bg);
    stroke: var(--vis-primary);
}

/* Links */
.graph-container .link {
    stroke: var(--vis-text-sub);
    stroke-opacity: 0.4;
    stroke-width: 1.5px;
    stroke-dasharray: 5 3;
}

/* Labels */
.graph-container .label {
    font-size: 13px;
    fill: var(--vis-text-main);
    dominant-baseline: middle;
    text-anchor: middle;
    pointer-events: none;
    user-select: none;
    font-family: 'Outfit', sans-serif;
}

/* Terms (Smaller text under labels) */
.graph-container .term {
    font-size: 11px;
    fill: var(--vis-text-sub);
    text-anchor: middle;
    opacity: 1;
    transition: fill 0.2s ease, font-size 0.2s ease, font-weight 0.2s ease;
}

.graph-container g:hover .term {
    fill: var(--vis-primary);
    font-size: 13px;
    font-weight: bold;
}

/* ======================================================
   Tense Table
   ====================================================== */
#tense-table-wrapper {
    width: 100%;
    display: block;
    margin-bottom: 20px;
    padding-left: 40px;
    padding-right: 40px;
    padding-top: 20px;
}

#tense-table-wrapper table {
    border-collapse: collapse;
    width: 100%;
    table-layout: fixed;
    border-radius: 12px;
    overflow: hidden; /* Rounded corners for table */
    box-shadow: var(--vis-glass-shadow);
}

#tense-table-wrapper th,
#tense-table-wrapper td {
    border: 1px solid var(--vis-glass-border);
    padding: 12px 8px;
    text-align: center;
    position: relative;
    color: var(--vis-text-main);
    font-size: 0.9rem;
}

#tense-table-wrapper th {
    background-color: rgba(0, 0, 0, 0.05); /* Subtle Header tint */
    font-weight: 600;
    cursor: default;
}
body.dark-mode #tense-table-wrapper th {
    background-color: rgba(255, 255, 255, 0.1);
}

#tense-table-wrapper td {
    background-color: var(--vis-glass-bg);
}

/* Tooltips inside table */
#tense-table-wrapper .tense-tooltip {
    position: absolute;
    min-width: 60px;
    width: auto;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--vis-text-main); /* Contrast background */
    color: var(--vis-glass-bg); /* Contrast text (simplified hack using background var as text color for tooltips) */
    border: 1px solid var(--vis-glass-border);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    white-space: nowrap;
    z-index: 10;
    text-align: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

/* Better color inversion for tooltip in themes */
body:not(.dark-mode) #tense-table-wrapper .tense-tooltip {
    background: #1a1a1a;
    color: #ffffff;
}
body.dark-mode #tense-table-wrapper .tense-tooltip {
    background: #ffffff;
    color: #000000;
}

#tense-table-wrapper th:hover .tense-tooltip,
#tense-table-wrapper td:hover .tense-tooltip {
    opacity: 1;
}

/* ======================================================
   Responsive Styles
   ====================================================== */
@media (max-width:520px) {
    .ptv-tree-container.ptv--vertical .ptv-word-box {
        flex-direction: column;
        align-items: stretch;
    }

    .ptv-tree-container.ptv--vertical .ptv-word-box>*+* {
        border-left: 0;
        margin-left: 0;
        padding-left: 0;
        border-top: 1px solid var(--vis-glass-border);
        margin-top: 6px;
        padding-top: 6px;
    }

    .ptv-field {
        white-space: normal;
    }

    .ptv-field.phonetic,
    .ptv-field.lemma,
    .ptv-field.upos {
        text-align: left;
    }
}
