*{
    box-sizing: border-box;
}

html, body{
    background-color: #DEDEDE;
    height: 99%;
    overflow: hidden;
}

#alternate{
    display: none;
}

#alternate h1{
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center; /* For horizontal centering of text within the h1 */
    width: 100%; /* Ensure the h1 takes full width for text-align to work */
}

.TreeElement{
    cursor: help;
    position: absolute;
    top:0!important;
    left:0!important;
    opacity: 0;
    height: 2.5vw;
    width: 2.5vw;
    border-radius: 50%;
    background-color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bolder;
    font-size: 2.5vh;
    border: 2px solid rgb(37, 201, 37);
    transition: border 1s, opacity 1s, background-color 1s;
    z-index: 5!important;
}



.TreeElement.empty{
    opacity: 1;
    border-radius: 0;
    border: 2px solid grey!important;
    height: 2vw;
    width: 2vw;
    z-index: 1!important;
    transition: 0;
}

.TreeElement.empty.small{
    height: 1.75vw;
    width: 1.75vw;
    font-size: 1.75vh;
}

.TreeElement.transform{
    transition: border 1s, opacity 1s, transform 1s ease-in-out, width 1s, height 1s, font-size 1s;
}


.TreeElement.small{
    height: 2vw;
    width: 2vw;
    font-size: 2vh;
}


.TreeElement.small .avl.bottom::after{
    font-size: 0.7vw;
}

/* The overlay span that hosts the pseudo-labels */
.TreeElement span.avl{
    position: absolute;      /* sits over the node */
    inset: 0;                /* fill the TreeElement */
    font-weight: bolder;
    font-size: 0.8rem;
    color: red;
    pointer-events: none;   /* labels don't block clicks */
}

/* Hide all labels by default */
.TreeElement .avl::after{
    content: attr(data-val);
    display: none;
    position: absolute;      /* needed for offsets below */
    color: red;
}

/* Show labels when active */
.TreeElement.active .avl::after{
    display: inline !important;
}

/* Top label: centered above the node */
.TreeElement .avl.top::after{
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
}

/* Left label: vertically centered to the left */
.TreeElement .avl.left::after{
    top: 100%;
    right: 100%;
    transform: translateY(-50%);
}

/* Right label: vertically centered to the right */
.TreeElement .avl.right::after{
    top: 100%;
    left: 100%;
    transform: translateY(-50%);
}

/* Bottom label: centered above the node */
.TreeElement .avl.bottom::after{
    text-align: center;
    width: 100%;
    height: 100%;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1vw;
    color: green;
    font-weight: bolder;
}



.TreeElement.search{
    border: 2px solid rgb(71 173 199);;
}

.TreeElement.doubleRotation{
    --t: 0deg;
    --r: 0px;
    /*--offsetX: 0vw;
    --offsetY: 0vh;*/
    --x: 0;
    --y: 0;
    /*transform: translateX(calc(var(--offsetX) + cos(var(--angle)) * var(--radius))) translateY(calc(var(--offsetY) + sin(var(--angle)) * -1 * var(--radius)))!important;*/
    /*transform: translateX(calc(var(--offsetX))) translateY(calc(var(--offsetY)));*/
    /*transform: translateX(calc(var(--x) + var(--r)*cos(var(--t)))) translateY(calc(var(--y) + var(--r)*sin(var(--t))));*/
    transform: translate(
        calc(var(--x) + var(--r) * cos(var(--t))),
        calc(var(--y) + var(--r) * sin(var(--t)))
    );
    transition: none!important;
}


.dot{
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: black;
}

.triangle-svg{
    width: 100px; /* let the transform scale property handle its final size */
    height: 100px;
    will-change: transform;
    z-index: 10;
    position: relative;
}

.subtreelabel {
    display: block;
    position: relative;
    width: fit-content;
}

.subtreelabel::after {
    content: attr(label);
    position: absolute;
    top: 100%;               /* just below the bottom of the triangle */
    left: 50%;               /* horizontally centered relative to parent */
    transform: translateX(-50%); /* adjust so center aligns, not left edge */
    
    /* Optional styling: */
    margin-top: 4px;
    font-size: 1.1vw;
    font-weight: bolder;
    text-align: center;
    width: max-content;      /* or 100% if you want it full-width */
}

.triangle-svg polygon{
    stroke: black;
    fill: none;
    stroke-width: 3px;
}

.no-animation{
    transition: none!important; 
}

.five{
    width: 5vw;
    height: 100%;
}

.left-color, .right-color{
    position: absolute;
    top: 0;
    background-color: red;
}

.ruler{
    position: absolute;
    top: 0;
    height: 100%;
    width: 1px;
    background-color: black;
}

.middle{
    left: calc(50vw - 0.5px);
}

.right-color{
    right: 0!important;
}
.left-color{
    left: 0!important;
}

.traverser{
    position: absolute;
    font-size: 3vw;
    top:0 !important;
    left: 0 !important;
    opacity: 0;
    transition: opacity 0.5s, transform 1s;
    z-index: 3;
    /*background-color: rgba(255, 0, 0, 0.3); */
}

.line {
  position: absolute;
  height: 2px;
  width: 100px; /* fixed base width */
  background-color: black;
  transition: background-color 2s;
  transform-origin: 0 0;
  
}

.line.transform{
    transition: transform 1s ease-in-out, opacity 1s, background-color 2s;
    will-change: transform;
}

.line.doubleRotation{
    --t: 0;
    --x: 0;
    --y: 0;
    --l: 0;
    transition: none;
    transform: translate(var(--x), var(--y)) rotate(var(--t)) scaleX(var(--l));
}

.comparatorTransform{
    position: absolute;
    opacity: 0;
    transition: opacity 1s ease-out;
    mix-blend-mode: difference;
}

.comparatorTransform.aft{
    left: 2.5vw;
}

.comparatorTransform.bef{
    right: 2.5vw;
}



@media screen and (max-width: 999px), (max-height: 559px) {
    #main, .TreeElement, .line{
        display: none!important;
    }
    #alternate{
        display: block;
    }
}

#inputtd{
    width: 25%;
}

#inputtd > *{
    width: 100%;
}


#control-panel {
    font-weight: 900;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1.2rem 0 1vh 0;
    border: 2px solid black;
    background-color: rgb(193 229 194);
    font-family: "Ubuntu Mono", monospace;
    text-align: center;
    z-index: 10;
}

#control-panel legend {
    position: absolute;
    top: -0.7em;
    left: 50%;
    transform: translateX(-50%);
    padding: 0 0.4rem;
    background-color: #DEDEDE;
    font-size: 2.5vw;
    white-space: nowrap;
}

#control-panel legend{
    font-size: 2.5vw;
}

#control-panel table {
    min-width: 25vw;
    display: inline-table;
    /*vertical-align: middle; */  /* aligns the tables themselves 
    font-size: 20px;*/
    border: 2px solid black;
    min-height: 20vh;
}

#control-panel th,
#control-panel td {
    text-align: center;       /* horizontal centering */
    /*vertical-align: middle; */  /* vertical centering */
    padding: 0.5vh;    
    border: 1px solid black;         /* spacing for readability */
}

#control-panel > tr:first-child{
    border-right: 1px solid black;
}

#console-container {
    padding: 0 !important;
    height: 26vh;
    max-height: 26vh;
    overflow: hidden;
    width: 40vw;
}

#console {
    height: 26vh;
    max-height: 26vh;
    width: 40vw;
    overflow-y: auto;
    overflow-x: hidden;

    border: 1px solid black;
    background-color: black;
    color: white;
    font-family: "Ubuntu Mono", monospace;
    font-weight: 500;
    font-style: normal;
    font-size: 1vw;
    z-index: 4;
    text-align: left;
}

#console b{
    color: rgb(58, 197, 58);
    margin-right: 3px;
}

#cursor{
    transition: color .1s;
    margin-left: -6px;
}

#console-bar {
    height: 24px;
    background-color: #2c2c2c;
    border-bottom: 1px solid #444;
    display: flex;
    align-items: center;
    padding: 0 10px;
    gap: 8px;
    position: sticky;
    top: 5px;
    left: 0;
    font-family: sans-serif;
    width: 100%;
}

.console-dot {
    height: 15px;
    width: 15px;
    border-radius: 50%;
    align-items: center;
    text-align: center;
    color: white;
    display: flex;
    font-size: 15px;
    justify-content: center;
    font-weight: bold;
    cursor: pointer;
}

.console-dot.red {
    background-color: #ff5f56;
}

.console-dot.yellow {
    background-color: #ffbd2e;
}

.console-dot.green {
    background-color: #27c93f;
    
}


#text{
    white-space: pre;
}

#console a{
    color: cyan;
}

#toggle-animation-button{
    width: 100%;
    height: 100%;
    font-size: 1vw;
}

#control-panel input,
#control-panel button,
#control-panel label {
    font-family: "Ubuntu Mono", monospace;
    font-weight: 900;
}

#inputtd {
    width: 15vw;
    height: 26vh;
    padding: 0.5vh;
}

#key-input {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 0;
    font-size: 25px;
    text-align: center;
    font-family: "Ubuntu Mono", monospace;
    font-weight: 900;
}