* {
    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);
}

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

html,
body {
    -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 */
}

/* 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;
    }
}

@media (prefers-reduced-motion: reduce) {
    .title-logo {
        animation: none;
        transform: none;
        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 {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid #555;
    padding: 12px 30px;
    font-size: 1em;
    border-radius: 8px;
    cursor: pointer;
    transition: filter 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    min-width: 180px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.start-btn:hover {
    filter: brightness(1.15);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

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

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

.copyright a {
    color: #fff;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.2s;
}

.more-contact-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.contact-icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    position: relative;
    top: -2px;
    color: #fff;
    transition: none;
}

.contact-icon-link:hover {
    color: #fff;
}

.contact-icon-link svg {
    width: 1.35em;
    height: 1.35em;
}

.copyright .contact-icon-link,
.copyright .contact-icon-link:hover,
.copyright .contact-icon-link:visited {
    color: #fff;
}

.contact-icon-link path {
    fill: currentColor;
}

.copyright a:hover {
    color: #fff;
}

.break-mobile {
    display: inline;
}

.space-desktop {
    display: none;
}

.space-inline {
    display: inline;
}

@media (min-width: 800px) {
    .break-mobile {
        display: none;
    }
    
    .space-desktop {
        display: inline;
    }
}

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

/* 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;
    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-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;
}

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

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

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

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

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

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

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

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

.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;
}

.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;
}

.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: #4fc3f7;
}

.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);
}

/* 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;
    flex: 1;
}

.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: 2000px;
    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-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:hover,
    .matrix-item .matrix-info-btn:hover,
    .vector-item .matrix-info-btn:hover {
        filter: brightness(1.15);
        box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
    }
}

.matrix-item .matrix-apply-btn {
    color: #4CAF50;
}

.matrix-item .matrix-apply-btn:active {
    background: #4CAF50;
    color: white;
}

.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);
    font-size: 12px;
    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 {
        filter: brightness(1.15);
        box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
    }
}

.matrix-item .remove-btn:active {
    background: #E74C3C;
}

.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);
    font-size: 12px;
    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 {
        filter: brightness(1.15);
        box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
    }
}

.vector-item .remove-btn:active {
    background: #E74C3C;
}

.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;
    position: relative;
    background: var(--canvas-bg);
    overscroll-behavior: none;
}

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

.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);
}

/* Eigenvalue Info Panel (bottom-right) */
.eigenvalue-panel {
    position: fixed;
    bottom: max(12px, calc(var(--safe-area-bottom, 0px) + 12px));
    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 #904AE2;
    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;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.info-panel-close-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.4);
}

.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;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    .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;
        font-size: 10px;
    }
    
    .matrix-item .matrix-name {
        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;
    }
}