/* Mobile-Specific Styles (< 768px) */

@media (max-width: 768px) {

    /* ========== Bottom Sheet Component (BottomSheet.ts) ========== */

    /* Overlay (backdrop with blur) */
    .bottom-sheet-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0);
        backdrop-filter: blur(0px);
        -webkit-backdrop-filter: blur(0px);
        transition: background var(--duration-slow) var(--easing-standard),
            backdrop-filter var(--duration-slow) var(--easing-standard);
        pointer-events: none;
        z-index: calc(var(--z-panels) - 1);
        display: none;
    }

    .bottom-sheet-overlay--visible {
        background: rgba(0, 0, 0, 0.3);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        pointer-events: auto;
    }

    /* Sheet container */
    .bottom-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 60%;
        max-height: 90vh;
        background: var(--gradient-card);
        border: 2px solid rgba(100, 100, 150, 0.5);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        box-shadow: var(--shadow-sheet);
        z-index: var(--z-panels);
        transform: translateY(100%);
        transition: transform var(--duration-slow) var(--easing-standard);
        pointer-events: auto;
        display: none;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .bottom-sheet--open {
        transform: translateY(0);
    }

    /* Drag handle */
    .drag-handle {
        display: block;
        width: 24px;
        height: 4px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 2px;
        margin: var(--space-2) auto;
        cursor: grab;
        flex-shrink: 0;
        transition: background var(--duration-fast) ease;
    }

    .drag-handle:hover {
        background: rgba(255, 255, 255, 0.5);
    }

    .drag-handle:active {
        cursor: grabbing;
        background: rgba(255, 255, 255, 0.6);
    }

    /* Sheet content (scrollable) */
    .sheet-content {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 0 var(--space-4) var(--space-4);
    }

    /* Safe area support (iOS notch) */
    @supports (padding: env(safe-area-inset-bottom)) {
        .sheet-content {
            padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
        }
    }

    /* Respect prefers-reduced-motion */
    @media (prefers-reduced-motion: reduce) {

        .bottom-sheet,
        .bottom-sheet-overlay {
            transition: opacity var(--duration-fast) ease;
        }

        .bottom-sheet--open {
            transform: translateY(0);
            opacity: 1;
        }

        .bottom-sheet:not(.bottom-sheet--open) {
            opacity: 0;
        }
    }

    /* ========== Legacy Bottom Sheet Pattern (deprecated) ========== */
    .bottom-sheet__drag-handle {
        display: block;
        width: 40px;
        height: 4px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 2px;
        margin: var(--space-2) auto;
        cursor: grab;
    }

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

    /* ========== Full-Screen List Screens ========== */
    .screen {
        position: fixed;
        top: 48px;
        /* Below TopBar */
        left: 0;
        right: 0;
        bottom: 64px;
        /* Above BottomNav */
        background: var(--bg-panel);
        z-index: var(--z-overlays);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* Screen Header */
    .screen-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: var(--space-4);
        background: var(--gradient-panel);
        border-bottom: 1px solid rgba(100, 100, 150, 0.3);
        flex-shrink: 0;
    }

    .screen-title {
        font-size: var(--text-xl);
        font-weight: bold;
        color: #fff;
        margin: 0;
    }

    .screen-count {
        font-size: var(--text-sm);
        color: var(--ui-neutral);
        background: rgba(255, 255, 255, 0.1);
        padding: 2px 8px;
        border-radius: var(--radius-full);
        margin-left: var(--space-2);
    }

    .screen-action-btn {
        width: 40px;
        height: 40px;
        background: var(--ui-primary);
        border: none;
        border-radius: 50%;
        color: #fff;
        font-size: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all var(--duration-fast) ease;
    }

    .screen-action-btn:active {
        transform: scale(0.9);
    }

    /* Screen List Container */
    .screen-list {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: var(--space-2);
    }

    /* List Card (Base/Hero Item) */
    .list-card {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-3);
        margin-bottom: var(--space-2);
        background: var(--gradient-card);
        border: 1px solid rgba(100, 100, 150, 0.3);
        border-radius: var(--radius-lg);
        min-height: 72px;
        cursor: pointer;
        transition: all var(--duration-fast) ease;
    }

    .list-card:active {
        transform: scale(0.98);
    }

    .list-card-icon {
        font-size: 32px;
        line-height: 1;
        flex-shrink: 0;
    }

    .list-card-info {
        flex: 1;
        min-width: 0;
    }

    .list-card-name-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: var(--space-1);
    }

    .list-card-name {
        font-size: var(--text-base);
        font-weight: 600;
        color: #fff;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .list-card-level {
        font-size: var(--text-sm);
        color: var(--ui-warning);
        font-weight: 600;
        flex-shrink: 0;
        margin-left: var(--space-2);
    }

    .list-card-stats {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        font-size: var(--text-sm);
        color: var(--ui-neutral);
        margin-top: var(--space-1);
    }

    .stat-item {
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .stat-value {
        color: #fff;
        font-weight: 600;
    }

    .list-card-location {
        font-size: var(--text-xs);
        color: rgba(255, 255, 255, 0.5);
        font-family: 'Courier New', monospace;
    }

    .list-card-arrow {
        font-size: 24px;
        color: var(--ui-neutral);
        flex-shrink: 0;
    }

    /* Hero-specific styles */
    .hero-hp-container {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        margin-top: var(--space-1);
    }

    .hero-hp-text {
        font-size: var(--text-sm);
        color: var(--ui-neutral);
        white-space: nowrap;
    }

    .hero-hp-bar {
        flex: 1;
        height: 4px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 2px;
        overflow: hidden;
    }

    .hero-hp-fill {
        height: 100%;
        transition: width var(--duration-normal) ease;
        border-radius: 2px;
    }

    .hero-state {
        font-size: var(--text-xs);
        padding: 2px 6px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: var(--radius-sm);
        white-space: nowrap;
    }

    /* Empty State */
    .screen-empty {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: var(--space-8);
        text-align: center;
        height: 100%;
    }

    .screen-empty-icon {
        font-size: 64px;
        margin-bottom: var(--space-4);
        opacity: 0.5;
    }

    .screen-empty-title {
        font-size: var(--text-lg);
        font-weight: 600;
        color: #fff;
        margin-bottom: var(--space-2);
    }

    .screen-empty-text {
        font-size: var(--text-sm);
        color: var(--ui-neutral);
        max-width: 300px;
    }

    /* Safe area adjustments */
    @supports (padding: env(safe-area-inset-top)) {
        .screen {
            top: calc(48px + env(safe-area-inset-top));
        }
    }

    @supports (padding: env(safe-area-inset-bottom)) {
        .screen {
            bottom: calc(64px + env(safe-area-inset-bottom));
        }
    }

    /* ========== Touch Optimizations ========== */
    button,
    a,
    .clickable {
        min-width: var(--touch-min);
        min-height: var(--touch-min);
    }

    /* Primary actions get larger touch target */
    .btn-primary,
    .action-button {
        min-width: var(--touch-comfortable);
        min-height: var(--touch-comfortable);
    }

    /* ========== Dimmed Background ========== */
    .overlay-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0);
        transition: background var(--duration-slow) ease;
        pointer-events: none;
        z-index: calc(var(--z-panels) - 1);
    }

    .overlay-backdrop--visible {
        background: rgba(0, 0, 0, 0.5);
        pointer-events: auto;
    }

    /* ========== Hide desktop-only elements ========== */
    .desktop-only {
        display: none !important;
    }

    /* ========== More Dropdown (MoreScreen.ts) ========== */

    .more-dropdown {
        position: fixed;
        top: 56px;
        right: 8px;
        min-width: 180px;
    }

    /* ========== Hero Detail Sheet (HeroDetailSheet.ts) ========== */

    .hero-detail {
        display: flex;
        flex-direction: column;
        gap: var(--space-4);
    }

    /* Header */
    .hero-detail-header {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-2) 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .hero-detail-avatar {
        font-size: 40px;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    .hero-detail-info {
        flex: 1;
        min-width: 0;
    }

    .hero-detail-name {
        font-size: var(--text-lg);
        font-weight: 600;
        color: #fff;
        margin: 0 0 var(--space-1) 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .hero-detail-level {
        font-size: var(--text-sm);
        color: var(--ui-warning);
        font-weight: 600;
        margin-right: var(--space-2);
    }

    .hero-detail-state {
        display: inline-block;
        font-size: var(--text-xs);
        padding: 2px 8px;
        border-radius: var(--radius-sm);
        font-weight: 600;
    }

    /* State badges */
    .badge-idle {
        background: rgba(100, 200, 100, 0.2);
        color: #4ade80;
    }

    .badge-moving {
        background: rgba(59, 130, 246, 0.2);
        color: #3b82f6;
    }

    .badge-combat {
        background: rgba(239, 68, 68, 0.2);
        color: #ef4444;
    }

    .badge-resting {
        background: rgba(168, 85, 247, 0.2);
        color: #a855f7;
    }

    .badge-danger {
        background: rgba(239, 68, 68, 0.3);
        color: #fee2e2;
    }

    .hero-detail-close-btn {
        width: 32px;
        height: 32px;
        background: rgba(255, 255, 255, 0.1);
        border: none;
        border-radius: 50%;
        color: #fff;
        font-size: 18px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        transition: all var(--duration-fast) ease;
    }

    .hero-detail-close-btn:active {
        transform: scale(0.9);
        background: rgba(255, 255, 255, 0.2);
    }

    /* Stats Section */
    .hero-detail-stats {
        display: flex;
        flex-direction: column;
        gap: var(--space-3);
    }

    .stat-hp label {
        font-size: var(--text-sm);
        color: var(--ui-neutral);
        margin-bottom: var(--space-1);
        display: block;
    }

    .progress-bar {
        position: relative;
        height: 8px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: var(--radius-full);
        overflow: hidden;
        margin-bottom: var(--space-1);
    }

    .progress-bar-fill {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        background: var(--entity-hero);
        border-radius: var(--radius-full);
        transition: width var(--duration-normal) ease;
    }

    .progress-bar-text {
        font-size: var(--text-sm);
        color: #fff;
        font-weight: 600;
    }

    .stat-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--space-2);
    }

    .stat-item {
        font-size: var(--text-sm);
        color: var(--ui-neutral);
    }

    .stat-item b {
        color: #fff;
        font-weight: 600;
    }

    /* Behavior Section */
    .hero-detail-behavior h3 {
        font-size: var(--text-base);
        color: #fff;
        margin: 0 0 var(--space-2) 0;
    }

    .behavior-status {
        font-size: var(--text-sm);
        color: var(--ui-neutral);
        margin: 0 0 var(--space-3) 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .btn-primary {
        width: 100%;
        height: 48px;
        background: linear-gradient(135deg, var(--ui-primary), var(--ui-secondary));
        border: none;
        border-radius: var(--radius-lg);
        color: #fff;
        font-size: var(--text-base);
        font-weight: 600;
        cursor: pointer;
        transition: all var(--duration-fast) ease;
    }

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

    .btn-set-behavior {
        /* Inherit from btn-primary */
    }

    /* Action Log Section */
    .hero-detail-logs h3 {
        font-size: var(--text-base);
        color: #fff;
        margin: 0 0 var(--space-2) 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .btn-expand-logs {
        width: 24px;
        height: 24px;
        background: transparent;
        border: none;
        color: var(--ui-neutral);
        font-size: 20px;
        cursor: pointer;
        transition: transform var(--duration-fast) ease;
    }

    .btn-expand-logs:active {
        transform: rotate(90deg);
    }

    .log-items {
        display: flex;
        flex-direction: column;
        gap: var(--space-2);
    }

    .log-item {
        display: flex;
        flex-direction: column;
        gap: 4px;
        padding: var(--space-2);
        background: rgba(255, 255, 255, 0.05);
        border-radius: var(--radius-md);
    }

    .log-item time {
        font-size: var(--text-xs);
        color: var(--ui-neutral);
    }

    .log-item span {
        font-size: var(--text-sm);
        color: #fff;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Quick Actions Footer */
    .hero-detail-actions {
        display: flex;
        gap: var(--space-2);
        padding-top: var(--space-2);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .btn-action {
        flex: 1;
        height: 44px;
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: var(--radius-md);
        color: #fff;
        font-size: var(--text-sm);
        cursor: pointer;
        transition: all var(--duration-fast) ease;
    }

    .btn-action:active:not(:disabled) {
        transform: scale(0.98);
        background: rgba(255, 255, 255, 0.15);
    }

    .btn-action:disabled {
        opacity: 0.45;
        cursor: not-allowed;
    }

    /* ============================================
       BaseDetailSheet Component
       ============================================ */

    .base-detail {
        display: flex;
        flex-direction: column;
        gap: var(--space-4);
    }

    /* Header */
    .base-detail-header {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-2) 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .base-detail-icon {
        font-size: 40px;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    .base-detail-info {
        flex: 1;
        min-width: 0;
    }

    .base-detail-name {
        font-size: var(--text-lg);
        font-weight: 600;
        color: #fff;
        margin: 0 0 var(--space-1) 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .base-detail-level {
        font-size: var(--text-sm);
        color: var(--ui-warning);
        font-weight: 600;
        margin-right: var(--space-2);
    }

    .base-detail-capacity {
        font-size: var(--text-xs);
        color: var(--ui-neutral);
        font-weight: 500;
    }

    .base-detail-close-btn {
        width: 32px;
        height: 32px;
        background: rgba(255, 255, 255, 0.1);
        border: none;
        border-radius: 50%;
        color: #fff;
        font-size: 18px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        transition: all var(--duration-fast) ease;
    }

    .base-detail-close-btn:active {
        transform: scale(0.9);
        background: rgba(255, 255, 255, 0.2);
    }

    /* Resources Section */
    .base-detail-resources {
        display: flex;
        flex-direction: column;
        gap: var(--space-2);
    }

    .base-detail-resources label {
        font-size: var(--text-sm);
        color: var(--ui-neutral);
        font-weight: 500;
    }

    /* Quick Actions Section */
    .base-detail-quick-actions {
        display: flex;
        flex-direction: column;
        gap: var(--space-2);
    }

    .base-detail-quick-actions h3 {
        font-size: var(--text-base);
        color: #fff;
        margin: 0;
        font-weight: 600;
    }

    .action-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--space-2);
    }

    .action-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        min-height: 72px;
        padding: var(--space-2);
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: var(--radius-md);
        color: #fff;
        cursor: pointer;
        transition: all var(--duration-fast) ease;
    }

    .action-btn:active:not(.disabled) {
        transform: scale(0.95);
        background: rgba(255, 255, 255, 0.15);
    }

    .action-btn.disabled {
        opacity: 0.45;
        cursor: not-allowed;
        pointer-events: none;
    }

    .action-icon {
        font-size: 24px;
        line-height: 1;
    }

    .action-label {
        font-size: var(--text-sm);
        font-weight: 600;
        text-align: center;
    }

    .action-cost {
        font-size: 11px;
        color: var(--ui-neutral);
        font-weight: 500;
    }

    /* Heroes at Base Section */
    .base-detail-heroes {
        display: flex;
        flex-direction: column;
        gap: var(--space-2);
    }

    .base-detail-heroes h3 {
        font-size: var(--text-base);
        color: #fff;
        margin: 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-weight: 600;
    }

    .btn-expand-heroes {
        width: 24px;
        height: 24px;
        background: transparent;
        border: none;
        color: var(--ui-neutral);
        font-size: 20px;
        cursor: pointer;
        transition: transform var(--duration-fast) ease;
    }

    .btn-expand-heroes--rotated {
        transform: rotate(90deg);
    }

    .hero-list {
        list-style: none;
        margin: 0;
        padding: 0;
        display: flex;
        flex-direction: column;
        gap: var(--space-2);
        max-height: 120px;
        overflow-y: auto;
    }

    .hero-list--expanded {
        max-height: 300px;
    }

    .hero-list-item {
        padding: var(--space-2);
        background: rgba(255, 255, 255, 0.05);
        border-radius: var(--radius-md);
        font-size: var(--text-sm);
        color: #fff;
        cursor: pointer;
        transition: background var(--duration-fast) ease;
    }

    .hero-list-item:active {
        background: rgba(255, 255, 255, 0.1);
    }

    .hero-list-empty {
        padding: var(--space-3);
        text-align: center;
        font-size: var(--text-sm);
        color: var(--ui-neutral);
    }

    /* Desktop adjustments (≥1024px) */
    @media (min-width: 1024px) {
        .action-grid {
            grid-template-columns: repeat(4, 1fr);
        }

        .action-btn {
            min-height: 80px;
        }
    }

    /* ========== Safe area inset adjustments ========== */
    @supports (padding: env(safe-area-inset-bottom)) {
        .bottom-sheet {
            bottom: calc(-70% - env(safe-area-inset-bottom));
        }

        .bottom-sheet__content {
            padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
        }
    }
}