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

:root {
    /* Light theme */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --accent: #2563eb;
    --accent-light: #3b82f6;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --purple: #9333ea;
    --q-color: #d97706;
    --r-color: #16a34a;
    --s-color: #2563eb;
    --border-color: #cbd5e1;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

.app {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Header */
.header {
    text-align: center;
    padding: 0.75rem 0;
}

.header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.header p strong {
    color: var(--success);
}

/* Make header relative for absolute positioning */
.header {
    position: relative;
}

/* Header Left (Credits + Course CTA) */
.header-left {
    position: absolute;
    top: 0.5rem;
    left: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
}

/* Credits Link */
.credits-link {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
}

.credits-link:hover {
    color: var(--accent);
}

/* Course CTA Button */
.course-cta-btn {
    display: inline-block;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white !important;
    padding: 0.35rem 0.7rem;
    border-radius: 6px;
    font-size: 0.65rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

.course-cta-btn:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(37, 99, 235, 0.4);
    color: white !important;
    text-decoration: none;
}

/* Language Toggle */
.language-toggle {
    position: absolute;
    top: 0.5rem;
    right: 0;
    display: flex;
    gap: 0.25rem;
}

.lang-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

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

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

/* Main Layout */
.main-layout {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 1rem;
    align-items: start;
}

/* ECG Section */
.ecg-section {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    width: fit-content;
}

.ecg-columns {
    display: grid;
    grid-template-columns: repeat(2, auto);
    gap: 0.75rem;
    justify-content: start;
}

.ecg-column h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--bg-tertiary);
}

/* Lead Strips */
.lead-strip {
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 0.5rem;
    border: 2px solid var(--border-color);
    transition: border-color 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    width: fit-content;  /* Shrink to canvas size exactly */
}

.lead-strip:last-child {
    margin-bottom: 0;
}

/* Interactive leads */
.lead-strip.interactive {
    border-color: var(--success);
}

.lead-strip.interactive:hover {
    border-color: #4ade80;
}

/* Calculated leads */
.lead-strip.calculated {
    opacity: 0.85;
    border-color: var(--bg-tertiary);
}

.lead-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.lead-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent-light);
    min-width: 35px;
}

.lead-badge {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.lead-badge.interactive {
    background: rgba(34, 197, 94, 0.2);
    color: var(--success);
}

.lead-badge.calculated {
    background: rgba(148, 163, 184, 0.15);
    color: var(--text-muted);
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 0.6rem;
}

.lead-angle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: 'SF Mono', Monaco, monospace;
    margin-left: auto;
}

.lead-strip canvas {
    display: block;
    width: 280px;
    height: 100px;
    touch-action: none; /* Prevent scrolling while interacting */
}

/* Advanced mode - taller leads for better amplitude visibility */
.app.advanced-mode .lead-strip canvas {
    height: 150px;
}

/* Basic mode - wider canvas for multiple beats */
.app.basic-mode .lead-strip canvas {
    width: 400px;
    height: 80px;
}

.lead-strip.interactive canvas {
    cursor: crosshair;
}

.lead-strip.calculated canvas {
    cursor: default;
}

/* Tutorial Info */
.tutorial-info {
    margin-top: 0.75rem;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

/* Analysis Section */
.analysis-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Axis Comparison */
.axis-comparison {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1rem;
    border: 1px solid var(--border-color);
}

.axis-comparison h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}

.axis-methods {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.axis-methods.expanded {
    grid-template-columns: repeat(3, 1fr);
}

.axis-method {
    background: var(--bg-secondary);
    border-radius: 6px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
}

.method-header {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 0.3rem;
}

.method-icon {
    width: 18px;
    height: 18px;
    background: var(--accent);
    color: #fff;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
}

.method-title {
    font-weight: 600;
    font-size: 0.65rem;
    color: var(--text-secondary);
}

/* Info Button */
.info-btn {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-size: 0.6rem;
    font-weight: 700;
    cursor: pointer;
    margin-left: auto;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-family: Georgia, serif;
    font-style: italic;
}

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

.method-description {
    font-size: 0.6rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.method-values {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    margin-bottom: 0.3rem;
    padding: 0.25rem;
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.method-values.compact {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.method-values.compact .method-value {
    flex: 1;
    min-width: 45%;
}

.method-values.compact .method-value.full {
    flex: 100%;
}

.method-value {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
}

.method-value .label {
    color: var(--text-muted);
}

.method-value .value {
    font-family: 'SF Mono', Monaco, monospace;
    font-weight: 500;
    color: var(--text-primary);
}

.method-value .value.highlight {
    color: var(--accent);
    font-weight: 700;
}

.method-value .value.polarity-indicator {
    font-size: 0.8rem;
    font-weight: 700;
    width: 20px;
    text-align: center;
}

.method-value .value.polarity-indicator.positive {
    color: var(--success);
}

.method-value .value.polarity-indicator.negative {
    color: var(--danger);
}

.axis-result {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.25rem;
}

.axis-result.small {
    font-size: 0.6rem;
}

.axis-label {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.axis-value {
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'SF Mono', Monaco, monospace;
}

.axis-value.range {
    font-size: 0.9rem;
}

.detail-text {
    font-size: 0.6rem;
    color: var(--text-muted);
    font-family: 'SF Mono', Monaco, monospace;
}

.axis-classification {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.3rem 0.6rem;
    border-radius: 15px;
    text-align: center;
}

.axis-classification.normal {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}

.axis-classification.lad {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.axis-classification.rad {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.axis-classification.extreme {
    background: rgba(168, 85, 247, 0.15);
    color: var(--purple);
}

/* QRS Duration Box */
.qrs-duration-box {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding: 0.6rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.duration-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.duration-value {
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'SF Mono', Monaco, monospace;
}

.duration-value.normal { color: var(--success); }
.duration-value.warning { color: var(--warning); }
.duration-value.danger { color: var(--danger); }

/* Frontal Plane & Cabrera */
.frontal-plane,
.cabrera-circle {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 0.85rem;
    text-align: center;
    border: 1px solid var(--border-color);
}

.frontal-plane h3,
.cabrera-circle h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.frontal-plane canvas {
    background: var(--bg-tertiary);
    border-radius: 8px;
    width: 100%;
    max-width: 280px;
    aspect-ratio: 1;
    border: 1px solid var(--border-color);
}

.cabrera-circle canvas {
    background: var(--bg-tertiary);
    border-radius: 8px;
    width: 100%;
    max-width: 180px;
    aspect-ratio: 1;
    border: 1px solid var(--border-color);
}

/* Method Selector for Cabrera */
.method-selector {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.method-selector select {
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-family: inherit;
    cursor: pointer;
    width: 100%;
    max-width: 180px;
}

.method-selector select:focus {
    outline: none;
    border-color: var(--accent);
}

.selected-method-result {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.cabrera-axis {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: 'SF Mono', Monaco, monospace;
    color: var(--text-primary);
}

/* Presets Bar */
.presets-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: var(--bg-secondary);
    border-radius: 12px;
    flex-wrap: wrap;
    border: 1px solid var(--border-color);
}

.presets-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-right: 0.25rem;
}

.preset-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.4rem 0.85rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

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

/* Footer */
.footer {
    text-align: center;
    padding: 0.75rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.legend {
    display: flex;
    justify-content: center;
    gap: 1.25rem;
    margin-bottom: 0.4rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dot.q { background: var(--q-color); }
.dot.r { background: var(--r-color); }
.dot.s { background: var(--s-color); }

/* Mode Toggle */
.mode-toggle {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.mode-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.5rem 1.25rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

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

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

/* Basic Mode Specific */
.basic-mode-only {
    display: none;
}

.app.basic-mode .basic-mode-only {
    display: block;
}

.app.basic-mode .advanced-mode-only {
    display: none;
}

/* Basic mode: Hide Frontal Plane and Cabrera */
.app.basic-mode .frontal-plane,
.app.basic-mode .cabrera-circle {
    display: none;
}

/* Basic mode: Side-by-side layout (leads left, wheel right) */
.app.basic-mode .main-layout {
    display: flex;
    flex-direction: row;
    gap: 2rem;
    align-items: flex-start;
}

.app.basic-mode .ecg-section {
    order: 1;
}

.app.basic-mode .axis-wheel-container {
    order: 2;
    position: sticky;
    top: 1rem;
}

/* Axis Wheel Container */
.axis-wheel-container {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.25rem;
    border: 1px solid var(--border-color);
    text-align: center;
}

.axis-wheel-container h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.wheel-instructions {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

/* Wheel Wrapper */
.wheel-wrapper {
    position: relative;
    width: 220px;
    height: 220px;
    margin: 0 auto 1rem;
}

/* Axis Wheel */
.axis-wheel {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid var(--border-color);
    position: relative;
    cursor: grab;
    background: var(--bg-tertiary);
    overflow: hidden;
    user-select: none;
    touch-action: none;
}

.axis-wheel:active {
    cursor: grabbing;
}

/* Colored zones - using conic gradient */
/* ECG angle mapping: 0°=right, 90°=down, -90°=up, ±180°=left */
/* CSS starts at top (ECG -90°), so from 60deg aligns to ECG -30° */
.axis-wheel::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: conic-gradient(
        from 60deg,
        rgba(34, 197, 94, 0.35) 0deg 120deg,      /* Normal: ECG -30° to +90° (GREEN, 120° span) */
        rgba(239, 68, 68, 0.30) 120deg 210deg,    /* RAD: ECG +90° to +180° (RED, 90° span) */
        rgba(245, 206, 100, 0.35) 210deg 300deg,  /* Extreme: ECG ±180° to -90° (YELLOW, 90° span) */
        rgba(147, 197, 253, 0.35) 300deg 360deg   /* LAD: ECG -90° to -30° (BLUE, 60° span) */
    );
}

/* Hide individual zone divs (using CSS gradient instead) */
.wheel-zone {
    display: none;
}

/* Degree markers */
.wheel-marker {
    position: absolute;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    font-family: 'SF Mono', Monaco, monospace;
}

.wheel-marker[data-angle="0"] {
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
}

.wheel-marker[data-angle="90"] {
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
}

.wheel-marker[data-angle="180"] {
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
}

.wheel-marker[data-angle="-90"] {
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
}

/* Lead labels */
.wheel-lead {
    position: absolute;
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--accent);
    background: var(--bg-secondary);
    padding: 0.15rem 0.3rem;
    border-radius: 3px;
    border: 1px solid var(--border-color);
}

/* Lead positions on the wheel (based on their angles) */
.wheel-lead[data-lead="I"] {
    right: 25px;
    top: 50%;
    transform: translateY(-50%);
}

.wheel-lead[data-lead="II"] {
    right: 35px;
    bottom: 25px;
}

.wheel-lead[data-lead="III"] {
    left: 35px;
    bottom: 25px;
}

.wheel-lead[data-lead="aVR"] {
    left: 25px;
    top: 35px;
}

.wheel-lead[data-lead="aVL"] {
    right: 25px;
    top: 35px;
}

.wheel-lead[data-lead="aVF"] {
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
}

/* Rotating indicator line */
.wheel-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50%;
    height: 4px;
    background: linear-gradient(90deg, transparent 0%, var(--danger) 30%, var(--danger) 100%);
    transform-origin: left center;
    transform: rotate(60deg);
    border-radius: 0 2px 2px 0;
    pointer-events: none;
    z-index: 10;
}

.wheel-indicator::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 10px solid var(--danger);
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
}

/* Center display */
.wheel-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70px;
    height: 70px;
    background: var(--bg-secondary);
    border-radius: 50%;
    border: 3px solid var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 20;
    pointer-events: none;
}

.wheel-center span {
    font-size: 1.3rem;
    font-weight: 700;
    font-family: 'SF Mono', Monaco, monospace;
    color: var(--text-primary);
}

.basic-classification {
    font-size: 1.1rem;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    display: inline-block;
    margin-top: 0.5rem;
}

/* Modal Styles */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 450px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.modal-content h3 {
    margin-bottom: 1rem;
    color: var(--text-primary);
    font-size: 1.1rem;
    padding-right: 2rem;
}

.modal-content h4 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
}

.modal-content p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.6;
    margin-bottom: 0.5rem;
}

.modal-content code {
    display: block;
    background: var(--bg-tertiary);
    padding: 0.75rem;
    border-radius: 6px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 0.8rem;
    color: var(--text-primary);
    white-space: pre-wrap;
    margin-top: 0.25rem;
}

/* Responsive */

/* Tablet landscape */
@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 1fr;
    }

    .analysis-section {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }

    .axis-comparison {
        grid-column: 1 / -1;
    }

    .axis-methods.expanded {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Tablet portrait */
@media (max-width: 900px) {
    /* Make header left/right elements flow better */
    .header {
        padding-top: 2.5rem;
    }

    .header-left {
        position: relative;
        top: auto;
        left: auto;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
        margin-bottom: 0.5rem;
    }

    .language-toggle {
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
    }

    /* Basic mode: stack vertically on narrower screens */
    .app.basic-mode .main-layout {
        flex-direction: column;
        align-items: center;
        gap: 1.5rem;
    }

    .app.basic-mode .axis-wheel-container {
        position: relative;
        top: auto;
        order: -1;
    }
}

/* Tablet/Mobile */
@media (max-width: 768px) {
    .app {
        padding: 0.75rem;
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    }

    .header {
        padding-top: 0.5rem;
    }

    .header h1 {
        font-size: 1.4rem;
    }

    .header p {
        font-size: 0.85rem;
    }

    /* Stack header elements vertically */
    .header-left {
        position: relative;
        top: auto;
        left: auto;
        flex-direction: column;
        align-items: center;
        gap: 0.4rem;
        margin-bottom: 0.75rem;
    }

    .language-toggle {
        position: relative;
        top: auto;
        right: auto;
        margin-bottom: 0.5rem;
    }

    .ecg-columns {
        grid-template-columns: 1fr;
    }

    .analysis-section {
        grid-template-columns: 1fr;
    }

    .axis-methods,
    .axis-methods.expanded {
        grid-template-columns: 1fr;
    }

    /* Responsive canvas sizing */
    .lead-strip canvas {
        width: 100%;
        max-width: 320px;
    }

    .app.basic-mode .lead-strip canvas {
        width: 100%;
        max-width: 380px;
    }

    .ecg-section {
        width: 100%;
    }

    .lead-strip {
        width: 100%;
        max-width: 340px;
    }

    .app.basic-mode .lead-strip {
        max-width: 400px;
    }

    /* Presets bar */
    .presets-bar {
        justify-content: center;
        padding: 0.75rem;
    }

    .presets-label {
        width: 100%;
        text-align: center;
        margin-bottom: 0.25rem;
    }

    .preset-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.7rem;
    }

    /* Axis wheel */
    .wheel-wrapper {
        width: 200px;
        height: 200px;
    }

    .wheel-center {
        width: 60px;
        height: 60px;
    }

    .wheel-center span {
        font-size: 1.1rem;
    }

    /* Larger touch targets for info buttons */
    .info-btn {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }

    /* Modal adjustments */
    .modal-content {
        margin: 0.5rem;
        padding: 1.25rem;
        max-height: 90vh;
    }

    .modal-close {
        width: 36px;
        height: 36px;
        font-size: 1.75rem;
    }

    /* Mode toggle larger touch targets */
    .mode-btn {
        padding: 0.6rem 1.5rem;
        font-size: 0.9rem;
    }

    .lang-btn {
        padding: 0.35rem 0.65rem;
        font-size: 0.75rem;
    }
}

/* Mobile phones */
@media (max-width: 480px) {
    .app {
        padding: 0.5rem;
        padding-left: max(0.5rem, env(safe-area-inset-left));
        padding-right: max(0.5rem, env(safe-area-inset-right));
        gap: 0.75rem;
    }

    .header h1 {
        font-size: 1.2rem;
    }

    .header p {
        font-size: 0.8rem;
        padding: 0 0.25rem;
    }

    /* Ensure minimum readable font sizes */
    .method-title {
        font-size: 0.75rem;
    }

    .method-description {
        font-size: 0.7rem;
    }

    .method-value {
        font-size: 0.75rem;
    }

    .lead-badge {
        font-size: 0.6rem;
        padding: 0.15rem 0.4rem;
    }

    .ecg-column h3 {
        font-size: 0.75rem;
    }

    /* Full width ECG strips */
    .lead-strip {
        max-width: 100%;
    }

    .lead-strip canvas {
        width: 100%;
        max-width: 100%;
        min-width: 260px;
    }

    .app.basic-mode .lead-strip {
        max-width: 100%;
    }

    .app.basic-mode .lead-strip canvas {
        max-width: 100%;
    }

    /* Axis wheel for small screens */
    .wheel-wrapper {
        width: 180px;
        height: 180px;
    }

    .wheel-center {
        width: 55px;
        height: 55px;
    }

    .wheel-center span {
        font-size: 1rem;
    }

    .wheel-marker {
        font-size: 0.6rem;
    }

    .wheel-lead {
        font-size: 0.55rem;
        padding: 0.1rem 0.25rem;
    }

    .wheel-instructions {
        font-size: 0.7rem;
    }

    /* Presets - wrap nicely */
    .presets-bar {
        padding: 0.5rem;
        gap: 0.4rem;
    }

    .preset-btn {
        padding: 0.45rem 0.6rem;
        font-size: 0.65rem;
        flex: 1 1 auto;
        min-width: calc(33% - 0.4rem);
        text-align: center;
    }

    .presets-label {
        font-size: 0.75rem;
    }

    /* Classification badges */
    .axis-classification {
        font-size: 0.65rem;
        padding: 0.25rem 0.5rem;
    }

    .basic-classification {
        font-size: 0.95rem;
        padding: 0.4rem 0.8rem;
    }

    /* Footer */
    .footer {
        font-size: 0.7rem;
        padding: 0.5rem;
    }

    .legend {
        gap: 0.75rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    /* QRS Duration box */
    .qrs-duration-box {
        flex-direction: column;
        gap: 0.25rem;
        padding: 0.5rem;
    }

    .duration-label {
        font-size: 0.75rem;
    }

    .duration-value {
        font-size: 1rem;
    }

    /* Cabrera circle */
    .cabrera-circle {
        padding: 0.75rem;
    }

    .method-selector select {
        font-size: 0.8rem;
        padding: 0.5rem;
        width: 100%;
        max-width: 200px;
    }

    .cabrera-axis {
        font-size: 1.3rem;
    }

    /* Course CTA button */
    .course-cta-btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.6rem;
    }

    /* Credits link */
    .credits-link {
        font-size: 0.65rem;
    }

    /* Info button - ensure touch-friendly */
    .info-btn {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
        min-width: 32px;
    }

    /* Mode toggle */
    .mode-toggle {
        gap: 0.4rem;
    }

    .mode-btn {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }
}

/* Landscape orientation on phones */
@media (max-width: 900px) and (orientation: landscape) {
    .app.basic-mode .main-layout {
        flex-direction: row;
        align-items: flex-start;
    }

    .app.basic-mode .axis-wheel-container {
        order: 2;
        position: sticky;
        top: 0.5rem;
    }

    .wheel-wrapper {
        width: 160px;
        height: 160px;
    }

    .wheel-center {
        width: 50px;
        height: 50px;
    }

    .wheel-center span {
        font-size: 0.9rem;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover states that don't work on touch */
    .lead-strip.interactive:hover {
        border-color: var(--success);
    }

    /* Ensure adequate touch targets */
    .preset-btn,
    .mode-btn,
    .lang-btn {
        min-height: 44px;
    }

    .info-btn {
        min-width: 44px;
        min-height: 44px;
    }

    /* Add active states for touch feedback */
    .preset-btn:active,
    .mode-btn:active,
    .lang-btn:active {
        transform: scale(0.95);
        opacity: 0.9;
    }

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