/* ============ SwipeStudy — dark + vibrant design system ============ */
:root {
  --bg: #0b0b13;
  --bg2: #131322;
  --card: #1a1a2e;
  --card2: #21213a;
  --line: #2c2c4a;
  --text: #f1f0ff;
  --muted: #8f8fb3;
  --accent: #7c5cff;
  --accent2: #ff4d8d;
  --grad: linear-gradient(135deg, #7c5cff 0%, #ff4d8d 100%);
  --good: #2bd97c;
  --good-bg: rgba(43, 217, 124, .12);
  --bad: #ff5470;
  --bad-bg: rgba(255, 84, 112, .12);
  --gold: #ffcf5c;
  --radius: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  overflow: hidden;
  position: fixed; inset: 0;
  user-select: none; -webkit-user-select: none;
}
input, textarea { user-select: text; -webkit-user-select: text; }

#app { height: 100%; display: flex; flex-direction: column; }
#fx-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 900; }

button { font-family: inherit; border: none; cursor: pointer; color: inherit; background: none; font-size: 1rem; }

/* ============ screens ============ */
.screen { flex: 1; display: flex; flex-direction: column; overflow: hidden; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(16px + var(--safe-top)) 18px calc(90px + var(--safe-bottom)); }

/* ============ header ============ */
.hdr { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.hdr h1 { font-size: 1.7rem; font-weight: 800; letter-spacing: -.5px; }
.hdr h1 .grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hdr .sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }

.iconbtn {
  width: 42px; height: 42px; border-radius: 14px; background: var(--card);
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
  border: 1px solid var(--line); transition: transform .1s;
}
.iconbtn:active { transform: scale(.92); }

/* ============ stat pills ============ */
.pills { display: flex; gap: 10px; margin-bottom: 20px; }
.pill {
  flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 12px 10px; text-align: center;
}
.pill .v { font-size: 1.35rem; font-weight: 800; }
.pill .l { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }
.pill .v.fire { color: var(--gold); }
.pill .v.good { color: var(--good); }

/* ============ course cards ============ */
.sec-title { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin: 18px 0 10px; }
.course-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; display: flex; align-items: center; gap: 14px;
  transition: transform .12s;
}
.course-card:active { transform: scale(.98); }
.course-emoji {
  width: 52px; height: 52px; border-radius: 16px; font-size: 1.6rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  background: var(--bg2); border: 1px solid var(--line);
}
.course-info { flex: 1; min-width: 0; }
.course-info .name { font-weight: 700; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.course-info .meta { color: var(--muted); font-size: .8rem; margin-top: 3px; }
.ring { width: 46px; height: 46px; flex-shrink: 0; position: relative; }
.ring svg { transform: rotate(-90deg); }
.ring .pct { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: .68rem; font-weight: 800; }
.mastered-badge { color: var(--gold); font-size: .78rem; font-weight: 700; }

.btn {
  display: block; width: 100%; padding: 15px; border-radius: 16px; font-weight: 700; font-size: 1rem;
  text-align: center; transition: transform .1s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--grad); color: #fff; box-shadow: 0 6px 24px rgba(124, 92, 255, .35); }
.btn.ghost { background: var(--card); border: 1px solid var(--line); }
.btn.danger { background: var(--bad-bg); color: var(--bad); border: 1px solid rgba(255,84,112,.3); }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ============ tab bar ============ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 100;
  display: flex; padding: 8px 20px calc(8px + var(--safe-bottom));
  background: rgba(11, 11, 19, .88); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; color: var(--muted); font-size: .68rem; font-weight: 600; }
.tab .ico { font-size: 1.35rem; }
.tab.active { color: var(--text); }
.tab.active .ico { filter: drop-shadow(0 0 8px rgba(124, 92, 255, .8)); }

/* ============ quiz screen ============ */
.quiz-screen { position: relative; background: radial-gradient(120% 60% at 50% -10%, #1c1638 0%, var(--bg) 60%); }
.quiz-top {
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + var(--safe-top)) 16px 10px;
}
.quiz-top .close { font-size: 1.5rem; color: var(--muted); width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; }
.quiz-progress { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.session-score { font-size: .78rem; color: var(--muted); text-align: center; }
.session-score b { color: var(--text); }
.combo { font-weight: 800; font-size: .9rem; color: var(--gold); min-width: 52px; text-align: right; }

.card-stack { flex: 1; position: relative; padding: 8px 16px calc(16px + var(--safe-bottom)); }
.qcard {
  position: absolute; inset: 8px 16px calc(16px + var(--safe-bottom));
  background: var(--card); border: 1px solid var(--line); border-radius: 26px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
  touch-action: pan-y;
  will-change: transform;
}
.qcard.behind { transform: scale(.94) translateY(14px); opacity: .5; pointer-events: none; }
.qcard.leaving { transition: transform .32s cubic-bezier(.5, 0, .8, .5), opacity .3s; pointer-events: none; }
.qcard.entering { animation: cardIn .3s cubic-bezier(.2, .8, .3, 1.1); }
@keyframes cardIn { from { transform: scale(.94) translateY(20px); opacity: .4; } to { transform: none; opacity: 1; } }
.qcard.snapback { transition: transform .25s cubic-bezier(.2, .8, .3, 1.2); }

.qcard.flash-good { animation: flashGood .5s ease; }
.qcard.flash-bad { animation: flashBad .45s ease; }
@keyframes flashGood {
  0% { box-shadow: 0 0 0 rgba(43,217,124,0); }
  30% { box-shadow: 0 0 60px rgba(43, 217, 124, .8), inset 0 0 40px rgba(43,217,124,.15); border-color: var(--good); }
  100% { box-shadow: 0 18px 50px rgba(0,0,0,.5); }
}
@keyframes flashBad {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); } 40% { transform: translateX(9px); }
  60% { transform: translateX(-6px); } 80% { transform: translateX(4px); }
}
.qcard.flash-bad { border-color: var(--bad); box-shadow: 0 0 50px rgba(255, 84, 112, .45); }

.qcard-inner { flex: 1; display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 20px 20px 14px; }
.qmeta { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.chip { font-size: .7rem; font-weight: 700; padding: 5px 11px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); color: var(--muted); }
.chip.topic { color: #b9a5ff; border-color: rgba(124, 92, 255, .4); }
.chip.diff1 { color: var(--good); } .chip.diff2 { color: var(--gold); } .chip.diff3 { color: var(--accent2); }
.qtext { font-size: 1.16rem; font-weight: 700; line-height: 1.45; margin-bottom: 18px; white-space: pre-wrap; }

.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  text-align: left; padding: 14px 16px; border-radius: 16px; background: var(--bg2);
  border: 1.5px solid var(--line); font-size: .95rem; line-height: 1.35; font-weight: 500;
  transition: transform .08s, border-color .15s, background .15s;
  display: flex; gap: 10px; align-items: flex-start;
}
.choice:active { transform: scale(.98); }
.choice .key {
  width: 24px; height: 24px; border-radius: 8px; flex-shrink: 0; font-size: .75rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center; background: var(--card2); color: var(--muted);
}
.choice.sel-good { background: var(--good-bg); border-color: var(--good); }
.choice.sel-good .key { background: var(--good); color: #04160c; }
.choice.sel-bad { background: var(--bad-bg); border-color: var(--bad); }
.choice.sel-bad .key { background: var(--bad); color: #1c0409; }
.choice.reveal { border-color: var(--good); }
.choice.dim { opacity: .45; }
.choice[disabled] { pointer-events: none; }

.short-area { display: flex; flex-direction: column; gap: 10px; }
.short-area textarea {
  background: var(--bg2); border: 1.5px solid var(--line); border-radius: 16px; color: var(--text);
  padding: 14px; font-size: 1rem; font-family: inherit; min-height: 92px; resize: none; outline: none;
}
.short-area textarea:focus { border-color: var(--accent); }
.selfmark { display: flex; gap: 10px; }
.selfmark .btn { flex: 1; padding: 12px; }
.selfmark .yes { background: var(--good-bg); color: var(--good); border: 1px solid rgba(43,217,124,.35); }
.selfmark .no { background: var(--bad-bg); color: var(--bad); border: 1px solid rgba(255,84,112,.35); }

/* ============ result panel ============ */
.result {
  margin-top: 16px; border-radius: 18px; padding: 16px;
  animation: slideUp .3s cubic-bezier(.2, .8, .3, 1.1);
}
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.result.good { background: var(--good-bg); border: 1px solid rgba(43, 217, 124, .35); }
.result.bad { background: var(--bad-bg); border: 1px solid rgba(255, 84, 112, .35); }
.result .verdict { font-size: 1.15rem; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.result.good .verdict { color: var(--good); }
.result.bad .verdict { color: var(--bad); }
.result .expl { margin-top: 9px; font-size: .92rem; line-height: 1.5; color: var(--text); white-space: pre-wrap; }
.result .refans { margin-top: 9px; font-size: .9rem; line-height: 1.5; color: var(--text); background: rgba(255,255,255,.05); border-radius: 12px; padding: 10px 12px; white-space: pre-wrap; }
.result .refans b { color: var(--good); }

.swipe-hint {
  padding: 10px 0 4px; text-align: center; color: var(--muted); font-size: .8rem;
  display: flex; justify-content: center; gap: 18px; align-items: center;
  animation: fadeIn .4s ease .15s both;
}
.swipe-hint .k { color: var(--text); font-weight: 700; }
.swipe-hint.pre { margin-top: auto; padding-top: 16px; font-size: .74rem; opacity: .8; }
.bounce { display: inline-block; animation: bounceUp 1.2s ease infinite; }
@keyframes bounceUp { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

.next-btns { display: flex; gap: 10px; padding: 4px 0 2px; }
.next-btns .btn { padding: 12px; font-size: .9rem; }

/* ============ mastery / celebration overlay ============ */
.overlay {
  position: fixed; inset: 0; z-index: 800; background: rgba(8, 8, 16, .92);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center; padding: 28px;
  animation: fadeIn .3s ease;
}
.overlay .box { text-align: center; max-width: 420px; width: 100%; }
.overlay .big { font-size: 4rem; animation: pop .5s cubic-bezier(.2, .8, .3, 1.4); }
@keyframes pop { from { transform: scale(.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.overlay h2 { font-size: 1.7rem; font-weight: 800; margin: 12px 0 8px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.overlay p { color: var(--muted); line-height: 1.5; margin-bottom: 22px; }

/* ============ topic bars ============ */
.topic-row { margin-bottom: 14px; }
.topic-row .t { display: flex; justify-content: space-between; font-size: .88rem; margin-bottom: 6px; }
.topic-row .t .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 10px; }
.topic-row .t .lv { color: var(--muted); font-size: .75rem; flex-shrink: 0; }
.bar { height: 8px; border-radius: 99px; background: var(--bg2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--grad); transition: width .6s cubic-bezier(.2, .8, .3, 1); }
.bar > i.weak { background: linear-gradient(90deg, #ff5470, #ff9a5c); }
.bar > i.strong { background: linear-gradient(90deg, #2bd97c, #7c5cff); }

/* ============ activity chart ============ */
.chart { display: flex; align-items: flex-end; gap: 5px; height: 110px; padding: 10px 0 4px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 100%; }
.chart .col .stack { width: 100%; max-width: 26px; display: flex; flex-direction: column; justify-content: flex-end; border-radius: 6px; overflow: hidden; flex: 1; }
.chart .col .g { background: var(--good); }
.chart .col .b { background: var(--bad); opacity: .75; }
.chart .col .d { font-size: .6rem; color: var(--muted); }

/* ============ forms ============ */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .8rem; font-weight: 700; color: var(--muted); margin-bottom: 7px; text-transform: uppercase; letter-spacing: .5px; }
.field input[type=text], .field input[type=password], .field select {
  width: 100%; background: var(--card); border: 1.5px solid var(--line); border-radius: 14px;
  color: var(--text); padding: 13px 14px; font-size: 1rem; font-family: inherit; outline: none;
  appearance: none; -webkit-appearance: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field .hint { font-size: .78rem; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.field .hint a { color: var(--accent); }

.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px 16px; text-align: center;
  color: var(--muted); margin-bottom: 14px; transition: border-color .2s;
}
.dropzone.drag { border-color: var(--accent); color: var(--text); }
.dropzone .big-ico { font-size: 2rem; margin-bottom: 8px; }
.filelist { margin-bottom: 14px; }
.file-row {
  display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; font-size: .88rem;
}
.file-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .st { font-size: .75rem; color: var(--muted); flex-shrink: 0; }
.file-row .st.ok { color: var(--good); }
.file-row .st.err { color: var(--bad); }
.file-row .rm { color: var(--muted); font-size: 1.1rem; padding: 0 2px; }

.genlog {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
  font-size: .82rem; color: var(--muted); line-height: 1.6; max-height: 180px; overflow-y: auto;
  font-family: ui-monospace, monospace;
}
.genlog .ok { color: var(--good); }
.genlog .err { color: var(--bad); }

.spinner {
  width: 18px; height: 18px; border: 2.5px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner.big-spin { width: 44px; height: 44px; border-width: 4px; }

/* ============ language / translate ============ */
.lang-badge { color: #b9a5ff; font-size: .78rem; font-weight: 700; }
.lang-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0 2px; }
.lang-opt {
  padding: 12px 8px; border-radius: 14px; background: var(--card); border: 1px solid var(--line);
  color: var(--text); font-size: .9rem; font-weight: 600; transition: transform .08s, border-color .15s;
}
.lang-opt:hover { border-color: var(--accent); }
.lang-opt:active { transform: scale(.95); }

/* ============ toast ============ */
#toast-root { position: fixed; top: calc(14px + var(--safe-top)); left: 0; right: 0; z-index: 950; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--card2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 20px; border-radius: 999px; font-size: .88rem; font-weight: 600;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5); animation: toastIn .3s cubic-bezier(.2, .8, .3, 1.2);
  max-width: 86vw; text-align: center;
}
.toast.gold { border-color: rgba(255, 207, 92, .5); color: var(--gold); }
.toast.good { border-color: rgba(43, 217, 124, .5); color: var(--good); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px) scale(.9); } to { opacity: 1; transform: none; } }
.toast.out { transition: opacity .3s, transform .3s; opacity: 0; transform: translateY(-10px); }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; line-height: 1.6; }
.empty .big-ico { font-size: 2.6rem; margin-bottom: 10px; }

@media (min-width: 700px) {
  #app { max-width: 470px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .tabbar { max-width: 470px; margin: 0 auto; }
}
