:root {
    /* Color Palette - Minimalist / Swiss Style */
    --bg-app: #f4f5f7;
    --bg-card: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-light: #e5e7eb;
    
    /* Brand / Action */
    --primary: #334155; /* Slate */
    --primary-hover: #1e293b;
    --secondary: #ffffff;
    --secondary-hover: #f9fafb;
    
    /* Functional Colors */
    --c-success: #10b981;
    --c-danger: #ef4444;
    --c-warning: #f59e0b;
    --c-info: #3b82f6;

    /* Spacing */
    --radius: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

/* Reset & Base */
* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-size: 16px;
    line-height: 1.5;
}

/* Main Wrapper */
.main-wrapper {
    width: 100%;
    max-width: 550px;
    padding: 20px;
}

.container {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 30px;
    height: 90vh; /* Fixed height for the main container */
    max-height: 900px;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Typography */
h1, h2, h3 { margin: 0 0 10px 0; font-weight: 700; letter-spacing: -0.02em; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.4rem; }
p { margin: 0 0 15px 0; color: var(--text-muted); }

/* Buttons */
button {
    font-family: inherit;
    border: none;
    cursor: pointer;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-primary {
    background-color: var(--primary);
    color: #fff;
    padding: 14px 20px;
    width: 100%;
}
.btn-primary:hover { background-color: var(--primary-hover); transform: translateY(-1px); }
.btn-primary:disabled { background-color: var(--border-light); color: var(--text-muted); cursor: not-allowed; transform: none; }

.btn-secondary {
    background-color: var(--secondary);
    color: var(--text-main);
    border: 1px solid var(--border-light);
    padding: 14px 20px;
    width: 100%;
}
.btn-secondary:hover { background-color: var(--secondary-hover); border-color: #d1d5db; }

.btn-text {
    background: none;
    color: var(--text-muted);
    text-decoration: underline;
    font-size: 0.85rem;
    padding: 10px;
}
.btn-text:hover { color: var(--text-main); }

.btn-stop { background-color: var(--c-danger) !important; color: white !important; border: none; }

/* Views */
.view { display: none; height: 100%; flex-direction: column; }
.view.active { display: flex; animation: fadeIn 0.4s ease; }
.hidden { display: none !important; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* === Home View === */
.home-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    padding: 40px 0;
}
.home-header { margin-bottom: 40px; }
.subtitle { font-size: 0.85rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.hero-section { margin-bottom: 50px; }

/* === Talents & Shop Grid === */
.grid-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
    flex: 1;
    overflow-y: auto;
    padding: 4px; /* prevent shadow clip */
}

.talent-card, .shop-card {
    background: #fff;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.talent-card:hover, .shop-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.talent-card.selected {
    background-color: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.talent-card.selected .talent-desc { color: rgba(255,255,255,0.8); }
.talent-name, .shop-name { font-weight: 600; font-size: 0.95rem; margin-bottom: 5px; display: block; }
.talent-desc, .shop-desc { font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; }

.shop-price { font-weight: 600; margin-top: 10px; font-size: 0.85rem; color: var(--c-success); display: block; }
.shop-owned { opacity: 0.6; background: #fafafa; }
.shop-recurring {
    display: inline-block;
    margin-top: 8px;
    font-size: 0.75rem;
    color: #ef4444; /* Red warning color */
    background-color: #fef2f2; /* Light red background */
    border: 1px solid #fee2e2;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 600;
}
/* === Stats Allocation === */
.points-badge {
    background: var(--bg-app); padding: 5px 10px; border-radius: 20px;
    font-size: 0.85rem; font-weight: 600; color: var(--text-main); display: inline-block;
}
.stats-container { margin: 20px 0; display: flex; flex-direction: column; gap: 15px; }
.stat-control {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px; background: #fff; border-bottom: 1px solid var(--border-light);
}
.stat-info { display: flex; flex-direction: column; }
.stat-name { font-weight: 600; font-size: 1rem; }
.stat-meta { font-size: 0.75rem; color: var(--text-muted); }
.control-group { display: flex; align-items: center; gap: 12px; }
.btn-icon {
    width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border-light);
    background: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; color: var(--primary); padding: 0;
}
.btn-icon:hover { background: var(--bg-app); }
.stat-display { font-weight: 700; font-size: 1.1rem; min-width: 25px; text-align: center; font-variant-numeric: tabular-nums; }
.vertical-gap { display: flex; flex-direction: column; gap: 10px; }

/* === Game HUD === */
.hud {
    background: var(--bg-app);
    border-radius: var(--radius);
    padding: 15px;
    margin-bottom: 15px;
    flex-shrink: 0;
}
.stats-row {
    display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 15px;
}
.stat-pill {
    background: #fff; padding: 6px 10px; border-radius: 6px;
    font-size: 0.75rem; font-weight: 600; color: var(--text-muted);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05); flex: 1; text-align: center;
    white-space: nowrap;
}
.stat-pill span { color: var(--text-main); font-weight: 700; margin-left: 4px; }
.stat-pill.highlight span { color: var(--c-warning); }

.assets-row {
    display: flex; justify-content: space-between; border-top: 1px solid rgba(0,0,0,0.05); padding-top: 10px;
}
.asset-item { text-align: center; flex: 1; }
.asset-item .label { display: block; font-size: 0.65rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: 2px; }
.asset-item .value { font-weight: 700; font-size: 0.95rem; font-variant-numeric: tabular-nums; color: var(--c-success); }

/* === Game Log (FIXED) === */
.death-wrapper {
    display: block; /* Override grid display */
    background: #fef2f2;
}
.dead-text {
    text-align: center;
    color: var(--c-danger);
    font-weight: 700;
    padding: 15px;
}
.log-container {
    flex: 1; /* Takes up remaining space */
    overflow-y: auto; /* Scrollable */
    padding: 10px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: #fff;
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    /* Fixed scroll behavior fix */
    min-height: 0; 
}

/* New Grid Layout for alignment */
.log-entry {
    display: grid;
    grid-template-columns: 40px 1fr; /* Fixed Age width | Flexible Content width */
    gap: 12px;
    align-items: start;
    font-size: 0.9rem;
}

.log-age {
    background: var(--text-main); 
    color: #fff; 
    font-size: 0.75rem;
    padding: 4px 0;
    border-radius: 4px; 
    font-weight: 700; 
    text-align: center;
    margin-top: 2px; /* Visual optical alignment */
}

/* The text wrapper now handles the background colors, not the parent row */
.log-text { 
    color: var(--text-main); 
    padding: 6px 10px;
    border-radius: 6px;
    line-height: 1.5;
}

/* Modifiers applied to log-text */
.log-text.major { background: #fffbeb; border-left: 3px solid var(--c-warning); }
.log-text.bad { background: #fef2f2; border-left: 3px solid var(--c-danger); }
.log-text.good { background: #ecfdf5; border-left: 3px solid var(--c-success); }
.log-text.dead { color: var(--c-danger); font-weight: 700; background: #fef2f2; }

.dead-entry { 
    grid-column: 1 / -1; /* Span full width */
    text-align: center;
    color: var(--c-danger); 
    font-weight: 700; 
    background: #fef2f2; 
    padding: 15px; 
    border-radius: var(--radius); 
}

/* === Controls === */
.controls-area { margin-top: auto; flex-shrink: 0; }
.secondary-controls { display: flex; gap: 10px; margin-top: 10px; }

/* === Shop === */
.shop-wallet { text-align: right; color: var(--c-success); font-weight: 700; font-family: monospace; }
.footer-action { margin-top: auto; padding-top: 15px; flex-shrink: 0; }

/* === Summary === */
.report-card { text-align: center; animation: fadeIn 0.5s; flex: 1; overflow-y: auto; }
.rank-badge {
    background: var(--text-main); color: #fff; padding: 5px 15px;
    border-radius: 20px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px;
    display: inline-block; margin-bottom: 15px;
}
.final-score { font-size: 3rem; font-weight: 800; color: var(--primary); line-height: 1; margin-bottom: 5px; }
.final-networth { color: var(--c-success); font-weight: 600; margin-bottom: 30px; }

.summary-stats-grid {
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; margin-bottom: 30px;
}
.s-stat { display: flex; flex-direction: column; align-items: center; background: var(--bg-app); padding: 10px 5px; border-radius: 6px; }
.s-lbl { font-size: 0.6rem; text-transform: uppercase; color: var(--text-muted); }
.s-val { font-weight: 700; font-size: 1.1rem; }

.summary-details { text-align: left; background: var(--bg-app); padding: 20px; border-radius: var(--radius); }
.detail-item { margin-bottom: 10px; border-bottom: 1px dashed var(--border-light); padding-bottom: 10px; }
.detail-item:last-child { border: none; margin: 0; padding: 0; }
.d-label { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; color: var(--text-muted); display: block; }
.d-content { font-size: 0.95rem; color: var(--text-main); }

/* === Toast === */
#toast-container { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast {
    background: rgba(0,0,0,0.85); color: #fff; padding: 12px 24px;
    border-radius: 50px; font-size: 0.9rem; font-weight: 500;
    backdrop-filter: blur(4px); animation: fadeUp 0.3s ease;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
/* Achievements Grid in Summary */
.ach-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
    margin-top: 5px;
}

.ach-badge {
    background: #fff;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 10px 5px;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: transform 0.2s;
}

.ach-badge:hover {
    transform: translateY(-2px);
    border-color: var(--c-warning);
}

.ach-icon {
    font-size: 1.5rem;
    margin-bottom: 5px;
}

.ach-name {
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-main);
}

.ach-empty {
    grid-column: 1 / -1;
    text-align: center;
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 10px;
}
/* Mobile Tweak */
@media (max-width: 480px) {
    .main-wrapper { padding: 0; }
    .container { height: 100vh; max-height: none; border-radius: 0; padding: 20px; }
    .hero-section { display: none; }
    .log-entry { font-size: 0.6rem;}
    .asset-item .value { font-size: 0.7rem; }

}