:root {
    --bg-window: #252525;
    --bg-canvas: #2f2f2f;
    --text: #ffffff;
    
    --color-blue: #03698f;
    --color-red: #860037;
    --color-green: #00703c;
    
    --color-ground: #4d2b8c;
    --color-ground-line: #29102d;
    --color-vertex: #c8c8c8;
    
    --btn-bg: #444;
    --btn-hover: #555;
    --btn-active: #666;
}

body {
    margin: 0; padding: 0;
    font-family: 'Courier New', Courier, monospace;
    background-color: var(--bg-window);
    color: var(--text);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.navbar {
    flex: 0 0 auto;
}

.toolbar {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    background-color: var(--bg-window);
    border-bottom: 1px solid #333;
    gap: 10px;
}

.divider { width: 1px; height: 24px; background: #555; margin: 0 5px; }
.spacer { flex-grow: 1; }
.label { font-weight: bold; font-size: 14px; }

button {
    cursor: pointer;
    border: 1px solid #555;
    border-radius: 5px;
    background: var(--btn-bg);
    color: white;
    font-size: 16px;
    font-family: inherit;
    box-shadow: none;
    transform: none;
    display: flex; align-items: center; justify-content: center;
}
button:hover { background: var(--btn-hover); transform: none; box-shadow: none; }
button:active { background: var(--btn-active); transform: none; box-shadow: none; }

.tool-btn, .icon-btn { width: 40px; height: 40px; }
.icon-btn { padding: 5px; }
.icon-btn img { width: 28px; height: 28px; display: block; }
.toolbar .tool-btn { padding: 0; font-size: 13px; }
.toolbar button.active-toggle, .hotpotch-menu .active-toggle { background: #2d5a2d; border-color: #72b772; }
.action-btn { padding: 0 15px; height: 40px; background: #2d5a2d; }
.action-btn:hover { background: #3a6f3a; }

.color-btn { width: 40px; height: 40px; border-radius: 20px; border: 2px solid white; }
.color-btn.blue { background-color: var(--color-blue); }
.color-btn.red { background-color: var(--color-red); }
.color-btn.green { background-color: var(--color-green); }
.color-btn.edit-active { border: 2px solid #ffaa00; box-shadow: 0 0 8px #ffaa00; }

.result-label { margin-left: 10px; font-size: 16px; font-family: monospace; }

.menu-wrap { position: relative; }
.menu-btn { width: 40px; height: 40px; border-radius: 20px; font-size: 24px; line-height: 1; padding: 4px 0 0; }
.hotpotch-menu {
    position: absolute;
    right: 0;
    top: 48px;
    z-index: 20;
    min-width: 240px;
    padding: 6px;
    background: #2a2a2a;
    border: 1px solid #555;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}
.hotpotch-menu[hidden] { display: none; }
.hotpotch-menu .menu-item {
    width: 100%;
    min-height: 36px;
    justify-content: flex-start;
    padding: 8px 14px;
    border-radius: 4px;
    box-shadow: none;
    font-size: 14px;
    text-align: left;
}
.hotpotch-menu .menu-item + .menu-item { margin-top: 4px; }
.help-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
}
.help-dialog {
    width: min(620px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    overflow: auto;
    background: #2a2a2a;
    border: 1px solid #666;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
    padding: 22px;
}
.help-dialog h2 { margin-top: 0; }
.help-dialog li { margin: 8px 0; }
.help-actions { display: flex; justify-content: flex-end; margin-top: 18px; }

.canvas-container {
    flex-grow: 1;
    background-color: var(--bg-canvas);
    position: relative;
}

svg {
    display: block;
    user-select: none;
    touch-action: none;
}

/* SVG Elements styles */
.edge { stroke-width: 8; stroke-linecap: round; fill: none; cursor: pointer; transition: stroke-width 0.1s; }
.edge:hover { stroke-width: 12; }
.edge.blue { stroke: var(--color-blue); }
.edge.red { stroke: var(--color-red); }
.edge.green { stroke: var(--color-green); }
.edge.best { filter: drop-shadow(0 0 6px #fff); }
.edge.dimmed { opacity: 0.45; }

.vertex { fill: var(--color-vertex); stroke: black; stroke-width: 2; cursor: pointer; }
.vertex.ground { fill: var(--color-ground); }
.vertex.pending { stroke: white; stroke-width: 3; stroke-dasharray: 4; }

.slash {
    stroke: rgba(190, 190, 190, 0.7);
    stroke-width: 5;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    pointer-events: none;
}

.hint-label {
    fill: #fff;
    font: 700 14px Consolas, monospace;
    paint-order: stroke;
    stroke: rgba(0, 0, 0, 0.85);
    stroke-width: 4px;
}

@media (max-width: 700px) {
    body {
        height: 100dvh;
    }

    .navbar {
        gap: 16px;
        padding: 10px 12px;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .navbar::-webkit-scrollbar {
        display: none;
    }

    .navbar .logo {
        flex: 0 0 auto;
        margin-right: 0;
        font-size: 1.15rem;
    }

    .navbar a {
        flex: 0 0 auto;
        font-size: 0.9rem;
    }

    .toolbar {
        flex-wrap: wrap;
        gap: 6px;
        padding: 8px;
    }

    .toolbar .divider,
    .toolbar .spacer,
    .toolbar .label {
        display: none;
    }

    .tool-btn,
    .icon-btn,
    .color-btn,
    .menu-btn {
        width: 36px;
        height: 36px;
    }

    .color-btn,
    .menu-btn {
        border-radius: 18px;
    }

    .icon-btn img {
        width: 25px;
        height: 25px;
    }

    .action-btn {
        height: 36px;
        padding: 0 10px;
        font-size: 14px;
    }

    .result-label {
        order: 2;
        width: 100%;
        max-height: 2.6em;
        margin: 0;
        overflow: auto;
        overflow-wrap: anywhere;
        font-size: 12px;
        line-height: 1.3;
    }

    .hotpotch-menu {
        top: 42px;
        max-width: calc(100vw - 16px);
        max-height: calc(100dvh - 120px);
        overflow-y: auto;
    }

    .help-dialog {
        box-sizing: border-box;
        width: calc(100vw - 24px);
        max-height: calc(100dvh - 24px);
        padding: 16px;
    }

    .edge {
        stroke-width: 10;
    }

    .edge:hover {
        stroke-width: 10;
    }

    .vertex {
        stroke-width: 3;
    }
}

@media (max-width: 350px) {
    .toolbar {
        gap: 5px;
    }

    .tool-btn,
    .icon-btn,
    .color-btn,
    .menu-btn {
        width: 32px;
        height: 32px;
    }

    .action-btn {
        height: 32px;
        padding: 0 7px;
    }
}
