/* ================================================================
   CT Scan Viewer – Screen Styles
   ================================================================ */

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

:root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-light: #21262d;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --green: #3fb950;
    --red: #f85149;
    --orange: #d29922;
    --col-left-w: 220px;
    --col-right-w: 280px;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* ── App shell ─────────────────────────────────────────────────── */

#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

#content {
    flex: 1;
    min-height: 0;
    width: 100%;
    padding: 0;
}

/* ── Start / Intro page ─────────────────────────────────────────── */

.start-intro {
    padding: 48px 40px;
    max-width: 640px;
}

.start-intro h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 16px;
}

.start-intro h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 24px 0 12px;
}

.start-intro p {
    color: var(--text-muted);
    margin-bottom: 12px;
    line-height: 1.7;
}

.start-intro .hint {
    margin-top: 32px;
    color: var(--accent);
    font-size: 15px;
}

/* ── Exercise list page ─────────────────────────────────────────── */

.exercises-page {
    padding: 32px;
    max-width: 1200px;
    margin: 0 auto;
    overflow-y: auto;
    height: 100%;
}

.exercises-page h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 24px;
}

.exercises-page h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 28px 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.case-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 12px;
}

.case-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
    transition: border-color 0.15s, background 0.15s;
}

.case-card:hover {
    border-color: var(--accent);
    background: var(--surface-light);
    text-decoration: none;
}

.case-card .case-number {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.case-card .case-title {
    font-size: 15px;
    color: var(--text);
    margin-top: 4px;
}

.case-card .case-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* ================================================================
   THREE-COLUMN VIEWER LAYOUT
   ================================================================ */

.viewer-three-col {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* ── Side columns toggle state ────────────────────────────────── */

.viewer-three-col.side-cols-hidden .col-left,
.viewer-three-col.side-cols-hidden .col-right,
.viewer-three-col.side-cols-hidden .resize-handle {
    display: none;
}

/* ── Left column: case nav ─────────────────────────────────────── */

.col-left {
    width: var(--col-left-w);
    min-width: 120px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.col-left-header {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    flex-shrink: 0;
}

.col-left-header a {
    color: var(--text-muted);
    font-size: 12px;
}

.col-left-header a:hover {
    color: var(--accent);
    text-decoration: none;
}

.case-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.case-list-group {
    margin-bottom: 4px;
}

.case-list-type {
    padding: 8px 12px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

.case-list-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 5px 12px;
    font-size: 12px;
    color: var(--text-muted);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background 0.1s;
    line-height: 1.4;
}

.case-list-item:hover {
    background: var(--surface-light);
    color: var(--text);
    text-decoration: none;
}

.case-list-item.active {
    background: var(--surface-light);
    border-left-color: var(--accent);
    color: var(--text);
}

.case-list-num {
    font-weight: 700;
    font-size: 11px;
    color: var(--accent);
    min-width: 16px;
    flex-shrink: 0;
}

.case-list-desc {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* ── Center column: viewer ─────────────────────────────────────── */

.col-center {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.viewer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 8px;
}

.viewer-toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.viewer-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.viewer-row {
    flex: 1;
    display: flex;
    min-height: 0;
}

.viewer-viewport {
    flex: 1;
    position: relative;
    background: #000;
    overflow: hidden;
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
    min-height: 0;
}

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

/* Markers overlay */
.markers-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.marker {
    position: absolute;
    pointer-events: auto;
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    display: none;
    transform: translate(-50%, -50%);
    z-index: 10;
}

.marker.placed {
    display: block;
    animation: markerPop 0.2s ease-out;
}

@keyframes markerPop {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }

    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.marker img {
    width: 80px;
    height: 80px;
    pointer-events: none;
}

/* Answer nav buttons (overlaid in viewer) */
.answer-nav-overlay {
    position: absolute;
    right: 12px;
    top: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 15;
    opacity: 1;
    transition: opacity 0.25s ease;
}

.answer-nav-overlay.btn-hidden {
    opacity: 0;
    pointer-events: none;
}

.answer-nav-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--green);
    background: rgba(22, 27, 34, 0.85);
    color: var(--green);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, box-shadow 0.15s;
}

.answer-nav-btn:hover {
    background: rgba(63, 185, 80, 0.2);
    box-shadow: 0 0 8px rgba(63, 185, 80, 0.3);
}

/* Vertical slider */
.viewer-slider-track {
    width: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px 0;
    flex-shrink: 0;
    background: transparent;
    border: none;
    position: relative;
}

.answer-dots {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    pointer-events: none;
    z-index: 20;
    overflow: visible;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.answer-dots.visible {
    opacity: 1;
}

.answer-dot {
    position: absolute;
    left: 50%;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--green);
    transform: translate(-50%, -50%);
    opacity: 0.5;
    transition: opacity 0.15s, box-shadow 0.15s, width 0.15s, height 0.15s;
}

.answer-dot.active {
    opacity: 1;
    width: 14px;
    height: 14px;
    box-shadow: 0 0 10px 4px var(--green);
}

input[type="range"].vertical-slider {
    writing-mode: vertical-lr;
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 100%;
    min-height: 100px;
    background: transparent;
    cursor: pointer;
    border: none;
    outline: none;
}

.slider-side-number {
    position: absolute;
    bottom: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid var(--border);
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 12px;
    color: var(--accent);
    font-weight: 700;
    pointer-events: none;
    z-index: 25;
    font-variant-numeric: tabular-nums;
}

input[type="range"].vertical-slider::-webkit-slider-runnable-track {
    width: 1px;
    background: var(--accent);
}

input[type="range"].vertical-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    transform: translateX(-4.5px);
}

/* ── Right column: text & answers ──────────────────────────────── */

.col-right {
    width: var(--col-right-w);
    min-width: 120px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
}

/* ── Resize handles ───────────────────────────────────────────── */

.resize-handle {
    width: 5px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    transition: background 0.15s;
}

.resize-handle:hover,
.resize-handle.active {
    background: var(--accent);
}

.info-section {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.info-section h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.info-body {
    font-size: 13px;
    line-height: 1.7;
    color: var(--text);
}

.info-body p {
    margin-bottom: 8px;
}

.answer-section {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.35s ease, opacity 0.3s ease, padding 0.3s ease;
    padding-top: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.answer-section.visible {
    max-height: 500px;
    opacity: 1;
    padding-top: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

/* ── Buttons ───────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 5px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.btn:hover {
    background: var(--surface-light);
    border-color: var(--accent);
    text-decoration: none;
    color: var(--text);
}

.btn-primary {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}

.btn-primary:hover {
    background: #2ea043;
    border-color: #2ea043;
    color: #fff;
}

.btn-danger {
    background: transparent;
    border-color: var(--border);
    color: var(--red);
}

.btn-danger:hover {
    background: rgba(248, 81, 73, 0.1);
    border-color: var(--red);
}

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

.btn-answer-nav {
    background: var(--surface-light);
    border-color: var(--green);
    color: var(--green);
}

.btn-answer-nav:hover {
    background: rgba(63, 185, 80, 0.15);
    border-color: var(--green);
    color: var(--green);
}

/* Animated show/hide for toolbar buttons */
.btn-animated {
    transition: opacity 0.25s ease, transform 0.25s ease, background 0.15s, border-color 0.15s;
    opacity: 1;
    transform: scale(1);
}

.btn-animated.btn-hidden {
    opacity: 0;
    transform: scale(0.85);
    pointer-events: none;
    position: absolute;
    width: 0;
    overflow: hidden;
    padding: 0;
    margin: 0;
    border: 0;
}

.kbd-hint {
    display: inline-block;
    padding: 0px 4px;
    font-size: 10px;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text-muted);
    font-family: monospace;
    margin-left: 2px;
}

.slider-label {
    font-size: 13px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.marker-count {
    font-size: 11px;
    color: var(--text-muted);
}

/* ── Modal ─────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 20px;
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    padding: 32px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.visible .modal-content {
    transform: translateY(0);
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
    transition: color 0.15s;
}

.modal-close:hover {
    color: var(--text);
}

.modal-content h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 20px;
    padding-right: 32px;
}

.modal-content h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 24px 0 12px;
}

.modal-content p {
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.7;
}

.modal-footer {
    margin-top: 32px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

/* ── Introduction Link ─────────────────────────────────────────── */

.intro-link {
    margin-left: auto;
    font-size: 11px;
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.intro-link:hover {
    text-decoration: underline;
}

/* ── Loading overlay ───────────────────────────────────────────── */

.viewer-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    z-index: 50;
    opacity: 1;
    transition: opacity 0.4s ease;
}

.viewer-loading.hidden {
    opacity: 0;
    pointer-events: none;
}

.viewer-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.viewer-loading .load-text {
    margin-top: 16px;
    color: var(--text-muted);
    font-size: 14px;
}

.viewer-loading .load-progress {
    margin-top: 8px;
    width: 200px;
    height: 4px;
    background: var(--surface-light);
    border-radius: 2px;
    overflow: hidden;
}

.viewer-loading .load-progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.2s;
    width: 0%;
}

/* ── Scroll hint ───────────────────────────────────────────────── */

.scroll-hint {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.5s;
    z-index: 20;
}

.scroll-hint.hidden {
    opacity: 0;
}

/* ── Scrollbar styling ─────────────────────────────────────────── */

.case-list::-webkit-scrollbar,
.col-right::-webkit-scrollbar {
    width: 6px;
}

.case-list::-webkit-scrollbar-track,
.col-right::-webkit-scrollbar-track {
    background: transparent;
}

.case-list::-webkit-scrollbar-thumb,
.col-right::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.case-list::-webkit-scrollbar-thumb:hover,
.col-right::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}