:root {
    --primary: #8B0000;
    --primary-dark: #5C0000;
    --primary-light: #B22222;
    --accent: #DC143C;
    
    /* Light Mode (Default) */
    --bg-main: #f4f4f9;
    --bg-card: #ffffff;
    --bg-input: #f0f0f0;
    --text-main: #222222;
    --text-muted: #666666;
    --border-color: #dddddd;
    
    --success: #2ecc71;
    --warning: #f39c12;
    --card-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

body.dark-mode {
    /* Premium Dark Mode */
    --bg-main: #1a1a1a;
    --bg-card: #2a2a2a;
    --bg-input: #333333;
    --text-main: #f5f5f5;
    --text-muted: #aaaaaa;
    --border-color: #444444;
    --card-shadow: 0 4px 15px rgba(0,0,0,0.4);
}

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

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: var(--bg-main);
            color: var(--text-main);
            min-height: 100vh;
            padding-bottom: 80px;
        }

        /* Header */
        header {
            background: linear-gradient(135deg, var(--primary-dark), var(--primary));
            padding: 12px 15px;
            position: sticky;
            top: 0;
            z-index: 100;
            box-shadow: 0 2px 10px rgba(0,0,0,0.5);
        }

        .header-content {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 10px;
        }

        .header-left {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .hamburger {
            background: none;
            border: none;
            cursor: pointer;
            padding: 8px;
            display: flex;
            flex-direction: column;
            gap: 4px;
        }

        .hamburger span {
            display: block;
            width: 22px;
            height: 2px;
            background: white;
            border-radius: 1px;
            transition: transform 0.3s;
        }

        .header-title {
            font-size: 1.1em;
            font-weight: bold;
            color: #ffffff;
        }

        .header-info {
            display: flex;
            gap: 15px;
            font-size: 0.9em;
            color: rgba(255,255,255,0.9);
        }

        .header-info span {
            background: rgba(0,0,0,0.3);
            padding: 4px 10px;
            border-radius: 4px;
        }

        /* Side Menu */
        .menu-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0,0,0,0.6);
            z-index: 200;
            opacity: 0;
            visibility: hidden;
            transition: opacity 0.3s, visibility 0.3s;
        }

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

        .side-menu {
            position: fixed;
            top: 0;
            left: -280px;
            width: 280px;
            height: 100%;
            background: var(--bg-card);
            z-index: 201;
            transition: left 0.3s ease;
            display: flex;
            flex-direction: column;
        }

        .side-menu.open {
            left: 0;
        }

        .menu-header {
            background: var(--primary);
            padding: 20px 15px;
            font-size: 1.2em;
            font-weight: bold;
        }

        .menu-items {
            flex: 1;
            padding: 10px 0;
        }

        .menu-item {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 15px 20px;
            color: var(--text-main);
            text-decoration: none;
            font-size: 0.95em;
            cursor: pointer;
            transition: background 0.2s;
            border: none;
            background: none;
            width: 100%;
            text-align: left;
        }

        .menu-item:hover {
            background: rgba(220, 20, 60, 0.1);
        }

        .menu-item svg {
            width: 20px;
            height: 20px;
            fill: var(--accent);
        }

        .menu-divider {
            height: 1px;
            background: var(--border-color);
            margin: 10px 0;
        }

        .menu-section-title {
            padding: 10px 20px 5px;
            font-size: 0.75em;
            color: var(--text-muted);
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        /* User Auth Section */
        .user-section {
            padding: 15px;
            background: rgba(0,0,0,0.2);
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: var(--primary);
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            font-size: 1.2em;
            overflow: hidden;
        }

        .user-avatar img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .user-info {
            flex: 1;
            overflow: hidden;
        }

        .user-name {
            font-weight: bold;
            font-size: 0.95em;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .user-email {
            font-size: 0.75em;
            color: var(--text-muted);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .login-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            width: 100%;
            padding: 12px;
            background: white;
            color: #333;
            border: none;
            border-radius: 6px;
            font-weight: bold;
            cursor: pointer;
            font-size: 0.9em;
        }

        .login-btn:hover {
            background: #f0f0f0;
        }

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

        .sync-status {
            font-size: 0.7em;
            color: var(--success);
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .sync-status.offline {
            color: var(--text-muted);
        }

        /* Main Layout */
        main {
            max-width: 1200px;
            margin: 0 auto;
            padding: 15px;
            display: grid;
            gap: 15px;
        }

        /* Cards */
        .card {
            background: var(--bg-card);
            border-radius: 12px;
            padding: 15px;
            border: 1px solid var(--border-color);
            box-shadow: var(--card-shadow);
        }

        .card-title {
            color: var(--accent);
            font-size: 0.85em;
            font-weight: bold;
            text-transform: uppercase;
            letter-spacing: 1px;
            margin-bottom: 12px;
            padding-bottom: 8px;
            border-bottom: 1px solid var(--border-color);
        }

        /* Form Elements */
        input, select, textarea {
            background: var(--bg-input);
            border: 1px solid var(--border-color);
            color: var(--text-main);
            padding: 10px 12px;
            border-radius: 6px;
            font-size: 16px; /* Prevents iOS Safari from zooming in */
            width: 100%;
            transition: border-color 0.2s, box-shadow 0.2s;
        }

        input:focus, select:focus, textarea:focus {
            outline: none;
            border-color: var(--accent);
            box-shadow: 0 0 0 2px rgba(220, 20, 60, 0.2);
        }

        input[type="number"] {
            text-align: center;
            -moz-appearance: textfield;
        }

        input[type="number"]::-webkit-outer-spin-button,
        input[type="number"]::-webkit-inner-spin-button {
            -webkit-appearance: none;
        }

        label {
            display: block;
            font-size: 0.75em;
            color: var(--text-muted);
            margin-bottom: 6px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        /* Grid Layouts */
        .grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
        .grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
        .grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
        .grid-6 { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }

        /* Basic Info Section */
        #basic-info .grid-2 {
            margin-bottom: 10px;
        }

        /* Ability Scores */
        .ability-block {
            text-align: center;
            background: var(--bg-input);
            border-radius: 8px;
            padding: 10px 5px;
            border: 1px solid var(--border-color);
        }

        .ability-block:hover {
            border-color: var(--accent);
        }

        .ability-name {
            font-size: 0.7em;
            font-weight: bold;
            color: var(--accent);
            margin-bottom: 5px;
        }

        .ability-mod {
            font-size: 1.5em;
            font-weight: bold;
            margin-bottom: 5px;
        }

        .ability-score input {
            width: 50px;
            padding: 5px;
            font-size: 14px;
        }

        /* Combat Stats */
        .combat-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
            gap: 10px;
        }

        .stat-box {
            text-align: center;
            background: var(--bg-input);
            border-radius: 8px;
            padding: 12px 4px;
            border: 1px solid var(--border-color);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 85px;
        }

        .stat-box.highlight {
            border-color: var(--accent);
            background: rgba(220, 20, 60, 0.1);
        }

        .stat-value {
            font-size: 1.8em;
            font-weight: bold;
            line-height: 1.2;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 1.4em; /* Fixed height to match inputs */
        }

        .stat-value input {
            font-size: 1em; /* Inherit from .stat-value */
            font-family: inherit;
            font-weight: bold;
            width: 100%;
            padding: 0;
            background: transparent;
            border: none;
            text-align: center;
            color: inherit;
            height: 100%;
            margin: 0;
            outline: none;
        }

        .stat-label {
            font-size: 0.62em;
            color: var(--text-muted);
            text-transform: uppercase;
            margin-top: 5px;
            text-align: center;
            width: 100%;
            white-space: nowrap;
            letter-spacing: 0.3px;
        }

        /* HP Section */
        .hp-container {
            display: flex;
            gap: 10px;
            align-items: center;
            flex-wrap: wrap;
        }

        .hp-box {
            flex: 1;
            min-width: 70px;
            text-align: center;
        }

        .hp-current input {
            font-size: 1.8em;
            font-weight: bold;
            color: var(--success);
            width: 70px;
        }

        .hp-divider {
            font-size: 1.5em;
            color: var(--text-muted);
        }

        .hp-max input {
            font-size: 1.2em;
            width: 60px;
        }

        .hp-temp input {
            font-size: 1em;
            width: 50px;
            color: var(--warning);
        }

        /* Death Saves */
        .death-saves {
            display: flex;
            gap: 20px;
            justify-content: center;
            margin-top: 10px;
        }

        .save-group {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .save-group span {
            font-size: 0.8em;
            color: var(--text-muted);
        }

        .save-dots {
            display: flex;
            gap: 5px;
        }

        .save-dot {
            width: 18px;
            height: 18px;
            border-radius: 50%;
            border: 2px solid var(--border-color);
            background: transparent;
            cursor: pointer;
            transition: all 0.2s;
        }

        .save-dot.success.active {
            background: var(--success);
            border-color: var(--success);
        }

        .save-dot.failure.active {
            background: var(--accent);
            border-color: var(--accent);
        }

        /* Skills & Saves */
        .skill-list {
            display: grid;
            gap: 6px;
        }

        .skill-item, .save-item {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 6px 8px;
            background: var(--bg-input);
            border-radius: 4px;
            font-size: 0.85em;
        }

        .skill-item:hover, .save-item:hover {
            background: rgba(220, 20, 60, 0.1);
        }

        .prof-checkbox {
            width: 16px;
            height: 16px;
            cursor: pointer;
            accent-color: var(--accent);
        }

        .skill-mod {
            font-weight: bold;
            min-width: 30px;
            text-align: center;
            color: var(--accent);
        }

        .skill-name {
            flex: 1;
        }

        .skill-ability {
            font-size: 0.7em;
            color: var(--text-muted);
            text-transform: uppercase;
        }

        .expertise-checkbox {
            width: 14px;
            height: 14px;
            cursor: pointer;
            accent-color: var(--warning);
        }

        /* Attacks */
        .attack-row {
            display: grid;
            grid-template-columns: 2fr 1fr 2fr 1fr auto;
            gap: 8px;
            margin-bottom: 8px;
            align-items: center;
        }

        .attack-row input {
            padding: 6px 8px;
            font-size: 0.85em;
        }

        .btn-remove {
            background: var(--accent);
            border: none;
            color: white;
            width: 28px;
            height: 28px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 1.2em;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .btn-add {
            background: var(--primary);
            border: none;
            color: white;
            padding: 8px 15px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 0.85em;
            margin-top: 10px;
        }

        .btn-add:hover, .btn-remove:hover {
            opacity: 0.9;
        }

        /* Spellcasting */
        .spell-header {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 10px;
            margin-bottom: 15px;
        }

        .spell-slots {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-bottom: 15px;
        }

        .slot-group {
            text-align: center;
            background: var(--bg-input);
            padding: 8px;
            border-radius: 6px;
            min-width: 60px;
        }

        .slot-level {
            font-size: 0.7em;
            color: var(--text-muted);
            margin-bottom: 4px;
        }

        .slot-inputs {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 3px;
        }

        .slot-inputs input {
            width: 25px;
            padding: 4px;
            font-size: 0.9em;
        }

        .spell-list-container textarea {
            min-height: 100px;
            font-size: 0.9em;
        }

        /* Equipment */
        .currency-row {
            display: flex;
            gap: 8px;
            margin-bottom: 15px;
            flex-wrap: wrap;
        }

        .currency-item {
            display: flex;
            align-items: center;
            gap: 5px;
            background: var(--bg-input);
            padding: 6px 10px;
            border-radius: 4px;
        }

        .currency-item label {
            margin: 0;
            font-weight: bold;
        }

        .currency-item input {
            width: 60px;
            padding: 5px;
        }

        .equipment-list textarea {
            min-height: 150px;
            font-size: 0.9em;
        }

        /* Features & Traits */
        .features-list textarea {
            min-height: 120px;
            font-size: 0.9em;
            margin-bottom: 10px;
        }

        /* Personality */
        .personality-section textarea {
            min-height: 60px;
            font-size: 0.9em;
            margin-bottom: 10px;
        }

        /* Notes */
        .notes-area textarea {
            min-height: 100px;
        }

        /* Footer Actions */
        .footer-actions {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background: var(--bg-card);
            padding: 12px 20px;
            border-top: 1px solid var(--border-color);
            z-index: 100;
        }

        .btn {
            padding: 14px 30px;
            border: none;
            border-radius: 8px;
            font-weight: bold;
            cursor: pointer;
            font-size: 1em;
            transition: transform 0.2s;
            text-align: center;
            width: 100%;
        }

        .btn:hover {
            transform: translateY(-1px);
        }

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

        .btn-reset {
            background: var(--border-color);
            color: var(--text-main);
        }

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

        /* Save Indicator */
        .save-indicator {
            position: fixed;
            top: 70px;
            right: 20px;
            background: var(--success);
            color: white;
            padding: 8px 15px;
            border-radius: 4px;
            font-size: 0.85em;
            opacity: 0;
            transition: opacity 0.3s;
            z-index: 200;
        }

        .save-indicator.show {
            opacity: 1;
        }

        /* Responsive */
        @media (max-width: 768px) {
            .grid-6 { grid-template-columns: repeat(3, 1fr); }
            .grid-4 { grid-template-columns: repeat(2, 1fr); }
            .combat-grid { grid-template-columns: repeat(auto-fit, minmax(125px, 1fr)); }
            .attack-row { grid-template-columns: 1fr 1fr; }
            .attack-row input:nth-child(1) { grid-column: 1 / -1; }
            .header-info { display: none; }
            .spell-header { grid-template-columns: 1fr; }
        }


        /* Modal */
        .modal-overlay {
            position: fixed;
            top: 0; left: 0; right: 0; bottom: 0;
            background: rgba(0,0,0,0.7);
            z-index: 300;
            display: none;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

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

        .modal {
            background: var(--bg-card);
            border-radius: 12px;
            padding: 25px;
            max-width: 500px;
            width: 100%;
            max-height: 85vh;
            overflow-y: auto;
            border: 1px solid var(--border-color);
        }

        .modal h3 {
            color: var(--accent);
            margin-bottom: 15px;
            font-size: 1.1em;
        }

        .modal input[type="text"] {
            margin-bottom: 12px;
        }

        .modal-actions {
            display: flex;
            gap: 10px;
            margin-top: 20px;
        }

        .modal-actions button {
            flex: 1;
            padding: 12px;
            border: none;
            border-radius: 6px;
            font-weight: bold;
            cursor: pointer;
            font-size: 0.9em;
        }

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

        .modal-btn-secondary {
            background: var(--border-color);
            color: var(--text-main);
        }

        .invite-code-display {
            background: var(--bg-input);
            border: 2px dashed var(--accent);
            padding: 15px;
            border-radius: 8px;
            text-align: center;
            margin: 15px 0;
        }

        .invite-code-display .code {
            font-size: 1.8em;
            font-weight: bold;
            color: var(--accent);
            letter-spacing: 3px;
            font-family: monospace;
        }

        .invite-code-display .label {
            font-size: 0.75em;
            color: var(--text-muted);
            margin-top: 5px;
        }

        /* DM Dashboard */
        .dm-dashboard {
            display: none;
        }

        .dm-dashboard.active {
            display: block;
        }

        .dm-char-card {
            background: var(--bg-input);
            border: 1px solid var(--border-color);
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 10px;
        }

        .dm-char-card:hover {
            border-color: var(--accent);
        }

        .dm-char-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
        }

        .dm-char-name {
            font-weight: bold;
            font-size: 1.1em;
        }

        .dm-char-meta {
            font-size: 0.8em;
            color: var(--text-muted);
        }

        .dm-char-stats {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
            gap: 8px;
            margin-top: 10px;
        }

        .dm-stat {
            text-align: center;
            background: var(--bg-card);
            padding: 6px;
            border-radius: 4px;
            font-size: 0.85em;
        }

        .dm-stat .val {
            font-weight: bold;
            color: var(--accent);
        }

        .dm-stat .lbl {
            font-size: 0.7em;
            color: var(--text-muted);
        }

        .dm-transfer-btn {
            background: var(--primary);
            color: white;
            border: none;
            padding: 8px 12px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 0.8em;
            margin-top: 8px;
        }

        .dm-transfer-btn:hover {
            background: var(--primary-light);
        }

        .campaign-badge {
            display: inline-block;
            background: var(--primary);
            color: white;
            padding: 2px 8px;
            border-radius: 10px;
            font-size: 0.7em;
            margin-left: 8px;
        }

        .transfer-list {
            margin-top: 10px;
        }

        .transfer-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            background: var(--bg-input);
            padding: 10px 12px;
            border-radius: 6px;
            margin-bottom: 6px;
            font-size: 0.9em;
        }

        .transfer-item .transfer-info {
            flex: 1;
        }

        .transfer-item .transfer-from {
            font-size: 0.75em;
            color: var(--text-muted);
        }

        .transfer-accept {
            background: var(--success);
            color: white;
            border: none;
            padding: 6px 12px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 0.8em;
            margin-left: 8px;
        }

        .transfer-reject {
            background: var(--accent);
            color: white;
            border: none;
            padding: 6px 12px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 0.8em;
            margin-left: 4px;
        }

        .member-list {
            margin-top: 10px;
        }

        .member-item {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 8px 12px;
            background: var(--bg-input);
            border-radius: 6px;
            margin-bottom: 6px;
        }

        .member-item .member-role {
            font-size: 0.7em;
            color: var(--warning);
            text-transform: uppercase;
        }

        @media (min-width: 769px) {
            main {
                grid-template-columns: repeat(2, 1fr);
            }

            #basic-info {
                grid-column: span 2;
            }

            #abilities {
                grid-column: span 2;
            }

            #combat, #attacks, #spellcasting, #equipment, #features, #personality, #notes {
                grid-column: span 1;
            }
        }

        @media (min-width: 1024px) {
            main {
                grid-template-columns: repeat(3, 1fr);
            }

            #basic-info {
                grid-column: span 3;
            }

            #abilities {
                grid-column: span 3;
            }

            #skills {
                grid-column: span 1;
                grid-row: span 2;
            }

            #saves {
                grid-column: span 1;
            }
        }