:root {
    --bg-color: #0c0d12;
    --card-bg: #141620;
    --panel-bg: #181b28;
    --item-bg: #222638;
    --text-main: #f1f3f9;
    --text-muted: #8a94a6;
    --accent-primary: #6366f1;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --border-color: #2b2f42;
    --input-bg: #0d0f17;
    --btn-default-bg: #1e2235;
    --btn-default-hover: #282c44;
    --surprise-bg: #2b2015;
    --danger-border: #6b1d1d;
    --danger-bg: rgba(239, 68, 68, 0.04);
    --danger-btn-bg: #5e1919;
    --danger-btn-color: #ffd6d6;
}

:root.light-theme {
    --bg-color: #f1f3f5;
    --card-bg: #ffffff;
    --panel-bg: #f8fafc;
    --item-bg: #f1f5f9;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --accent-primary: #4f46e5;
    --accent-success: #059669;
    --accent-warning: #d97706;
    --border-color: #e2e8f0;
    --input-bg: #ffffff;
    --btn-default-bg: #f8fafc;
    --btn-default-hover: #f1f5f9;
    --surprise-bg: #fef3c7;
    --danger-border: #fca5a5;
    --danger-bg: rgba(239, 68, 68, 0.05);
    --danger-btn-bg: #fee2e2;
    --danger-btn-color: #991b1b;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    transition: background-color 0.25s ease, color 0.25s ease;
}

#app {
    width: 100%;
    max-width: 500px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    margin: 40px auto;
    padding: 32px 32px 104px 32px; /* Bottom padding prevents nav overlap */
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
    position: relative;
    min-height: 700px;
    display: flex;
    flex-direction: column;
    transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

@media (max-width: 520px) {
    body {
        background-color: var(--card-bg);
    }
    #app {
        margin: 0;
        border-radius: 0;
        border: none;
        box-shadow: none;
        min-height: 100vh;
        padding: 24px 20px 96px 20px;
    }
}

.view-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
    animation: slideIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    flex: 1;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

h2 { 
    margin: 0; 
    font-size: 1.4rem; 
    font-weight: 700; 
    letter-spacing: -0.02em; 
    line-height: 1.25;
}

p { 
    margin: 0; 
    line-height: 1.45; 
    color: var(--text-muted); 
    font-size: 0.95rem;
}

/* BUTTONS & ERGONOMIC TOUCH TARGETS */
.btn {
    background-color: var(--btn-default-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 14px 20px;
    border-radius: 14px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    transition: transform 0.1s cubic-bezier(0.25, 1, 0.5, 1), background-color 0.15s ease, border-color 0.15s ease;
    min-height: 48px;
    user-select: none;
}
.btn:hover { background-color: var(--btn-default-hover); }
.btn:active { transform: scale(0.96); }

.btn-category {
    background-color: var(--btn-default-bg);
    border: 1px solid var(--border-color);
    min-height: 72px;
    height: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
}
.btn-category:hover { border-color: var(--accent-primary); background-color: var(--btn-default-hover); }

.btn-primary { 
    background-color: var(--accent-primary); 
    color: #ffffff;
    border-color: transparent; 
}
.btn-primary:hover { background-color: #4f46e5; }

.btn-success { 
    background-color: var(--accent-success); 
    color: #ffffff;
    border-color: transparent; 
}
.btn-success:hover { background-color: #059669; }

.btn-small { 
    padding: 8px 14px; 
    font-size: 0.8rem; 
    border-radius: 10px; 
    min-height: 36px;
}

.btn-secondary-muted {
    background-color: transparent;
    border: 1px dashed var(--border-color);
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 12px;
}
.btn-secondary-muted:hover {
    background-color: var(--btn-default-hover);
    color: var(--text-main);
}

.btn-option-reroll {
    background-color: var(--surprise-bg);
    border: 1px solid var(--accent-warning);
    color: var(--text-main);
}
.btn-option-reroll:hover {
    background-color: var(--btn-default-hover);
}

.btn-option-snooze {
    background-color: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--text-main);
}
.btn-option-snooze:hover {
    background-color: var(--btn-default-hover);
}

.category-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* ACTIVE TWIG EXECUTION CARD */
.twig-card {
    background-color: var(--panel-bg);
    border-left: 4px solid var(--accent-primary);
    border-top: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    padding: 24px;
    border-radius: 0 16px 16px 0;
    font-size: 1.15rem;
    font-weight: 500;
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.pencil-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease;
}
.pencil-btn:hover { background: var(--border-color); color: var(--text-main); }

.custom-textarea {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-main);
    padding: 12px;
    font-family: inherit;
    font-size: 0.95rem;
    box-sizing: border-box;
    resize: vertical;
}
.custom-textarea:focus { border-color: var(--accent-primary); outline: none; }

.custom-input {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    padding: 0 14px;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.15s ease;
    height: 48px;
    flex: 1;
    min-width: 0;
}
.custom-input:focus {
    border-color: var(--accent-primary);
}

.meta-group { display: flex; flex-direction: column; gap: 4px; }
.progress-text { font-size: 0.8rem; color: var(--accent-primary); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.button-stack { display: flex; flex-direction: column; gap: 10px; }

.tabs-container { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; }

.branch-accordion {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--panel-bg);
    overflow: hidden;
    margin-bottom: 10px;
}

.branch-header {
    background: var(--item-bg);
    padding: 14px 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}
.branch-header:hover { background: var(--btn-default-hover); }

.branch-content { display: none; padding: 16px; background: var(--panel-bg); flex-direction: column; gap: 16px; }
.branch-accordion.open .branch-content { display: flex; }
.branch-accordion.open .arrow { transform: rotate(90deg); }
.arrow { transition: transform 0.2s ease; display: inline-block; font-size: 0.8rem; }

.customizer-twig-item {
    background: var(--item-bg);
    padding: 14px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-left: 3px solid var(--border-color);
}
.customizer-twig-item.modified { border-left-color: var(--accent-warning); }

.twig-meta-row { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--text-muted); }

.settings-gear-btn {
    position: absolute;
    top: 24px;
    right: 24px;
    background: none;
    border: none;
    font-size: 1.45rem;
    cursor: pointer;
    z-index: 999;
    color: var(--text-muted);
    transition: color 0.15s ease, transform 0.2s ease;
    line-height: 1;
    padding: 4px;
}
.settings-gear-btn:hover {
    color: var(--text-main);
    transform: rotate(45deg);
}

/* PREMIUM BOTTOM TAB NAV BAR */
.mobile-nav-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 72px;
    background-color: var(--panel-bg);
    border-top: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border-bottom-left-radius: 24px;
    border-bottom-right-radius: 24px;
    overflow: hidden;
    z-index: 1000;
}

@media (max-width: 520px) {
    .mobile-nav-bar {
        position: fixed;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        height: calc(72px + env(safe-area-inset-bottom, 0px));
    }
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    transition: color 0.15s ease, transform 0.1s ease;
}
.mobile-nav-item:active {
    transform: scale(0.94);
}
.mobile-nav-item.active {
    color: var(--accent-primary);
}
.mobile-nav-icon {
    font-size: 1.3rem;
    line-height: 1;
}

/* HIGH-END DUAL GRID PLANNER CARDS */
.planner-tiles-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
}

.planner-tile {
    background-color: var(--item-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    height: 96px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    transition: transform 0.1s cubic-bezier(0.25, 1, 0.5, 1), background-color 0.15s ease, border-color 0.15s ease;
}
.planner-tile:active {
    transform: scale(0.95);
}
.planner-tile.active {
    border-color: var(--accent-primary);
    background-color: var(--panel-bg);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.08);
}
.planner-tile-icon {
    font-size: 1.5rem;
    line-height: 1;
}
.planner-tile-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.planner-tile.active .planner-tile-label {
    color: var(--accent-primary);
}
.planner-tile-badge {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text-main);
}

/* SCRATCHPAD & TODAY'S LIST */
.scratchpad-add-row {
    display: flex;
    gap: 8px;
}
.scratchpad-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.scratchpad-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--item-bg);
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

/* HIGH-DENSITY 2-COLUMN BADGES GRID */
.badges-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
}

.badge-box {
    background-color: var(--item-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 8px;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}
.badge-box.unlocked {
    border-color: var(--accent-primary);
    background-color: rgba(99, 102, 241, 0.03);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.04);
}
.badge-box-icon {
    font-size: 2rem;
    line-height: 1;
    transition: filter 0.15s ease;
}
.badge-box.locked .badge-box-icon {
    filter: grayscale(100%) opacity(25%);
}
.badge-box-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.25;
}
.badge-box.locked .badge-box-title {
    color: var(--text-muted);
}
.badge-box-status {
    font-size: 0.62rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}
.badge-box.unlocked .badge-box-status {
    color: var(--accent-success);
}

.toast-notification {
    position: fixed;
    bottom: 96px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background-color: var(--accent-success);
    color: #ffffff;
    padding: 12px 24px;
    border-radius: 50px;
    font-size: 0.9rem;
    font-weight: bold;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 2000;
    text-align: center;
    white-space: nowrap;
}
.toast-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* STABILITY & CUSTOM ALERTS IMPROVEMENTS */
.live-action-area {
    min-height: 110px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.scratchpad-warning-inline {
    background-color: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--text-main);
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 8px;
    animation: slideIn 0.22s ease-out;
}

.room-aura-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    display: block;
}

/* FIRST-RUN ONBOARDING OVERLAY STYLES */
.onboarding-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.onboarding-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 32px;
    max-width: 420px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    animation: slideIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    text-align: left;
}

.onboarding-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
}

.onboarding-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--border-color);
    transition: background-color 0.2s ease;
}

.onboarding-dot.active {
    background-color: var(--accent-primary);
}

.onboarding-content-area {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.onboarding-subtitle {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.onboarding-text {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-main);
    margin: 0;
}

.onboarding-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.onboarding-footer.centered-single {
    justify-content: center;
}

.onboarding-back-btn {
    background-color: var(--btn-default-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.onboarding-next-btn,
.onboarding-begin-btn {
    flex: 1;
}

.onboarding-footer.centered-single .onboarding-begin-btn {
    max-width: 200px;
    width: 100%;
}

/* HELP SECTION STYLES */
.settings-help-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-help-title {
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: block;
}

.help-replay-btn {
    background-color: var(--btn-default-bg);
    border: 1px solid var(--border-color);
    font-size: 0.9rem;
    padding: 12px;
    font-weight: 600;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* CONTEXTUAL HELP PANELS ENGINE */
.meta-group-relative {
    position: relative;
    padding-right: 44px;
}

.meta-group-relative.offset-gear {
    padding-right: 80px;
}

.help-trigger-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: var(--btn-default-bg);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    padding: 0;
}

.help-trigger-btn:hover {
    background-color: var(--btn-default-hover);
    color: var(--text-main);
    border-color: var(--accent-primary);
}

.meta-group-relative.offset-gear .help-trigger-btn {
    right: 36px;
}

.help-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(12, 13, 18, 0.6);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 4000;
}

.help-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.help-panel {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    width: 100%;
    max-width: 500px;
    background-color: var(--card-bg);
    border-top: 1px solid var(--border-color);
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    padding: 24px;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.3);
    z-index: 4001;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
}

.help-panel.active {
    transform: translateX(-50%) translateY(0);
}

.help-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.help-panel-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent-primary);
}

.help-panel-close-btn {
    background-color: var(--btn-default-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.help-panel-close-btn:hover {
    background-color: var(--btn-default-hover);
}

.help-panel-body {
    text-align: left;
}

.help-panel-text {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-main);
    margin: 0;
}

/* LANGUAGE SELECT LAYOUT OVERLAYS */
.language-select-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.language-select-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 32px;
    max-width: 420px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    animation: slideIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    text-align: center;
}

.language-select-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.language-select-h2 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.35;
}

.language-select-p {
    font-size: 0.82rem;
    line-height: 1.45;
    color: var(--text-muted);
}

.language-large-btn {
    width: 100%;
    min-height: 56px;
    font-size: 1.05rem;
    font-weight: 700;
}

/* SETTINGS LANGUAGE BUTTON STATES */
.language-toggle-btn {
    font-size: 0.85rem;
    font-weight: 600;
}

.language-toggle-btn.active {
    background-color: var(--accent-primary);
    color: #ffffff;
    border-color: transparent;
}