/* ============================================
   Word Counter - Mobile-First Styles
   ============================================ */

/* CSS Variables for theming */
:root {
    /* Light mode colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --border-color: #e0e0e0;
    --accent-color: #2563eb;
    --accent-hover: #1d4ed8;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --counter-bg: #f9fafb;
    --modal-bg: rgba(0, 0, 0, 0.5);
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Dark mode colors */
        --bg-primary: #1a1a1a;
        --bg-secondary: #2a2a2a;
        --text-primary: #f5f5f5;
        --text-secondary: #a0a0a0;
        --border-color: #404040;
        --accent-color: #3b82f6;
        --accent-hover: #60a5fa;
        --success-color: #34d399;
        --danger-color: #f87171;
        --counter-bg: #252525;
        --modal-bg: rgba(0, 0, 0, 0.7);
        --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.5);
    }
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    /* Use dynamic viewport height to avoid iOS keyboard issues */
    height: 100dvh;
    height: 100vh; /* Fallback */
    overflow: hidden;
    /* Prevent page scrolling on mobile */
    position: fixed;
    inset: 0;
    /* iOS Safari: prevent elastic scrolling */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
    /* Prevent any scrolling */
    touch-action: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: fixed;
    inset: 0;
    /* Prevent pull-to-refresh and elastic scrolling on mobile */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
    /* Prevent page scrolling - allow only in textarea */
    touch-action: none;
    /* Contain layout to prevent scroll propagation */
    contain: layout style;
}

/* ============================================
   Header
   ============================================ */
.header {
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    padding-top: max(0.75rem, env(safe-area-inset-top));
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
    /* Animation properties for keyboard collapse */
    max-height: 200px; /* Large enough to contain header content */
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                padding 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.25s ease,
                border-bottom-width 0.3s ease;
    opacity: 1;
    will-change: max-height, padding, opacity;
    /* Prevent touch interactions from scrolling page */
    touch-action: none;
}

/* Header collapsed state when virtual keyboard is open */
.header.keyboard-collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    border-bottom-width: 0;
    box-shadow: none;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    max-width: 100%;
}

.header-title h1,
.header-title-mobile,
.header-title-desktop {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.header-title-desktop {
    display: none;
}

.header-title-mobile {
    display: block;
}

/* Desktop devices always show desktop title */
.desktop-device .header-title-desktop {
    display: block;
}

.desktop-device .header-title-mobile {
    display: none;
}

/* Mobile devices always show mobile title */
.mobile-device .header-title-desktop {
    display: none;
}

.mobile-device .header-title-mobile {
    display: block;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 0.25rem 0 0 0;
}

/* ============================================
   iOS Safari Add to Home Screen Banner
   ============================================ */
.ios-banner {
    background-color: var(--accent-color);
    color: #ffffff;
    padding: 0.75rem 1rem;
    padding-top: max(0.75rem, env(safe-area-inset-top));
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: none;
    animation: slideDown 0.3s ease-out;
}

@media (prefers-color-scheme: dark) {
    .ios-banner {
        background-color: #1e40af; /* Darker blue for dark mode */
    }
}

.ios-banner[aria-hidden="false"] {
    display: block;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.ios-banner-content {
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
}

.ios-banner-text {
    margin: 0;
    font-size: 0.875rem;
    font-weight: 500;
    text-align: center;
    line-height: 1.4;
}

.ios-banner-actions {
    display: flex;
    gap: 0.75rem;
    width: 100%;
    justify-content: center;
}

.ios-banner-btn {
    padding: 0.5rem 1.25rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    min-height: 2.5rem;
    flex: 1;
    max-width: 10rem;
}

.ios-banner-btn-primary {
    background-color: #ffffff;
    color: var(--accent-color);
}

.ios-banner-btn-primary:hover,
.ios-banner-btn-primary:focus-visible {
    background-color: rgba(255, 255, 255, 0.9);
    outline: none;
    transform: translateY(-1px);
}

.ios-banner-btn-primary:active {
    transform: translateY(0);
}

.ios-banner-btn-secondary {
    background-color: transparent;
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.ios-banner-btn-secondary:hover,
.ios-banner-btn-secondary:focus-visible {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.8);
    outline: none;
}

.ios-banner-btn-secondary:active {
    background-color: rgba(255, 255, 255, 0.15);
}

/* Remove focus styles after tap on iOS/touch devices */
.ios-banner-btn:focus:not(:focus-visible) {
    outline: none;
}

@media (min-width: 480px) {
    .ios-banner-content {
        flex-direction: row;
        justify-content: space-between;
    }
    
    .ios-banner-text {
        text-align: left;
        flex: 1;
    }
    
    .ios-banner-actions {
        flex: 0 0 auto;
        width: auto;
    }
    
    .ios-banner-btn {
        flex: 0 0 auto;
        max-width: none;
    }
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: all 0.2s ease;
    min-width: 2.5rem;
    justify-content: center;
}

.icon-btn:hover,
.icon-btn:focus-visible {
    background-color: var(--bg-secondary);
    border-color: var(--accent-color);
    outline: none;
}

/* Remove focus styles after tap on iOS/touch devices */
.icon-btn:focus:not(:focus-visible) {
    background-color: transparent;
    border-color: var(--border-color);
    outline: none;
}

.icon-btn:active {
    transform: scale(0.95);
}

/* Disabled button state */
.icon-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.icon-btn:disabled:hover,
.icon-btn:disabled:focus-visible {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--text-primary);
}

/* Danger styling for Clear button */
.icon-btn-danger {
    color: var(--danger-color);
}

.icon-btn-danger:hover,
.icon-btn-danger:focus-visible {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: var(--danger-color);
    color: var(--danger-color);
}

@media (prefers-color-scheme: dark) {
    .icon-btn-danger:hover,
    .icon-btn-danger:focus-visible {
        background-color: rgba(248, 113, 113, 0.15);
    }
}

.icon-btn-danger:disabled {
    color: var(--danger-color);
    opacity: 0.4;
}

.icon-btn-danger:disabled:hover,
.icon-btn-danger:disabled:focus-visible {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--danger-color);
}

.icon-btn .icon {
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn .icon svg {
    width: 1em;
    height: 1em;
    stroke: currentColor;
    fill: none;
    flex-shrink: 0;
}

.icon-btn .label {
    display: none;
}

/* Show labels on wider screens */
@media (min-width: 480px) {
    .icon-btn {
        padding: 0.5rem 0.75rem;
    }
    
    .icon-btn .label {
        display: inline;
    }
}

/* ============================================
   Counter Bar (between header and editor)
   ============================================ */
.counter-bar {
    background-color: var(--counter-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    padding-bottom: 0.5rem;
    flex-shrink: 0;
    position: relative;
    z-index: 5;
    /* Animation properties for keyboard collapse transition */
    transition: padding-top 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: padding-top;
    /* Allow horizontal pan for counter scrolling, prevent vertical */
    touch-action: pan-x;
    overflow-y: hidden;
    overflow-x: visible;
}

/* Counter bar at very top when header is collapsed */
.counter-bar.keyboard-top {
    /* Remove top border as it's now at the very top */
    border-top-width: 0;
    /* Add safe-area padding for notched devices but minimal */
    padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
}

.counter-bar-content {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
    /* Hide scrollbar but keep functionality */
    scrollbar-width: none;
    -ms-overflow-style: none;
    /* Allow horizontal pan only, prevent triggering page scroll */
    touch-action: pan-x;
    /* Contain scroll to this element */
    overscroll-behavior-x: contain;
}

.counter-bar-content::-webkit-scrollbar {
    display: none;
}

/* Swipe chevron indicator */
.counter-bar-chevron {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 2.5rem;
    height: 100%;
    display: flex;
    align-items: center;
    color: var(--text-secondary);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 10;
}

.counter-bar-chevron-left {
    left: 0;
    justify-content: flex-start;
    background: linear-gradient(to left, transparent 0%, var(--counter-bg) 70%);
    padding-left: 0.5rem;
}

.counter-bar-chevron-right {
    right: 0;
    justify-content: flex-end;
    background: linear-gradient(to right, transparent 0%, var(--counter-bg) 70%);
    padding-right: 0.5rem;
}

.counter-bar-chevron.visible {
    opacity: 1;
}

.counter-bar-chevron svg {
    width: 1.125rem;
    height: 1.125rem;
    stroke: currentColor;
    stroke-width: 3;
    fill: none;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2));
}

/* Hide chevron on wider screens where all counters are visible */
@media (min-width: 768px) {
    .counter-bar-chevron {
        display: none;
    }
}

.counter-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    min-width: 4rem;
    flex-shrink: 0;
}

.counter-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: capitalize;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.counter-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.progress-item {
    min-width: 6rem;
    gap: 0.15rem;
}

.progress-bar {
    width: 100%;
    height: 0.25rem;
    background-color: var(--border-color);
    border-radius: 0.15rem;
    overflow: hidden;
    margin: 0.1rem 0;
}

.progress-fill {
    height: 100%;
    background-color: var(--accent-color);
    border-radius: 0.25rem;
    transition: width 0.3s ease;
    width: 0%;
}

/* Wider screens: show all counters without scrolling */
@media (min-width: 768px) {
    .counter-bar-content {
        justify-content: space-around;
        overflow-x: visible;
    }
    
    .counter-item {
        min-width: auto;
        flex: 1;
        max-width: 10rem;
    }
}

/* ============================================
   Main Content / Editor
   ============================================ */
.main-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* Space for buttons bar at bottom */
    padding-bottom: 0;
    /* Allow vertical touch scrolling for child textarea */
    touch-action: pan-y;
}

/* Desktop min-height - applies regardless of window width */
.desktop-device .main-content {
    min-height: 100px; /* Prevent editor from collapsing on desktop */
}

.desktop-device .editor {
    min-height: 100px; /* Ensure editor has minimum height on desktop */
}

@media (min-width: 768px) {
    .desktop-device .main-content {
        padding-bottom: 0;
    }
}

.editor {
    width: 100%;
    height: 100%;
    padding: 1rem;
    border: none;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.8;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    resize: none;
    outline: none;
    overflow-y: auto;
    overflow-x: hidden;
    /* Prevent horizontal scroll */
    word-wrap: break-word;
    overflow-wrap: break-word;
    /* Smooth scrolling */
    scroll-behavior: smooth;
    /* Better text rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Allow scrolling only in textarea */
    touch-action: pan-y;
    /* Prevent textarea from causing page scroll */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Mobile editor padding */
.mobile-device .editor {
    padding-bottom: calc(1rem + 3rem);
}

.editor::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.editor:focus {
    outline: none;
}

/* ============================================
   Desktop Footer Container
   ============================================ */
.desktop-footer-container {
    display: block;
}

/* On mobile, hide the footer but show buttons bar */
/* Always apply mobile styles for mobile devices regardless of width */
.mobile-device .desktop-footer-container .page-footer {
    display: none;
}

.mobile-device .desktop-footer-container .buttons-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    transform: translateY(0);
    will-change: transform;
    box-shadow: none;
}

/* Desktop always shows desktop layout regardless of window width */
.desktop-device .desktop-footer-container .page-footer {
    display: block;
}

.desktop-device .desktop-footer-container .buttons-bar {
    position: static;
    transform: none;
    will-change: auto;
    box-shadow: none;
}

/* ============================================
   Buttons Bar (at the very bottom)
   ============================================ */
/* Mobile buttons-bar - fixed positioning */
.mobile-device .buttons-bar {
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    padding-bottom: max(0.25rem, env(safe-area-inset-bottom));
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 15;
    box-shadow: none;
    /* Will be adjusted by JavaScript to align with keyboard top */
    transform: translateY(0);
    will-change: transform;
    /* Prevent touch interactions from scrolling page */
    touch-action: none;
}

.buttons-bar-content {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Mobile buttons-bar-content */
.mobile-device .buttons-bar-content {
    justify-content: space-between;
}

/* Desktop buttons-bar-content */
.desktop-device .buttons-bar-content {
    justify-content: space-around;
}

.copyright-mobile {
    font-size: 0.875rem;
    color: var(--text-secondary);
    opacity: 0.6;
    margin-right: auto;
    padding: 0.5rem 0;
    display: none;
    display: flex;
    align-items: center;
}

/* Mobile copyright styling */
.mobile-device .copyright-mobile {
    padding: 0;
    height: auto;
    line-height: 1.5;
}

/* Base button styles - apply to mobile by default */
.mobile-device .buttons-bar .icon-btn {
    flex: 1;
    min-width: 0;
    padding: 0.75rem 0.5rem;
    font-size: 0.875rem;
}

.mobile-device .buttons-bar .icon-btn .icon {
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-device .buttons-bar .icon-btn .icon svg {
    width: 1.25rem;
    height: 1.25rem;
    stroke: currentColor;
    fill: none;
    flex-shrink: 0;
}

.mobile-device .buttons-bar .icon-btn .label {
    display: block;
    font-size: 0.7rem;
    margin-top: 0.25rem;
}

/* Mobile button sizing for wider mobile screens */
@media (min-width: 480px) {
    .mobile-device .buttons-bar .icon-btn {
        padding: 0.75rem 1rem;
    }
    
    .mobile-device .buttons-bar .icon-btn .label {
        font-size: 0.75rem;
    }
}

/* ============================================
   More Menu (Mobile Only)
   ============================================ */
.more-menu-container {
    position: relative;
    display: none;
}

.buttons-bar .more-btn {
    flex: 0 0 auto;
    margin-left: auto;
    font-size: 1.0rem !important;
    font-weight: 500;
    padding: 0.75rem 1.5rem;
}

/* Mobile more button styling */
.mobile-device .buttons-bar .more-btn {
    padding: 0.375rem 1.25rem;
    margin-bottom: 0;
    align-self: flex-end;
    height: auto;
    line-height: 1.5;
}

.buttons-bar .more-btn .label {
    font-size: 1.0rem !important;
    margin-top: 0;
}

.more-menu-dropdown {
    position: absolute;
    bottom: calc(100% + 0.5rem);
    right: 0;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    min-width: 10rem;
    opacity: 0;
    visibility: hidden;
    transform: translateY(0.5rem);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    z-index: 20;
    padding: 0.25rem;
    margin-bottom: 0.5rem;
}

.more-menu-dropdown[aria-hidden="false"] {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.more-menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    color: var(--text-primary);
    font-size: 1.0rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    text-align: left;
}

.more-menu-item:hover,
.more-menu-item:focus-visible {
    background-color: var(--bg-secondary);
    outline: none;
}

/* Remove focus styles after tap on iOS/touch devices */
.more-menu-item:focus:not(:focus-visible) {
    background-color: transparent;
    outline: none;
}

.more-menu-item:active {
    transform: scale(0.98);
}

/* Disabled menu item state */
.more-menu-item:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.more-menu-item:disabled:hover,
.more-menu-item:disabled:focus-visible {
    background-color: transparent;
    color: var(--text-primary);
}

/* Danger styling for Clear menu item */
.more-menu-item-danger {
    color: var(--danger-color);
}

.more-menu-item-danger:hover,
.more-menu-item-danger:focus-visible {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

@media (prefers-color-scheme: dark) {
    .more-menu-item-danger:hover,
    .more-menu-item-danger:focus-visible {
        background-color: rgba(248, 113, 113, 0.15);
    }
}

.more-menu-item-danger:disabled {
    color: var(--danger-color);
    opacity: 0.4;
}

.more-menu-item-danger:disabled:hover,
.more-menu-item-danger:disabled:focus-visible {
    background-color: transparent;
    color: var(--danger-color);
}

.more-menu-item .icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.more-menu-item .icon svg {
    width: 1.125rem;
    height: 1.125rem;
    stroke: currentColor;
    fill: none;
}

.more-menu-item .label {
    display: block;
    font-size: 1.0rem;
    margin: 0;
}

.more-menu-hint {
    cursor: default;
    opacity: 0.7;
    font-size: 0.875rem;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    border-top: 1px solid var(--border-color);
    margin-top: 0.25rem;
    padding-top: 0.75rem;
}

.more-menu-hint:hover,
.more-menu-hint:focus-visible {
    background-color: transparent;
}

.more-menu-hint:active {
    transform: none;
}

.more-menu-hint .label {
    font-size: 0.875rem;
    line-height: 1.4;
}

/* Mobile: Hide individual buttons, show More button */
/* Apply mobile styles regardless of width if mobile device */
.mobile-device .buttons-bar-content {
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0;
    min-height: auto;
    gap: 0;
}

.mobile-device .buttons-bar-content > .icon-btn:not(.more-btn) {
    display: none;
}

.mobile-device .more-menu-container {
    display: block;
    align-self: center;
    margin-bottom: 0;
}

.mobile-device .copyright-mobile {
    display: flex;
    margin-right: 0;
    margin-bottom: 0;
    padding: 0;
    align-self: center;
}

/* Desktop: Show all buttons, hide More button */
/* Apply desktop styles regardless of window width */
.desktop-device .buttons-bar {
    display: none;
}

.desktop-device .desktop-footer-container {
    display: block;
    flex-shrink: 0;
}

.desktop-device .desktop-footer-container .buttons-bar {
    display: block;
    position: static;
    transform: none;
    will-change: auto;
    box-shadow: none;
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    z-index: 15;
    touch-action: auto;
}

.desktop-device .buttons-bar-content {
    justify-content: space-around;
    align-items: center;
    padding-bottom: 0;
    min-height: auto;
    gap: 0.5rem;
}

.desktop-device .buttons-bar-content > .icon-btn:not(.more-btn) {
    display: flex !important; /* Force display on desktop */
}

.desktop-device .buttons-bar .icon-btn {
    font-size: 1rem;
    padding: 0.35rem 0.5rem; /* Consistent padding for desktop regardless of window size */
    flex: 1; /* Make buttons occupy full width equally */
    min-width: 0; /* Allow buttons to shrink if needed */
}

.desktop-device .buttons-bar .icon-btn .label {
    font-size: 0.875rem;
    display: block; /* Ensure label is visible on desktop */
    margin-top: 0.25rem;
}

.desktop-device .buttons-bar .icon-btn .icon {
    font-size: 0.875rem; /* Consistent icon size for desktop */
    display: flex;
    align-items: center;
    justify-content: center;
}

.desktop-device .buttons-bar .icon-btn .icon svg {
    width: 0.875rem; /* Consistent icon size for desktop */
    height: 0.875rem;
    stroke: currentColor;
    fill: none;
    flex-shrink: 0;
}

.desktop-device .more-menu-container {
    display: none;
}

.desktop-device .copyright-mobile {
    display: none;
}


/* ============================================
   Footer (Desktop Only)
   ============================================ */
.page-footer {
    display: none;
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 1rem;
    text-align: left;
    position: relative;
    z-index: 5;
}

.footer-content {
    max-width: 100%;
    margin: 0 auto;
}

.copyright-desktop {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
}

.desktop-description {
    display: none;
    padding: 0.5rem 1rem 1.5rem;
    margin: 0 auto;
}

.desktop-description p {
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-secondary);
    opacity: 0.7;
    margin: 0;
    text-align: left;
}

/* Desktop devices always show description and footer regardless of window width */
.desktop-device .desktop-footer-container .page-footer {
    display: block;
}

.desktop-device .desktop-description {
    display: block;
}

@media (min-width: 768px) {
    /* Only apply desktop styles if not a mobile device */
    
    /* Limit all content to 900px width on desktop */
    .desktop-device .header-content {
        max-width: 900px;
        margin: 0 auto;
    }
    
    .desktop-device .counter-bar-content {
        max-width: 900px;
        margin: 0 auto;
    }
    
    .desktop-device .main-content {
        max-width: 900px;
        margin: 0 auto;
        width: 100%;
    }
    
    .desktop-device .desktop-footer-container {
        max-width: 100%;
    }
    
    .desktop-device .desktop-footer-container .buttons-bar-content {
        max-width: 900px;
        margin: 0 auto;
    }
    
    .desktop-device .desktop-description {
        max-width: 900px;
        margin: 0 auto;
    }
    
    .desktop-device .desktop-footer-container .footer-content {
        max-width: 900px;
        margin: 0 auto;
    }
}

/* ============================================
   Modal / Settings
   ============================================ */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

.modal[aria-hidden="false"] {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--modal-bg);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--bg-primary);
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 28rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    position: relative;
    z-index: 1;
    border: 1px solid var(--border-color);
    /* Enable smooth scrolling on iOS */
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 767px) {
    .modal-content {
        max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

.close-btn {
    background: transparent;
    border: none;
    font-size: 2rem;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.25rem;
    transition: all 0.2s ease;
}

.close-btn:hover,
.close-btn:focus-visible {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    outline: none;
}

/* Remove focus styles after tap on iOS/touch devices */
.close-btn:focus:not(:focus-visible) {
    background-color: transparent;
    color: var(--text-secondary);
    outline: none;
}

.modal-body {
    padding: 1.5rem;
}

.setting-group {
    margin-bottom: 1.5rem;
}

.setting-group:last-child {
    margin-bottom: 0;
}

.setting-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.setting-group label[for="wordGoal"] {
    font-weight: 700;
}

.setting-section-label {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.setting-group .setting-section-label,
.setting-group label.setting-section-label {
    font-weight: 700;
    margin-bottom: 1.0rem;
}

.setting-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 0.25rem 0 0 0;
    padding-left: calc(1.25rem + 0.75rem); /* Align with checkbox label text */
    font-style: normal;
    line-height: 1.4;
}

@media (min-width: 768px) {
    .setting-hint {
        font-size: 0.8125rem;
    }
}

.counter-visibility-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.3rem;
}

.counter-visibility-group .checkbox-label {
    font-weight: normal;
}

.setting-value {
    float: right;
    color: var(--accent-color);
    font-weight: 600;
}

.reading-speed-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.reading-speed-container input[type="range"] {
    flex: 1;
}

.reading-speed-value {
    color: var(--accent-color);
    font-weight: 600;
    font-size: 1rem;
    min-width: 3rem;
    text-align: right;
    flex-shrink: 0;
}

input[type="range"] {
    width: 100%;
    height: 0.5rem;
    border-radius: 0.25rem;
    background: var(--border-color);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    transition: all 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    background: var(--accent-hover);
}

input[type="range"]::-moz-range-thumb {
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.1);
    background: var(--accent-hover);
}

select,
input[type="number"] {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
}

select:focus-visible,
input[type="number"]:focus-visible {
    border-color: var(--accent-color);
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Remove focus styles after tap on iOS/touch devices */
select:focus:not(:focus-visible),
input[type="number"]:focus:not(:focus-visible) {
    border-color: var(--border-color);
    outline: none;
}

/* Word goal container with presets */
.word-goal-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.word-goal-container input[type="number"] {
    width: 100%;
}

.word-goal-presets {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.preset-pill {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 1.5rem;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preset-pill:hover,
.preset-pill:focus-visible {
    background-color: var(--accent-color);
    color: #ffffff;
    border-color: var(--accent-color);
    outline: none;
    transform: translateY(-1px);
}

/* Remove focus styles after tap on iOS/touch devices */
.preset-pill:focus:not(:focus-visible) {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-color);
    outline: none;
    transform: none;
}

.preset-pill:active {
    transform: translateY(0);
}

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

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
}

input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    cursor: pointer;
    accent-color: var(--accent-color);
}

.btn-secondary {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary:hover,
.btn-secondary:focus-visible {
    background-color: var(--border-color);
    outline: none;
}

/* Remove focus styles after tap on iOS/touch devices */
.btn-secondary:focus:not(:focus-visible) {
    background-color: var(--bg-secondary);
    outline: none;
}

/* ============================================
   Bottom Sheet
   ============================================ */
.bottom-sheet {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1500;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.bottom-sheet[aria-hidden="false"] {
    pointer-events: auto;
    opacity: 1;
}

.bottom-sheet-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.bottom-sheet[aria-hidden="false"] .bottom-sheet-backdrop {
    opacity: 1;
}

.bottom-sheet-content {
    position: relative;
    background-color: var(--bg-primary);
    border-top-left-radius: 1rem;
    border-top-right-radius: 1rem;
    width: 100%;
    max-width: 100%;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
}

.bottom-sheet[aria-hidden="false"] .bottom-sheet-content {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 2.5rem;
    height: 0.25rem;
    background-color: var(--border-color);
    border-radius: 0.125rem;
    margin: 0.75rem auto;
    cursor: grab;
    touch-action: none;
    position: relative;
}

.bottom-sheet-handle:active {
    cursor: grabbing;
}

/* Make handle area more touchable */
.bottom-sheet-handle::before {
    content: '';
    position: absolute;
    top: -1rem;
    left: 50%;
    transform: translateX(-50%);
    width: 4rem;
    height: 2.5rem;
    /* Invisible but touchable area */
}

.bottom-sheet-content.dragging {
    transition: none;
}

/* Desktop: Center the sheet like a modal dialog */
@media (min-width: 768px) {
    .bottom-sheet {
        align-items: center;
        padding: 1rem;
    }
    
    .bottom-sheet-content {
        width: auto;
        max-width: 28rem;
        border-radius: 1rem;
        border-top-left-radius: 1rem;
        border-top-right-radius: 1rem;
        padding-top: 1.5rem;
        padding-bottom: 1rem;
        transform: translateY(0) scale(0.95);
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    }
    
    .bottom-sheet[aria-hidden="false"] .bottom-sheet-content {
        transform: translateY(0) scale(1);
    }
    
    .bottom-sheet-handle {
        display: none;
    }
    
    .bottom-sheet-header {
        padding: 0 1.5rem 0.5rem;
    }
    
    .bottom-sheet-actions {
        padding: 1rem 1.5rem 0;
    }
}

.bottom-sheet-header {
    padding: 1rem 1.5rem 0.5rem;
    text-align: center;
}

.bottom-sheet-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.bottom-sheet-actions {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    padding-top: 1.5rem;
}

.btn-sheet-cancel,
.btn-sheet-destructive {
    flex: 1;
    min-width: 0;
    padding: 0.75rem 2.5rem;
    border-radius: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.btn-sheet-cancel {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-sheet-cancel:hover,
.btn-sheet-cancel:focus-visible {
    background-color: var(--border-color);
    outline: none;
}

/* Remove focus styles after tap on iOS/touch devices */
.btn-sheet-cancel:focus:not(:focus-visible) {
    background-color: var(--bg-secondary);
    outline: none;
}

.btn-sheet-cancel:active {
    transform: scale(0.98);
}

.btn-sheet-destructive {
    background-color: var(--danger-color);
    color: #ffffff;
}

.btn-sheet-destructive:hover,
.btn-sheet-destructive:focus-visible {
    background-color: #dc2626;
    outline: none;
}

/* Remove focus styles after tap on iOS/touch devices */
.btn-sheet-destructive:focus:not(:focus-visible) {
    background-color: var(--danger-color);
    outline: none;
}

.btn-sheet-destructive:active {
    transform: scale(0.98);
}

@media (prefers-color-scheme: dark) {
    .btn-sheet-destructive:hover,
    .btn-sheet-destructive:focus-visible {
        background-color: #fca5a5;
    }
    
    .btn-sheet-destructive:focus:not(:focus-visible) {
        background-color: var(--danger-color);
    }
}

/* ============================================
   Toast Notification
   ============================================ */
.toast {
    position: fixed;
    bottom: calc(6rem + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    max-width: 90%;
    text-align: center;
}

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

.toast-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.toast-header {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    white-space: nowrap;
}

.toast-undo-btn {
    background: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
    padding: 0.75rem 2.5rem;
    border-radius: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    white-space: nowrap;
    width: 100%;
    max-width: 28rem;
}

.toast-undo-btn:hover,
.toast-undo-btn:focus-visible {
    background-color: var(--accent-color);
    color: #ffffff;
    outline: none;
}

/* Remove focus styles after tap on iOS/touch devices */
.toast-undo-btn:focus:not(:focus-visible) {
    background-color: transparent;
    color: var(--accent-color);
    outline: none;
}

.toast-undo-btn:active {
    transform: scale(0.95);
}

/* ============================================
   Landscape Orientation Warning (Mobile)
   ============================================ */
.landscape-warning {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-primary);
    z-index: 3000;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
}

.landscape-warning-content {
    max-width: 20rem;
}

.landscape-warning-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.7;
}

.landscape-warning h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.landscape-warning p {
    font-size: 1rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0;
}

/* Show landscape warning on mobile devices in landscape orientation */
.mobile-device.landscape-mode .landscape-warning {
    display: flex;
}

/* Hide main content when in landscape mode on mobile */
.mobile-device.landscape-mode .header,
.mobile-device.landscape-mode .counter-bar,
.mobile-device.landscape-mode .main-content,
.mobile-device.landscape-mode .buttons-bar,
.mobile-device.landscape-mode .desktop-footer-container,
.mobile-device.landscape-mode .ios-banner {
    display: none !important;
}

/* ============================================
   Accessibility
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    /* Ensure header collapse still works but instantly */
    .header,
    .counter-bar {
        transition: none !important;
    }
}

/* Focus styles for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* ============================================
   Print styles
   ============================================ */
@media print {
    .header,
    .counter-bar,
    .modal {
        display: none;
    }
    
    .main-content {
        height: auto;
    }
}

