:root {
    color-scheme: light;
    --ink: #171a1f;
    --muted: #5f6671;
    --panel: rgba(251, 251, 248, 0.88);
    --panel-strong: rgba(255, 255, 252, 0.95);
    --border: rgba(32, 38, 46, 0.16);
    --blue: #0867d8;
    --blue-soft: rgba(8, 103, 216, 0.13);
    --amber: #b46a00;
    --green: #237052;
    --surface: #f5f5f0;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--surface);
}

button,
input {
    font: inherit;
}

.app-shell {
    min-height: 100vh;
}

.stage {
    position: relative;
    min-height: 100vh;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.74), rgba(244, 245, 241, 0.92)),
        radial-gradient(circle at 18% 14%, rgba(8, 103, 216, 0.10), transparent 34%),
        radial-gradient(circle at 72% 78%, rgba(35, 112, 82, 0.09), transparent 30%),
        #f7f7f3;
}

.viewer {
    position: absolute;
    inset: 0;
}

.viewer canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.mobile-panel {
    display: contents;
}

.topbar {
    position: absolute;
    top: 18px;
    left: 18px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    z-index: 5;
    max-width: min(58vw, 760px);
}

.action-stack {
    display: grid;
    gap: 8px;
}

.primary-action {
    border: 1px solid rgba(5, 73, 154, 0.18);
    border-radius: 8px;
    background: #095fc4;
    color: #fff;
    min-height: 42px;
    padding: 0 18px;
    box-shadow: 0 8px 28px rgba(17, 68, 125, 0.19);
    cursor: pointer;
}

.primary-action:disabled {
    cursor: default;
    background: #7b8490;
    box-shadow: none;
}

.playback-controls {
    display: flex;
    gap: 7px;
}

.playback-button {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(95, 102, 113, 0.55);
    border-radius: 999px;
    background: transparent;
    color: #646b75;
    cursor: pointer;
}

.playback-button svg {
    width: 18px;
    height: 18px;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.playback-button:hover,
.playback-button:focus-visible {
    outline: none;
    color: var(--ink);
    border-color: rgba(95, 102, 113, 0.86);
    background: rgba(255, 255, 255, 0.44);
}

.playback-button:disabled {
    cursor: default;
    opacity: 0.42;
}

.status {
    min-height: 42px;
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    background: var(--panel);
    backdrop-filter: blur(14px);
}

.status:empty {
    display: none;
}

.side-stack {
    position: absolute;
    top: 18px;
    right: 18px;
    z-index: 5;
    width: 230px;
    max-width: calc(100vw - 36px);
    display: grid;
    gap: 10px;
}

.rotation-panel,
.explanation-card {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-strong);
    box-shadow: 0 12px 34px rgba(30, 36, 43, 0.14);
    backdrop-filter: blur(16px);
}

.explanation-card {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.explanation-card p {
    margin: 0;
}

.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: 700;
}

.genus-badge {
    flex: 0 0 auto;
    border-radius: 999px;
    padding: 4px 8px;
    color: #0f5138;
    background: rgba(35, 112, 82, 0.12);
    font-size: 12px;
}

.rotation-list {
    display: grid;
    gap: 6px;
}

.rotation-row {
    width: 100%;
    display: grid;
    grid-template-columns: 34px 1fr;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(32, 38, 46, 0.10);
    border-radius: 8px;
    padding: 7px 8px;
    background: rgba(255, 255, 255, 0.74);
    text-align: left;
    color: var(--ink);
    cursor: pointer;
}

.rotation-row:hover,
.rotation-row:focus-visible {
    outline: none;
    border-color: rgba(8, 103, 216, 0.42);
    background: rgba(255, 255, 255, 0.95);
}

.rotation-row.active {
    border-color: rgba(8, 103, 216, 0.54);
    background: var(--blue-soft);
}

.vertex-id {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #eef0ed;
    font-weight: 800;
}

.rotation-row.active .vertex-id {
    color: #fff;
    background: var(--blue);
}

.neighbor-list {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    min-width: 0;
    font-variant-numeric: tabular-nums;
}

.neighbor-chip {
    min-width: 26px;
    border-radius: 999px;
    padding: 3px 8px;
    text-align: center;
    background: #f2f3f0;
    border: 1px solid rgba(32, 38, 46, 0.10);
    font-weight: 700;
}

.neighbor-chip.active {
    color: #fff;
    background: var(--blue);
    border-color: var(--blue);
}

.cycle-mark {
    color: var(--muted);
    font-weight: 650;
}

.slider-panel {
    position: absolute;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    z-index: 5;
    width: min(760px, calc(100vw - 36px));
    padding: 13px 16px 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-strong);
    box-shadow: 0 12px 34px rgba(30, 36, 43, 0.13);
    backdrop-filter: blur(16px);
}

.slider-label {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 8px;
}

.slider-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 88px;
    gap: 12px;
    align-items: center;
}

#rotation_slider {
    width: 100%;
    accent-color: var(--blue);
}

.rotation-number {
    width: 88px;
    min-height: 34px;
    border: 1px solid rgba(32, 38, 46, 0.18);
    border-radius: 8px;
    padding: 0 8px;
    color: var(--ink);
    background: #fff;
    font-weight: 750;
    font-variant-numeric: tabular-nums;
}

.rotation-number:focus {
    outline: 2px solid rgba(8, 103, 216, 0.28);
    outline-offset: 2px;
}

.next-rotation-button {
    display: none;
}

@media (max-width: 760px) {
    html,
    body,
    .app-shell {
        height: 100%;
        overflow: hidden;
    }

    .stage {
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
        background: #f7f7f3;
    }

    .viewer {
        inset: 0 0 auto;
        height: 50dvh;
    }

    .mobile-panel {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        top: 50dvh;
        z-index: 5;
        display: block;
        overflow-y: auto;
        padding: 12px 12px calc(14px + env(safe-area-inset-bottom));
        background: rgba(245, 245, 240, 0.98);
        -webkit-overflow-scrolling: touch;
    }

    .topbar {
        position: static;
        max-width: none;
        display: block;
        margin: 0 0 10px;
    }

    .action-stack {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 10px;
    }

    .primary-action {
        order: 2;
        width: 100%;
        min-height: 44px;
        padding: 0 12px;
    }

    .playback-controls {
        order: 1;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    #playback_start,
    #playback_end {
        display: none;
    }

    .playback-button {
        width: 100%;
        height: 44px;
        border-radius: 8px;
    }

    .status {
        display: none;
    }

    .side-stack {
        position: static;
        width: auto;
        max-width: none;
        display: grid;
        gap: 10px;
    }

    .explanation-card {
        order: 1;
    }

    .rotation-panel {
        order: 2;
    }

    .rotation-panel,
    .explanation-card,
    .slider-panel {
        box-shadow: none;
        backdrop-filter: none;
    }

    .slider-panel {
        position: static;
        transform: none;
        width: auto;
        margin-top: 10px;
        padding: 0;
        border: 0;
        background: transparent;
    }

    .slider-label,
    .slider-controls {
        display: none;
    }

    .next-rotation-button {
        width: 100%;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 1px solid rgba(32, 38, 46, 0.16);
        border-radius: 8px;
        background: rgba(255, 255, 252, 0.95);
        color: var(--ink);
        font-weight: 800;
        cursor: pointer;
    }
}
