* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg: #0a0f0a;
    --bg-card: rgba(0, 230, 118, 0.06);
    --bg-card-hover: rgba(0, 230, 118, 0.12);
    --accent: #00e676;
    --accent-dim: rgba(0, 230, 118, 0.3);
    --secondary: #00bcd4;
    --text: #e0e0e0;
    --text-dim: #888;
    --text-bright: #fff;
    --danger: #ff5252;
    --gold: #ffd700;
    --border: rgba(0, 230, 118, 0.15);
    --radius: 16px;
    --radius-sm: 10px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --header-h: 56px;
    --tab-h: 64px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
}

/* ===== HEADER ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-h);
    padding: 0 16px;
    background: rgba(10, 15, 10, 0.95);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.logo-icon {
    font-size: 24px;
    filter: drop-shadow(0 0 8px var(--accent));
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.streak-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 215, 0, 0.15);
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid rgba(255, 215, 0, 0.3);
}

.streak-fire { font-size: 16px; }
.streak-num {
    font-size: 14px;
    font-weight: 700;
    color: var(--gold);
}

/* ===== SCREENS ===== */
.screen-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 16px);
    scroll-behavior: smooth;
}

.screen-container::-webkit-scrollbar { display: none; }

.screen-header {
    margin-bottom: 20px;
}

.screen-header h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-bright);
    margin-bottom: 4px;
}

.screen-subtitle {
    font-size: 14px;
    color: var(--text-dim);
}

/* ===== TAB BAR ===== */
.tab-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: var(--tab-h);
    padding-bottom: var(--safe-bottom);
    background: rgba(10, 15, 10, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    position: sticky;
    bottom: 0;
    z-index: 100;
}

.tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 11px;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: var(--radius-sm);
    position: relative;
}

.tab.active {
    color: var(--accent);
}

.tab.active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: var(--accent);
    border-radius: 0 0 3px 3px;
}

.tab-icon { font-size: 22px; }
.tab-label { font-weight: 500; }

/* ===== ENCYCLOPEDIA ===== */
.chapters-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chapter-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    cursor: pointer;
    transition: all 0.25s;
    display: flex;
    align-items: center;
    gap: 14px;
}

.chapter-card:hover, .chapter-card:active {
    background: var(--bg-card-hover);
    border-color: var(--accent-dim);
    transform: translateY(-1px);
}

.chapter-icon {
    font-size: 36px;
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 230, 118, 0.1);
    border-radius: 14px;
}

.chapter-info { flex: 1; }

.chapter-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-bright);
    margin-bottom: 4px;
}

.chapter-desc {
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.4;
}

.chapter-arrow {
    color: var(--accent-dim);
    font-size: 18px;
    flex-shrink: 0;
}

/* Chapter detail */
.chapter-detail {
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

.back-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    padding: 8px 0;
    margin-bottom: 12px;
}

.chapter-content {
    line-height: 1.7;
    font-size: 15px;
}

.chapter-content h3 {
    font-size: 20px;
    color: var(--text-bright);
    margin: 24px 0 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chapter-content h3:first-child {
    margin-top: 0;
}

.chapter-content p {
    margin-bottom: 12px;
    color: var(--text);
}

.chapter-content .fact-box {
    background: rgba(0, 230, 118, 0.08);
    border-left: 3px solid var(--accent);
    padding: 14px 16px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin: 16px 0;
    font-size: 14px;
}

.chapter-content .fact-box .fact-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 6px;
}

.chapter-content .danger-box {
    background: rgba(255, 82, 82, 0.08);
    border-left: 3px solid var(--danger);
    padding: 14px 16px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin: 16px 0;
    font-size: 14px;
}

.chapter-content .danger-box .fact-label {
    color: var(--danger);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    margin-bottom: 6px;
}

.chapter-content ul {
    padding-left: 20px;
    margin-bottom: 12px;
}

.chapter-content li {
    margin-bottom: 8px;
    color: var(--text);
}

.chapter-content strong {
    color: var(--text-bright);
}

.nutrient-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 16px 0;
}

.nutrient-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    text-align: center;
}

.nutrient-icon { font-size: 28px; margin-bottom: 4px; }
.nutrient-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-bright);
    margin-bottom: 2px;
}
.nutrient-desc {
    font-size: 11px;
    color: var(--text-dim);
}

/* ===== FOOD CONSTRUCTOR ===== */
.food-section {
    margin: 20px 0;
}

.food-section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.food-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.food-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.food-item:hover {
    background: var(--bg-card-hover);
}

.food-item.selected {
    border-color: var(--accent);
    background: rgba(0, 230, 118, 0.12);
}

.food-emoji { font-size: 22px; }
.food-name { font-size: 14px; color: var(--text-bright); flex: 1; }
.food-portion { font-size: 12px; color: var(--text-dim); }

.food-totals {
    background: rgba(0, 188, 212, 0.08);
    border: 1px solid rgba(0, 188, 212, 0.2);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 16px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    text-align: center;
    gap: 8px;
}

.food-total-item span:first-child {
    font-size: 11px;
    color: var(--text-dim);
    display: block;
    margin-bottom: 2px;
}

.food-total-item span:last-child {
    font-size: 18px;
    font-weight: 700;
    color: var(--secondary);
}

/* ===== PULSE / TRACKER ===== */
.score-ring {
    position: relative;
    width: 140px;
    height: 140px;
    margin: 0 auto 24px;
}

.ring-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.ring-bg {
    fill: none;
    stroke: rgba(0, 230, 118, 0.1);
    stroke-width: 8;
}

.ring-fill {
    fill: none;
    stroke: var(--accent);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 326.73;
    stroke-dashoffset: 326.73;
    transition: stroke-dashoffset 0.8s ease, stroke 0.5s;
    filter: drop-shadow(0 0 6px var(--accent-dim));
}

.ring-fill.gold {
    stroke: var(--gold);
    filter: drop-shadow(0 0 12px rgba(255, 215, 0, 0.5));
}

.ring-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.ring-percent {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-bright);
    display: block;
}

.ring-label {
    font-size: 12px;
    color: var(--text-dim);
}

.habits-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
}

.habit-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

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

.habit-item.checked {
    background: rgba(0, 230, 118, 0.1);
    border-color: var(--accent);
}

.habit-check {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.25s;
    font-size: 14px;
}

.habit-item.checked .habit-check {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
}

.habit-icon { font-size: 22px; flex-shrink: 0; }

.habit-info { flex: 1; }
.habit-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-bright);
}
.habit-desc {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 1px;
}

/* Week history */
.week-history {
    margin-top: 8px;
}

.week-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 10px;
}

.week-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.week-day {
    text-align: center;
}

.week-day-name {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.week-day-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-dim);
    transition: all 0.3s;
}

.week-day-dot.filled {
    background: var(--accent);
    color: var(--bg);
}

.week-day-dot.partial {
    background: var(--accent-dim);
    color: var(--text-bright);
}

.week-day-dot.today {
    border: 2px solid var(--accent);
}

/* ===== COLONY ===== */
.colony-container {
    width: 100%;
    aspect-ratio: 1;
    border-radius: var(--radius);
    overflow: hidden;
    background: radial-gradient(ellipse at center, rgba(0, 230, 118, 0.05) 0%, var(--bg) 70%);
    border: 1px solid var(--border);
    margin-bottom: 16px;
}

#colonyCanvas {
    width: 100%;
    height: 100%;
}

.colony-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.colony-stat {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    text-align: center;
}

.colony-stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--accent);
    display: block;
}

.colony-stat-label {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}

/* ===== ANIMATIONS ===== */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-in {
    animation: fadeIn 0.3s ease forwards;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 481px) {
    #app {
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
    }
}

@media (max-width: 360px) {
    .nutrient-grid {
        grid-template-columns: 1fr;
    }
    .food-totals {
        grid-template-columns: repeat(2, 1fr);
    }
}
