/* Telegram gives its theme colours as --tg-theme-* CSS variables (light/dark follow the app). */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --accent: var(--tg-theme-button-color, #3478f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-section-bg-color, var(--bg));
  --again: #ef4444; --hard: #f59e0b; --good: #22c55e; --easy: #3b82f6;
  --radius: 20px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg2); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none;
}
.view { min-height: 100vh; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto; }
.hidden { display: none !important; }
.center { text-align: center; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
h1 { font-size: 26px; margin: 2px 0 0; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

/* Home */
.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.streak { background: var(--card); border-radius: 999px; padding: 6px 12px; font-weight: 600; }
.hero { display: flex; align-items: center; gap: 20px; background: var(--card); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.ring { position: relative; width: 120px; height: 120px; flex: none; }
.ring svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.ring circle { fill: none; stroke-width: 10; stroke-linecap: round; }
.ring-bg { stroke: var(--bg2); }
.ring-fg { stroke: var(--accent); stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset .8s ease; }
.ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-text b { font-size: 32px; line-height: 1; }
.ring-text span { font-size: 12px; color: var(--hint); }
.hero-stats { display: grid; gap: 10px; flex: 1; }
.hero-stats div { display: flex; justify-content: space-between; align-items: baseline; }
.hero-stats b { font-size: 20px; order: 2; }
.hero-stats span { color: var(--hint); }
.big { width: 100%; padding: 16px; border-radius: 16px; font-size: 18px; font-weight: 600; }
.primary { background: var(--accent); color: var(--accent-text); }
.primary:disabled { opacity: .45; }
.panel { background: var(--card); border-radius: var(--radius); padding: 16px; margin-top: 14px; }
.row { display: flex; justify-content: space-between; margin-top: 10px; }
.heat { display: grid; grid-template-rows: repeat(7, auto); grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 3px; }
.heat i { aspect-ratio: 1; border-radius: 3px; background: var(--bg2); }
.heat i.l1 { background: color-mix(in srgb, var(--good) 35%, var(--bg2)); }
.heat i.l2 { background: color-mix(in srgb, var(--good) 60%, var(--bg2)); }
.heat i.l3 { background: var(--good); }
.heat i.today { outline: 2px solid var(--accent); }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 110px; }
.bars div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: 12px; color: var(--hint); }
.bars i { width: 100%; background: var(--accent); border-radius: 6px 6px 2px 2px; min-height: 3px; margin: 3px 0; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; }
.seg { display: flex; background: var(--bg2); border-radius: 10px; padding: 2px; }
.seg button { padding: 6px 12px; border-radius: 8px; font-weight: 600; }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.switch { appearance: none; width: 50px; height: 30px; border-radius: 30px; background: var(--bg2); position: relative; transition: .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: .2s; }
.switch:checked { background: var(--good); }
.switch:checked::after { left: 23px; }

/* Review */
#review { display: flex; flex-direction: column; height: 100vh; }
.progress { height: 6px; background: var(--card); border-radius: 6px; overflow: hidden; }
#bar { height: 100%; width: 0; background: var(--good); transition: width .3s; }
.review-top { display: flex; justify-content: space-between; align-items: center; margin: 6px 0; }
.icon { font-size: 24px; padding: 0 6px; color: var(--hint); }
.stage { flex: 1; position: relative; perspective: 1400px; display: flex; min-height: 0; }
.card { flex: 1; position: relative; transform-style: preserve-3d; transition: transform .45s cubic-bezier(.2,.8,.2,1); }
.card.flipped { transform: rotateY(180deg); }
.card.dragging { transition: none; }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--card); border-radius: 28px; box-shadow: 0 8px 30px rgba(0,0,0,.08);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 28px; text-align: center; }
.back { transform: rotateY(180deg); }
.tag { position: absolute; top: 18px; left: 20px; font-size: 12px; font-weight: 700; color: var(--hint); text-transform: uppercase; letter-spacing: .06em; }
.word { font-size: clamp(26px, 8vw, 40px); font-weight: 700; line-height: 1.2; word-break: break-word; }
.meaning { font-size: 22px; margin-top: 14px; color: var(--hint); }
.hint { margin-top: 14px; font-size: 14px; }
.sound { font-size: 26px; width: 58px; height: 58px; border-radius: 50%; background: var(--bg2); margin-top: 22px; }
.sounds { display: flex; gap: 14px; }
.swipe-label { position: absolute; top: 40%; font-size: 22px; font-weight: 800; padding: 8px 16px; border-radius: 12px; opacity: 0; pointer-events: none; color: #fff; }
.swipe-label.left { left: 10px; background: var(--again); }
.swipe-label.right { right: 10px; background: var(--good); }
.answer { padding-top: 14px; }
.rates { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rate { border-radius: 16px; padding: 12px 4px; color: #fff; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rate b { font-size: 15px; } .rate span { font-size: 12px; opacity: .9; }
.rate:active, .big:active { transform: scale(.97); }
.again { background: var(--again); } .hard { background: var(--hard); } .good { background: var(--good); } .easy { background: var(--easy); }

/* Done */
#done { display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.party { font-size: 72px; animation: pop .6s ease; }
@keyframes pop { 0% { transform: scale(.3); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
.toast { position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); z-index: 20; max-width: 90%; text-align: center; transform: translateX(-50%); background: rgba(0,0,0,.8); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; }

/* 📚 Words */
.two { display: flex; gap: 10px; margin-top: 10px; }
.two .big { flex: 1; font-size: 16px; padding: 14px 8px; }
.secondary { background: var(--card); color: var(--text); }
.danger { color: var(--again); }
.search, .field { width: 100%; font: inherit; color: var(--text); background: var(--card); border: 0;
  border-radius: 12px; padding: 12px 14px; outline: none; user-select: text; -webkit-user-select: text; }
.field { background: var(--bg2); margin: 4px 0 12px; font-size: 18px; }
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 10px 0; padding-bottom: 2px; scrollbar-width: none; }
.chips button { flex: none; padding: 7px 12px; border-radius: 999px; background: var(--card); font-size: 14px; }
.chips button.on { background: var(--accent); color: var(--accent-text); }
.copybar { width: 100%; text-align: left; background: color-mix(in srgb, var(--accent) 15%, var(--card));
  border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; font-weight: 600; }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 14px;
  border-bottom: 1px solid var(--bg2); }
.item:last-child { border-bottom: 0; }
.item b { display: block; font-weight: 600; }
.item span { color: var(--hint); font-size: 14px; }
.pill { flex: none; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; color: #fff; }
.pill.new { background: var(--easy); } .pill.learning { background: var(--hard); }
.pill.learned { background: var(--good); } .pill.hidden { background: var(--hint); }
.fab { position: fixed; right: 20px; bottom: calc(24px + env(safe-area-inset-bottom)); width: 58px; height: 58px;
  border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 30px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); }
#words { padding-bottom: 100px; }
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; z-index: 10; }
.sheet { width: 100%; max-width: 560px; margin: 0 auto; background: var(--card); border-radius: 22px 22px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .25s ease; }
.sheet .big { margin-top: 8px; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
.pill { font-style: normal; }
.sheet .secondary { background: var(--bg2); }
.starter { background: color-mix(in srgb, var(--good) 14%, var(--card)); }
.more-starter { background: var(--bg2); font-size: 15px; margin-top: 8px; }

/* 🎤 Speaking */
.showrow { display: flex; gap: 10px; }
.showrow .big { flex: 1; }
.mic { flex: none; width: 58px; border-radius: 16px; background: var(--card); font-size: 26px; }
.mic.rec { background: var(--again); animation: pulse 1s infinite; }
.mic.wait { opacity: .5; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.said { margin-top: 16px; font-size: 15px; background: var(--bg2); border-radius: 12px; padding: 8px 12px; }
.said u { color: var(--again); text-decoration-thickness: 2px; }
.rate.suggest { outline: 3px solid var(--text); outline-offset: 2px; }
