/* Menu list inside settings modal (Result view) */
.menu-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

/* Re-measure / Continue Choice */
.choice-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.choice-card {
    display: block;
    width: 100%;
    text-align: left;
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.choice-card:hover { transform: translateY(-1px); }
.choice-card.active { border-color: var(--accent); background: var(--bg-tertiary); }

.choice-title { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.choice-sub { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.choice-desc { font-size: 12px; color: var(--text-secondary); margin-top: 6px; }

.menu-list .menu-item {
    font-size: 14px;
    padding: 10px 12px;
    text-align: center;
    color: var(--warning);
    width: auto;
    display: inline-block;
}
/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --border: #dee2e6;
    --shadow: rgba(0, 0, 0, 0.1);
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
}

body.dark-theme {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #3d3d3d;
    --text-primary: #f8f9fa;
    --text-secondary: #adb5bd;
    --accent: #60a5fa;
    --accent-hover: #3b82f6;
    --border: #495057;
    --shadow: rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 100vw;
    overflow-x: hidden;
}

/* Allow text selection in input fields */
input,
textarea,
.form-input,
.form-select {
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

/* Header */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px var(--shadow);
}

header h1 {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
    text-align: center;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.icon-btn:active {
    background: var(--bg-tertiary);
}

/* Main Content */
main {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
}

/* Buttons */
.btn {
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:active {
    background: var(--accent-hover);
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:active {
    background: var(--border);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-block {
    width: 100%;
    display: block;
}

/* Home Screen */
.home-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.fab-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: flex-end;
    z-index: 50;
}

/* Centered FAB variant for Home and Project pages */
.fab-container.fab-centered {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    align-items: center;
    bottom: 24px;
}

.fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px var(--shadow);
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.fab:active {
    transform: scale(0.95);
}

.fab.large {
    width: 72px;
    height: 72px;
}

/* Pulsating animation for primary stopwatch FAB */
.fab.pulse {
    animation: pulseFab 1.6s ease-in-out infinite;
}

@keyframes pulseFab {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .fab.pulse { animation: none; }
}

/* Folders Grid -> one per row list */
.folders-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.folder-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    border: 2px solid var(--border);
    transition: all 0.2s;
    position: relative;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    display: grid;
    grid-template-columns: 1fr; /* single column: name + count stack */
    gap: 12px;
    align-items: center;
    min-height: 88px;
}

.folder-card:active {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.folder-card h3 {
    font-size: 18px;
    margin: 0 0 6px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--folder-text, var(--text-primary));
    font-weight: 600;
}

.folder-count {
    color: var(--text-secondary);
    font-size: 14px;
}

.folder-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--danger);
    color: white;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.folder-delete:active {
    opacity: 1;
}

/* Stopwatch Screen */
.stopwatch-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 24px 0;
}

.time-display {
    font-size: 56px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: center;
    color: var(--accent);
    text-shadow: 0 2px 8px var(--shadow);
}

.current-lap {
    font-size: 28px; /* half of 56px */
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: center;
    color: var(--warning);
}

.controls {
    display: flex;
    gap: 16px;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.control-btn {
    min-width: 140px;
    padding: 20px 36px;
    font-size: 20px;
}

/* Stopwatch control buttons use themed border color */
.stopwatch-container .controls .control-btn {
    border: 2px solid var(--border);
}

/* New stacked layout for stopwatch controls */
.controls-stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 90%;
    max-width: 560px;
    align-items: center;
}

.controls-row {
    display: flex;
    gap: 16px;
    justify-content: center;
    width: 100%;
}

.btn-next-big {
    width: 100%;
    aspect-ratio: 1 / 1; /* square */
    padding: 0; /* aspect-ratio controls height */
    font-size: 24px;
}

.controls-row .control-btn {
    flex: 1 1 0;
    min-width: 0; /* allow full stretch to match big button width */
}

/* Generic two-pane layout (stacks on portrait, splits on landscape) */
.two-pane {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}
.pane-left,
.pane-right {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0; /* prevent overflow when shrinking */
}

/* Laps */
.laps-container {
    width: 100%;
    margin-top: 32px;
}

.laps-header {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.laps-list {
    background: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
}

.lap-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.lap-item.lap-highlight {
    background: rgba(245, 158, 11, 0.12);
    box-shadow: inset 0 0 0 2px var(--warning);
}

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

.lap-number {
    font-weight: 600;
    color: var(--text-secondary);
}

.lap-times {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.lap-time {
    font-weight: 600;
    margin-bottom: 4px;
}

.lap-cumulative {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Results List */
.results-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result-item {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    border: 2px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    display: grid;
    grid-template-columns: 88px 1fr auto;
    gap: 12px;
    align-items: center;
    min-height: 88px; /* ensure uniform height */
    -webkit-tap-highlight-color: transparent;
}

.result-item:active {
    transform: translateX(4px);
    border-color: var(--accent);
}

.result-item.dragging {
    opacity: 0.6;
}

.result-info h3 {
    font-size: 16px;
    margin-bottom: 4px;
}

.result-meta {
    color: var(--text-secondary);
    font-size: 14px;
}

/* result thumbnail */
.result-thumb {
    width: 100%;
    aspect-ratio: 1 / 1; /* make it square within the 88px column */
    height: auto;
    border-radius: 10px;
    object-fit: cover;
    background: var(--bg-tertiary);
    overflow: hidden;
    align-self: center;
}

.result-thumb.placeholder {
    display: inline-block;
}

/* Kebab menu popover */
.menu-popover {
    position: absolute;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px var(--shadow);
    padding: 8px;
    z-index: 2000;
    min-width: 220px;
}

.menu-item {
    display: block;
    width: 100%;
    padding: 12px 14px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    text-align: left;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    white-space: nowrap;
}

.menu-item:hover,
.menu-item:active {
    background: var(--bg-tertiary);
}

.result-delete {
    background: var(--danger);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

/* Result Detail */
.result-detail {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.result-image {
    width: 100%;
    max-height: 300px;
    object-fit: cover;
    border-radius: 12px;
}

.stats-grid {
    display: grid;
    grid-template-columns: minmax(80px, 1fr) auto minmax(80px, 1fr);
    gap: 12px;
    align-items: stretch;
    max-width: 100%;
}

.stat-card {
    background: var(--bg-secondary);
    padding: 12px 8px;
    border-radius: 12px;
    text-align: center;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0; /* Allow flex children to shrink below content size */
}

/* Make the Laps card visually narrower and centered */
.stat-laps {
    justify-self: center;
    width: 96px;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-value {
    font-size: clamp(16px, 4vw, 24px);
    font-weight: 700;
    color: var(--accent);
    word-break: break-word;
    overflow-wrap: break-word;
    line-height: 1.2;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: 16px;
    padding: 24px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px var(--shadow);
}

/* Wide modal variant (e.g., calculator split layout) */
.modal-content.wide {
    max-width: min(92vw, 720px);
}

/* Pop-in animation for lovely entrance */
.modal-content.pop-animate {
    animation: modalPopIn 260ms cubic-bezier(0.18, 0.89, 0.32, 1.28);
    transform-origin: center;
}

@keyframes modalPopIn {
    0% { transform: scale(0.9) translateY(10px); opacity: 0; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .modal-content.pop-animate {
        animation: none;
        transform: none;
    }
}

/* Touch reorder visuals */
.drag-ghost {
    border: 2px dashed var(--accent);
    border-radius: 12px;
    opacity: 0.95;
    box-shadow: 0 8px 16px rgba(0,0,0,0.25);
    transform: translate3d(0,0,0);
}
.placeholder-slot {
    border: 2px dashed var(--border);
    border-radius: 12px;
    margin: 6px 0;
    background: var(--bg-tertiary);
}

.modal-header {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.modal-close-x {
    background: transparent;
    border: none;
    font-size: 26px; /* increased by ~30% */
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 8px 10px;
    border-radius: 8px;
}
.modal-close-x:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
}

.form-input,
.form-select {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--accent);
}

.file-input-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
    width: 100%;
}

.file-input-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 2px dashed var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.file-input-label:active {
    background: var(--border);
}

.file-input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.image-preview {
    margin-top: 12px;
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-radius: 8px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.modal-actions .btn {
    flex: 1;
}

/* Calc Tabs */
.calc-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border);
}

.calc-tab {
    flex: 1;
    padding: 12px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.calc-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.calc-result {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    text-align: center;
    margin-top: 20px;
}

.calc-result-label {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 8px;
}

.calc-result-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent);
}

/* Calculator split layout */
.calc-layout {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas:
        "display"
        "keypad";
    gap: 12px;
}
.calc-panel { display: flex; flex-direction: column; gap: 12px; }
.calc-left { grid-area: keypad; }
.calc-right { grid-area: display; }
.calc-keys-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(56px, 1fr));
    gap: 8px;
}
.calc-keys-grid .btn { height: 54px; font-size: 18px; }
/* Live preview of calculator result */
.calc-live { font-size: 18px; color: var(--text-secondary); text-align: right; min-height: 20px; }

/* Empty State */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 16px;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

/* Responsive */
@media (min-width: 768px) {
    header h1 {
        font-size: 24px;
    }
    
    main {
        padding: 24px;
        max-width: 1200px;
        margin: 0 auto;
        width: 100%;
    }
    
    .time-display {
        font-size: 72px;
    }
    .current-lap { font-size: 36px; }
    
    .folders-grid { flex-direction: column; }

    .result-detail .stats-grid {
        grid-template-columns: 1fr auto 1fr;
    }

    .stat-laps {
        width: 120px;
    }
}

@media (min-width: 1024px) {
    .modal-content {
        max-width: 600px;
    }

    .calc-layout {
        grid-template-columns: auto 1fr; /* keypad left, display right on wider screens */
        grid-template-areas: "keypad display";
    }
}

/* Prefer split calc layout on landscape, even on phones */
@media screen and (orientation: landscape) {
    .modal-content.wide { max-width: min(96vw, 820px); }
    .calc-layout {
        grid-template-columns: minmax(220px, 0.9fr) 1.1fr;
        grid-template-areas: "keypad display";
        gap: 16px;
    }
    #calcMain { font-size: 36px; }
}

/* Touch Feedback */
@media (hover: hover) {
    .icon-btn:hover,
    .folder-card:hover,
    .result-item:hover {
        opacity: 0.9;
    }
    
    .btn:hover {
        opacity: 0.95;
    }
}

/* Theme Palette Customization */
.theme-palette-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.palette-card {
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.palette-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.palette-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}

.palette-preview {
    display: flex;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 8px;
    pointer-events: none;
}

.palette-preview > div {
    pointer-events: none;
}

.palette-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    pointer-events: none;
}

/* Saved Custom Themes */
.saved-themes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-top: 12px;
}

.saved-theme-card {
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    transition: all 0.2s;
}

.saved-theme-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.saved-theme-preview {
    display: flex;
    height: 50px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 8px;
}

.saved-theme-preview > div {
    flex: 1;
}

.saved-theme-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    text-align: center;
    word-break: break-word;
}

.saved-theme-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.color-picker {
    width: 100%;
    height: 48px;
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    background: var(--bg-secondary);
}

.color-picker::-webkit-color-swatch-wrapper {
    padding: 4px;
}

.color-picker::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

/* Theme toggle already has user-select: none from body */

/* Folder dragging state */
.folder-card.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

/* Color palette picker */
.color-palette-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.color-palette-btn {
    width: 100%;
    aspect-ratio: 1;
    border: 3px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.color-palette-btn:hover {
    transform: scale(1.1);
}

.color-palette-btn.selected {
    border-color: var(--text-primary);
    border-width: 4px;
    box-shadow: 0 0 0 2px var(--accent);
}

/* Folder menu button */
.folder-menu {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.2);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-primary);
    transition: all 0.2s;
    z-index: 10;
}

.folder-menu:hover {
    background: rgba(0, 0, 0, 0.3);
    transform: scale(1.1);
}

/* Safe Area Insets for Notched Devices */
@supports (padding-top: env(safe-area-inset-top)) {
    header {
        padding-top: max(16px, env(safe-area-inset-top));
    }
    
    .fab-container {
        bottom: max(24px, env(safe-area-inset-bottom));
        right: max(24px, env(safe-area-inset-right));
    }

    .fab-container.fab-centered {
        bottom: max(24px, env(safe-area-inset-bottom));
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }
}

/* Orientation Lock Overlay */
.orientation-lock {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    color: var(--text-primary);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    font-size: 18px;
    text-align: center;
    padding: 20px;
}

/* Landscape support for small devices */
@media screen and (orientation: landscape) and (max-width: 896px) {
    /* Keep overlay hidden in landscape; we want the UI usable */
    .orientation-lock { display: none; }

    html, body, #app { width: 100vw; height: 100svh; overflow-x: hidden; }
    header { padding: 12px; }
    main { padding: 12px; overflow-x: hidden; overflow-y: auto; }

    /* Generic two-pane split */
    .two-pane { grid-template-columns: 1.1fr 1fr; align-items: start; }
    .stopwatch-container.two-pane { grid-template-columns: 1.2fr 1fr; }
    .result-detail.two-pane { grid-template-columns: 0.9fr 1.1fr; }

    /* Stopwatch layout: place time and controls side-by-side */
    .stopwatch-container {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 16px;
        max-width: 100vw;
    }
    .time-display { font-size: 42px; }
    .current-lap { font-size: 20px; }
    .pane-right .current-lap { text-align: left; margin-bottom: 8px; }

    .controls { width: auto; gap: 12px; }
    .controls-stack { width: min(55vw, 420px); max-width: 55vw; }
    .btn-next-big { aspect-ratio: auto; height: 120px; font-size: 20px; }
    .controls-row .control-btn { min-width: 120px; }

    /* Result detail: use two columns where possible and limit image height */
    .result-image { max-height: 40vh; }
    .result-detail .stats-grid { grid-template-columns: 1fr 1fr; }
    .pane-right .laps-list { max-height: calc(100svh - 220px); overflow-y: auto; }

    /* FAB: tuck tighter in landscape */
    .fab-container { bottom: 12px; right: 12px; }
}

/* Help Dialog Layout */
.help-layout {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: 70vh;
}

.help-toc {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
}

.help-toc-title {
    font-weight: 700;
    margin-bottom: 8px;
    font-size: 15px;
}

.help-toc nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.toc-link {
    color: var(--accent);
    text-decoration: none;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 14px;
    transition: background 0.15s ease;
}

.toc-link:hover {
    background: var(--bg-tertiary);
}

.help-content-scroll {
    overflow: auto;
    padding-right: 4px;
}

.help-section {
    margin-bottom: 20px;
}

.help-section h3 {
    margin: 0 0 8px;
    font-size: 18px;
}

.help-section p,
.help-section ul {
    color: var(--text-secondary);
    line-height: 1.5;
}

.help-section ul {
    padding-left: 20px;
    margin-top: 8px;
}

.help-section li {
    margin-bottom: 6px;
}

/* Responsive: two-column layout on larger screens */
@media (min-width: 768px) {
    .help-layout {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }

    .help-toc {
        position: static;
        top: auto;
        align-self: stretch;
        max-height: none;
        overflow-y: visible;
    }
}
