:root {
  --indigo: #4f46e5; --indigo-dark: #4338ca; --indigo-light: #eef2ff;
  --emerald: #059669; --emerald-light: #ecfdf5; --emerald-border: #a7f3d0;
  --rose: #e11d48; --rose-light: #fff1f2; --rose-border: #fecdd3;
  --amber: #d97706; --amber-light: #fffbeb; --amber-border: #fde68a;
  --slate-900: #0f172a; --slate-700: #334155; --slate-500: #64748b;
  --slate-400: #94a3b8; --slate-200: #e2e8f0; --slate-100: #f1f5f9; --slate-50: #f8fafc;
  --radius: 1.5rem;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--slate-50); color: var(--slate-900);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- Loading / Auth ---------- */
.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; color: var(--slate-400); font-size: 0.8rem; }
.auth-card { max-width: 380px; width: 100%; background: #fff; border: 1px solid var(--slate-200); border-radius: var(--radius); padding: 1.75rem; box-shadow: 0 20px 40px -20px rgba(0,0,0,.15); text-align: center; }
.auth-logo { display: inline-flex; padding: .75rem; border-radius: 1rem; background: var(--indigo); color: #fff; font-size: 1.25rem; margin-bottom: .5rem; box-shadow: 0 10px 20px -8px rgba(79,70,229,.5); }
.auth-title { font-size: 1.1rem; font-weight: 800; margin: .25rem 0 0; }
.auth-subtitle { font-size: .7rem; color: var(--slate-500); margin: 0 0 1rem; }
.field { text-align: left; margin-bottom: .75rem; }
.field label { display: block; font-size: .65rem; font-weight: 700; color: var(--slate-500); text-transform: uppercase; margin-bottom: .25rem; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--slate-50); border: 1px solid var(--slate-200); border-radius: .75rem;
  padding: .6rem .7rem; font-size: .78rem; color: var(--slate-900); font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--indigo); }
.auth-error { font-size: .7rem; color: var(--rose); background: var(--rose-light); border: 1px solid var(--rose-border); border-radius: .75rem; padding: .5rem; margin: 0 0 .75rem; }
.auth-toggle { font-size: .7rem; color: var(--slate-500); margin-top: 1rem; }
.auth-toggle button { background: none; border: none; color: var(--indigo); font-weight: 700; cursor: pointer; font-size: .7rem; padding: 0; }

/* ---------- Buttons ---------- */
.btn-primary { background: var(--indigo); color: #fff; font-weight: 700; padding: .7rem 1rem; border-radius: 1rem; border: none; font-size: .75rem; cursor: pointer; transition: background .15s; }
.btn-primary:hover { background: var(--indigo-dark); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-block { width: 100%; }
.btn-logout { font-size: .65rem; font-weight: 700; color: var(--slate-500); background: var(--slate-100); border: none; padding: .4rem .7rem; border-radius: .75rem; cursor: pointer; }
.btn-logout:hover { color: var(--rose); background: var(--rose-light); }

/* ---------- Header ---------- */
.app-header { background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--slate-200); position: sticky; top: 0; z-index: 30; }
.header-inner { max-width: 1200px; margin: 0 auto; padding: 0 1rem; height: 4rem; display: flex; align-items: center; justify-content: space-between; }
.header-brand { display: flex; align-items: center; gap: .75rem; }
.brand-icon { padding: .55rem; border-radius: 1rem; background: var(--indigo); color: #fff; box-shadow: 0 10px 20px -8px rgba(79,70,229,.4); }
.brand-title { font-size: .95rem; font-weight: 800; margin: 0; display: flex; align-items: center; gap: .4rem; }
.brand-badge { font-size: .55rem; font-family: ui-monospace, monospace; padding: .15rem .5rem; border-radius: 999px; background: var(--indigo-light); color: var(--indigo); font-weight: 700; }
.brand-sub { font-size: .6rem; color: var(--slate-500); margin: -2px 0 0; font-weight: 500; }
.header-stats { display: flex; align-items: center; gap: 1rem; }
.stat-pill { display: flex; align-items: center; gap: .35rem; background: var(--slate-100); padding: .3rem .8rem; border-radius: 1rem; border: 1px solid var(--slate-200); font-size: .7rem; font-weight: 700; }
.user-block { display: flex; align-items: center; gap: .5rem; border-left: 1px solid var(--slate-200); padding-left: 1rem; }
.user-name { font-size: .68rem; color: var(--slate-500); font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Layout / Tabs ---------- */
.app-main { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem; }
.tab-nav { display: flex; gap: .5rem; border-bottom: 1px solid var(--slate-200); padding-bottom: .75rem; margin-bottom: 1.5rem; overflow-x: auto; }
.tab-btn { flex-shrink: 0; padding: .6rem 1rem; border-radius: 1rem; font-weight: 700; font-size: .72rem; border: 1px solid transparent; background: none; cursor: pointer; color: var(--slate-500); white-space: nowrap; }
.tab-btn:hover { color: var(--slate-900); background: rgba(226,232,240,.5); }
.tab-btn.active { background: #fff; color: var(--indigo); border-color: var(--indigo-light); box-shadow: 0 4px 10px -4px rgba(79,70,229,.2); }

/* ---------- Cards ---------- */
.card { background: #fff; border: 1px solid var(--slate-200); border-radius: var(--radius); padding: 1.5rem; box-shadow: 0 2px 10px -4px rgba(0,0,0,.06); margin-bottom: 1.5rem; }
.card-title { font-size: 1rem; font-weight: 700; margin: 0; }
.card-sub { font-size: .72rem; color: var(--slate-500); margin: .15rem 0 0; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: 1fr; gap: .75rem; }
@media (min-width: 640px) { .grid-3 { grid-template-columns: repeat(2, 1fr); } .cards-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .grid-2 { grid-template-columns: 2fr 1fr; } .grid-3 { grid-template-columns: repeat(4, 1fr); } .cards-grid { grid-template-columns: repeat(3, 1fr); } }

/* ---------- Battery / Mindset ---------- */
.battery-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--slate-100); }
.battery-readout { display: flex; align-items: center; gap: .75rem; background: var(--slate-50); padding: .6rem 1rem; border-radius: 1rem; border: 1px solid var(--slate-200); }
.battery-bar-track { width: 3rem; height: 1.5rem; background: var(--slate-200); border-radius: .4rem; padding: 2px; }
.battery-bar-fill { height: 100%; border-radius: .3rem; transition: width .3s; }
.slider-block label { display: flex; justify-content: space-between; font-size: .72rem; margin-bottom: .25rem; font-weight: 600; }
.slider-block input[type=range] { width: 100%; accent-color: var(--indigo); }
.mindset-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
@media (min-width: 640px) { .mindset-grid { grid-template-columns: repeat(4, 1fr); } }
.mindset-card { padding: .7rem; border-radius: 1rem; border: 1px solid var(--slate-200); background: #fff; cursor: pointer; }
.mindset-card.selected { box-shadow: 0 0 0 2px rgba(79,70,229,.2); }
.mindset-emoji { font-size: 1.2rem; }
.mindset-name { font-size: .72rem; font-weight: 700; margin: .25rem 0 0; }
.mindset-desc { font-size: .6rem; color: var(--slate-500); }
.traffic-banner { margin-top: 1.25rem; padding: .85rem 1rem; border-radius: 1rem; border: 1px solid; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; }

/* ---------- Rules / Playbook ---------- */
.rule-item { padding: .85rem; border-radius: 1rem; border: 1px solid var(--slate-200); background: var(--slate-50); display: flex; align-items: center; gap: .7rem; cursor: pointer; margin-bottom: .5rem; font-size: .72rem; font-weight: 600; }
.rule-item.checked { background: var(--emerald-light); border-color: var(--emerald-border); color: #065f46; }
.rule-check { width: 1rem; height: 1rem; border-radius: .4rem; border: 1px solid var(--slate-300); background: #fff; display: flex; align-items: center; justify-content: center; font-size: .65rem; flex-shrink: 0; }
.rule-item.checked .rule-check { background: var(--emerald); border-color: var(--emerald); color: #fff; }
.trap-item { padding: .7rem; background: var(--rose-light); border: 1px solid var(--rose-border); border-radius: 1rem; font-size: .72rem; color: #9f1239; font-weight: 500; margin-bottom: .5rem; }
.example-row { padding: 1rem; background: var(--slate-50); border: 1px solid var(--slate-200); border-radius: 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.example-thumb { width: 3.2rem; height: 3.2rem; object-fit: cover; border-radius: .8rem; border: 1px solid var(--slate-300); cursor: pointer; }

/* ---------- Forms ---------- */
.toggle-group { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.toggle-btn { padding: .6rem; border-radius: 1rem; font-weight: 700; font-size: .72rem; border: 1px solid var(--slate-200); background: var(--slate-50); color: var(--slate-600); cursor: pointer; }
.toggle-btn.active-green { background: var(--emerald); color: #fff; border-color: var(--emerald); }
.toggle-btn.active-red { background: var(--rose); color: #fff; border-color: var(--rose); }
.toggle-btn.active-indigo { background: var(--indigo); color: #fff; border-color: var(--indigo); }
.upload-box { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: .85rem; border: 2px dashed var(--slate-300); border-radius: 1rem; cursor: pointer; background: #fff; text-align: center; }
.upload-box:hover { border-color: var(--indigo); }
.image-preview-row { display: flex; align-items: center; justify-content: space-between; margin-top: .5rem; padding: .4rem; border: 1px solid var(--indigo-light); border-radius: 1rem; background: #fff; }
.image-preview-row img { width: 3rem; height: 3rem; object-fit: cover; border-radius: .7rem; }
.xp-badge { font-size: .68rem; font-family: monospace; font-weight: 700; color: var(--indigo); background: var(--indigo-light); padding: .25rem .7rem; border-radius: .75rem; border: 1px solid #c7d2fe; }
.inline-add { display: flex; gap: .5rem; margin-top: .5rem; }
.inline-add input { flex: 1; }

/* ---------- Stats / Reality ---------- */
.stat-card { background: #fff; border-radius: var(--radius); padding: 1.5rem; box-shadow: 0 2px 10px -4px rgba(0,0,0,.06); }
.stat-card.green { border: 1px solid var(--emerald-border); }
.stat-card.red { border: 1px solid var(--rose-border); }
.stat-value { font-size: 1.7rem; font-weight: 800; font-family: monospace; margin: .4rem 0 0; }

/* ---------- Cards grid (Notes / History) ---------- */
.cards-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.item-card { background: #fff; border: 1px solid var(--slate-200); border-radius: var(--radius); overflow: hidden; box-shadow: 0 2px 8px -4px rgba(0,0,0,.06); display: flex; flex-direction: column; }
.item-thumb { height: 9rem; width: 100%; object-fit: cover; cursor: pointer; }
.item-thumb-placeholder { height: 9rem; width: 100%; background: var(--slate-100); display: flex; align-items: center; justify-content: center; color: var(--slate-400); font-size: 1.5rem; }
.item-body { padding: 1rem; display: flex; flex-direction: column; gap: .5rem; flex: 1; }
.item-tag { font-size: .68rem; font-weight: 800; background: var(--slate-100); padding: .15rem .5rem; border-radius: .6rem; width: fit-content; }
.item-strategy { font-size: .65rem; font-weight: 700; color: var(--indigo); }
.item-criteria-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.item-criteria { border-radius: .7rem; padding: .5rem; font-size: .68rem; }
.item-criteria.entry { background: var(--emerald-light); border: 1px solid var(--emerald-border); color: #065f46; }
.item-criteria.exit { background: var(--rose-light); border: 1px solid var(--rose-border); color: #9f1239; }
.item-learning { background: var(--indigo-light); border: 1px solid #c7d2fe; border-radius: .7rem; padding: .5rem; font-size: .72rem; color: #3730a3; font-weight: 600; }
.item-notes { font-size: .72rem; color: var(--slate-600); }
.item-footer { display: flex; justify-content: space-between; align-items: center; font-size: .65rem; color: var(--slate-400); margin-top: auto; padding-top: .4rem; border-top: 1px solid var(--slate-100); }
.item-delete { background: none; border: none; color: var(--slate-300); cursor: pointer; font-size: .75rem; }
.item-delete:hover { color: var(--rose); }
.badge-long { background: var(--emerald); color: #fff; padding: .1rem .5rem; border-radius: .5rem; font-size: .6rem; font-weight: 800; position: absolute; top: .5rem; left: .5rem; }
.badge-short { background: var(--rose); color: #fff; padding: .1rem .5rem; border-radius: .5rem; font-size: .6rem; font-weight: 800; position: absolute; top: .5rem; left: .5rem; }
.thumb-wrap { position: relative; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.8); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 100; }
.modal-card { max-width: 60rem; width: 100%; background: #fff; border-radius: 1.5rem; overflow: hidden; box-shadow: 0 30px 60px -20px rgba(0,0,0,.4); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: .9rem 1.2rem; border-bottom: 1px solid var(--slate-100); background: var(--slate-50); font-size: .7rem; font-weight: 700; color: var(--indigo); }
.modal-header button { background: var(--slate-200); border: none; border-radius: 999px; width: 1.8rem; height: 1.8rem; cursor: pointer; }
.modal-body { padding: 1rem; max-height: 80vh; overflow: auto; display: flex; align-items: center; justify-content: center; background: var(--slate-900); }
.modal-body img { max-width: 100%; height: auto; border-radius: .8rem; }

/* ---------- Misc ---------- */
.section-title { font-size: .85rem; font-weight: 700; display: flex; align-items: center; gap: .4rem; margin: 0 0 .25rem; }
.uppercase-label { font-size: .65rem; font-weight: 700; color: var(--slate-500); text-transform: uppercase; margin-bottom: .3rem; display: block; }
.empty-msg { font-size: .75rem; color: var(--slate-400); font-style: italic; text-align: center; padding: 2rem 0; grid-column: 1 / -1; }
