* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Dark Mode Colors (Default) - Matching Graphiti */
    --bg-primary: #1A2F42;
    --bg-secondary: #2A3F5A;
    --canvas-bg: #606060;
    --text-primary: #E8F4FD;
    --text-secondary: #888;
    --accent-color: #4A90E2;
    --accent-hover: #6BA3E8;
    --panel-bg: rgba(26, 47, 66, 0.95);
    --border-color: #555;
    --input-bg: #3A4F6A;
    --button-bg: #4A90E2;
    
    /* Safe area support for iOS - for full-screen rendering into notch and chrome areas */
    --safe-area-top: env(safe-area-inset-top);
    --safe-area-bottom: env(safe-area-inset-bottom);
    --safe-area-left: env(safe-area-inset-left);
    --safe-area-right: env(safe-area-inset-right);
    --history-controls-size: 38px;
    --history-controls-gap: 8px;
    --history-controls-reserve: 50px;
}

html[data-theme="light"] {
    /* Light Mode - Canvas/graph paper changes */
    --canvas-bg: #FDFDFD;
}

html,
body {
    width: 100%;
    height: 100%;
    height: var(--actual-vh, 100vh);
    min-height: 100vh;
    min-height: var(--actual-vh, 100vh);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    overscroll-behavior: none; /* Prevent iOS rubber band scrolling */
    touch-action: none; /* Prevent default touch behaviors */
    /* Prevent touch behaviors on mobile */
    -webkit-touch-callout: none; /* iOS callout */
    -webkit-user-select: none; /* Safari */
    -khtml-user-select: none; /* Konqueror HTML */
    -moz-user-select: none; /* Old Firefox */
    -ms-user-select: none; /* Internet Explorer/Edge */
    user-select: none; /* Non-prefixed version */
}

/* Keep semantic content available to screen readers without visual layout impact */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* Title Screen */
.title-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100%;
    background: #1A2F42;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.title-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.title-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 30px;
    padding: 40px 20px;
}

.title-logo {
    max-width: 60vw;
    max-height: 30vh;
    width: auto;
    height: auto;
    object-fit: contain;
    image-rendering: auto;
    image-rendering: smooth;
    -ms-interpolation-mode: bicubic;
    backface-visibility: visible;
    -webkit-backface-visibility: visible;
    will-change: transform, opacity;
    -webkit-user-drag: none;
    pointer-events: auto;
    transform-origin: center center;
    transform-style: preserve-3d;
    transform: perspective(1200px) rotateY(180deg) scale(0);
    opacity: 0;
    animation: title-logo-startup-reveal 2s cubic-bezier(0.25, 0.8, 0.25, 1) both;
}

@keyframes title-logo-startup-reveal {
    0% {
        transform: perspective(1200px) rotateY(180deg) scale(0);
        opacity: 0;
    }

    100% {
        transform: perspective(1200px) rotateY(0deg) scale(1);
        opacity: 1;
    }
}

.title-tagline {
    font-size: 1.15em;
    font-weight: 500;
    color: var(--text-primary);
    margin: 0;
    font-style: italic;
}

.wip-notice {
    font-size: 0.9em;
    color: #ffcc00;
    margin: 20px 0;
    opacity: 0.8;
    line-height: 1.5;
    text-align: center;
}

.start-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 180px;
    padding: 8px 30px;
    border: 1px solid rgba(82, 218, 103, 0.9);
    border-radius: 8px;
    background: #198A42;
    color: #FFFFFF;
    font-size: 1.1em;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 22px rgba(53, 224, 88, 0.18), 0 2px 8px rgba(0, 0, 0, 0.35);
    transition: filter 0.2s, box-shadow 0.2s, transform 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.start-btn:hover {
    filter: brightness(1.05);
    transform: translateY(-1px);
    box-shadow: 0 10px 28px rgba(53, 224, 88, 0.28), 0 4px 12px rgba(0, 0, 0, 0.4);
}

.start-btn:active {
    filter: brightness(1.1);
}

.start-btn:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.9);
    outline-offset: 3px;
}

.title-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.worksheets-link-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.worksheets-link {
    color: #fff;
    font-size: 0.95em;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 0.2s;
}

.worksheets-link:visited {
    color: #fff;
}

.worksheets-link:hover {
    color: #B7DCFF;
}

.new-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    top: 1px;
    padding: 2px 7px;
    border-radius: 999px;
    background: #ffcc00;
    color: #1A2F42;
    font-size: 0.62em;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1.2;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.copyright {
    position: absolute;
    bottom: calc(20px + var(--safe-area-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    max-width: 90%;
    text-align: center;
    line-height: 1.3;
    font-size: 0.8em;
    color: #fff;
}

.copyright .tools-row {
    display: block;
}

.copyright a {
    color: #fff;
    text-decoration: none;
}

.copyright a:not(.contact-icon-link) {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.copyright .tool-link {
    white-space: nowrap;
}

.copyright .tools-row a.tool-link:nth-of-type(1) {
    color: #FF355E;
}

.copyright .tools-row a.tool-link:nth-of-type(1):hover {
    color: #FF5C7D;
}

.copyright .tools-row a.tool-link:nth-of-type(1):active {
    color: #FF2A52;
}

.copyright .tools-row a.tool-link:nth-of-type(2) {
    color: #39FF14;
}

.copyright .tools-row a.tool-link:nth-of-type(2):hover {
    color: #66FF47;
}

.copyright .tools-row a.tool-link:nth-of-type(2):active {
    color: #2EEA0F;
}

.copyright .tools-row a.tool-link:nth-of-type(3) {
    color: #00C8FF;
}

.copyright .tools-row a.tool-link:nth-of-type(3):hover {
    color: #35D6FF;
}

.copyright .tools-row a.tool-link:nth-of-type(3):active {
    color: #00B8EB;
}

/* Fourth tool (Korovatron) - yellow */
.copyright .tools-row a.tool-link:nth-of-type(4) {
    color: #ffcc00;
}

.copyright .tools-row a.tool-link:nth-of-type(4):hover {
    color: #ffdd33;
}

.copyright .tools-row a.tool-link:nth-of-type(4):active {
    color: #ffb700;
}

@media (orientation: landscape) and (max-height: 500px) {
    .title-content {
        height: 100%;
        justify-content: flex-start;
        gap: 16px;
        padding-top: 20px;
        padding-bottom: max(20px, calc(20px + var(--safe-area-bottom)));
    }

    .copyright {
        position: static;
        bottom: auto;
        left: auto;
        transform: none;
        margin-top: auto;
        max-width: 100%;
        padding-top: 12px;
    }
}

.copyright .tool-name {
    color: inherit;
    font-weight: 700;
}

.copyright .tool-description {
    display: none;
}

@media (max-width: 700px) {
    .copyright .tool-separator {
        display: none;
    }

    .copyright .tool-description {
        display: none;
    }

    /* On narrow screens hide all tool links except the fourth (Korovatron) */
    .copyright .tool-link {
        display: none;
    }

    .copyright .tool-link:nth-of-type(4) {
        display: block;
        margin-top: 2px;
    }
}

.container {
    position: relative;
    height: 100vh;
    height: var(--actual-vh, 100vh); /* Mobile: JS-calculated height for iOS PWA fix */
    min-height: var(--actual-vh, 100vh);
    width: 100vw;
    overscroll-behavior: none;
}

.main-app {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: var(--actual-vh, 100vh);
    min-height: var(--actual-vh, 100vh);
}

/* Hamburger Menu Button */
.panel-toggle-btn {
    position: fixed;
    top: 20px;
    top: max(20px, calc(env(safe-area-inset-top) + 10px));
    right: 20px;
    right: max(20px, calc(env(safe-area-inset-right) + 20px));
    z-index: 1001;
    width: 40px;
    height: 40px;
    background: rgba(42, 63, 90, 0.95);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    padding: 10px;
    backdrop-filter: blur(5px);
    transition: all 0.3s ease;
    touch-action: manipulation; /* Prevents double-tap zoom delay on mobile */
    -webkit-tap-highlight-color: transparent; /* Removes tap highlight on mobile */
}

@media (hover: hover) {
    .panel-toggle-btn:hover {
        background: rgba(74, 144, 226, 0.9);
    }
}

.panel-toggle-btn.active {
    background: rgba(231, 76, 60, 0.9);
}

@media (hover: hover) {
    .panel-toggle-btn.active:hover {
        background: rgba(192, 57, 43, 0.95);
    }
}

.panel-toggle-btn span {
    display: block;
    width: 20px;
    height: 2px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 2px;
    transition: all 0.3s ease;
}

/* Hamburger to X animation */
.panel-toggle-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.panel-toggle-btn.active span:nth-child(2) {
    opacity: 0;
}

.panel-toggle-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* Control Panel */
.control-panel {
    position: absolute;
    left: 0;
    top: 0;
    width: 330px;
    height: 100vh;
    height: var(--actual-vh, 100vh);
    min-height: var(--actual-vh, 100vh);
    background: var(--panel-bg);
    backdrop-filter: blur(5px);
    padding: 20px;
    padding-top: max(20px, calc(env(safe-area-inset-top) + 10px));
    padding-bottom: max(20px, calc(env(safe-area-inset-bottom) + 10px));
    overflow-y: auto;
    overscroll-behavior: contain; /* Contain rubber banding within panel, don't affect parent */
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y; /* Allow vertical scrolling */
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease;
    z-index: 1000;
}

.control-panel.closed {
    transform: translateX(-100%);
}

/* Allow text selection in inputs and labels */
.control-panel input,
.control-panel label,
.control-panel textarea {
    -webkit-user-select: text;
    user-select: text;
}

.control-panel h1 {
    color: var(--accent-color);
    margin-bottom: 5px;
    font-size: 28px;
}

.panel-logo {
    max-width: 200px;
    width: 100%;
    height: auto;
    margin: 0 auto 15px;
    display: block;
    -webkit-user-drag: none;
    pointer-events: auto;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}

.control-panel h3 {
    margin-top: 20px;
    margin-bottom: 10px;
    color: var(--text-primary);
    font-size: 16px;
}

.panel-separator {
    border-top: 1px solid #555;
    margin: 15px 0;
}

/* Top Button Row */
.top-button-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    margin-bottom: 8px;
    position: relative;
}

.top-button-row.four-col-row {
    grid-template-columns: repeat(4, 1fr);
}
.top-button-row.two-col-row {
    grid-template-columns: repeat(2, 1fr);
}

.top-btn {
    padding: 8px;
    font-size: 10px;
    height: 40px;
    line-height: 1.2;
    background: #2A3F5A;
    border: 1px solid #555;
    border-radius: 4px;
    color: #e0e0e0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    min-width: 0;
    box-sizing: border-box;
}
.top-btn:disabled {
    cursor: not-allowed;
}

.top-btn:disabled:hover {
    background: #2A3F5A;
}

.bottom-controls-row {
    align-items: center;
}

.bottom-half-buttons {
    display: flex;
    gap: 4px;
    align-items: center;
    width: 100%;
}

.bottom-half-btn {
    flex: 1;
    min-width: 0;
}

.share-controls-row {
    grid-template-columns: minmax(0, 1fr);
    margin-bottom: 0;
}

.share-link-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    letter-spacing: 0.08em;
    font-size: 11px;
    font-weight: 700;
}

.share-link-btn svg {
    flex: 0 0 auto;
}

@media (hover: hover) {
    .top-btn:hover {
        background: #354d6b;
    }

    .lattice-density-control.disabled:hover {
        background: #2A3F5A;
    }

    #grid-toggle-btn:hover,
    #intersection-toggle-btn:hover {
        background: #354d6b !important;
    }
}

.inv-option {
    color: #666;
    transition: color 0.2s;
}

.inv-option.inv-active {
    color: #ffffff;
}

.inv-separator {
    margin: 0 3px;
    color: #666;
}

.vec-icon {
    color: #666;
    transition: color 0.2s;
    cursor: pointer;
    width: 20px;
    height: 20px;
}

.vec-icon.vec-active {
    color: #ffffff;
}

.vec-separator {
    color: #666;
    font-size: 14px;
    line-height: 1;
}

.grid-icon {
    color: #666;
    transition: color 0.2s;
    cursor: pointer;
}

.grid-icon.grid-active {
    color: #ffffff;
}

.grid-separator {
    color: #666;
}

.intersection-icon {
    color: #666;
    transition: color 0.2s;
    cursor: pointer;
}

.intersection-icon.intersection-active {
    color: #ffffff;
}

.intersection-separator {
    color: #666;
}

.dim-option {
    color: #666;
    transition: color 0.2s;
    font-size: 14px;
    line-height: 1;
}

.dim-option.dim-active {
    color: #ffffff;
}

.dim-separator {
    margin: 0 6px;
    color: #666;
    font-size: 14px;
    line-height: 1;
}

#dimension-toggle-btn:disabled {
    background: #243549;
    border-color: #4a5564;
    opacity: 0.65;
}

#dimension-toggle-btn:disabled .dim-option,
#dimension-toggle-btn:disabled .dim-option.dim-active,
#dimension-toggle-btn:disabled .dim-separator {
    color: #7d8794;
}

.theme-icon {
    color: #666;
    transition: color 0.2s;
}

.theme-icon.theme-active {
    color: #ffffff;
}

.theme-separator {
    color: #666;
}

.size-option {
    color: #666;
    transition: color 0.2s;
    line-height: 1;
}

.size-option.size-active {
    color: #ffffff;
}

.size-separator {
    color: #666;
}

.lattice-controls-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 8px;
}

#lattice-toggle-btn {
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    gap: 0;
    padding-top: 5px;
    padding-bottom: 5px;
}

.lattice-label {
    font-size: 10px;
    letter-spacing: 0.4px;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1;
}

.lattice-state-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    line-height: 1;
}

.lattice-state-divider {
    font-size: 10px;
    color: #666;
}

.lattice-state {
    font-size: 10px;
    color: #666;
    transition: color 0.2s;
}

.lattice-state.lattice-active {
    color: #ffffff;
}

.lattice-density-control {
    height: 40px;
    padding: 4px 6px;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    overflow: hidden;
}

.lattice-density-control.disabled {
    opacity: 0.55;
}

.lattice-density-header {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    line-height: 1;
}

.lattice-density-label {
    font-size: 9px;
    letter-spacing: 0.45px;
    color: rgba(255, 255, 255, 0.8);
}

.lattice-density-slider {
    display: block;
    width: 100%;
    min-width: 0;
    margin: 0;
    accent-color: var(--accent-color);
    cursor: pointer;
    box-sizing: border-box;
}

.lattice-density-slider:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.add-button {
    position: relative;
    padding: 8px 12px;
    font-size: 14px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2A3F5A;
    border: 1px solid #555;
    border-radius: 4px;
    color: #e0e0e0;
    cursor: pointer;
    transition: background 0.2s;
}

.add-plus-icon {
    display: block;
    width: 12px;
    height: 12px;
    margin-right: 4px;
    flex-shrink: 0;
}

@media (hover: hover) {
    .add-button:hover {
        background: #354d6b;
    }
}

.add-dropdown {
    position: absolute;
    top: 42px;
    left: 0;
    background: #2A3F5A;
    border: 1px solid #555;
    border-radius: 4px;
    min-width: 200px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

.add-dropdown .dropdown-item {
    padding: 10px 12px;
    color: #e0e0e0;
    cursor: pointer;
    border-bottom: 1px solid #3a4a5f;
    transition: background 0.2s;
}

.add-dropdown .dropdown-item:last-child {
    border-bottom: none;
}

.add-dropdown .dropdown-separator:last-child,
.add-dropdown .dropdown-header:last-child {
    border-bottom: none;
}

@media (hover: hover) {
    .add-dropdown .dropdown-item:hover {
        background: #354d6b;
    }
}

.add-dropdown .dropdown-item strong {
    margin-right: 6px;
    color: rgba(255, 255, 255, 0.92);
}

.add-dropdown .dropdown-separator {
    height: 1px;
    background: #555;
    margin: 4px 0;
}

.add-dropdown .dropdown-header {
    padding: 8px 12px;
    color: #888;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: rgba(0, 0, 0, 0.2);
}

.add-dropdown .dropdown-accordion-header {
    width: 100%;
    border: none;
    -webkit-appearance: none;
    appearance: none;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.92);
    font: inherit;
    line-height: 1.2;
    min-height: 30px;
}

@media (hover: hover) {
    .add-dropdown .dropdown-accordion-header:hover {
        background: rgba(255, 255, 255, 0.12);
    }
}

.add-dropdown .dropdown-accordion-arrow {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.92);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    min-width: 12px;
    height: 12px;
    line-height: 1;
    transition: transform 0.2s ease;
    transform-origin: center;
}

.add-dropdown .dropdown-accordion-header[aria-expanded="true"] .dropdown-accordion-arrow {
    transform: rotate(90deg);
}

.add-dropdown .dropdown-accordion-label {
    color: rgba(255, 255, 255, 0.92);
    flex: 1;
    line-height: 1.2;
}

.add-dropdown .dropdown-accordion-content {
    max-height: 420px;
    overflow: hidden;
    opacity: 1;
    transition: max-height 0.25s ease, opacity 0.2s ease;
}

.add-dropdown .dropdown-accordion-content.collapsed {
    max-height: 0;
    opacity: 0;
}

/* App Mode Selector */
.app-mode-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.app-mode-btn {
    flex: 1;
    padding: 12px;
    border: 2px solid var(--accent-color);
    background: var(--bg-secondary);
    color: var(--accent-color);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    font-size: 15px;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

@media (hover: hover) {
    .app-mode-btn:hover {
        filter: brightness(1.15);
        transform: translateY(-1px);
    }
}

.app-mode-btn.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

/* View Controls */
.view-controls {
    margin-bottom: 20px;
    text-align: center;
}

.view-controls .secondary-btn {
    width: 100%;
}

/* Theme toggle button styling in panel */
#theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
}

#theme-toggle svg {
    flex-shrink: 0;
}

#theme-toggle span {
    font-size: 13px;
}

/* Mode Content Containers */
.mode-content {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Dimension Selector */
.dimension-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.mode-btn {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--accent-color);
    background: var(--bg-secondary);
    color: var(--accent-color);
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
}

@media (hover: hover) {
    .mode-btn:hover {
        filter: brightness(1.15);
    }
}

.mode-btn.active {
    background: var(--accent-color);
    color: white;
}

/* Matrix Input */
.matrix-input {
    margin-bottom: 20px;
}

.matrix-grid {
    display: grid;
    gap: 8px;
    max-width: 200px;
}

.matrix-2x2 {
    grid-template-columns: repeat(2, 1fr);
}

.matrix-3x3 {
    grid-template-columns: repeat(3, 1fr);
}

.matrix-grid input {
    width: 100%;
    padding: 8px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    background: var(--input-bg);
    color: var(--text-primary);
}

.matrix-grid input:focus {
    outline: none;
    border-color: var(--accent-color);
    filter: brightness(1.15);
}

/* Hide number input spinners */
.matrix-grid input::-webkit-outer-spin-button,
.matrix-grid input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.matrix-grid input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Equation inputs for lines and planes */
.equation-input {
    width: 50px;
    padding: 6px 8px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    background: var(--input-bg);
    color: var(--text-primary);
}

.equation-input:focus {
    outline: none;
    border-color: var(--accent-color);
    filter: brightness(1.15);
}

/* Hide number input spinners for equation inputs */
.equation-input::-webkit-outer-spin-button,
.equation-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.equation-input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Presets */
.presets {
    margin-bottom: 20px;
}

.preset-btn {
    display: block;
    width: 100%;
    padding: 8px;
    margin-bottom: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

@media (hover: hover) {
    .preset-btn:hover {
        background: var(--accent-color);
        color: white;
        border-color: var(--accent-color);
    }
}

/* Geometry Mode */
.geometry-type-selector {
    margin-bottom: 20px;
}

.geometry-type-btn {
    display: inline-block;
    padding: 6px 12px;
    margin-right: 6px;
    margin-bottom: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
}

@media (hover: hover) {
    .geometry-type-btn:hover {
        filter: brightness(1.15);
    }
}

.geometry-type-btn.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.geometry-input {
    margin-bottom: 20px;
}

.coord-input {
    margin-bottom: 12px;
}

.coord-input label {
    display: inline-block;
    margin-right: 10px;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 13px;
}

.coord-input input {
    width: 70px;
    padding: 6px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    text-align: center;
    font-size: 13px;
    background: var(--input-bg);
    color: var(--text-primary);
    margin-left: 4px;
}

.coord-input input:focus {
    outline: none;
    border-color: var(--accent-color);
    filter: brightness(1.15);
}

/* Hide number input spinners */
.coord-input input::-webkit-outer-spin-button,
.coord-input input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.coord-input input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

#geometry-list {
    max-height: 200px;
    overflow-y: auto;
}

/* Animation Controls */
.animation-controls {
    margin-bottom: 20px;
}

.primary-btn, .secondary-btn {
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.primary-btn {
    background: var(--accent-color);
    color: white;
}

@media (hover: hover) {
    .primary-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(74, 144, 226, 0.4);
    }
}

.apply-transformation-btn {
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    background: #2A3F5A;
    border: 1px solid #555;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    color: #e0e0e0;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (hover: hover) {
    .apply-transformation-btn:hover {
        background: #354d6b;
    }
}

.secondary-btn {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

@media (hover: hover) {
    .secondary-btn:hover {
        filter: brightness(1.15);
    }
}

.slider-control {
    margin-top: 15px;
}

.slider-control label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.slider-control input[type="range"] {
    width: 100%;
    margin-bottom: 5px;
}

.slider-control span {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent-color);
}

/* Vector Display */
.vector-display {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid var(--border-color);
    color: var(--text-primary);
}

#geometry-list {
    max-height: 200px;
    overflow-y: auto;
}

#objects-container {
    margin-bottom: 15px;
}

/* Collapsible Groups */
.object-group {
    margin-bottom: 12px;
}

.object-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s ease;
}

@media (hover: hover) {
    .object-group-header:hover {
        background: rgba(255, 255, 255, 0.12);
    }
}

.group-arrow {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.7);
    transition: transform 0.2s ease;
}

.group-label {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 2px;
}

.group-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 18px;
    padding: 0 6px;
    border-radius: 6px;
    background: #ffcc00;
    color: #000000;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
}

.group-add-btn {
    margin-left: auto;
}

.group-add-btn {
    width: 20px;
    height: 20px;
    -webkit-appearance: none;
    appearance: none;
    background: #2A3F5A;
    border: 1px solid #555;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: normal;
    line-height: 1;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.group-add-icon {
    display: block;
    width: 10px;
    height: 10px;
}

@media (hover: hover) {
    .group-add-btn:hover {
        filter: brightness(1.15);
        box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
    }
}

.group-add-btn:active {
    transform: scale(0.9);
}

.object-group-items {
    margin-top: 8px;
    padding-left: 0px;
    max-height: 9999px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease, margin-top 0.3s ease;
    opacity: 1;
}

.object-group-items.collapsed {
    max-height: 0;
    margin-top: 0;
    opacity: 0;
}

.matrix-item {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 10px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    border-left: 3px solid;
}

.matrix-item.disabled {
    opacity: 0.7;
}

.matrix-item .matrix-main-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.matrix-item .matrix-content {
    flex: 1;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
}

.matrix-item .matrix-name {
    font-size: 18px;
    font-weight: bold;
    font-style: italic;
    color: var(--text-primary);
    flex-shrink: 0;
}

.matrix-item .matrix-transform-label {
    display: none;
    margin-bottom: 6px;
    align-self: flex-start;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.02em;
    border-radius: 999px;
    padding: 3px 8px;
}

.matrix-item .matrix-transform-label.visible {
    display: inline-flex;
}

.matrix-sequence-item {
    border-left-style: solid;
}

.matrix-item .matrix-sequence-content {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}

.matrix-sequence-input {
    width: 100%;
    height: 30px;
    padding: 6px 8px;
    text-align: center;
    font-size: 12px;
    line-height: 1.2;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-family: inherit;
}

.matrix-sequence-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(144, 74, 226, 0.2);
}

.matrix-sequence-input.matrix-sequence-input-hidden {
    display: none;
}

.matrix-sequence-playback-display {
    display: none;
    width: 100%;
    height: 30px;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--input-bg);
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1;
    letter-spacing: 0.04em;
    user-select: none;
    pointer-events: none;
    overflow: hidden;
}

.matrix-sequence-playback-display.playback-mode {
    display: flex;
}

.matrix-sequence-playback-char {
    display: inline-block;
    padding: 0 1px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    transition: font-size 0.12s ease, transform 0.12s ease, color 0.12s ease, background-color 0.12s ease;
}

.matrix-sequence-playback-char.active {
    padding: 1px 3px;
    font-size: 18px;
    color: #FFE066;
    background: #D62828;
    border-radius: 3px;
    transform: translateY(-1px);
}

.matrix-sequence-item .matrix-controls {
    justify-content: center;
}

.matrix-item .matrix-controls {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    min-height: 100%;
}

.matrix-item .color-indicator {
    width: 20px;
    height: 20px;
    border-radius: 5px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: all 0.2s ease;
}

@media (hover: hover) {
    .matrix-item .color-indicator:hover {
        border-color: rgba(255, 255, 255, 0.5);
        transform: scale(1.1);
    }
}

.matrix-item .matrix-apply-btn,
.matrix-item .matrix-info-btn,
.vector-item .matrix-info-btn {
    width: 20px;
    height: 20px;
    background: #2A3F5A;
    border: 1px solid #555;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

@media (hover: hover) {
    .matrix-item .matrix-apply-btn:not(:disabled):hover,
    .matrix-item .matrix-info-btn:not(:disabled):hover,
    .vector-item .matrix-info-btn:not(:disabled):hover {
        filter: brightness(1.15);
        box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
    }
}

.matrix-item .matrix-apply-btn:disabled,
.matrix-item .matrix-info-btn:disabled,
.vector-item .matrix-info-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    filter: grayscale(0.4);
    box-shadow: none;
}

.matrix-item .matrix-apply-btn {
    /* background and color set via inline style from matrix colour */
}

.matrix-item .matrix-apply-btn:active {
    filter: brightness(0.85);
}

.matrix-item .matrix-info-btn,
.vector-item .matrix-info-btn {
    font-size: 11px;
    font-weight: bold;
    font-style: italic;
    color: #64B5F6;
}

.matrix-item .matrix-info-btn:active,
.vector-item .matrix-info-btn:active {
    background: #64B5F6;
    color: white;
}

.matrix-item .remove-btn {
    width: 20px;
    height: 20px;
    background: #2A3F5A;
    border: 1px solid #555;
    color: var(--text-primary);
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

@media (hover: hover) {
    .matrix-item .remove-btn:hover {
        background: rgba(180, 60, 60, 0.7);
        border-color: #b43c3c;
    }
}

.matrix-item .remove-btn:active {
    background: rgba(180, 60, 60, 0.7);
}

.matrix-grid-container {
    display: flex;
    gap: 4px;
    align-items: stretch;
    justify-content: center;
}

.matrix-item .matrix-grid {
    display: grid;
    gap: 4px;
}

.matrix-item .matrix-grid.matrix-2x2 {
    grid-template-columns: repeat(2, 1fr);
}

.matrix-item .matrix-grid.matrix-3x3 {
    grid-template-columns: repeat(3, 1fr);
}

.matrix-item .matrix-grid input {
    width: 50px;
    padding: 4px;
    font-size: 12px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    color: var(--text-primary);
    text-align: center;
    outline: none;
}

.matrix-item .matrix-grid input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(144, 74, 226, 0.2);
}

.matrix-bracket {
    font-size: 70px;
    color: var(--text-primary);
    font-weight: 300;
    line-height: 0.8;
    user-select: none;
    display: flex;
    align-items: center;
    transform: translateY(-12px);
}

.vector-item {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 10px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    border-left: 3px solid;
}

.vector-item.disabled {
    opacity: 0.7;
}

.vector-item .vector-main-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.vector-item .vector-controls {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    min-height: 100%;
}

.vector-item .color-indicator {
    width: 20px;
    height: 20px;
    border-radius: 5px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

@media (hover: hover) {
    .vector-item .color-indicator:hover {
        border-color: rgba(255, 255, 255, 0.5);
        transform: scale(1.1);
    }
}

.vector-item .color-indicator:active {
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.vector-item .remove-btn {
    width: 20px;
    height: 20px;
    background: #2A3F5A;
    border: 1px solid #555;
    color: var(--text-primary);
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

@media (hover: hover) {
    .vector-item .remove-btn:hover {
        background: rgba(180, 60, 60, 0.7);
        border-color: #b43c3c;
    }
}

.vector-item .remove-btn:active {
    background: rgba(180, 60, 60, 0.7);
}

.vector-item .form-toggle-btn {
    width: 20px;
    height: 20px;
    background: #2A3F5A;
    border: 1px solid #555;
    color: var(--text-primary);
    font-size: 10px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

@media (hover: hover) {
    .vector-item .form-toggle-btn:hover {
        filter: brightness(1.15);
        box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
    }
}

.vector-coordinates {
    display: flex;
    gap: 8px;
    flex: 1;
}

.vector-coord-input {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.vector-coord-input label {
    font-size: 13px;
    color: var(--text-primary);
    font-style: italic;
    font-weight: bold;
}

.vector-coord-input input {
    width: 100%;
    padding: 6px 8px;
    font-size: 13px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    outline: none;
}

.vector-coord-input input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

/* Hide number input spinners */
.vector-coord-input input::-webkit-outer-spin-button,
.vector-coord-input input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.vector-coord-input input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Canvas Container */
.canvas-container {
    width: 100%;
    height: 100vh;
    height: var(--actual-vh, 100vh);
    min-height: var(--actual-vh, 100vh);
    position: relative;
    background: var(--canvas-bg);
    overscroll-behavior: none;
}

#three-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
    cursor: -webkit-grab;
    touch-action: none; /* Prevent default touch behaviors */
    -webkit-user-select: none;
    user-select: none;
}

#three-canvas:active {
    cursor: grabbing;
    cursor: -webkit-grabbing;
}

.plane-extent-control {
    position: fixed;
    top: 68px;
    top: max(68px, calc(env(safe-area-inset-top) + 58px));
    right: 20px;
    right: max(20px, calc(env(safe-area-inset-right) + 20px));
    width: 190px;
    background: rgba(42, 63, 90, 0.95);
    border: 1px solid #555;
    border-radius: 8px;
    padding: 8px 10px;
    backdrop-filter: blur(5px);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
    z-index: 900;
}

.plane-extent-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text-primary);
    margin-bottom: 4px;
}

#plane-extent-value {
    min-width: 20px;
    text-align: right;
    font-weight: bold;
}

#plane-extent-slider {
    width: 100%;
    accent-color: var(--accent-color);
}

.drag-vector-overlay {
    position: fixed;
    top: 0;
    left: 0;
    background: rgba(42, 63, 90, 0.95);
    border: 1px solid #555;
    border-radius: 8px;
    padding: 8px 10px;
    backdrop-filter: blur(5px);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
    z-index: 900;
    pointer-events: none;
}

.drag-vector-overlay-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    letter-spacing: 0.25px;
    margin-bottom: 5px;
}

.drag-vector-overlay-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-primary);
    text-align: center;
    font-weight: 600;
    letter-spacing: 0.2px;
    line-height: 1.2;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.drag-axis-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.drag-axis-label {
    color: rgba(255, 255, 255, 0.9);
}

.drag-axis-value {
    display: inline-block;
    text-align: left;
    font-size: 13px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-variant-numeric: tabular-nums;
}

.drag-axis-divider {
    color: rgba(255, 255, 255, 0.45);
}

.drag-vector-overlay-hint {
    margin-top: 5px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.72);
    letter-spacing: 0.2px;
    text-align: center;
}

.history-controls {
    position: fixed;
    right: max(20px, calc(var(--safe-area-right, 0px) + 20px));
    bottom: max(12px, calc(var(--safe-area-bottom, 0px) + 12px));
    display: flex;
    gap: var(--history-controls-gap);
    z-index: 95;
    pointer-events: auto;
}

.history-btn {
    width: var(--history-controls-size);
    height: var(--history-controls-size);
    border: 1px solid #555;
    border-radius: 8px;
    background: rgba(42, 63, 90, 0.95);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: filter 0.2s ease, opacity 0.2s ease, transform 0.15s ease;
    backdrop-filter: blur(6px);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
    .history-btn:hover:not(:disabled) {
        filter: brightness(1.15);
    }
}

.history-btn:active:not(:disabled) {
    transform: translateY(1px);
}

.history-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

/* Eigenvalue Info Panel (bottom-right) */
.eigenvalue-panel {
    position: fixed;
    bottom: calc(max(12px, calc(var(--safe-area-bottom, 0px) + 12px)) + var(--history-controls-reserve));
    right: max(20px, calc(var(--safe-area-right, 0px) + 20px));
    background: rgba(58, 79, 106, 0.95);
    border: 1px solid #555555;
    border-radius: 4px;
    border-left: 8px solid transparent;
    padding: 12px 16px;
    min-width: 260px;
    max-width: 350px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    font-size: 14px;
    color: var(--text-primary);
    z-index: 100;
    pointer-events: auto;
    user-select: none;
    max-height: calc(100dvh - 32px - var(--safe-area-top, 0px) - var(--safe-area-bottom, 0px));
    overflow-y: auto;
}

@supports not (height: 100dvh) {
    .eigenvalue-panel {
        max-height: calc(100vh - 32px - var(--safe-area-top, 0px) - var(--safe-area-bottom, 0px));
    }
}

.eigenvalue-panel.info-panel-large {
    transform: scale(1.2);
    transform-origin: bottom right;
}

.eigenvalue-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.eigenvalue-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    line-height: 1.4;
}

.eigenvalue-header {
    font-weight: bold;
    font-size: 15px;
    color: #FFFFFF;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 6px;
}

.info-panel-close-btn {
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.08);
    color: #FFFFFF;
    width: 20px;
    height: 20px;
    border-radius: 3px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s ease, border-color 0.2s ease;
}

@media (hover: hover) {
    .info-panel-close-btn:hover {
        background: rgba(180, 60, 60, 0.7);
        border-color: #b43c3c;
    }
}

.info-panel-close-btn:active {
    background: rgba(180, 60, 60, 0.7);
}

.eigenvalue-values {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.eigenvalue-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.char-equation-row {
    align-items: center;
}

.eigenvalue-label {
    font-weight: bold;
    color: #FFFFFF;
    white-space: nowrap;
}

.eigenvalue-value {
    text-align: right;
    color: #E8F4FD;
    flex: 1;
    word-break: break-all;
}

.eigenvector {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

/* Scrollbar Styling - Hidden */
.control-panel {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.control-panel::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

/* Help modal (Graphiti-style) */
.shortcuts-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease;
}

.shortcuts-overlay.show {
    display: flex;
}

.shortcuts-content {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 30px 40px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    margin: 0 20px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

.shortcuts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 20px 0;
    font-size: 24px;
}

.shortcuts-content h2 {
    margin: 0;
    color: #fff;
    font-size: 24px;
    text-align: left;
}

.shortcuts-youtube-logo {
    display: block;
    width: 40px;
    height: 40px;
}

.shortcuts-section {
    margin-bottom: 20px;
}

.shortcuts-section h3 {
    color: #4A90E2;
    font-size: 16px;
    margin: 0 0 10px 0;
    font-weight: 600;
}

.shortcut-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.shortcut-item:last-child {
    border-bottom: none;
}

.shortcut-description {
    color: #ccc;
    font-size: 14px;
}

.shortcuts-close {
    margin-top: 20px;
    text-align: center;
    color: #fff;
    font-size: 13px;
}

.touch-only {
    display: none;
}

.desktop-only {
    display: inline;
}

.shortcuts-overlay.touch-navigation-mode .touch-only {
    display: inline;
}

.shortcuts-overlay.touch-navigation-mode .desktop-only,
.shortcuts-overlay.touch-navigation-mode .keyboard-only {
    display: none !important;
}

.custom-modal-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(5, 12, 18, 0.72);
    z-index: 3000;
    padding: 20px;
}

.custom-modal-overlay.show {
    display: flex;
}

.custom-modal {
    width: min(380px, 100%);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: rgba(26, 47, 66, 0.98);
    padding: 24px 22px 20px;
    box-shadow: 0 28px 56px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.custom-modal-message {
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.4;
    margin: 0;
}

.custom-modal-input {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 9px 12px;
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
    box-sizing: border-box;
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}

.custom-modal-input:focus {
    border-color: var(--accent-color);
}

.custom-modal-error {
    color: #E76F51;
    font-size: 0.82rem;
    min-height: 1.1em;
    margin: -6px 0 -4px;
}

.custom-modal-error:empty {
    display: none;
}

.custom-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.custom-modal-actions .top-btn {
    min-width: 88px;
    height: 34px;
    padding: 6px 12px;
    font-size: 12px;
}

.app-toast {
    position: fixed;
    left: 50%;
    bottom: max(18px, calc(var(--safe-area-bottom) + 18px));
    transform: translate(-50%, 14px);
    z-index: 3200;
    padding: 10px 14px;
    border: 1px solid rgba(0, 0, 0, 0.28);
    border-radius: 10px;
    background: rgba(185, 241, 138, 0.97);
    color: #11233a;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.01em;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.26);
}

.app-toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    :root {
        --history-controls-size: 34px;
        --history-controls-reserve: 46px;
    }

    .control-panel {
        width: 330px;
    }
    
    .panel-toggle-btn {
        width: 40px;
        height: 40px;
    }
    
    /* Adjust matrix sizing for mobile */
    .matrix-bracket {
        font-size: 60px;
        transform: translateY(-8px);
    }
    
    .matrix-item .matrix-grid input {
        width: 38px;
        padding: 3px;
        font-size: 11px;
    }
    
    .matrix-item .color-indicator {
        width: 16px;
        height: 16px;
    }
    
    .matrix-item .remove-btn {
        width: 16px;
        height: 16px;
    }
    
    .matrix-item .matrix-name {
        font-size: 16px;
    }

    .matrix-item .matrix-transform-label {
        margin-bottom: 4px;
    }

    .matrix-sequence-input {
        height: 28px;
        font-size: 11px;
    }

    .matrix-sequence-playback-display {
        height: 28px;
    }

    .matrix-sequence-playback-char {
        font-size: 11px;
    }

    .matrix-sequence-playback-char.active {
        font-size: 16px;
    }
}

@media (max-width: 500px) {
    .shortcuts-content {
        padding: 20px;
        margin: 0 20px;
        max-width: calc(100% - 40px);
    }
}

@media (hover: none) and (pointer: coarse) {
    .touch-only {
        display: inline;
    }

    .desktop-only {
        display: none !important;
    }
}

@media (min-width: 1024px) {
    .copyright {
        font-size: 1em;
    }
}