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

:root {
    --bg:           #f0f2f5;
    --surface:      #ffffff;
    --surface2:     #f4f6f8;
    --text:         #1a1a2e;
    --text-muted:   #6c757d;
    --border:       #e0e4e8;
    --primary:      #4a90d9;
    --primary-dark: #2c6fad;
    --primary-bg:   rgba(74,144,217,0.12);
    --success:      #27ae60;
    --error:        #dc3545;
    --radius:       14px;
    --radius-sm:    8px;
    --shadow:       0 2px 10px rgba(0,0,0,0.07);
    --shadow-md:    0 4px 24px rgba(0,0,0,0.10);
}

[data-theme="dark"] {
    --bg:         #0e0e1a;
    --surface:    #1a1a2e;
    --surface2:   #22223a;
    --text:       #e8e8f0;
    --text-muted: #7777aa;
    --border:     #2d2d50;
    --primary-bg: rgba(74,144,217,0.18);
    --shadow:     0 2px 10px rgba(0,0,0,0.3);
    --shadow-md:  0 4px 24px rgba(0,0,0,0.4);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background 0.2s, color 0.2s;
}

/* ── Header ── */
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}
.header-logo {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--primary);
    text-decoration: none;
    letter-spacing: -0.3px;
}
.header-nav { display: flex; gap: 0.2rem; }
.nav-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--surface2); color: var(--text); }

/* ── Layout ── */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

/* ── Auth ── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}
.auth-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}
.auth-logo-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.auth-logo {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.5px;
}

/* ── Tabs ── */
.tab-bar {
    display: flex;
    background: var(--surface2);
    border-radius: var(--radius-sm);
    padding: 3px;
    margin-bottom: 1.5rem;
    gap: 3px;
}
.tab-btn {
    flex: 1;
    padding: 0.5rem;
    border: none;
    background: none;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.tab-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.form-group input,
.note-input {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface2);
    color: var(--text);
    font-size: 1rem;
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
}
.form-group input:focus,
.note-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}
.note-input { resize: vertical; min-height: 80px; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-full { width: 100%; }

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    background: var(--surface2);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.icon-btn:hover { background: var(--border); }

/* ── Score grid ── */
.tracker-card { text-align: center; }
.tracker-question { font-size: 1.3rem; font-weight: 700; margin-bottom: 0.35rem; }
.tracker-hint { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.5rem; }

.score-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.55rem;
    margin-bottom: 1rem;
}
.score-btn {
    aspect-ratio: 1 / 1;
    border: 2px solid var(--border);
    border-radius: 50%;
    background: var(--surface2);
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.12s, border-color 0.12s, background 0.12s, box-shadow 0.12s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.score-btn:hover {
    border-color: var(--primary);
    transform: scale(1.08);
}

/* ── Context panel ── */
.context-panel { margin-top: 1rem; text-align: left; }
.context-panel.hidden { display: none; }
.context-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 0.75rem;
}
.tag-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-bottom: 0.9rem;
}
.tag-btn {
    padding: 0.38rem 0.85rem;
    border: 1.5px solid var(--border);
    border-radius: 999px;
    background: none;
    color: var(--text-muted);
    font-size: 0.83rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.13s;
    font-family: inherit;
}
.tag-btn:hover { border-color: var(--primary); color: var(--primary); }
.tag-btn.active { background: var(--primary-bg); border-color: var(--primary); color: var(--primary); font-weight: 700; }

/* ── Success ── */
.success-msg {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: rgba(39,174,96,0.13);
    border: 1px solid rgba(39,174,96,0.35);
    border-radius: var(--radius-sm);
    color: var(--success);
    font-weight: 700;
    text-align: center;
}
.success-msg.hidden { display: none; }

/* ── Alerts ── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    font-weight: 500;
}
.alert-error   { background: rgba(220,53,69,0.1);  border: 1px solid rgba(220,53,69,0.3);  color: var(--error); }
.alert-success { background: rgba(39,174,96,0.12); border: 1px solid rgba(39,174,96,0.3);  color: var(--success); }
.alert.hidden  { display: none; }

/* ── Recent entries ── */
.section-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 1rem;
}
.recent-list { display: flex; flex-direction: column; gap: 0.85rem; }
.recent-item { display: flex; gap: 0.75rem; align-items: flex-start; }
.recent-score {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: 800;
    flex-shrink: 0;
    color: #fff;
}
.recent-meta { flex: 1; min-width: 0; }
.recent-date { font-size: 0.8rem; color: var(--text-muted); }
.recent-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.3rem; }
.recent-tag {
    font-size: 0.74rem;
    padding: 0.15rem 0.55rem;
    background: var(--primary-bg);
    color: var(--primary);
    border-radius: 999px;
    font-weight: 600;
}
.recent-note { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.3rem; white-space: pre-wrap; word-break: break-word; }

/* ── History ── */
.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
.period-btns { display: flex; gap: 0.4rem; }
.period-btn {
    padding: 0.35rem 0.8rem;
    border: 1.5px solid var(--border);
    border-radius: 999px;
    background: none;
    color: var(--text-muted);
    font-size: 0.83rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.13s;
    font-family: inherit;
}
.period-btn.active { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }
.stats-row { display: flex; gap: 1.5rem; margin-bottom: 1.25rem; }
.stat { text-align: center; }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--primary); line-height: 1; }
.stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 0.2rem; }
.chart-wrap { position: relative; height: 220px; }

/* ── Settings ── */
.settings-group {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}
.settings-group:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.settings-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 0.75rem;
}
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.toggle-btn {
    padding: 0.5rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.13s;
    font-family: inherit;
}
.toggle-btn.active { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); font-weight: 700; }

/* ── Utility ── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); font-size: 0.9rem; padding: 0.5rem 0; }

/* ── Mobile ── */
@media (max-width: 420px) {
    .card { padding: 1.1rem; }
    .auth-card { padding: 1.5rem; }
    .tracker-question { font-size: 1.1rem; }
    .score-btn { font-size: 0.95rem; }
    .score-grid { gap: 0.4rem; }
    .history-header { flex-direction: column; align-items: flex-start; }
}
