/* iPhone Screw Diagram Styles */
/* Minimalist Apple HIG Dashboard Design */

:root {
    /* Base Colors - Apple Light Theme */
    --apple-blue: #007AFF;
    --apple-blue-dark: #0056CC;
    --apple-green: #34C759;
    --apple-red: #FF3B30;
    --apple-orange: #FF9500;
    
    /* Grays */
    --system-gray-1: #8E8E93;
    --system-gray-2: #AEAEB2;
    --system-gray-3: #C7C7CC;
    --system-gray-4: #D1D1D6;
    --system-gray-5: #E5E5EA;
    --system-gray-6: #F2F2F7;
    
    /* Backgrounds & Text */
    --page-bg: #F5F5F7;
    --card-bg: rgba(255, 255, 255, 0.85);
    --text-primary: #1D1D1F;
    --text-secondary: #86868B;
    
    /* UI Elements */
    --border-color: rgba(0, 0, 0, 0.08); /* 1px thin stroke */
    --divider-color: rgba(60, 60, 67, 0.12); /* Standard Apple separator */
    
    /* Shadows - Subtle and realistic */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.08);
    
    /* Glassmorphism Defaults */
    --glass-blur: blur(24px) saturate(180%);
}

/* Dark Theme Overrides */
html[data-theme="dark"] {
    --page-bg: #000000;
    --card-bg: rgba(44, 44, 46, 0.75);
    --text-primary: #F5F5F7;
    --text-secondary: #98989D;
    --border-color: rgba(255, 255, 255, 0.1);
    --divider-color: rgba(255, 255, 255, 0.12);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
    --apple-blue: #0A84FF;
}

html[data-theme="dark"] .global-header {
    background: rgba(28, 28, 30, 0.8);
}

html[data-theme="dark"] .menu-header {
    background: rgba(28, 28, 30, 0.9);
}

html[data-theme="dark"] footer {
    background: rgba(28, 28, 30, 0.8);
}

/* Basic Reset and Font Styling */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
    background-color: var(--page-bg);
    color: var(--text-primary);
    line-height: 1.4;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-top: 50px !important; /* Force consistent header spacer across all views */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Global Header Override */
.global-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
    padding: 0 20px;
    background: rgba(245, 245, 247, 0.8);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: 0.5px solid var(--border-color);
    z-index: 1000;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
}

.global-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
    text-decoration: none;
    transition: opacity 0.2s;
}

.global-title:hover {
    opacity: 0.7;
}

.global-title i {
    font-size: 18px;
    color: var(--apple-blue);
}

.global-title h1 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0;
}

.global-nav {
    display: flex;
    align-items: center;
    gap: 16px;
    border-left: 1px solid var(--divider-color);
    padding-left: 16px;
}

.global-nav a {
    color: var(--system-gray-1);
    transition: color 0.2s;
    font-size: 16px;
}

.global-nav a:hover,
.global-nav a[style*="color: #4f46e5"] {
    color: var(--apple-blue) !important;
}

/* Local App Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    padding: 0 20px;
    z-index: 100;
    background: transparent;
    pointer-events: none;
}

header > * {
    pointer-events: auto;
}

.header-left {
    position: fixed;
    top: 20px; /* Precise hub bar centerline alignment */
    left: 20px;
    height: 44px; /* Unify with hub bar height */
    display: flex;
    align-items: center;
    z-index: 20000;
}

.header-right {
    position: fixed;
    top: 13px; /* Precise hub bar centerline alignment */
    right: 20px;
    height: 44px; /* Unify with hub bar height */
    display: flex;
    align-items: center;
    z-index: 10000;
}

.hamburger-btn {
    background: var(--card-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 0.5px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border-radius: 50%;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, transform 0.2s ease;
    color: var(--text-primary);
    width: 44px;
    height: 44px;
    -webkit-tap-highlight-color: transparent;
    font-size: 18px;
}

.hamburger-btn:hover {
    transform: scale(1.05);
}

.icon:active {
    opacity: 0.4;
}

.header-center {
    display: none; /* Hide redundant text to unify the header cleanly */
}


/* Menu Overlay */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.menu-overlay.open {
    opacity: 1;
    visibility: visible;
}

/* Hamburger Menu - iOS Native Feel */
.hamburger-menu {
    position: fixed;
    top: 0;
    left: -100%;
    width: 320px;
    max-width: 85vw;
    height: 100vh;
    background: var(--page-bg);
    z-index: 999;
    transition: transform 0.4s cubic-bezier(0.19, 1, 0.22, 1);
    transform: translateX(-100%);
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 0.5px solid var(--border-color);
    -webkit-overflow-scrolling: touch;
}

.hamburger-menu.open {
    left: 0;
    transform: translateX(0);
    box-shadow: 20px 0 60px rgba(0, 0, 0, 0.2);
}

.menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 0.5px solid var(--divider-color);
    position: sticky;
    top: 0;
    background: rgba(245, 245, 247, 0.9);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    z-index: 10;
}

.menu-logo {
    display: flex;
    align-items: center;
}

.menu-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.4px;
}

.close-menu {
    background: none;
    border: none;
    color: var(--apple-blue);
    font-size: 17px;
    cursor: pointer;
    padding: 0;
    font-weight: 400;
    -webkit-tap-highlight-color: transparent;
}

.close-menu:active {
    opacity: 0.5;
}

.menu-content {
    padding: 16px 0 40px 0;
}

.menu-section {
    margin-bottom: 24px;
}

.menu-section-title {
    color: var(--text-secondary);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 0 20px 8px 20px;
}

/* iOS-Style List Items */
.menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--text-primary);
    text-decoration: none;
    padding: 14px 20px;
    font-size: 17px;
    transition: background-color 0.15s;
    letter-spacing: -0.4px;
    -webkit-tap-highlight-color: transparent;
    background: var(--card-bg);
    margin: 0 16px 2px 16px;
    border-radius: 10px;
}

.menu-item:active {
    background-color: var(--system-gray-5);
}

.menu-item.active {
    background-color: var(--apple-blue);
    color: white;
}

.menu-item.active .menu-item-chevron {
    color: rgba(255, 255, 255, 0.8);
}

.menu-item-text {
    flex: 1;
}

.menu-item-chevron {
    color: var(--system-gray-3);
    font-size: 14px;
    margin-left: 8px;
}

.new-badge {
    display: inline-block;
    background: var(--apple-red);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 6px;
    margin-left: 8px;
    text-transform: uppercase;
}

/* iOS-Style Dropdown Groups */
.dropdown {
    background: var(--card-bg);
    margin: 0 16px 8px 16px;
    border-radius: 10px;
    overflow: hidden;
    transition: all 0.3s;
}

.dropdown-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 17px;
    user-select: none;
    letter-spacing: -0.4px;
    -webkit-tap-highlight-color: transparent;
    border-bottom: 0.5px solid transparent;
}

.dropdown.open .dropdown-header {
    border-bottom-color: var(--divider-color);
}

.dropdown-header:active {
    background-color: var(--system-gray-5);
}

.dropdown-arrow {
    transition: transform 0.2s ease;
    color: var(--text-secondary);
    font-size: 14px;
}

.dropdown.open .dropdown-arrow {
    transform: rotate(90deg);
}

.dropdown-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    background-color: rgba(255, 255, 255, 0.3);
}

.dropdown.open .dropdown-content {
    max-height: 600px;
}

.dropdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--apple-text);
    text-decoration: none;
    padding: 12px 20px 12px 40px;
    font-size: 15px;
    transition: background-color 0.15s ease;
    letter-spacing: -0.3px;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.05);
    -webkit-tap-highlight-color: transparent;
}

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

.dropdown-item:active {
    background-color: #e8e8e8;
}

.dropdown-item-chevron {
    color: #c7c7cc;
    font-size: 12px;
}

/* Main Content Styling */
main {
    padding: 0 16px 12px;
    max-width: 1200px;
    margin: 0 auto;
    flex: 1;
    overflow: visible;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 0;
}

body.view-active {
    height: 100vh;
    overflow: hidden;
}

body.view-active main {
    height: auto;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.title {
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 40px auto 4px;
    padding: 0 24px;
    flex-shrink: 0;
    letter-spacing: -0.5px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
}

/* Focus Mode Context Recovery */
body.guide-view-active .title {
    opacity: 1; /* Restore visibility */
    height: auto;
    font-size: 15px; /* Compact, breadcrumb style */
    font-weight: 500;
    margin: 24px auto 0;
    pointer-events: auto;
    overflow: visible;
}

body.guide-view-active .subtitle-container {
    opacity: 1; /* Restore visibility */
    height: auto;
    margin: 0 auto 4px;
    pointer-events: auto;
    overflow: visible;
}

body.guide-view-active .subtitle-container .image-title {
    font-size: 11px; /* Very subtle context */
    opacity: 0.6;
}

/* Hide breadcrumb navigation in Focus Mode */
body.guide-view-active .subtitle-nav-btn {
    display: none;
}

body.guide-view-active main {
    padding-top: 5px; /* Adjusted context-aware padding */
}

.title:hover {
    opacity: 0.7;
}

.title:active {
    opacity: 0.4;
}

.subtitle-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin: 0 0 2px 0;
}

.image-title {
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
    font-weight: 500;
    flex-shrink: 0;
    letter-spacing: -0.1px;
}

.subtitle-nav-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s, color 0.2s;
    opacity: 0;
    pointer-events: none;
}

.subtitle-nav-btn.show-in-guide {
    opacity: 1;
    pointer-events: auto;
}

.subtitle-nav-btn:hover {
    color: var(--text-primary);
    transform: scale(1.1);
}

.subtitle-nav-btn:active {
    transform: scale(0.9);
}

.subtitle-nav-btn svg {
    width: 14px;
    height: 14px;
}

#diagramSection {
    display: none;
    width: 100%;
    flex: 1;
    min-height: 0;
    flex-direction: column;
}

#diagramSection.active {
    display: flex !important;
}

#guideContainer {
    display: none;
}

#guideContainer.active {
    display: flex !important;
}

.diagram-container {
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin: 0 auto;
    width: 100%;
    max-width: 1400px;
    flex: 1;
    min-height: 0;
    position: relative;
}

.desktop-spacer {
    grid-column: 1;
    width: 44px; /* Matches width of .overlay-buttons on Desktop */
    opacity: 0;
    pointer-events: none;
}

.image-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
    flex: 1;
    position: relative;
    background: transparent;
    border-radius: 0;
    padding: 0 110px; /* Increased gutter for premium spacing between image and bar */
    box-shadow: none;
    border: none;
    min-height: 0;
}

.diagram-image {
    max-width: 100%;
    /* Desktop-optimized: taller image for better visibility on large screens */
    max-height: 580px;
    height: auto;
    object-fit: contain;
    transition: opacity 0.3s ease, transform 0.3s ease;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}

.overlay-buttons {
    position: absolute;
    top: 0; /* Aligned with top of image wrapper */
    right: 12px; /* Increased margin from the edge */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    gap: 18px; /* Generous spacing between larger buttons */
    padding: 12px;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(15px) saturate(180%);
    -webkit-backdrop-filter: blur(15px) saturate(180%);
    border-radius: 30px; /* Standardized pill shape for the bar */
    border: 0.5px solid var(--border-color);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    z-index: 100;
    margin: 0;
    width: fit-content;
}

/* Hide scrollbar for Chrome, Safari and Opera */
.overlay-buttons::-webkit-scrollbar {
    display: none;
}

/* Hide scrollbar for IE, Edge and Firefox */
.overlay-buttons {
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

.overlay-button {
    position: relative;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px) saturate(120%);
    -webkit-backdrop-filter: blur(12px) saturate(120%);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%; /* Standardized rounded/circle shape for buttons */
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    will-change: transform;
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.overlay-button:hover {
    background: #f5f5f7;
    transform: scale(1.05);
}

.overlay-button:active {
    transform: scale(0.95);
}

.overlay-button svg {
    width: 20px;
    height: 20px;
    stroke: #333;
    stroke-width: 2;
    fill: none;
}

.icon-torx {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 0;
}

.icon-torx svg {
    width: 20px;
    height: 20px;
}

.torx-icon {
    width: 18px;
    height: 18px;
    object-fit: contain;
}

.torx-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1;
    margin-top: 2px;
}

/* Navigation indicators */
.nav-indicators {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 8px 0;
    width: auto;
    z-index: 5;
    margin-top: 10px;
}

.nav-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #d2d2d7;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-dot.active {
    background: var(--apple-blue);
    transform: scale(1.2);
}

.nav-dot.active {
    background: var(--apple-blue);
}

/* Fullscreen Modal */
.fullscreen-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: var(--text-primary); /* Dark for focus */
    z-index: 9999;
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
}

.fullscreen-modal.active {
    display: flex;
    opacity: 1;
}

.fullscreen-content {
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.fullscreen-image {
    max-width: 100%;
    max-height: 95vh;
    object-fit: contain;
    border-radius: 8px;
    transition: transform 0.3s ease;
}

.fullscreen-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    z-index: 10000;
}

.fullscreen-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.fullscreen-close svg {
    width: 20px;
    height: 20px;
    stroke: rgba(255, 255, 255, 0.9);
    stroke-width: 2;
}

/* Footer Styling - App-like fixed at bottom */
footer {
    background: rgba(245, 245, 247, 0.8);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-top: 0.5px solid var(--border-color);
    padding: 8px 16px 20px; /* Extra padding for iOS bottom edge */
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    flex-shrink: 0;
}

footer p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 11px;
    letter-spacing: 0.2px;
}

/* ====================================================
   NOTES MODAL — Mobile-First Design
   Primary target: xs (≤480px) / bottom sheet iOS style
   ==================================================== */

.notes-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: none;
    justify-content: center;
    align-items: center; /* Centered card style on ALL devices */
    z-index: 10000;
}

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

/* Handle bar removed for centered card style */
.notes-modal-content::before {
    display: none;
}

.notes-modal-content {
    background: var(--bg-secondary, #fff);
    border-radius: 24px; /* Fully rounded card */
    width: 92%; /* Centered with side margins on mobile */
    max-width: 400px; /* Cap size on mobile */
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}

/* Desktop: centered dialog, capped width */
@media (min-width: 600px) {
    .notes-modal-content {
        width: 520px;
        max-width: 95vw;
        max-height: fit-content;
        border-radius: 28px;
        box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
    }
}

/* ---- Header ---- */
.notes-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 14px 10px;
    border-bottom: 0.5px solid var(--divider-color, rgba(0,0,0,0.1));
    gap: 10px;
    flex-shrink: 0;
}

.notes-modal-title-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

/* Order: [Title] [lang-toggle] ... [close] */
.notes-modal-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    flex-shrink: 0;
}

.lang-toggle {
    display: flex;
    background: var(--system-gray-5, rgba(0,0,0,0.06));
    border-radius: 7px;
    padding: 2px;
    flex-shrink: 0;
}

.lang-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 5px;
    transition: all 0.15s;
    letter-spacing: -0.1px;
}

.lang-btn.active {
    background: var(--card-bg, #fff);
    color: var(--apple-blue); /* System blue for active language */
    box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

.notes-modal-close {
    background: var(--system-gray-5, rgba(0,0,0,0.06));
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s;
    flex-shrink: 0;
}

.notes-modal-close:hover {
    background: var(--system-gray-4, rgba(0,0,0,0.12));
}

.notes-modal-close:active {
    background: var(--system-gray-3, rgba(0,0,0,0.18));
}

.notes-modal-close svg {
    width: 14px;
    height: 14px;
    stroke: var(--text-secondary);
    stroke-width: 2.5;
}

/* ---- Body ---- */
.notes-modal-body {
    padding: 16px 20px 24px;
    overflow-y: auto; /* Scrollable si le contenu dépasse max-height 85vh (écrans courts) — cartes du bas toujours cliquables */
    flex-shrink: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

/* Small screens: reduce horizontal padding */
@media (max-width: 420px) {
    .notes-modal-body {
        padding: 12px 14px 20px;
    }
}

.notes-modal-body::-webkit-scrollbar {
    display: none;
}

/* ---- Grid — 4 columns icon grid ---- */
.notes-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 1fr; /* All rows have same height */
    gap: 12px;
}

/* Small screens: tighten the grid */
@media (max-width: 420px) {
    .notes-grid {
        gap: 8px;
    }
}

@media (max-width: 360px) {
    .notes-grid {
        grid-template-columns: repeat(3, 1fr); /* 3 columns for very narrow screens */
        gap: 10px;
    }
}

/* ---- Component Card ---- */
/* --- Notes combinées (mode +) --- */
.combine-card {
    border-style: dashed;
}
.combine-card .combine-plus {
    font-size: 34px;
    font-weight: 300;
    line-height: 1;
    color: var(--text-color, #1d1d1f);
    transition: color 0.2s ease;
}
.combine-card .notes-card-title {
    font-size: 13px;
}
.combine-card:hover { transform: translateY(-2px); }
.combine-card.active {
    background: #0071e3;
    border-color: #0071e3;
}
.combine-card.active .combine-plus,
.combine-card.active .notes-card-title {
    color: #fff;
}
.combine-bar {
    display: none;
    width: 100%;
    margin: 0 0 12px;
    padding: 10px 14px;
    border-radius: 14px;
    background: var(--card-bg);
    border: 1px solid var(--border-color, rgba(0,0,0,0.10));
    font-size: 14px;
    color: var(--text-color, #1d1d1f);
    text-align: center;
}
.combine-bar.visible { display: block; }
.combine-bar .combine-count { font-weight: 600; }
.notes-card.combine-selected {
    border: 2px solid #0071e3;
    box-shadow: 0 0 0 4px rgba(0,113,227,0.15);
}
.combine-actions {
    display: none;
    width: 100%;
    margin-top: 4px;
}
.combine-actions.visible { display: flex; gap: 10px; }
.combine-btn {
    flex: 1;
    padding: 12px 18px;
    border-radius: 14px;
    border: none;
    background: #0071e3;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.combine-btn.secondary {
    background: var(--card-bg);
    color: var(--text-color, #1d1d1f);
    border: 1px solid var(--border-color, rgba(0,0,0,0.12));
}

.notes-card {
    background: var(--card-bg);
    border: 0.5px solid var(--border-color, rgba(0,0,0,0.08));
    border-radius: 18px;
    /* Aspect ratio removed to allow uniform grid height */
    min-height: 114px; 
    height: 100%;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.12, 0.4, 0.29, 1.46);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 6px 10px;
    gap: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    -webkit-tap-highlight-color: transparent;
    min-width: 0; /* Force shrinkage */
    width: 100%;
}

@media (max-width: 420px) {
    .notes-card {
        min-height: 100px;
    }
}

.notes-card:hover {
    transform: scale(1.04);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    border-color: var(--apple-blue);
}

.notes-card:active {
    transform: scale(0.94);
    transition: transform 0.08s ease;
}

.notes-card-icon {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: 12px;
}

/* Small screens: slightly smaller icons to fit columns */
@media (max-width: 420px) {
    .notes-card-icon {
        width: 40px;
        height: 40px;
    }
}

@media (max-width: 360px) {
    .notes-card-icon {
        width: 36px;
        height: 36px;
    }
}

.notes-card-title {
    font-size: 11px;
    text-align: center;
    color: var(--text-primary);
    font-weight: 500;
    line-height: 1.1;
    letter-spacing: -0.1px;
    width: 100%;
    /* Extra safety for long labels on mobile */
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Hidden elements */
.notes-card-icon-wrapper,
.notes-card-badge,
.notes-card-text {
    display: none;
}

/* ---- Disclaimer ---- */
.notes-disclaimer {
    margin-top: 10px;
    padding: 8px 12px;
    background: var(--system-gray-6, rgba(0,0,0,0.03));
    border-radius: 10px;
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.4;
    text-align: left;
    border: 0.5px solid var(--border-color, rgba(0,0,0,0.06));
}

/* ---- Legacy warning elements (keep for safety) ---- */
.notes-warning {
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
    padding: 10px 12px;
    background: var(--system-gray-6);
    border-radius: 10px;
    border: 0.5px solid var(--border-color);
}

.notes-warning p { margin-bottom: 6px; }
.notes-warning p:last-child { margin-bottom: 0; }

/* ====================================================
   COPY TOAST — iOS pill notification
   ==================================================== */
.copy-toast {
    position: fixed;
    bottom: 36px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--text-primary);
    color: white;
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 13px;
    font-weight: 500;
    z-index: 10001;
    opacity: 0;
    transition: all 0.35s cubic-bezier(0.19, 1, 0.22, 1);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.2px;
    pointer-events: none;
}

.copy-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.copy-toast-icon {
    width: 15px;
    height: 15px;
    color: var(--apple-green);
}

/* ---- Scrollbar hide (hamburger menu) ---- */
.hamburger-menu::-webkit-scrollbar {
    display: none;
}

.hamburger-menu {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Header Dropdown */
.header-dropdown {
    position: relative;
    display: inline-block;
    cursor: pointer;
}

.header-dropdown-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 16px;
    height: 44px;
    min-width: 180px;
    border-radius: 22px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--apple-blue);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(0, 122, 255, 0.35);
    font-weight: 600;
    font-size: 14px;
    letter-spacing: -0.2px;
    overflow: hidden;
    white-space: nowrap;
    cursor: pointer;
}

.header-dropdown-title:hover {
    background-color: var(--apple-blue-dark);
    box-shadow: 0 6px 20px rgba(0, 122, 255, 0.45);
    transform: translateY(-1px);
}

.header-dropdown-title:active {
    transform: scale(0.96);
}

.header-dropdown-arrow {
    font-size: 10px;
    transition: transform 0.2s;
    color: var(--text-secondary);
}

.header-dropdown.active .header-dropdown-arrow {
    transform: rotate(180deg);
}

.header-dropdown-content {
    position: absolute;
    top: 100%;
    right: 0;
    left: auto;
    transform: scale(0.95);
    transform-origin: top right;
    margin-top: 12px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    width: 100%;
    min-width: 240px; /* Standardized width to prevent model name cropping */
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
    border-radius: 16px;
    padding: 8px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);
    z-index: 1000;
    border: 0.5px solid var(--border-color);
    max-height: 80vh;
    overflow-y: auto;
}

.header-dropdown.active .header-dropdown-content {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

.header-dropdown-item {
    display: block;
    padding: 10px 16px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 400;
    transition: all 0.2s ease;
    text-align: right;
    white-space: nowrap;
    border-radius: 10px;
    margin-bottom: 2px;
    letter-spacing: -0.1px;
}

.header-dropdown-item:hover {
    background-color: var(--apple-blue);
    color: white;
    transform: translateX(4px);
}

.header-dropdown-item.current {
    color: white;
    font-weight: 500;
    background-color: var(--apple-blue);
}

/* Submenu Styles */
.dropdown-item-wrapper {
    display: flex;
    flex-direction: column;
}

.dropdown-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    cursor: pointer;
    transition: background-color 0.15s;
    border-radius: 8px;
    margin-bottom: 2px;
}

.dropdown-item-header:hover {
    background-color: var(--system-gray-6);
}

.dropdown-item-header.current {
    background-color: rgba(0, 122, 255, 0.1);
}

.dropdown-item-header.current .header-dropdown-item-link {
    color: var(--apple-blue);
    font-weight: 600;
}

.header-dropdown-item-link {
    display: block;
    padding: 12px 14px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    letter-spacing: -0.2px;
    border-radius: 8px;
    margin-bottom: 4px;
    transition: background-color 0.15s, color 0.15s;
    text-align: right;
}

.header-dropdown-item-link:hover {
    background-color: var(--system-gray-6);
}

.header-dropdown-group {
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 12px 12px 6px;
    margin-top: 4px;
}

.submenu-toggle {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px;
    transition: transform 0.2s;
}

.submenu-toggle.rotated {
    transform: rotate(180deg);
}

.submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background-color: transparent;
    padding-left: 12px;
}

.submenu.open {
    max-height: 500px; /* Adjust as needed */
    transition: max-height 0.4s cubic-bezier(0.19, 1, 0.22, 1);
}

.submenu-item {
    display: block;
    padding: 8px 12px 8px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    transition: color 0.15s, background-color 0.15s;
    border-left: 1.5px solid var(--divider-color);
    border-radius: 0 6px 6px 0;
    margin-bottom: 2px;
}

.submenu-item:hover {
    color: var(--apple-blue);
    background-color: var(--system-gray-6);
    border-left-color: var(--apple-blue);
}

/* Hamburger Menu Submenu Styles */
.hamburger-menu .submenu {
    margin: 0;
    padding-left: 0;
}

.hamburger-menu .dropdown-item-wrapper {
    margin: 0;
    background: transparent;
    border-radius: 0;
    overflow: hidden;
    border-bottom: 0.5px solid var(--divider-color);
}

.hamburger-menu .dropdown-item-wrapper:last-child {
    border-bottom: none;
}

.hamburger-menu .dropdown-item-header {
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 0;
    margin-bottom: 0;
}

.hamburger-menu .submenu-item {
    padding-left: 32px;
    border-left: none;
    border-radius: 0;
    margin-bottom: 0;
    border-bottom: 0.5px solid var(--divider-color);
    background: var(--system-gray-6);
}

.hamburger-menu .submenu-item:last-child {
    border-bottom: none;
}

.component-grid {
    display: grid; /* Visible by default — JS hides when entering diagram/guide view */
    grid-template-columns: repeat(4, 1fr);
    gap: 32px 16px;
    padding: 40px 24px 32px;
    margin: 0 auto 60px;
    width: 100%;
    max-width: 1100px;
    overflow: visible !important;
    align-items: start;
    justify-items: center;
}

/* When entering diagram or guide view, hide the grid */
body.view-active .component-grid {
    display: none;
}

.component-card {
    text-decoration: none;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-align: center;
    border: none;
    overflow: visible;
    cursor: pointer;
    background: transparent;
    border-radius: 0;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    animation: iconPop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
    width: 100%;
    max-width: 100px;
}

.component-card:hover {
    transform: translateY(-4px) scale(1.05);
}

.component-card:active {
    transform: scale(0.92);
    transition: all 0.1s ease;
}

.component-card .component-icon-svg {
    width: 76px;
    height: 76px;
    border-radius: 22.5%; /* Perfect iOS Squircle */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12), 
                0 1px 2px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.3s ease;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    object-fit: cover;
}

.component-card:hover .component-icon-svg {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18), 
                0 2px 4px rgba(0, 0, 0, 0.12);
}

.component-card-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-top: 10px;
    letter-spacing: -0.2px;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    width: 100%;
}

.component-card .component-icon-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: auto;
    flex-shrink: 0;
}

.component-card .component-card-text {
    padding: 0;
    width: 100%;
}

.component-grid .component-metadata {
    display: none;
}








@media (max-width: 1024px) {
    .component-grid {
        padding-left: 24px;
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
        align-items: start;
        justify-items: center;
    }

    /* Resolve superposition by saving horizontal space */
    .global-floating-nav a {
        font-size: 0 !important;
        gap: 0 !important;
        padding: 6px !important;
    }

    .global-title h1 {
        display: none !important;
    }

    .header-dropdown-prefix {
        display: none !important;
    }

    .header-dropdown-title {
        min-width: 130px !important; /* Adjusted for tablet spacing */
        padding: 0 16px !important;
    }

    .header-dropdown-content {
        min-width: 240px !important;
        right: 0 !important;
        left: auto !important;
    }

    .header-dropdown-item {
        text-align: left !important;
        padding: 12px 16px !important;
    }
}

@media (max-width: 650px) {
    .component-grid {
        /* Switch to 3 columns: iOS SpringBoard with longer labels needs more width */
        grid-template-columns: repeat(3, 1fr) !important;
        padding: 12px 8px;
        gap: 12px 8px; /* Tighter gap to avoid bottom cropping */
        overflow: visible !important;
        align-items: start;
        justify-items: center;
    }

    .component-card.card-large {
        grid-column: span 1;
    }

    .component-card {
        height: auto !important;
        min-height: unset !important;
        max-height: unset !important;
    }
    .component-card-text {
        padding: 4px 2px !important;
        flex-grow: 0 !important;
        overflow: visible !important;
    }
    .component-metadata {
        display: none !important;
    }
    .component-card-title {
        font-size: 11px;
        font-weight: 500;
        text-align: center;
        line-height: 1.2;
        max-width: 100%;
        margin: 0 auto;
        white-space: normal;
        overflow: visible !important;
    }
}



/* Header Dropdown Mobile Adjustments (Moved to consolidated media query at end) */













.component-card-text {
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    flex-grow: 0;
    width: 100%;
}

@keyframes iconPop {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}




.component-card-text {
    padding: 10px 8px; /* Balanced for SpringBoard */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    flex-grow: 0; /* Icon is the reference */
    width: 100%;
}


.component-card-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex-grow: 1;
}

@keyframes cardAppear {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Staggered animation for grid items */
.component-card:nth-child(1) { animation-delay: 0.05s; }
.component-card:nth-child(2) { animation-delay: 0.1s; }
.component-card:nth-child(3) { animation-delay: 0.15s; }
.component-card:nth-child(4) { animation-delay: 0.2s; }
.component-card:nth-child(5) { animation-delay: 0.25s; }
.component-card:nth-child(6) { animation-delay: 0.3s; }
.component-card:nth-child(7) { animation-delay: 0.35s; }
.component-card:nth-child(8) { animation-delay: 0.4s; }
.component-card:nth-child(9) { animation-delay: 0.45s; }
.component-card:nth-child(10) { animation-delay: 0.5s; }
.component-card:nth-child(11) { animation-delay: 0.55s; }
.component-card:nth-child(12) { animation-delay: 0.6s; }

.component-card:hover {
    transform: translateY(-2px);
    background: transparent;
    box-shadow: none;
    border-color: transparent;
}

.component-card:active {
    transform: scale(0.98);
    background-color: var(--system-gray-6);
}

.component-card-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-top: 8px;
    letter-spacing: -0.2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}



.component-metadata {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.component-metadata-spec {
    font-weight: 500;
    color: var(--apple-blue);
    margin-top: 2px;
}

.component-card-icon {
    font-size: 20px;
    color: var(--apple-blue);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 0 16px;
    border-left: 0.5px solid var(--divider-color);
}

.component-icon-svg {
    width: 70px;
    height: 70px;
    object-fit: cover;
    flex-shrink: 0;
    border-left: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 0 12px 12px 0;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .component-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 16px 8px;
        padding: 16px 10px;
    }

    .component-card {
        min-height: auto;
        max-height: none;
        border-radius: 0;
        max-width: 76px;
    }

    .component-card:active {
        transform: scale(0.92);
        box-shadow: none;
    }

    .component-card-title {
        font-size: 11px;
        padding: 0;
        margin-top: 6px;
    }

    .component-card .component-icon-svg {
        width: 64px;
        height: 64px;
        border-radius: 22.5%;
    }

    .header-dropdown-title {
        height: 36px;
        min-width: 130px;
        padding: 0 16px;
        font-size: 12px;
        border-radius: 18px;
    }

    .header-dropdown-arrow {
        font-size: 8px;
        margin-left: 8px;
    }
}




/* Responsive Adjustments */
@media (max-width: 768px) {
    .title {
        font-size: 18px;
        margin: 35px auto 0 !important;
        padding: 0 16px !important;
    }

    /* SpringBoard overrides the legacy grid here */

    /* Stack vertically on mobile */
    .diagram-container {
        display: flex;
        flex-direction: column;
        gap: 12px;
        align-items: center;
        max-width: 100%;
        width: 100% !important;
    }

    .image-wrapper {
        max-width: 100%;
        padding: 0;
        border-radius: 12px;
    }

    .diagram-image {
        /* App-like: locked to 8-button overlay bar height */
        max-height: 420px;
    }

    .guide-image {
        /* Adjusted for full text visibility and locked height to prevent layout jumps */
        height: 40vh;
    }


    .overlay-button {
        width: 44px; /* iOS Minimum Touch Target */
        height: 44px;
        border-radius: 22px; /* Pull pill shape */
    }

    main {
        padding: 0 12px 8px !important;
    }

    .hamburger-menu {
        width: 85%;
        max-width: 320px;
    }
}


/* Mobile Breakpoint Overrides (Moved to consolidated media query at end) */


/* Safe Area Insets for iPhone notch */
@supports (padding: max(0px)) {
    header {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }

    .hamburger-menu {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Plateau Modal */
.plateau-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: var(--text-primary); /* Dark focus backdrop */
    z-index: 9999;
    display: none;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
}

.plateau-modal.active {
    display: flex;
    opacity: 1;
}

.plateau-content {
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.plateau-image {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 16px;
    background: var(--page-bg);
    padding: 16px;
    box-shadow: 0 40px 80px rgba(0, 0, 0, 0.5); /* Deep shadow for focus */
}

.plateau-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    z-index: 10000;
}

.plateau-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.plateau-close svg {
    width: 20px;
    height: 20px;
    stroke: rgba(255, 255, 255, 0.9);
    stroke-width: 2;
}

.icon-custom {
    display: none;
    padding: 0;
    border: none;
    background: transparent;
    overflow: hidden;
}

.icon-custom.has-plateau {
    display: flex;
    width: 36px;
    height: 36px;
}

.plateau-thumb {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 50%;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Screw Tooltip (hover) */
.screw-tooltip {
    position: absolute;
    bottom: calc(100% + 10px);
    right: 0;
    background: var(--card-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-radius: 14px;
    padding: 12px;
    min-width: 220px;
    max-width: 280px;
    box-shadow: var(--shadow-md);
    border: 0.5px solid var(--border-color);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: all 0.2s cubic-bezier(0.19, 1, 0.22, 1);
    pointer-events: none;
}

.screw-tooltip.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.screw-tooltip-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 0.5px solid var(--divider-color);
    letter-spacing: -0.2px;
}

.screw-tooltip-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 380px;
    overflow-y: auto;
}

.screw-tooltip-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.15s;
}

.screw-tooltip-item:hover {
    background: var(--system-gray-6);
}

.screw-tooltip-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 0.5px solid var(--border-color);
}

.screw-tooltip-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.screw-tooltip-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.screw-tooltip-part {
    font-size: 11px;
    color: var(--apple-blue);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    letter-spacing: -0.3px;
}

.screw-empty {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 8px 0;
    text-align: center;
}

/* Torx button wrapper for tooltip positioning */
.torx-wrapper {
    position: relative;
}

/* Tools button wrapper with submenu */
.tools-wrapper {
    position: relative;
}

.tools-wrapper > .overlay-button {
    width: 36px;
    height: 36px;
}

.tools-wrapper .overlay-button img {
    width: 18px;
    height: 18px;
    object-fit: contain;
}

.tools-row {
    display: none;
    flex-direction: column;
    gap: 8px;
    opacity: 0;
    overflow: hidden;
    transform: translateY(-8px);
    transition: opacity 0.25s ease-out, transform 0.25s ease-out;
    pointer-events: none;
}

.tools-row.active {
    display: flex;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
    overflow: visible;
    margin-top: 8px;
}

/* Fade transition for all overlay buttons - DISABLED */
.overlay-buttons>* {
    transition: none;
}

/* Hide all other buttons when security screws is active */
.overlay-buttons.security-mode>*:not(#securityScrewsRow) {
    opacity: 0 !important;
    transform: scale(0.9) !important;
    pointer-events: none !important;
    position: absolute !important;
    visibility: hidden !important;
}

.overlay-buttons.security-mode #securityScrewsRow {
    margin-top: 0;
}

/* Hide all other buttons when tools is active */
.overlay-buttons.tools-mode>*:not(#toolsRow) {
    opacity: 0 !important;
    transform: scale(0.9) !important;
    pointer-events: none !important;
    position: absolute !important;
    visibility: hidden !important;
}

.overlay-buttons.tools-mode #toolsRow {
    margin-top: 0;
}

/* Hide all other buttons when screws is active */
.overlay-buttons.screws-mode>*:not(#screwTypesRow) {
    opacity: 0 !important;
    transform: scale(0.9) !important;
    pointer-events: none !important;
    position: absolute !important;
    visibility: hidden !important;
}

.overlay-buttons.screws-mode #screwTypesRow {
    margin-top: 0;
}

/* Hide all other buttons when screwdrivers is active */
.overlay-buttons.screwdrivers-mode>*:not(#screwdriverTypesRow) {
    opacity: 0 !important;
    transform: scale(0.9) !important;
    pointer-events: none !important;
    position: absolute !important;
    visibility: hidden !important;
}

.overlay-buttons.screwdrivers-mode #screwdriverTypesRow {
    margin-top: 0;
}

/* Row animations */
#securityScrewsRow .overlay-button,
#toolsRow .overlay-button,
#screwTypesRow .overlay-button,
#screwdriverTypesRow .overlay-button {
    transition: none;
}

#securityScrewsRow.active .overlay-button,
#toolsRow.active .overlay-button,
#screwTypesRow.active .overlay-button,
#screwdriverTypesRow.active .overlay-button {
    animation: none;
}

#securityScrewsRow.active .overlay-button:nth-child(n),
#toolsRow.active .overlay-button:nth-child(n),
#screwTypesRow.active .overlay-button:nth-child(n),
#screwdriverTypesRow.active .overlay-button:nth-child(n) {
    animation-delay: 0.1s; /* Simplified animation sequence for Apple dashboard feel */
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Back button styling */
.back-btn {
    background: var(--text-primary) !important;
    color: white !important;
    border: none !important;
}

.back-btn:active {
    background: var(--text-secondary) !important;
    transform: scale(0.96) !important;
}

.back-btn svg {
    width: 20px;
    height: 20px;
    stroke: white;
    stroke-width: 2;
    fill: none;
}

/* XS breakpoint: All tool rows display horizontally */
@media (max-width: 768px) {
    #securityScrewsRow.active,
    #toolsRow.active,
    #screwTypesRow.active,
    #screwdriverTypesRow.active,
    #repairRow.active {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        justify-content: center !important;
    }

    /* Consistent button sizing for all buttons at XS breakpoint */
    .overlay-button,
    .back-btn,
    .repair-btn {
        width: 44px !important;
        height: 44px !important;
        border-radius: 22px !important;
    }

    .back-btn svg {
        width: 20px;
        height: 20px;
    }

    /* Flip tooltips above on mobile */
    .tool-btn-label {
        top: auto !important;
        bottom: calc(100% + 8px) !important;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
    }
}

.tools-row .overlay-button {
    position: relative;
}

.tools-row .overlay-button img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

/* Tool Buttons Tooltip Styling */
.tool-btn-label {
    position: absolute;
    right: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--card-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    padding: 6px 10px;
    border-radius: 8px;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
    border: 0.5px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: normal;
    opacity: 0 !important;
    visibility: hidden !important;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none !important;
    z-index: 100;
    letter-spacing: -0.2px;
}

.tools-row .overlay-button:hover .tool-btn-label,
.torx-wrapper:hover .tool-btn-label,
.tools-wrapper:hover .tool-btn-label,
.overlay-buttons>.overlay-button:hover .tool-btn-label,
.toggle-container .overlay-button:hover .tool-btn-label,
.torx-wrapper .overlay-button:hover .tool-btn-label,
.tools-wrapper .overlay-button:hover .tool-btn-label {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Repair button labels visible on hover and positioned above */
#repairRow .repair-btn .tool-btn-label {
    top: auto !important;
    bottom: calc(100% + 8px) !important;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
}

#repairRow .repair-btn:hover .tool-btn-label {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Screw color buttons */
.screw-color-btn {
    position: relative;
}

.screw-color-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: block;
    border: 2px solid rgba(0, 0, 0, 0.1);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Mode Toggle & Repair Styles */

/* Repair Mode Isolation */
.overlay-buttons.repair-mode>*:not(#repairRow) {
    display: none !important;
}

.overlay-buttons.repair-mode #repairRow {
    display: flex !important;
}

.toggle-mode-btn {
    padding: 6px !important;
    justify-content: center !important;
}



.repair-toggle-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

#smart-repair-container {
    display: none;
    margin-top: 0;
}

.smart-repair-btn {
    width: 38px !important;
    height: 38px !important;
    padding: 0 !important;
    justify-content: center !important;
    min-width: 38px;
    border-radius: 50% !important;
}

.smart-repair-btn .repair-toggle-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

/* Update exclusion list to keep smart repair and default repair toggle visible as needed */
.overlay-buttons.repair-mode > *:not(#repairRow):not(#smart-repair-container):not(#repair-toggle-container):not(.icon-prev):not(.icon-next):not(.icon-fullscreen):not(.icon-rotate) {
    display: none !important;
}

.repair-btn {
    width: 40px;
    height: 40px;
    padding: 0 !important;
    justify-content: center !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
    overflow: visible !important;
    /* Allow label to overflow */
    border-radius: 8px;
    position: relative;
    /* Required for label positioning */
}

.repair-btn:hover {
    background: rgba(0, 0, 0, 0.05) !important;
    transform: scale(1.1);
}

.repair-icon {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
    border-radius: 8px;
}

/* Hide main buttons when repair mode is active */
.overlay-buttons.repair-mode>*:not(#repairRow):not(.icon-prev):not(.icon-next):not(.icon-fullscreen):not(.icon-rotate) {
    display: none !important;
}

.overlay-buttons.repair-mode #repairRow {
    margin-top: 0;
}

/* Repair row hidden by default, shown when repair mode is active */
#repairRow {
    display: none;
}

#repairRow.active {
    display: flex !important;
}

.prereq-container {
    position: absolute;
    bottom: 12px;
    top: auto;
    left: 50%;
    width: 90%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 2000;
    background: var(--card-bg);
    padding: 10px;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    max-width: 90vw;
    flex-wrap: wrap;
    justify-content: center;
    border: 0.5px solid var(--border-color);
}

.prereq-title {
    width: 100%;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

.prereq-message {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--system-gray-6);
    padding: 6px 12px;
    border-radius: 8px;
    border: 0.5px solid var(--border-color);
}

/* ========== VIEW TOGGLE (Diagram / Guide) ========== */
.view-toggle {
    position: relative;
    margin: 2px auto 16px;
    z-index: 100;
    display: none; /* Managed by JS */
    justify-content: center;
    transform: scale(0.9);
    transform-origin: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.85); /* Apple-style translucent background */
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-radius: 14px;
    padding: 4px;
    width: fit-content;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08); /* Soft shadow */
    border: 0.5px solid rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.view-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 5px 16px;
    border: none;
    border-radius: 8px;
    background: transparent;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
    letter-spacing: -0.3px;
}

.view-toggle-btn.active {
    background: white;
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1),
                0 2px 8px rgba(0, 0, 0, 0.06);
}

.view-toggle-btn svg {
    opacity: 0.6;
    transition: opacity 0.2s;
}

.view-toggle-btn.active svg {
    opacity: 1;
    stroke: var(--apple-blue);
}

/* ========== GUIDE CONTAINER ========== */
.guide-container {
    width: 780px; /* Wider layout for better desktop visibility */
    max-width: 100%;
    margin: 0 auto;
    align-self: center; /* Prevent flex-column stretching */
    padding: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: visible;
    flex-shrink: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Section Tabs (Retrait / Réassemblage) */
.guide-section-tabs {
    display: flex;
    justify-content: center;
    gap: 2px;
    margin: 0; /* Removed auto-margin and bottom-margin for header integration */
    background: rgba(118, 118, 128, 0.12);
    border-radius: 9px;
    padding: 2px;
    width: fit-content;
    z-index: 10;
}

.guide-section-tab {
    padding: 4px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    gap: 4px;
    line-height: 1;
}

.guide-section-tab svg {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
}

.guide-tab-label {
    font-size: 12px;
    line-height: 1;
}

.guide-section-tab.active {
    background: white;
    color: var(--apple-blue);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1),
                0 2px 8px rgba(0, 0, 0, 0.06);
}

/* Carousel Layout — relative container for pinned chevrons */
.guide-carousel {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: flex-start; /* Flow from top */
    justify-content: center;
    gap: 12px;
    padding: 0 52px; /* Space for absolutely-positioned chevrons */
}

/* Navigation Chevrons — pinned at fixed vertical position */
.guide-nav {
    position: absolute;
    top: 216px; /* Pinned to the center of the 320px technical diagram (48px header + 8px margin + 160px half-image) */
    z-index: 10;
    width: 40px;
    height: 40px;
    border: 0.5px solid var(--border-color);
    border-radius: 50%;
    background: var(--card-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.19, 1, 0.22, 1);
    box-shadow: var(--shadow-sm);
    -webkit-tap-highlight-color: transparent;
}

.guide-prev {
    left: 0;
}

.guide-next {
    right: 0;
}

.guide-nav:hover {
    background: white;
    transform: scale(1.05); /* Pinned to 216px center */
    box-shadow: var(--shadow-md);
}

.guide-nav:active {
    transform: scale(0.96); /* Pinned to 216px center */
    background: var(--system-gray-6);
}

.guide-nav svg {
    width: 20px;
    height: 20px;
    stroke: var(--text-primary);
    fill: none;
    stroke-width: 1.5;
}

/* Slide Content */
.guide-slide {
    width: 100%;
    min-width: 0;
    background: white; /* Clean diagnostic white background */
    border-radius: 16px;
    border: 0.5px solid var(--border-color);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.guide-step-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr; /* 3-column grid for perfect centering */
    align-items: center;
    padding: 12px 24px; /* Slightly more compact vertical padding */
    flex-shrink: 0;
    gap: 12px;
    background: var(--card-bg);
    border-bottom: 0.5px solid var(--divider-color);
}

.guide-step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 24px;
    padding: 0 6px;
    background: var(--apple-blue);
    color: white;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    letter-spacing: -0.2px;
    width: fit-content;
    min-width: fit-content;
}

/* Guide Image */
.guide-image-wrapper {
    margin-top: 8px; /* Added breathing room from headers */
    padding: 16px; /* Increased padding for more breathing room, avoiding the edge-to-edge look */
    height: 340px; /* Taller fixed height for better desktop visibility */
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0; /* Don't shrink technical diagrams */
    background: white;
    overflow: hidden;
}

.guide-image {
    max-width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
    transition: transform 0.3s ease;
}

/* Guide Text Content */
.guide-text-content {
    padding: 8px 16px; /* Restored padding for flow layout */
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Stack text below image */
    overflow-y: visible; /* Let text flow entirely */
    overflow-x: hidden;
    min-height: 120px; /* Force minimum height to avoid layout shift */
    max-height: none; /* Let container expand naturally to the text */
    background: white;
    position: relative;
    flex: 1 1 auto;
}

.guide-text {
    font-size: 15px;
    line-height: 1.4;
    color: var(--text-primary);
    margin: 0 0 8px; /* Shaved margin from 12px to 8px */
    letter-spacing: -0.2px;
    font-weight: 400;
    white-space: pre-wrap; /* Preserve formatting for split text */
}

/* Pagination Dots for Sub-steps */
.guide-step-pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 10px !important;
    margin-top: 0 !important;
}

.pagination-dot {
    width: 6.5px;
    height: 6.5px;
    border-radius: 50%;
    background: #E5E5EA; /* Light gray */
    transition: all 0.2s ease;
    cursor: pointer;
    border: none;
    padding: 0;
}

.pagination-dot.active {
    background: var(--apple-blue) !important; /* Blue dot */
}

.guide-step-pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 2px; /* Tightened from 4px */
    margin-bottom: 4px; /* Shaved margin for bottom-aligned layout */
    padding-bottom: 2px; /* Ensure space at bottom */
}

.guide-prereq-badge {
    background: #FF9500;
    color: white;
    padding: 0 10px;
    height: 24px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    transition: transform 0.2s ease, background 0.2s ease;
}

.guide-prereq-badge:hover {
    background: #E68600;
    transform: scale(1.05);
}

.step-dot {
    width: 8px; /* Increased from 6px */
    height: 8px; /* Increased from 6px */
    border-radius: 50%;
    background-color: var(--system-gray-4);
    transition: all 0.2s ease;
    border: 1px solid rgba(0,0,0,0.05); /* Slight border for visibility */
}

.step-dot.active {
    background-color: var(--apple-blue);
    transform: scale(1.1); /* Subtle highlight */
}

.guide-substeps {
    margin: 0;
    padding: 0 0 0 20px;
    list-style: disc;
}

.guide-substeps li {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    margin-bottom: 10px;
    list-style: none;
    position: relative;
    padding-left: 14px;
}

.guide-substeps li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 7px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--apple-blue);
}

.substep-link {
    display: inline-block;
    margin-top: 2px;
    color: var(--apple-blue);
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
    padding: 2px 8px;
    border-radius: 6px;
    background: rgba(0, 122, 255, 0.08);
    transition: all 0.2s ease;
}

.substep-link:hover {
    background: rgba(0, 122, 255, 0.15);
    text-decoration: none;
}

.substep-link:active {
    transform: scale(0.97);
}

.guide-cross-link {
    display: inline-flex;
    align-items: center;
    color: #0071e3;
    text-decoration: none;
    font-weight: 500;
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 8px;
    background: rgba(0, 122, 255, 0.08);
    transition: all 0.2s ease;
    margin-top: 4px;
}

.guide-cross-link:hover {
    background: rgba(0, 122, 255, 0.15);
    text-decoration: none;
}

.guide-cross-link:active {
    transform: scale(0.97);
}

.guide-warning {
    font-size: 13px;
    line-height: 1.4;
    color: #FF9500;
    background: rgba(255, 149, 0, 0.08);
    padding: 8px 12px;
    border-radius: 8px;
    border-left: 3px solid #FF9500;
    margin-top: 4px;
    margin-bottom: 8px;
}

/* Prerequisite Warning Modal */
.prerequisite-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.prerequisite-modal.active {
    opacity: 1;
    visibility: visible;
}

.prerequisite-modal-content {
    background: var(--card-bg);
    width: 90%;
    max-width: 400px;
    border-radius: 16px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.19, 1, 0.22, 1);
    border: 0.5px solid var(--border-color);
}

.prerequisite-modal.active .prerequisite-modal-content {
    transform: scale(1);
}

.prerequisite-icon {
    width: 56px;
    height: 56px;
    margin-bottom: 16px;
    background: var(--apple-red);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.prerequisite-icon svg {
    width: 28px;
    height: 28px;
    stroke: currentColor;
    stroke-width: 2.5;
    fill: none;
}

.prerequisite-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    letter-spacing: -0.4px;
}

.prerequisite-text {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 24px;
}

.prerequisite-buttons {
    display: flex;
    gap: 12px;
    width: 100%;
}

.prerequisite-btn {
    flex: 1;
    padding: 12px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    letter-spacing: -0.2px;
}

.prerequisite-btn-cancel {
    background: var(--system-gray-6);
    color: var(--apple-blue);
}

.prerequisite-btn-cancel:active {
    background: var(--system-gray-5);
}

.prerequisite-btn-proceed {
    background: var(--apple-blue);
    color: white;
}

/* Adjust layout on small screens */
@media (max-width: 600px) {
    body.view-active {
        height: 100vh !important;
        height: 100dvh !important;
        overflow: hidden !important;
    }

    body.view-active main {
        height: auto !important;
        flex: 1 !important;
        min-height: 0 !important;
        overflow: hidden !important;
        padding-bottom: 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    header {
        height: 0 !important;
        background: transparent !important;
        border: none !important;
    }

    .header-center {
        display: none !important;
    }

    .header-left, .header-right {
        top: 8px !important;
        transform: scale(0.7);
        z-index: 10001 !important;
    }

    .header-left {
        left: 10px !important;
    }

    .header-right {
        right: 10px !important;
    }

    .global-floating-nav {
        top: 8px !important;
        padding: 4px 8px !important;
        transform: translateX(-50%) scale(0.8) !important;
    }

    main {
        padding: 0 10px 10px !important; /* Standardize top padding to 0 */
    }

    .title {
        font-size: 16px !important;
        margin: 35px auto 4px !important;
        padding: 0 !important;
    }
    
    .view-toggle {
        margin: 4px auto 12px !important; /* Adjusted bottom margin for mobile */
        transform: scale(0.85) !important;
    }

    .image-title {
        display: block !important;
        font-size: 13px !important;
        margin: 2px 0 6px !important; /* Removed 'auto' to prevent flex siblings from being pushed to screen edges */
        text-align: center !important;
        color: var(--text-secondary);
    }
    
    .desktop-spacer {
        display: none !important;
    }
    
    .diagram-container {
        display: flex !important;
        flex-direction: column !important;
        flex: 1 !important;
        height: auto !important;
        max-height: none !important;
        overflow: hidden !important;
        gap: 4px !important;
        width: fit-content !important;
        max-width: 94% !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }
    
    .image-wrapper {
        order: 0 !important;
        position: relative !important;
        flex: 1 !important;
        min-height: 0 !important;
        width: fit-content !important;
        max-width: 100% !important;
        margin: 0 auto !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    .nav-indicators {
        order: 1 !important;
        margin: 10px auto 5px !important;
    }

    .image-wrapper .overlay-buttons {
        order: 2 !important;
    }

    .diagram-image {
        width: auto !important;
        max-width: 100% !important;
        flex: 1 !important;
        min-height: 0 !important;
        object-fit: contain !important;
        /* Let Flexbox gracefully shrink the image based on exact available space */
        max-height: none !important;
    }

    .overlay-button {
        width: 32px !important;
        height: 32px !important;
    }
    
    .overlay-button svg {
        width: 16px !important;
        height: 16px !important;
    }

    .guide-container {
        width: 100%;
        max-width: 100%;
        padding: 0 8px;
    }
    
    .guide-carousel {
        gap: 6px;
        padding: 0 40px; /* Smaller padding on mobile */
    }
    
    .guide-nav {
        width: 32px;
        height: 32px;
        top: 160px; /* Aligned with smaller 200px image wrapper */
    }
    
    .guide-nav svg {
        width: 16px;
        height: 16px;
    }
    
    .guide-step-header {
        padding: 10px 12px 6px;
    }
    
    .guide-image-wrapper {
        padding: 8px 12px;
        height: 200px; /* Smaller fixed height on mobile */
    }

    .guide-text-content {
        padding: 10px 12px 14px;
    }
}

/* Guide Source Link — badge style, glass green */
.guide-source-link {
    justify-self: end;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 24px; /* Matches step badge perfectly */
    padding: 0 10px;
    gap: 5px;
    background: rgba(52, 199, 89, 0.85);
    color: white;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    letter-spacing: -0.2px;
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.guide-source-link:hover {
    background: rgba(52, 199, 89, 1);
    color: white;
    box-shadow: 0 2px 8px rgba(52, 199, 89, 0.3);
}

.guide-source-link .apple-logo {
    width: 12px;
    height: 16px;
    flex-shrink: 0;
}

.guide-source-link .external-icon {
    width: 11px;
    height: 11px;
    flex-shrink: 0;
    stroke: white;
    opacity: 0.9;
}

/* Tablet/Mobile Breakpoint: Reset buttons to bottom horizontal bar (Robust override) */
@media (max-width: 768px) {
    /* Header & Navigation */
    header {
        padding: 0 12px;
    }

    .header-dropdown-prefix {
        display: none;
    }

    .header-dropdown-title {
        min-width: 100px; /* Increased from 80px for better title label fit */
        padding: 0 12px;
    }

    .header-dropdown-content {
        min-width: 240px !important; /* Allow the menu to be wider than the toggle button */
        right: 0 !important;
        left: auto !important;
    }

    .header-dropdown-item {
        text-align: left !important; /* Standardize alignment for mobile lists */
        padding: 12px 16px !important;
    }

    .header-center {
        font-size: 16px;
    }

    .hamburger-menu {
        width: 100%; 
    }

    /* Main Content */
    main {
        padding: 0 8px 4px !important;
    }

    .title {
        font-size: 17px;
        margin: 35px auto 0 !important;
        padding: 0 8px !important;
    }

    .image-title {
        font-size: 14px;
    }

    /* Component Grid */
    .component-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 10px 4px; 
        padding: 10px 4px;
        align-items: start;
        justify-items: center;
    }

    .component-card-title {
        font-size: 10px;
    }

    .component-icon-svg {
        width: 72px !important;
        height: 72px !important;
        padding: 0 !important;
        border-radius: 16px !important;
    }

    /* Diagram Section (Reset to fit-content, no padding) */
    .diagram-container {
        width: fit-content;
        max-width: 94%;
        margin: 0 auto;
        gap: 8px;
    }

    .image-wrapper {
        width: fit-content;
        max-width: 100%;
        padding: 0 !important;
        border-radius: 8px;
        border: none;
        box-shadow: none;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
    }

    .nav-indicators {
        order: 1 !important;
        margin: 10px auto 5px !important;
    }

    .diagram-image {
        display: block;
        width: auto;
        max-width: 100%;
        border-radius: 4px;
        flex: 1 !important;
        min-height: 0 !important;
        object-fit: contain !important;
        max-height: none !important;
        box-shadow: none;
        order: 0 !important;
    }

    /* Overlay Buttons (Reset to bottom horizontal bar) */
    .image-wrapper .overlay-buttons {
        order: 2 !important;
        position: relative !important;
        top: auto !important;
        right: auto !important;
        left: auto !important;
        transform: none !important;
        flex-direction: row !important;
        flex-shrink: 0 !important; /* Critical to prevent image from cropping buttons */
        justify-content: center !important;
        gap: 6px !important;
        padding: 6px 16px !important;
        margin: 4px auto 10px !important;
        border-radius: 30px !important;
        background: rgba(255, 255, 255, 0.85) !important;
        box-shadow: var(--shadow-md) !important;
        width: fit-content !important;
        z-index: 100 !important;
        height: auto !important;
    }
}