:root {
    --border-col: #75b3f0;
    --button-col: #263631bf;
    --success-toast-inner: #a7ffa7;
}

body, html {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: Arial, sans-serif;
    background-color: #121212;
    color: #e0e0e0;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

* {
    touch-action: pan-y !important;
}

/* Navbar */
.navbar {
    background-color: #1f1f1f;
    color: #ffffff;
    padding: 0.5rem;
    font-size: 1.2rem;
    border-bottom: 2px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.nav-left,
.nav-right {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    position: relative;
    z-index: 1;
}

.nav-left #home {
    padding: 6px;
    background: transparent;
    border-color: transparent;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-left #home:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: transparent;
}

.nav-left #home svg path {
    transition: fill 0.2s ease;
}

.nav-left #home:hover svg path {
    fill: var(--border-col);
}

.nav-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
}

/* Main container */
.main {
    display: flex;
    height: calc(100dvh - 52px);
}

input[type="checkbox"] {
    /* Double-sized Checkboxes */
    -ms-transform: scale(1.5); /* IE */
    -moz-transform: scale(1.5); /* FF */
    -webkit-transform: scale(1.5); /* Safari and Chrome */
    -o-transform: scale(1.5); /* Opera */
    transform: scale(1.5);
    margin-bottom: 10px;
}

.sidebar {
    width: 23%;
    border-right: 2px solid #333;
    padding: 0.25rem 0.75rem 0.75rem;
    padding-bottom: 0;
    box-sizing: border-box;
    background-color: #1a1a1a;
    display: flex;
    flex-direction: column;
}

.filter-input {
    width: 100%;
    padding: 0.5rem;
    box-sizing: border-box;
    background-color: #2a2a2a;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 4px;
}

.pbl-grid {
    display: grid;
    flex: 1;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    align-content: start;
    gap: 0.5rem;

    max-height: calc(
        100dvh - 200px
    );
    overflow-y: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE 10+ */
}

.pbl-grid::-webkit-scrollbar {
    display: none; /* Chrome, Safari */
}

/* Base style for label */
.case {
    border: 3px solid #666; /* gray by default */
    font-weight: bold;
    min-width: 80px;
    height: 45px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #262626;
    color: #ffffff;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.hidden {
    display: none !important;
}

.case:hover {
    background-color: #333;
}

/* When a case is selected, color-code by barflip mode */
.case.checked-both {
    border-color: hsl(210, 80%, 70%);
    background-color: hsla(210, 30%, 15%, 0.5);
}

.case.checked-both:hover {
    background-color: color-mix(in srgb, hsla(210, 30%, 15%, 0.5), white 15%);
}

.case.checked-plus {
    border-color: hsl(40, 80%, 70%);
    background-color: hsla(40, 30%, 15%, 0.5);
}

.case.checked-plus:hover {
    background-color: color-mix(in srgb, hsla(40, 30%, 15%, 0.5), white 15%);
}

.case.checked-minus {
    border-color: hsl(110, 80%, 70%);
    background-color: hsla(110, 30%, 15%, 0.5);
}

.case.checked-minus:hover {
    background-color: color-mix(in srgb, hsla(110, 30%, 15%, 0.5), white 15%);
}

.content {
    flex: 1;
    padding: 1rem;
    background-color: #181818;
    color: #e0e0e0;
    overflow-y: auto;
}

.filter-input:focus,
.case:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--border-col);
}

.selection-grid {
    display: grid;
    justify-content: center;
    align-items: center;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    padding: .5rem 0;
}

.selection-btn {
    min-height: 40px;
    min-width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
    padding: 2px;
}

.selection-text {
    display: block;
    text-align: center;
    font-weight: bold;
    font-size: 1rem;
    background-color: #1a1a1a;
    color: #e0e0e0;
    margin-top: 0.9rem;
    margin-bottom: 0.4rem;
    width: 80%;
    align-self: center;
}

button {
    background-color: #2a2a2a;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 0.5rem;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

button:hover {
    background-color: var(--button-col);
    border-color: var(--border-col);
}

.top-bar {
    display: flex;
    justify-content: space-between;
    flex-direction: column;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid #333;
}

.bar-btn {
    background-color: #2a2a2a;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 0.5rem 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.bar-btn:hover {
    background-color: var(--button-col);
    border-color: var(--border-col);
}

.bar-scramble {
    text-align: center;
    flex: 1;
    font-size: 1.6rem;
    font-weight: bold;
    color: #e0e0e0;
    cursor: pointer;
    transition: color 0.2s ease;
}

.bar-scramble.generating {
    color: #555;
}

.bottom-bar .bar-scramble {
    font-size: 1.3rem;

}

.timer-box {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.timer-display {
    font-size: 3.5rem;
    font-weight: bold;
    text-align: center;
    margin: 0;
}

.bottom-info {
    text-align: center;
    font-size: 1rem;
    margin-top: auto;
    color: #aaa;
}

.content {
    flex: 1;
    padding: 1rem;
    background-color: #181818;
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.bottom-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem 0;
    border-top: 2px solid #333;
    padding-top: 25px;
}

#timer {
    font-size: 8em;
    color: white;
}

#timer.red {
    color: #ff4d4d;
}

#timer.green {
    color: #4dff4d;
}

.popup {
    background-color: #00000000;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: -1;

    display: flex;
    align-items: center;
    justify-content: center;
}

.popup.open {
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 999;
}

.popup-inner {
    background-color: #2d2a2a;
    width: 50%;
    height: 80%;
    opacity: 1;
    display: flex;
    flex-flow: column;
}

/* scramble popup */
.scram-bar,
.list-bar {
    flex: 0 1 auto;
    padding: 16px 20px;
    display: flex;
    font-size: 22px;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #2e2e2e;
    transition: all 0.2s ease-in-out;
}

.cross {
    padding: 5px;
    transition: all 0.2s ease-in-out;
}

.cross:hover {
    background-color: rgb(255, 255, 255, 0.13);
}

.pblname {
    flex: 0 1 auto;
    font-size: 40px;
    width: 100%;
    text-align: center;
}

.scram-canvas {
    background-color: #00000000;
    left: 0;
    top: 0;
}

#canvas-wrapper {
    width: 100%;
    flex: 1 1 auto;
}

.display-scram {
    user-select: text;
}

.list-menu {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    overflow: scroll;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE 10+ */
    border-top: #555 solid;
    border-bottom: #555 solid;
}

.list-item {
    box-sizing: border-box;
    display: flex;
    flex-direction: row;
    padding: 10px 20px;
    font-size: 1.5rem;
}

.list-item:hover {
    background-color: rgb(255, 255, 255, 0.13);
}

.list-item.highlighted {
    border: 3px solid var(--border-col) !important;
}

.list-item.selected {
    text-decoration: underline;
}

.list-btn {
    font-size: 18px;
    border-width: 2px;
    margin: 5px;
    min-width: 80px;
}

.list-btn.right {
    margin-left: auto;
}

.list-item:nth-child(even) {
    background-color: #2d2a2a;
    border: 3px solid #2d2a2a;
}

.list-item:nth-child(odd) {
    background-color: #343131;
    border: 3px solid #343131;
}

.sublist-name {
    background-color: #222222;
    padding: 10px 20px;
    font-weight: bold;
    text-align: center;
}

.list-buttons {
    background-color: #222222;
    padding: 10px;
    display: flex;
    flex-direction: row;
    align-items: center;
}

.help .help-checkboxes {
    width: fit-content;
}

/* Settings popup */
.settings-popup-inner {
    width: 440px;
    max-width: 95vw;
    height: auto !important;
    max-height: 90vh;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid #333;
    box-shadow: 0 16px 56px rgba(0,0,0,0.75);
    display: flex;
    flex-direction: column;
    background-color: #1e1e1e;
}

.settings-body {
    padding: 20px 28px 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 1rem;
    cursor: pointer;
    padding: 5px 7px;
    border-radius: 10px;
    transition: background-color 0.15s ease;
}

.settings-checkbox:hover {
    background-color: rgba(255,255,255,0.07);
}

.settings-row input[type="checkbox"] {
    flex-shrink: 0;
}

.settings-divider {
    border: none;
    border-top: 1px solid #444;
    margin: 4px 0;
}

.settings-action-btn {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border-radius: 10px;
    border: 1px solid #555;
    background-color: #2a2a2a;
    color: #e0e0e0;
    cursor: pointer;
    text-align: left;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.settings-action-btn:hover {
    background-color: var(--button-col);
    border-color: var(--border-col);
}

/* Switch to full width display*/
.visible-mobile {
    display: none;
}

.checkbox-wrapper {
    margin-bottom: 10px;
    padding: 6px 4px 2px;
    font-size: 0.9rem;
}

.checkboxtext {
    margin-left: 5px;
    display: inline;
}

.sidebar-check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 6px 4px 2px;
}

.equator-row {
    display: none;
}

/* Barflip override row in sidebar */
.barflip-override-row {
    display: flex;
    flex-direction: column;
    font-size: 0.9rem;
    padding: 0px 4px 10px;
    gap: 6px;
}

.barflip-override-label {
    font-weight: bold;
    text-align: center;
}

.barflip-toggle {
    display: flex;
    border: 1px solid #555;
    border-radius: 8px;
    height: 34px;
}

.barflip-toggle-btn {
    flex: 1;
    padding: 0 10px;
    background: transparent;
    color: #e0e0e0;
    border: 1px solid transparent;
    border-radius: 0;
    font-size: 0.85rem;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    user-select: none;
}

.barflip-toggle-btn:hover {
    background: rgba(255,255,255,0.08);
    border-color: transparent;
}

.barflip-toggle-btn.active {
    background: var(--button-col);
    border-color: var(--border-col);
}

.barflip-sep {
    width: 1px;
    background: #555;
    flex-shrink: 0;
    align-self: stretch;
}

.barflip-toggle-btn:first-child { border-radius: 7px 0 0 7px; }
.barflip-toggle-btn:last-child  { border-radius: 0 7px 7px 0; }

/* Help popup */
.help-popup-inner {
    width: 50vw;
    height: auto !important;
    max-height: 90vh;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid #333;
    box-shadow: 0 16px 56px rgba(0,0,0,0.75);
    background-color: #1e1e1e;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.help {
    padding: 8px 40px 20px;
    overflow-y: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: #444 transparent;
}

.help-section {
    padding: 4px 0;
}

.help-section p,
.help-keys p {
    margin: 6px 0;
    font-size: 0.95rem;
    line-height: 1.5;
}

/* Lump / Alg-reference modal — styled like settings popup */
.lump-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    overflow-y: auto;
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.lump-window {
    background-color: #1e1e1e;
    width: min(800px, 80vw);
    margin: auto;
    border-radius: 18px;
    border: 1px solid #333;
    box-shadow: 0 16px 56px rgba(0, 0, 0, 0.75);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.lump-header {
    flex: 0 0 auto;
    padding: 16px 20px;
    display: flex;
    font-size: 22px;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
}

.lump-window-title {
    font-weight: bold;
    color: #e0e0e0
}

.lump-close-btn {
    padding: 5px 8px;
    background: transparent;
    border: none;
    color: #e0e0e0;
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.2s;
    line-height: 1;
}

.lump-close-btn:hover {
    background-color: rgba(255, 255, 255, 0.13);
    border-color: transparent;
}

.lump-text {
    overflow-y: auto;
    padding: 20px 20px 28px;
    flex: 1;
    color: #e0e0e0;
    scrollbar-width: thin;
    scrollbar-color: #444 transparent;
    font-family: Arial, sans-serif;
    font-size: 11pt;
    line-height: 1.6;
}

.lump-text .lump-title {
    margin-left: 0;
    text-indent: 0;
    text-align: center;
    font-weight: bold;
    text-decoration: underline;
    margin-bottom: 0.8em;
    font-size: 20pt;
}

.lump-text .section-label {
    display: block;
    font-size: 12pt;
    margin-top: 0.5em;
}

.lump-text .section-label a {
    color: var(--border-col);
}

.lump-text > span {
    display: block;
    /* base indent for all non-title lines */
}

/* Loading popup */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-box {
    background-color: #1e1e1e;
    border: 1px solid #333;
    border-radius: 18px;
    box-shadow: 0 16px 56px rgba(0, 0, 0, 0.75);
    padding: 36px 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    min-width: 180px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #333;
    border-top-color: var(--border-col);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-message {
    font-size: 1rem;
    color: #aaa;
    text-align: center;
}

/* success toast */
.success-toast {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 99999;
    pointer-events: none;
}

.success-box {
    background-color: #0d2b0d;
    border: 1px solid #71fc71ce;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(153, 253, 153, 0.1);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    animation: toastIn 0.2s ease;
}

.success-icon {
    flex-shrink: 0;
}

.success-message {
    font-size: 1rem;
    font-weight: bold;
    color: var(--success-toast-inner);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
    from { opacity: 1; transform: translateX(-50%) translateY(0); }
    to   { opacity: 0; transform: translateX(-50%) translateY(-8px); }
}
.success-toast.fading {
    animation: toastOut 0.3s ease forwards;
}

@media screen and (max-width: 900px) {
    .sidebar {
        width: 30%;
    }

    .popup-inner {
        width: 100%;
        height: 100%;
    }

    .sidebar {
        width: 35%;
    }

    .nav-center {
        position: static;
        transform: none;
        pointer-events: auto;
    }

    .hidden-mobile {
        display: none;
    }

    .visible-mobile {
        display: block;
    }

    .full-width-mobile {
        width: 100%;
        border: 0;
    }

    .selection-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .help-popup-inner {
        width: 90vw;
    }
}

@media screen and (max-width: 600px) {
    .selection-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .lump-window {
        width: 95vw;
    }
}

@media screen and (max-width: 500px) {
    .navbar {
        display: grid;
        grid-template-areas:
            "center"
            "buttons";
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        row-gap: 0.5rem;
        justify-items: center;
        align-items: center;
    }

    .nav-center {
        grid-area: center;
        width: 100%;
        text-align: center;
        position: static;
        transform: none;
    }

    .nav-left {
        grid-area: buttons;
        display: flex;
        gap: 0.3rem;
        justify-content: flex-start;
        margin-right: auto;
    }

    .nav-right {
        grid-area: buttons;
        display: flex;
        gap: 0.3rem;
        justify-content: flex-end;
        margin-left: auto;
    }

    .nav-left button,
    .nav-right button {
        flex-shrink: 0;
    }
}

@media screen and (max-width: 290px) {
    .selection-grid {
        grid-template-columns: repeat(1, 1fr);
    }
}
