/* ===== Escaladom v2 — Escola Dominical =====
   Identidade: domingo de manhã. Verde-eucalipto + âmbar dourado.
   Display: Fraunces (serifa quente). Corpo: Inter. */

:root {
    --bg: #F5F3EC;
    --surface: #FFFFFF;
    --surface-2: #EEEBE1;
    --surface-3: #E6E2D5;
    --text: #22302B;
    --text-muted: #6E7A72;
    --primary: #2F5D50;
    --primary-soft: #6B9080;
    --primary-wash: #E4EDE8;
    --accent: #E0A458;
    --accent-deep: #C6853A;
    --gold: #D4A64A;
    --silver: #A9B0AE;
    --bronze: #BC8A5F;
    --danger: #B4433B;
    --danger-wash: #F6E3E1;
    --success: #3F7A5E;
    --border: #E0DCD0;
    --radius: 20px;
    --radius-sm: 13px;
    --shadow-sm: 0 1px 3px rgba(34,48,43,0.06);
    --shadow: 0 6px 24px rgba(34,48,43,0.10);
    --shadow-lg: 0 12px 40px rgba(34,48,43,0.16);
    --nav-h: 68px;
    --top-h: 60px;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="escuro"] {
    --bg: #161A18;
    --surface: #1F2522;
    --surface-2: #2A312D;
    --surface-3: #333B36;
    --text: #ECEFEA;
    --text-muted: #9BA6A0;
    --primary: #7FB49F;
    --primary-soft: #5C8574;
    --primary-wash: #24322C;
    --accent: #E8B570;
    --border: #333B36;
    --danger: #E27A72;
    --danger-wash: #3A2523;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow: 0 6px 24px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.5);
}

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

html, body { height: 100%; }

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

h1, h2, h3, .display {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 600;
    letter-spacing: -0.01em;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 100%; color: inherit; }
input, select, textarea { -webkit-appearance: none; appearance: none; }

/* ====== App frame ====== */
#app {
    max-width: 460px;
    margin: 0 auto;
    height: 100dvh;
    background: var(--bg);
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 60px rgba(34,48,43,0.08);
    display: flex;
    flex-direction: column;
}

/* ====== Top bar ====== */
.topbar {
    height: var(--top-h);
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 10;
}
.topbar .back-btn {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--surface); border: 1px solid var(--border);
    display: none; align-items: center; justify-content: center;
    cursor: pointer; font-size: 18px; color: var(--text); flex: 0 0 auto;
    transition: transform .15s var(--ease);
}
.topbar .back-btn:active { transform: scale(0.9); }
.topbar.has-back .back-btn { display: flex; }
.topbar .title { flex: 1; font-size: 19px; font-weight: 600; font-family: 'Fraunces', serif; }
.topbar .title small { display: block; font-family: 'Inter', sans-serif; font-size: 11.5px; color: var(--text-muted); font-weight: 500; letter-spacing: 0; margin-top: -2px; }
.topbar .tb-action {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--surface); border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 16px; position: relative; flex: 0 0 auto;
}
.topbar { gap: 6px; }
.topbar .title { min-width: 0; }
.topbar .title small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .tb-action .dot {
    position: absolute; top: 6px; right: 7px; width: 8px; height: 8px;
    background: var(--accent); border: 2px solid var(--surface); border-radius: 50%;
}

/* ====== Screen stack ====== */
.stack { flex: 1; position: relative; overflow: hidden; }
.screen {
    position: absolute; inset: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 16px calc(var(--nav-h) + 24px);
    background: var(--bg);
}
.screen-enter { animation: slideIn .34s var(--ease); }
.screen-back { animation: slideBack .34s var(--ease); }
@keyframes slideIn { from { transform: translateX(28px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slideBack { from { transform: translateX(-24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fadeUp { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ====== Bottom nav ====== */
.bottom-nav {
    position: absolute; bottom: 0; left: 0; right: 0;
    height: var(--nav-h);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    display: flex; z-index: 20;
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button {
    flex: 1; background: none; border: none; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--text-muted); font-size: 10.5px; font-weight: 600;
    transition: color .2s;
}
.bottom-nav button .ic {
    width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
    transition: transform .25s var(--ease);
}
.bottom-nav button.active { color: var(--primary); }
.bottom-nav button.active .ic { transform: translateY(-2px); }
.bottom-nav button.active .ic svg { stroke: var(--primary); }

/* ====== Cards ====== */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    animation: fadeUp .4s var(--ease) both;
}
.card.flat { box-shadow: none; }
.card > h3 { font-size: 16px; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h3 { font-size: 16px; }

.section-label {
    font-size: 12px; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.06em; margin: 22px 4px 10px;
}
.section-label:first-child { margin-top: 4px; }

/* ====== Hero greeting ====== */
.hero {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-soft) 100%);
    border-radius: var(--radius);
    padding: 22px 20px;
    color: #fff;
    margin-bottom: 16px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow);
    animation: fadeUp .4s var(--ease) both;
}
.hero::after {
    content: ''; position: absolute; top: -40px; right: -30px;
    width: 140px; height: 140px; border-radius: 50%;
    background: rgba(255,255,255,0.08);
}
.hero .greet { font-family: 'Fraunces', serif; font-size: 24px; font-weight: 600; position: relative; }
.hero .sub { font-size: 13px; opacity: 0.85; margin-top: 2px; position: relative; }

/* ====== Stat tiles ====== */
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.stat {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 16px; box-shadow: var(--shadow-sm); animation: fadeUp .4s var(--ease) both;
}
.stat .v { font-family: 'Fraunces', serif; font-size: 26px; font-weight: 600; color: var(--primary); line-height: 1; }
.stat .k { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; font-weight: 500; }
.stat.accent .v { color: var(--accent-deep); }

/* ====== List rows ====== */
.row {
    display: flex; align-items: center; gap: 12px;
    padding: 13px 0; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: none; }
.row .row-main { flex: 1; min-width: 0; }
.row .row-title { font-weight: 600; font-size: 14.5px; }
.row .row-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 1px; }
.row .row-ic {
    width: 42px; height: 42px; border-radius: 12px; flex: 0 0 auto;
    background: var(--primary-wash); color: var(--primary);
    display: flex; align-items: center; justify-content: center; font-size: 19px;
}

.chevron { color: var(--text-muted); font-size: 18px; flex: 0 0 auto; }

/* ====== Buttons ====== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 14px 18px; border-radius: 14px; border: none; cursor: pointer;
    font-weight: 600; font-size: 15px; width: 100%;
    background: var(--primary); color: #fff;
    transition: transform .14s var(--ease), box-shadow .2s, filter .2s;
    box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 30%, transparent);
}
.btn:active { transform: scale(0.975); }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: none; }
.btn.accent { background: var(--accent); color: #3A2A12; box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.danger { background: var(--danger); box-shadow: none; }
.btn.sm { width: auto; padding: 9px 14px; font-size: 13.5px; border-radius: 11px; box-shadow: none; }
.btn.block-mt { margin-top: 8px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.btn:disabled { opacity: 0.5; }

.pill-btn {
    background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
    padding: 8px 15px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--text);
}
.pill-btn.on { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ====== Forms ====== */
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; color: var(--text); }
.field input, .field select, .field textarea {
    width: 100%; padding: 13px 15px; border-radius: 13px;
    border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
    font-size: 15px; transition: border-color .2s, box-shadow .2s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-wash);
}
.field textarea { min-height: 92px; resize: vertical; }
.field select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236E7A72' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 15px center; padding-right: 38px;
}

/* ====== Tags ====== */
.tag {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
    background: var(--surface-2); color: var(--text-muted); letter-spacing: 0.02em;
}
.tag.green { background: var(--primary-wash); color: var(--primary); }
.tag.amber { background: #F6E9D2; color: var(--accent-deep); }
.tag.red { background: var(--danger-wash); color: var(--danger); }
[data-theme="escuro"] .tag.amber { background: #3D3018; color: var(--accent); }

/* ====== Podium / Ranking ====== */
.podium-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.rank-item {
    display: flex; align-items: center; gap: 13px;
    padding: 13px 14px; margin-bottom: 9px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 15px;
    animation: fadeUp .4s var(--ease) both;
}
.rank-item .place {
    width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
    display: flex; align-items: center; justify-content: center;
    font-family: 'Fraunces', serif; font-weight: 700; font-size: 16px;
    background: var(--surface-2); color: var(--text-muted);
}
.rank-item.p1 { border-color: color-mix(in srgb, var(--gold) 55%, var(--border)); background: linear-gradient(100deg, color-mix(in srgb, var(--gold) 12%, var(--surface)), var(--surface)); }
.rank-item.p1 .place { background: var(--gold); color: #4A3A12; }
.rank-item.p2 .place { background: var(--silver); color: #33393A; }
.rank-item.p3 .place { background: var(--bronze); color: #3A2517; }
.rank-item .rank-main { flex: 1; min-width: 0; }
.rank-item .rank-name { font-weight: 600; font-size: 14.5px; }
.rank-item .rank-sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.rank-item .rank-val { font-family: 'Fraunces', serif; font-weight: 600; font-size: 17px; color: var(--primary); flex: 0 0 auto; }
.rank-item.p1 .rank-val { color: var(--accent-deep); }
.rank-medal { font-size: 17px; }

/* ====== Calendar ====== */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.cal-head .m { font-family: 'Fraunces', serif; font-size: 17px; font-weight: 600; text-transform: capitalize; }
.cal-nav { width: 34px; height: 34px; border-radius: 10px; background: var(--surface-2); border: none; cursor: pointer; font-size: 16px; color: var(--text); flex: 0 0 auto; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; width: 100%; }
.cal-grid .dow { text-align: center; font-size: 10.5px; font-weight: 700; color: var(--text-muted); padding-bottom: 6px; min-width: 0; }
.cal-cell {
    aspect-ratio: 1; border-radius: 11px; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center; position: relative;
    background: var(--surface-2); color: var(--text); font-size: 13.5px; font-weight: 500;
    transition: transform .12s var(--ease); min-width: 0; width: 100%; padding: 0;
}
.cal-cell:active { transform: scale(0.92); }
.cal-cell.empty { background: transparent; cursor: default; }
.cal-cell.has::after {
    content: ''; position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%);
    width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
}
.cal-cell.today { background: var(--primary-wash); color: var(--primary); font-weight: 700; box-shadow: inset 0 0 0 1.5px var(--primary); }
.cal-cell.sel { background: var(--primary); color: #fff; }
.cal-cell.sel.has::after { background: #fff; }

/* ====== Empty state ====== */
.empty { text-align: center; padding: 44px 24px; color: var(--text-muted); }
.empty .ic { font-size: 40px; margin-bottom: 10px; opacity: 0.7; }
.empty .msg { font-size: 14px; }

/* ====== Checkbox rows (presença) ====== */
.check-row {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; margin-bottom: 8px; border-radius: 14px;
    background: var(--surface-2); cursor: pointer; transition: background .18s;
    user-select: none;
}
.check-row.on { background: var(--primary-wash); }
.check-row .box {
    width: 26px; height: 26px; border-radius: 8px; flex: 0 0 auto;
    border: 2px solid var(--border); background: var(--surface);
    display: flex; align-items: center; justify-content: center; color: #fff;
    transition: all .18s var(--ease);
}
.check-row.on .box { background: var(--primary); border-color: var(--primary); }
.check-row .nm { font-weight: 500; font-size: 14.5px; flex: 1; }

/* ====== FAB ====== */
.fab {
    position: absolute; bottom: calc(var(--nav-h) + 18px); right: 18px;
    width: 56px; height: 56px; border-radius: 18px; z-index: 15;
    background: var(--accent); color: #3A2A12; border: none; cursor: pointer;
    font-size: 26px; display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow-lg);
    transition: transform .16s var(--ease);
}
.fab:active { transform: scale(0.9) rotate(90deg); }

/* ====== Auth ====== */
.auth {
    height: 100dvh; max-width: 460px; margin: 0 auto;
    display: flex; flex-direction: column; justify-content: center;
    padding: 28px; background: var(--bg); overflow-y: auto;
}
.auth-brand { text-align: center; margin-bottom: 28px; }
.auth-brand .mark {
    width: 68px; height: 68px; border-radius: 20px; margin: 0 auto 14px;
    background: linear-gradient(135deg, var(--primary), var(--primary-soft));
    display: flex; align-items: center; justify-content: center; font-size: 34px;
    box-shadow: var(--shadow);
}
.auth-brand h1 { font-size: 27px; }
.auth-brand p { font-size: 13.5px; color: var(--text-muted); margin-top: 3px; }
.auth-links { text-align: center; margin-top: 18px; font-size: 13.5px; color: var(--text-muted); }
.auth-links a { color: var(--primary); font-weight: 600; }
.auth-sep { margin: 14px 0; text-align: center; font-size: 12px; color: var(--text-muted); position: relative; }

/* ====== Alerts ====== */
.alert { padding: 13px 15px; border-radius: 13px; font-size: 13.5px; margin-bottom: 15px; }
.alert.err { background: var(--danger-wash); color: var(--danger); }
.alert.ok { background: var(--primary-wash); color: var(--primary); }

/* ====== Bar chart (freq) ====== */
.bar-item { margin-bottom: 12px; }
.bar-item .bl { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 5px; }
.bar-item .bl .p { font-weight: 700; color: var(--primary); }
.bar-track { height: 9px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--primary-soft), var(--primary)); transition: width .6s var(--ease); }

/* ====== Toast ====== */
#toast {
    position: absolute; bottom: calc(var(--nav-h) + 22px); left: 50%; transform: translateX(-50%) translateY(20px);
    background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 999px;
    font-size: 13.5px; font-weight: 600; z-index: 100; opacity: 0; pointer-events: none;
    transition: all .3s var(--ease); white-space: nowrap; box-shadow: var(--shadow-lg);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ====== Loading ====== */
.loader { display: flex; justify-content: center; padding: 50px; }
.spin { width: 30px; height: 30px; border: 3px solid var(--surface-2); border-top-color: var(--primary); border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

.divider { height: 1px; background: var(--border); margin: 16px 0; }
.muted { color: var(--text-muted); font-size: 13px; }
.center { text-align: center; }
.mt { margin-top: 12px; }

/* Segmented control */
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.seg button { flex: 1; border: none; background: none; padding: 9px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--text-muted); cursor: pointer; transition: all .2s; }
.seg button.on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

@media print {
    body { overflow: visible; }
    #app { height: auto; max-width: 100%; box-shadow: none; }
    .topbar, .bottom-nav, .fab, .no-print { display: none !important; }
    .screen { position: static; padding: 0; overflow: visible; }
}

/* ====== Conteúdo HTML da lição ====== */
.licao-html { line-height: 1.7; font-size: 15px; }
.licao-html h1, .licao-html h2, .licao-html h3 { font-family: 'Fraunces', serif; color: var(--primary); margin: 18px 0 8px; line-height: 1.3; }
.licao-html h1 { font-size: 22px; }
.licao-html h2 { font-size: 19px; }
.licao-html h3 { font-size: 16px; }
.licao-html p { margin: 10px 0; }
.licao-html ul, .licao-html ol { margin: 10px 0; padding-left: 22px; }
.licao-html li { margin: 5px 0; }
.licao-html blockquote { border-left: 3px solid var(--accent); background: var(--surface-2); margin: 12px 0; padding: 10px 14px; border-radius: 0 10px 10px 0; font-style: italic; }
.licao-html img { max-width: 100%; height: auto; border-radius: 12px; margin: 10px 0; }
.licao-html a { color: var(--primary); font-weight: 600; text-decoration: underline; }
.licao-html strong { color: var(--text); }
.licao-html table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 14px; }
.licao-html td, .licao-html th { border: 1px solid var(--border); padding: 8px; text-align: left; }
.licao-html hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ====== Switch (interruptor) ====== */
.switch { position: relative; display: inline-block; width: 48px; height: 28px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: var(--surface-3); border-radius: 999px; transition: .25s; cursor: pointer; }
.switch .slider::before { content: ''; position: absolute; height: 22px; width: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .25s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* ====== Botão Google ====== */
.btn-google { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 13px; border-radius: 14px; border: 1.5px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; font-size: 15px; cursor: pointer; }
.btn-google img, .btn-google svg { width: 20px; height: 20px; }
