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

:root {
    --bg: #16181f;
    --bg-light: #1e222c;
    --bg-card: #222631;
    --bg-hover: #2c313f;
    --accent: #e72749;
    --accent-soft: #ff6b86;
    --accent-dim: rgba(231, 39, 73, 0.16);
    --accent-glow: rgba(231, 39, 73, 0.42);
    --text: #f1f5f9;
    --text-dim: #cbd5e1;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(22, 24, 31, 0.94);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}

.header-brand {
    flex-shrink: 0;
}

.header-brand img {
    display: block;
    height: 40px;
    width: auto;
}

.header-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.08rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.header-title span {
    color: var(--accent-soft);
}

.header-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.84rem;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    transition: var(--transition);
}

.header-back:hover {
    color: #fff;
    border-color: var(--accent);
}

@media (max-width: 900px) {
    .header-title {
        display: none;
    }
    .header-brand img {
        height: 32px;
    }
}

.app-layout {
    display: grid;
    grid-template-columns: 300px 1fr 310px;
    height: calc(100vh - 65px);
}

@media (max-width: 1150px) {
    .app-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
}

.sidebar,
.info-panel {
    padding: 18px 20px;
    overflow-y: auto;
    background: var(--bg);
}

.sidebar {
    border-right: 1px solid var(--border);
}

.info-panel {
    border-left: 1px solid var(--border);
}

@media (max-width: 1150px) {
    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        display: flex;
        flex-wrap: wrap;
        gap: 14px;
    }
    .sidebar .section {
        flex: 1;
        min-width: 240px;
    }
    .info-panel {
        border-left: none;
        border-top: 1px solid var(--border);
    }
}

.section {
    margin-bottom: 22px;
}

.section-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 7px;
}

.section-title::before {
    content: '';
    width: 3px;
    height: 12px;
    background: var(--accent);
    border-radius: 2px;
}

.control-group {
    margin-bottom: 13px;
}

.control-label {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 6px;
    display: block;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-row input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: rgba(255, 255, 255, 0.16);
    border-radius: 2px;
    outline: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 8px var(--accent-glow);
    transition: var(--transition);
}

.slider-row input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.18);
}

.slider-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    min-width: 56px;
    text-align: right;
    color: #fff;
    font-weight: 500;
}

.preset-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.preset-grid.single-col {
    grid-template-columns: 1fr;
}

.preset-btn {
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-dim);
    font-family: 'Outfit', sans-serif;
    font-size: 0.76rem;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.preset-btn:hover {
    border-color: rgba(231, 39, 73, 0.55);
    color: #fff;
    background: var(--bg-hover);
}

.preset-btn.active {
    border-color: var(--accent);
    color: #fff;
    background: var(--accent-dim);
    font-weight: 600;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 0;
}

.toggle-label {
    font-size: 0.82rem;
    color: var(--text-dim);
}

.toggle {
    width: 40px;
    height: 22px;
    background: rgba(255, 255, 255, 0.16);
    border-radius: 11px;
    cursor: pointer;
    position: relative;
    transition: var(--transition);
    border: none;
    outline: none;
}

.toggle.active {
    background: var(--accent);
}

.toggle::after {
    content: '';
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 3px;
    left: 3px;
    transition: var(--transition);
}

.toggle.active::after {
    left: 21px;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    font-family: 'Outfit', sans-serif;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
    text-decoration: none;
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: #fff;
}

.viewport {
    position: relative;
    overflow: hidden;
    background: radial-gradient(circle at 50% 48%, rgba(255, 255, 255, 0.03), var(--bg) 72%);
    min-height: 540px;
}

#instrumentCanvas {
    width: 100%;
    height: 100%;
    min-height: 540px;
    display: block;
    cursor: grab;
    touch-action: none;
}

#instrumentCanvas:active {
    cursor: grabbing;
}

.viewport-overlay {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    backdrop-filter: blur(12px);
    z-index: 10;
}

.viewport-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    font-size: 1.05rem;
}

.viewport-btn:hover {
    background: var(--bg-hover);
    color: var(--accent-soft);
}

.viewport-hint {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.74rem;
    color: var(--text-dim);
    background: rgba(22, 24, 31, 0.85);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: 20px;
    pointer-events: none;
    white-space: nowrap;
}

.info-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 12px;
}

.info-card-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 9px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.info-row:last-child {
    border-bottom: none;
}

.info-key {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.info-val {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: #fff;
    font-weight: 600;
}

.instrument-title {
    font-size: 1.32rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #ffffff;
    margin-bottom: 4px;
}

.instrument-sub {
    font-size: 0.83rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    line-height: 1.45;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    padding: 4px 10px;
    border-radius: 999px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    background: var(--bg-light);
    color: var(--text-dim);
}

.status-pill.sharp {
    border-color: rgba(231, 39, 73, 0.55);
    background: rgba(231, 39, 73, 0.16);
    color: #fff;
}

.status-pill.blur {
    border-color: rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-dim);
}

.formula-box {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.86rem;
    padding: 10px 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    color: var(--accent-soft);
    text-align: center;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    line-height: 1.5;
}

.retinal-preview-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #101218;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
}

.retinal-optotype {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.7rem;
    font-weight: 700;
    color: #fff;
    width: 54px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    transform: rotate(180deg);
    transition: filter 0.2s ease;
}
