:root {
  --bg: #14131a;
  --panel: #1e1c26;
  --panel-2: #282532;
  --text: #f3f0ea;
  --muted: #a39fae;
  --accent: #f5b14c;
  --accent-2: #e2557a;
  --radius: 22px;
  --top: calc(52px + env(safe-area-inset-top));
  --bottom: calc(62px + env(safe-area-inset-bottom));
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overscroll-behavior: none; }
body { font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--top); padding: env(safe-area-inset-top) 16px 0;
  display: flex; align-items: center; gap: 12px; background: linear-gradient(var(--bg) 70%, transparent); z-index: 10;
}
.brand { font-weight: 700; letter-spacing: .02em; flex: 1; }
.progress { position: relative; width: 36px; height: 36px; border: 0; background: none; padding: 0; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.progress .ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--panel-2); stroke-width: 3.5; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 3.5; stroke-linecap: round; stroke-dasharray: 94.25; stroke-dashoffset: 94.25; transition: stroke-dashoffset .4s; }
.progress.done .ring-fg { stroke: #6fd08c; }
.streak { font-weight: 700; font-size: 15px; min-width: 44px; text-align: right; }
.streak.cold { filter: grayscale(1); opacity: .6; }

main { position: fixed; inset: var(--top) 0 var(--bottom) 0; }
.view { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* Feed */
#view-feed { overflow: hidden; display: flex; flex-direction: column; }
.topic-strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 10px; scrollbar-width: none; flex: none; }
.topic-strip::-webkit-scrollbar { display: none; }
.topic-strip button { flex: none; border: 1px solid var(--panel-2); background: transparent; border-radius: 999px; padding: 5px 13px; font-size: 13px; color: var(--muted); text-transform: capitalize; }
.topic-strip button.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.feed { flex: 1; overflow-y: auto; scroll-snap-type: y mandatory; scrollbar-width: none; padding: 0 14px; }
.feed::-webkit-scrollbar { display: none; }
.slide { height: 100%; scroll-snap-align: start; scroll-snap-stop: always; padding-bottom: 14px; display: flex; }
.card {
  position: relative; flex: 1; border-radius: var(--radius); padding: 26px 22px 18px; display: flex; flex-direction: column;
  background: radial-gradient(120% 90% at 0% 0%, hsla(var(--h), 70%, 55%, .35), transparent 60%),
              radial-gradient(100% 80% at 100% 100%, hsla(calc(var(--h) + 40), 70%, 50%, .25), transparent 60%), var(--panel);
  overflow: hidden; user-select: none;
}
.card-meta { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.card-meta .topic { color: hsl(var(--h), 85%, 72%); font-weight: 700; }
.card h2 { font-family: Georgia, "Iowan Old Style", "Times New Roman", serif; font-size: clamp(24px, 6.5vw, 32px); line-height: 1.15; margin: 12px 0 10px; font-weight: 700; }
.card .body { font-size: 16px; line-height: 1.5; color: #e4e0d8; overflow-y: auto; flex: 1; min-height: 0; padding-right: 4px; }
.card .takeaway { margin-top: 14px; padding: 12px 14px; border-radius: 14px; background: rgba(255,255,255,.07); font-size: 15px; }
.card .takeaway b { display: block; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: hsl(var(--h), 85%, 72%); margin-bottom: 2px; }
.card .source { margin-top: 12px; font-size: 13px; color: var(--muted); font-style: italic; }
.card .source a { color: inherit; }
.card-actions { display: flex; gap: 6px; margin-top: 12px; justify-content: space-between; }
.card-actions button { flex: 1; border: 0; background: rgba(255,255,255,.06); border-radius: 14px; padding: 10px 0; font-size: 20px; line-height: 1; }
.card-actions button.on { background: rgba(255,255,255,.16); }
.card-actions .like.on { color: #ff6b8a; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,.1); color: var(--text); letter-spacing: .05em; }
.heart-pop { position: absolute; left: 50%; top: 45%; font-size: 90px; transform: translate(-50%, -50%) scale(.3); opacity: 0; pointer-events: none; animation: pop .7s ease-out; }
@keyframes pop { 30% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); } 100% { opacity: 0; transform: translate(-50%, -60%) scale(1); } }
.end-card { text-align: center; justify-content: center; align-items: center; gap: 14px; --h: 40; }
.end-card h2 { margin: 0; }
.end-card p { color: var(--muted); margin: 0; max-width: 300px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--panel-2); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Pages */
.page { padding: 4px 18px 40px; max-width: 640px; margin: 0 auto; }
.page h1 { font-family: Georgia, serif; font-size: 30px; margin: 4px 0 16px; }
.page h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 28px 0 10px; }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
input, textarea { width: 100%; background: var(--panel); border: 1px solid var(--panel-2); border-radius: 14px; padding: 12px 14px; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }
button.primary { width: 100%; border: 0; border-radius: 14px; padding: 13px; font-weight: 700; color: #1a1410; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
button.primary:disabled { opacity: .6; }
button.secondary { width: 100%; border: 1px solid var(--panel-2); background: var(--panel); border-radius: 14px; padding: 11px; margin-top: 10px; }
button.link { background: none; border: 0; color: var(--muted); text-decoration: underline; margin-top: 30px; padding: 0; }
.create-form { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.row input { width: 90px; }
.segmented { display: flex; background: var(--panel); border-radius: 14px; padding: 4px; margin-bottom: 16px; }
.segmented button { flex: 1; border: 0; background: none; padding: 9px; border-radius: 10px; color: var(--muted); }
.segmented button:disabled { opacity: .45; }
.segmented button.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.inline-form { display: flex; gap: 8px; margin-top: 8px; }
.inline-form button { border: 0; background: var(--panel-2); border-radius: 14px; padding: 0 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--panel-2); background: var(--panel); border-radius: 999px; padding: 6px 12px; font-size: 14px; text-transform: capitalize; display: inline-flex; gap: 8px; align-items: center; }
.chip.on { border-color: var(--accent); color: var(--accent); }
.chip .x { opacity: .5; }
.goal-row { display: flex; gap: 14px; align-items: center; }
.goal-row input { padding: 0; accent-color: var(--accent); border: 0; background: none; }
.goal-row span { white-space: nowrap; min-width: 90px; text-align: right; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--panel); border-radius: 16px; padding: 14px; text-align: center; }
.stat b { display: block; font-size: 26px; }
.stat span { font-size: 12px; color: var(--muted); }
.week { display: flex; gap: 6px; margin-top: 12px; align-items: flex-end; height: 80px; }
.week div { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); height: 100%; justify-content: flex-end; }
.week i { display: block; width: 100%; border-radius: 6px; background: var(--panel-2); min-height: 4px; }
.week i.met { background: linear-gradient(var(--accent), var(--accent-2)); }
.list-item { display: flex; align-items: center; gap: 12px; background: var(--panel); border-radius: 16px; padding: 14px 16px; margin-bottom: 8px; border: 0; width: 100%; text-align: left; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .count { color: var(--muted); }
.mini-card { background: var(--panel); border-radius: 16px; padding: 14px 16px; margin-bottom: 10px; border-left: 4px solid hsl(var(--h), 70%, 60%); }
.mini-card h3 { margin: 0 0 4px; font-family: Georgia, serif; font-size: 18px; }
.mini-card p { margin: 6px 0 0; color: #ddd8cf; font-size: 15px; }
.mini-card .meta { font-size: 12px; color: var(--muted); }
.mini-card .full { display: none; }
.mini-card.open .full { display: block; }
.mini-card.open .preview { display: none; }
.mini-card .preview { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.back { background: none; border: 0; color: var(--accent); padding: 0; margin-bottom: 10px; }
.search { margin-bottom: 14px; }
.notice { background: rgba(245,177,76,.12); border: 1px solid rgba(245,177,76,.35); border-radius: 14px; padding: 12px 14px; font-size: 14px; margin-top: 24px; }

/* Tab bar */
.tabbar { position: fixed; inset: auto 0 0 0; height: var(--bottom); padding-bottom: env(safe-area-inset-bottom); display: flex; background: rgba(20,19,26,.94); backdrop-filter: blur(12px); border-top: 1px solid var(--panel-2); z-index: 10; }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; color: var(--muted); font-size: 11px; gap: 2px; }
.tabbar a span { font-size: 20px; line-height: 1; }
.tabbar a.active { color: var(--text); }

/* Sheet + toast */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; }
.sheet { position: fixed; inset: auto 0 0 0; background: var(--panel); border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); z-index: 21; max-height: 75vh; overflow-y: auto; animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(100%); } }
.sheet h3 { margin: 0 0 12px; }
.sheet .list-item { background: var(--panel-2); }
.sheet .check { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--muted); display: grid; place-items: center; font-size: 13px; }
.sheet .check.on { background: var(--accent); border-color: var(--accent); color: #1a1410; }
.toast { position: fixed; left: 50%; bottom: calc(var(--bottom) + 14px); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 30; max-width: 90vw; text-align: center; }

/* Login */
body.login { display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; align-items: center; text-align: center; }
.login-card h1 { font-family: Georgia, serif; margin: 0 0 8px; }
.login-card .error { color: #ff6b8a; min-height: 1.5em; margin: 0; }

@media (min-width: 700px) {
  .feed { padding: 0 max(14px, calc(50% - 300px)); }
}

/* ---- v2: language, voice, reflections, review, levels, charts, animation ---- */
.icon-btn { border: 0; background: var(--panel); width: 36px; height: 36px; border-radius: 50%; font-size: 17px; display: grid; place-items: center; padding: 0; }
.icon-btn.on { background: var(--accent); box-shadow: 0 0 0 4px rgba(245,177,76,.25); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(245,177,76,.08); } }
.card-meta .spacer, .level-top .spacer { flex: 1; }
.card-meta .lang { border: 1px solid rgba(255,255,255,.2); background: transparent; border-radius: 8px; font-size: 11px; font-weight: 700; padding: 2px 7px; letter-spacing: .05em; color: var(--text); }
.card-content { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.card .reflection, .flash .reflection { margin-top: 10px; padding: 10px 14px; border-radius: 14px; border: 1px dashed rgba(255,255,255,.22); font-size: 14px; color: #ddd8cf; }
.card .reflection b, .flash .reflection b { display: block; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.card-actions .speak.on { background: var(--accent); color: #1a1410; animation: pulse 1.6s infinite; }
.card-actions .reflect.on { color: var(--accent); }
.mini-reflection { color: var(--accent) !important; font-size: 14px !important; }

/* text reveal when a card comes into view */
.slide .card .anim { opacity: 0; transform: translateY(14px); }
.slide .card.reveal .anim { animation: rise .55s cubic-bezier(.2,.7,.2,1) forwards; animation-delay: calc(var(--d, 0) * 90ms); }
@keyframes rise { to { opacity: 1; transform: none; } }
.slide .card.reveal { animation: glow 1.2s ease-out; }
@keyframes glow { from { filter: brightness(1.12); } }
@media (prefers-reduced-motion: reduce) { .slide .card .anim { opacity: 1; transform: none; animation: none !important; } }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translate(var(--x), 105vh) rotate(var(--r)); opacity: .9; } }

/* review */
.review-cta { display: flex; align-items: center; gap: 14px; width: 100%; border: 0; text-align: left; border-radius: 18px; padding: 16px; margin-bottom: 14px;
  background: linear-gradient(120deg, rgba(245,177,76,.22), rgba(226,85,122,.22)), var(--panel); }
.review-cta:disabled { opacity: .55; }
.review-cta .big { font-size: 30px; }
.review-cta small { display: block; color: var(--muted); }
.review-cta .pill { background: var(--accent); color: #1a1410; font-weight: 700; border-radius: 999px; padding: 2px 10px; }
.review-progress { height: 6px; border-radius: 999px; background: var(--panel-2); margin-bottom: 14px; overflow: hidden; }
.review-progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }
.flash { border-radius: var(--radius); padding: 22px; min-height: 52vh; display: flex; flex-direction: column; transition: transform .28s, opacity .28s;
  background: radial-gradient(120% 90% at 0% 0%, hsla(var(--h), 70%, 55%, .32), transparent 60%), var(--panel); }
.flash h2 { font-family: Georgia, serif; font-size: 28px; line-height: 1.2; margin: 14px 0; text-transform: none; letter-spacing: 0; color: var(--text); }
.flash .card-meta { display: flex; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.flash .card-meta .topic { color: hsl(var(--h), 85%, 72%); font-weight: 700; }
.flash .body { color: #e4e0d8; animation: rise .4s forwards; }
.flash .takeaway { margin-top: 12px; padding: 12px 14px; border-radius: 14px; background: rgba(255,255,255,.07); }
.flash .takeaway b { display: block; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: hsl(var(--h), 85%, 72%); }
.flash-hidden { margin-top: auto; }
.grade { display: flex; gap: 10px; margin-top: 18px; }
.grade button { flex: 1; border: 0; border-radius: 14px; padding: 13px; font-weight: 700; }
.grade .forgot { background: var(--panel-2); color: var(--text); }
.grade .gotit { background: #6fd08c; color: #10241a; }
.flash.fly-right { transform: translateX(110%) rotate(8deg); opacity: 0; }
.flash.fly-left { transform: translateX(-110%) rotate(-8deg); opacity: 0; }
.review-done { text-align: center; padding: 30px 10px; }
.review-done .big { font-size: 54px; }
.review-done p { color: var(--muted); }

/* level, freezes, badges */
.level-card { background: linear-gradient(120deg, rgba(245,177,76,.18), rgba(226,85,122,.18)), var(--panel); border-radius: 18px; padding: 16px; margin-bottom: 10px; }
.level-top { display: flex; align-items: center; gap: 10px; }
.level-top .lv { background: var(--accent); color: #1a1410; font-weight: 800; border-radius: 10px; padding: 2px 8px; font-size: 13px; }
.level-top b { font-size: 18px; }
.level-top .xp { color: var(--muted); font-size: 14px; }
.xpbar { height: 8px; border-radius: 999px; background: rgba(0,0,0,.35); margin: 10px 0 6px; overflow: hidden; }
.xpbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; transition: width .6s; }
.level-card small { color: var(--muted); font-size: 12px; }
.freezes { margin: 12px 0 0; font-size: 15px; }
.freezes small { color: var(--muted); font-size: 12px; }
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.badge-item { background: var(--panel); border-radius: 14px; padding: 12px 6px; text-align: center; opacity: .38; filter: grayscale(1); }
.badge-item.earned { opacity: 1; filter: none; background: linear-gradient(160deg, rgba(245,177,76,.16), transparent), var(--panel); }
.badge-item span { font-size: 26px; display: block; }
.badge-item b { font-size: 12px; display: block; margin-top: 4px; }
.badge-item small { font-size: 10px; color: var(--muted); display: block; line-height: 1.3; }

/* heatmap */
.heatmap { background: var(--panel); border-radius: 16px; padding: 12px; }
.hm-months { display: grid; font-size: 10px; color: var(--muted); margin-bottom: 4px; }
.hm-months span { white-space: nowrap; }
.hm-grid { display: grid; grid-template-rows: repeat(7, 1fr); gap: 3px; }
.hm-grid i, .hm-legend i { display: block; aspect-ratio: 1; border-radius: 3px; background: var(--panel-2); }
.hm-legend { display: flex; align-items: center; gap: 4px; justify-content: flex-end; margin-top: 8px; font-size: 11px; color: var(--muted); }
.hm-legend i { width: 11px; }
.h1 { background: rgba(245,177,76,.3) !important; }
.h2 { background: rgba(245,177,76,.55) !important; }
.h3 { background: #f5b14c !important; }
.h4 { background: #e2557a !important; }
.hf { background: #7db7ff !important; }

/* topic chart */
.tbar { display: grid; grid-template-columns: 110px 1fr 34px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 14px; }
.tbar span { text-transform: capitalize; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.tbar div { background: var(--panel); border-radius: 999px; height: 12px; overflow: hidden; }
.tbar i { display: block; height: 100%; border-radius: 999px; background: hsl(var(--h), 70%, 62%); animation: grow .8s ease-out; transform-origin: left; }
@keyframes grow { from { transform: scaleX(0); } }
.tbar b { text-align: right; font-weight: 600; }
.week i.frozen { background: repeating-linear-gradient(135deg, #7db7ff 0 6px, #9cc8ff 6px 12px); }
