/* General Body and Container Styles */
body {
    font-family: sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    padding: 10px;
    background-color: #333;
    color: white;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

button {
    padding: 8px 12px;
    border: none;
    border-radius: 5px;
    background-color: #555;
    color: white;
    cursor: pointer;
    transition: background-color 0.2s;
}

button:hover {
    background-color: #777;
}

#graph-container {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
    background-color: #f0f0f0;
}

/* Grid background for snap-to-grid */
.grid-background {
    background-image: linear-gradient(to right, #ccc 1px, transparent 1px),
                      linear-gradient(to bottom, #ccc 1px, transparent 1px);
    background-size: 20px 20px;
}

/* Node Styles */
.node {
    --node-size: 50px; /* Default size */
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    border-width: 2px;
    border-style: solid;
    cursor: grab;
    transition: border-color 0.2s, background-color 0.2s, box-shadow 0.2s, transform 0.2s;
    z-index: 10;
}

/* Node Shapes */
.node.circle {
    width: var(--node-size);
    height: var(--node-size);
    border-radius: 50%;
}

.node.square {
    width: var(--node-size);
    height: var(--node-size);
    border-radius: 5px;
}

.node.triangle {
    width: var(--node-size);
    height: var(--node-size);
    position: absolute;
    /* Use clip-path to create a triangle shape */
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
    /* We still need a background to be visible, so fill with transparent for the CSS background color property */
    background-color: transparent !important;
}

.node.triangle::before {
    /* Create a pseudo-element for the actual fill and border */
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    bottom: 2px;
    background-color: inherit; /* Use the parent's background color */
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
    z-index: -1;
}

.node.triangle::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: transparent;
    border: 2px solid;
    border-color: inherit;
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
    z-index: -2;
}

/* Node labels (KaTeX rendering) */
.node .katex {
    /* Adjustments for labels in nodes */
    font-size: calc(var(--node-size) * 0.4);
    pointer-events: none; /* Prevents clicks on the label from interfering with dragging */
}

.node.selected {
    box-shadow: 0 0 10px 5px rgba(255, 255, 0, 0.7);
    z-index: 100;
}

.node:active {
    cursor: grabbing;
}

/* Edge SVG Styles */
.edge-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.edge-path {
    stroke: black;
    stroke-width: 2;
    fill: none;
    transition: stroke 0.2s;
    pointer-events: all;
    cursor: pointer;
}

.edge-path.selected {
    stroke: yellow;
}

.control-handle {
    fill: black;
    stroke: yellow;
    stroke-width: 1;
    pointer-events: all;
    cursor: move;
}

.control-handle-line {
    stroke: gray;
    stroke-dasharray: 4;
    stroke-width: 1;
    pointer-events: none;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    padding-top: 50px;
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 600px;
}

.close-btn {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close-btn:hover, .close-btn:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

#tikz-output {
    width: 100%;
    height: 300px;
    margin-top: 10px;
}
