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

:root {
    --bg: #1e1e1e;
    --surface: #2a2a2a;
    --surface2: #333;
    --border: #3d3d3d;
    --accent: #818cf8;
    --accent-dim: #6366f1;
    --accent-glow: rgba(129,140,248,0.2);
    --green: #34d399;
    --green-dim: #059669;
    --amber: #fbbf24;
    --text: #e8e8e8;
    --text2: #999;
    --text3: #666;
    --white: #2a2a2a;
    --red: #f87171;
    --sidebar-w: 240px;
}

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh; height: 100dvh;
    display: flex; flex-direction: column;
    overflow: hidden;
}

/* ====== AD ====== */
.ad-banner {
    width: 100%; background: #171717;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0; padding: 4px 8px; text-align: center;
}
.ad-placeholder {
    display: inline-block; max-width: 728px; width: 100%;
    height: 40px; line-height: 40px;
    color: var(--text3); font-size: 9px; letter-spacing: 1px;
    border: 1px dashed var(--border); border-radius: 3px;
}

/* ====== SIDEBAR ====== */
.sidebar {
    position: fixed; left: 0; top: 0;
    width: var(--sidebar-w); height: 100dvh;
    background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    z-index: 100; overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
}
.sidebar.open { transform: translateX(0); }
.sidebar-header {
    padding: 14px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.sidebar-close {
    background: none; border: none; color: var(--text2);
    font-size: 24px; cursor: pointer; transition: color 0.15s;
}
.sidebar-close:hover { color: var(--text); }
.sidebar-title { font-size: 14px; font-weight: 700; color: var(--text); }
.sidebar-body { padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.sb-group { display: flex; flex-direction: column; gap: 6px; }
.sb-label {
    font-size: 11px; color: var(--text2); font-weight: 500;
    display: flex; flex-direction: column; gap: 4px;
}
.sb-label input {
    width: 100%; background: var(--surface); border: 2px solid var(--border);
    border-radius: 8px; padding: 9px 10px; color: var(--text);
    font-size: 16px; outline: none; font-family: inherit; -webkit-appearance: none;
    transition: border-color 0.2s;
}
.sb-label input:focus { border-color: var(--accent); }
.toggle-row { display: flex; gap: 4px; }
.toggle-btn {
    flex: 1; padding: 8px; text-align: center;
    font-size: 12px; font-weight: 600;
    color: var(--text2); background: var(--bg);
    border: 2px solid var(--border); border-radius: 8px;
    cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.toggle-btn:hover { border-color: var(--text2); }
.toggle-btn.active { color: var(--accent); border-color: var(--accent); background: rgba(129,140,248,0.08); }
.clear-btn {
    width: 100%; padding: 9px; background: var(--red); border: none;
    border-radius: 8px; color: #fff; font-size: 12px; font-weight: 600;
    cursor: pointer; font-family: inherit; transition: background 0.15s;
}
.clear-btn:hover { background: #dc2626; }
.sb-stats { border-top: 1px solid var(--border); padding-top: 10px; }
.sb-divider { font-size: 9px; text-transform: uppercase; letter-spacing: 1px; color: var(--text3); padding-bottom: 6px; font-weight: 600; }
.stat-row {
    display: flex; justify-content: space-between; padding: 6px 0;
    font-size: 12px; color: var(--text); border-bottom: 1px solid var(--border);
}
.stat-row:last-child { border-bottom: none; }
.stat-val { font-weight: 700; }
.gain { color: var(--green); }
.loss { color: var(--red); }
.tour-replay-btn {
    width: 100%; padding: 8px; margin-top: 8px;
    background: none; border: 1px solid var(--border);
    border-radius: 8px; color: var(--text2);
    font-size: 11px; font-weight: 500;
    cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.tour-replay-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ====== OVERLAY ====== */
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 90;
}
.sidebar-overlay.open { display: block; }

/* ====== MAIN ====== */
.main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.topbar {
    height: 44px; display: flex; align-items: center; gap: 6px;
    padding: 0 10px; border-bottom: 1px solid var(--border);
    flex-shrink: 0; background: var(--surface);
}
.menu-btn {
    background: none; border: none; color: var(--text);
    cursor: pointer; padding: 4px; display: flex; align-items: center;
    -webkit-tap-highlight-color: transparent;
}
.page-title { font-size: 14px; font-weight: 700; color: var(--text); flex: 1; }
.theme-toggle {
    background: none; border: none; color: var(--text2);
    cursor: pointer; padding: 4px; display: flex; align-items: center;
    transition: color 0.15s;
}
.theme-toggle:hover { color: var(--text); }
.guide-btn {
    padding: 5px 10px; background: var(--accent); color: #fff;
    border: none; border-radius: 6px; font-size: 10px; font-weight: 600;
    cursor: pointer; font-family: inherit; white-space: nowrap;
}

.content {
    flex: 1; padding: 8px;
    display: flex; flex-direction: column;
    min-height: 0; overflow: hidden; gap: 6px;
}

/* ====== VIEW TOGGLE ====== */
.view-toggle {
    display: flex; gap: 4px; flex-shrink: 0;
    background: var(--bg); border-radius: 10px; padding: 3px;
}
.view-btn {
    flex: 1; padding: 7px; text-align: center;
    font-size: 12px; font-weight: 600;
    color: var(--text2); background: none;
    border: none; border-radius: 8px;
    cursor: pointer; font-family: inherit;
    transition: all 0.15s;
}
.view-btn.active {
    color: #fff; background: var(--accent);
}

/* ====== DEBT HERO ====== */
.debt-card {
    flex-shrink: 0; text-align: center;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; padding: 12px;
    position: relative; overflow: hidden;
}
.debt-card::before {
    content: ''; position: absolute; top: -30px; left: 50%;
    transform: translateX(-50%);
    width: 200px; height: 60px;
    background: radial-gradient(ellipse, var(--accent-glow) 0%, transparent 70%);
    pointer-events: none;
}
.debt-emoji {
    color: var(--accent); margin-bottom: 4px;
    display: inline-block; transition: color 0.3s;
}
.debt-emoji.happy { color: var(--green); }
.debt-emoji.sad { color: var(--red); }
.debt-number {
    font-size: 36px; font-weight: 800;
    letter-spacing: -1px; line-height: 1.1;
    transition: color 0.3s; position: relative;
}
.debt-number.surplus { color: var(--green); }
.debt-number.debt { color: var(--red); }
.debt-number.even { color: var(--text2); }
.debt-label {
    font-size: 11px; font-weight: 600; color: var(--text2);
    text-transform: uppercase; letter-spacing: 1px; margin-top: 2px;
}
.debt-sub { font-size: 9px; color: var(--text3); margin-top: 2px; }
.debt-bar-wrap { margin-top: 8px; }
.debt-bar-track {
    position: relative; height: 8px;
    background: var(--bg); border-radius: 4px; overflow: hidden;
}
.debt-bar-center {
    position: absolute; left: 50%; top: 0; bottom: 0;
    width: 2px; background: var(--text3); opacity: 0.4;
    transform: translateX(-50%);
}
.debt-bar-fill {
    position: absolute; top: 0; bottom: 0; border-radius: 4px;
    transition: left 0.6s ease, width 0.6s ease, background 0.3s;
}
.debt-bar-fill.surplus-bar { background: var(--green); }
.debt-bar-fill.debt-bar { background: var(--red); }
.debt-bar-labels {
    display: flex; justify-content: space-between;
    font-size: 8px; color: var(--text3); text-transform: uppercase;
    letter-spacing: 0.5px; margin-top: 3px;
}

/* ====== CHART ====== */
.chart-card {
    flex: 1; min-height: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; padding: 6px;
    display: flex; flex-direction: column;
}
.chart-card canvas {
    width: 100% !important; flex: 1;
    min-height: 60px; border-radius: 8px;
}

/* ====== LOG FORM ====== */
.log-card {
    flex-shrink: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; padding: 10px;
}
.log-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.log-label {
    display: flex; flex-direction: column; gap: 2px;
    font-size: 8px; color: var(--text3); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.log-label span { display: block; }
input[type="date"], input[type="time"] {
    width: 100%; background: var(--bg);
    border: 2px solid var(--border); border-radius: 8px;
    padding: 8px 8px; color: var(--text);
    font-size: 16px; outline: none;
    font-family: inherit; -webkit-appearance: none;
    transition: border-color 0.2s;
}
input[type="date"]:focus, input[type="time"]:focus { border-color: var(--accent); }
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator { filter: invert(0.7); }
.calc-hours {
    grid-column: 1 / -1;
    font-size: 18px; font-weight: 800; color: var(--accent);
    text-align: center; padding: 2px 0;
}
.log-btn {
    grid-column: 1 / -1;
    padding: 12px; background: var(--accent); color: #fff;
    border: none; border-radius: 10px; font-size: 15px; font-weight: 700;
    cursor: pointer; font-family: inherit;
    transition: background 0.15s;
}
.log-btn:hover { background: var(--accent-dim); }
.log-btn:active { transform: scale(0.97); }
.today-entry {
    font-size: 10px; color: var(--text3);
    text-align: center; margin-top: 6px; padding: 2px 0;
}
.today-entry.logged { color: var(--accent); font-weight: 500; }

/* ====== LIGHT MODE ====== */
body.light {
    --bg: #fff; --surface: #f5f5f0; --surface2: #eae8e0;
    --border: #e0ddd5; --text: #1a1a1a; --text2: #777;
    --text3: #aaa; --white: #fff;
}
body.light .ad-banner { background: #fafaf7; }
body.light .sidebar { background: #fff; box-shadow: 4px 0 20px rgba(0,0,0,0.08); }
body.light .topbar { background: #fff; }
body.light input, body.light select { background: #f5f5f0; color: #1a1a1a; }

/* ====== DESKTOP ====== */
@media (min-width: 769px) {
    .sidebar { transform: translateX(0); box-shadow: none; }
    .sidebar-close { display: none; }
    .menu-btn { display: none; }
    .main { margin-left: var(--sidebar-w); }
    .topbar { height: 50px; padding: 0 20px; }
    .page-title { font-size: 16px; }
    .content { padding: 16px; max-width: 800px; gap: 12px; }
    .ad-placeholder { height: 90px; line-height: 90px; }
    .debt-card { padding: 16px; }
    .debt-number { font-size: 48px; }
    .chart-card { padding: 12px; }
    .chart-card canvas { min-height: 200px; }
    .log-card { padding: 14px; }
    .log-row { grid-template-columns: 1fr 1fr 1fr; }
    .log-label { font-size: 9px; }
    input[type="date"], input[type="time"] { font-size: 14px; padding: 9px 10px; }
    .calc-hours { grid-column: 1 / -1; }
    .log-btn { grid-column: 1 / -1; padding: 12px; font-size: 14px; }
}

@media (max-width: 380px) {
    .debt-number { font-size: 28px; }
    .calc-hours { font-size: 12px; }
    .ad-placeholder { height: 30px; line-height: 30px; font-size: 8px; }
}

/* ====== TOUR ====== */
.tour-overlay {
    position: fixed; inset: 0; z-index: 300;
    background: rgba(0,0,0,0.75); pointer-events: auto;
}
.tour-highlight {
    position: fixed; z-index: 301;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.85);
    border: 2px solid var(--accent); border-radius: 10px;
    background: rgba(255,255,255,0.08);
    pointer-events: none; transition: all 0.3s ease;
}
.tour-tooltip {
    position: fixed; z-index: 302;
    background: #fff; border: none; color: #1a1a1a;
    border-radius: 12px; padding: 16px 18px;
    max-width: 300px; width: 90vw;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.tour-text { font-size: 14px; color: #1a1a1a !important; line-height: 1.5; margin-bottom: 12px; }
.tour-footer { display: flex; align-items: center; justify-content: space-between; }
.tour-step { font-size: 10px; color: #999 !important; }
.tour-skip { background: none; border: none; color: #999 !important; font-size: 11px; cursor: pointer; font-family: inherit; }
.tour-next { padding: 6px 14px; background: var(--accent); color: #fff; border: none; border-radius: 6px; font-size: 11px; font-weight: 600; cursor: pointer; font-family: inherit; }

::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
@supports (padding-bottom: env(safe-area-inset-bottom)) { body { padding-bottom: env(safe-area-inset-bottom); } }
