* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #0d0d14;
  --card: #16161f;
  --card2: #1c1c28;
  --text: #f0f0f5;
  --muted: #8a8a9e;
  --accent: #7c5cff;
  --accent2: #00d4a0;
  --wrong: #ff5470;
  --gold: #ffc744;
  --code-bg: #0a0a10;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

html, body { height: 100%; overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#app { display: flex; flex-direction: column; height: 100dvh; }

/* ---- top bar ---- */
#topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(8px + var(--safe-top)) 16px 8px;
  background: rgba(13,13,20,0.85); backdrop-filter: blur(12px);
  z-index: 10;
}
.logo { font-weight: 800; font-size: 18px; letter-spacing: -0.5px; }
.logo span { background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stats { display: flex; gap: 10px; font-size: 14px; font-weight: 700; }
.stats span { background: var(--card2); border-radius: 20px; padding: 4px 10px; }
#comboBadge { color: var(--gold); animation: pop 0.3s ease; }
.hidden { display: none !important; }

/* ---- main / feed ---- */
#view { flex: 1; overflow: hidden; position: relative; }
.feed {
  height: 100%; overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
}
.feed::-webkit-scrollbar { display: none; }

.card {
  height: 100%; scroll-snap-align: start; scroll-snap-stop: always;
  display: flex; flex-direction: column; justify-content: center;
  padding: 20px 20px 40px;
  position: relative;
}
.card-inner {
  background: var(--card);
  border: 1px solid #26263a;
  border-radius: 24px;
  padding: 24px 20px;
  max-height: 100%;
  overflow-y: auto;
  scrollbar-width: none;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.card-inner::-webkit-scrollbar { display: none; }

.badge {
  display: inline-block; font-size: 11px; font-weight: 800;
  padding: 4px 10px; border-radius: 12px; margin-bottom: 12px;
  letter-spacing: 0.5px;
}
.badge.concept { background: rgba(124,92,255,0.18); color: #a98fff; }
.badge.quiz { background: rgba(0,212,160,0.15); color: var(--accent2); }
.badge.code { background: rgba(255,199,68,0.15); color: var(--gold); }
.badge.molip { background: rgba(255,84,112,0.15); color: #ff8fa3; }
.badge.review { background: rgba(255,255,255,0.1); color: var(--muted); }
.badge.ref { background: transparent; border: 1px solid #33334a; color: var(--muted); float: right; }

.card h2 { font-size: 22px; line-height: 1.3; margin-bottom: 14px; letter-spacing: -0.3px; }
.card .body { font-size: 16px; line-height: 1.65; color: #d6d6e2; }
.card .body p { margin-bottom: 12px; }
.card .body b { color: var(--text); }
.card .body ul { margin: 0 0 12px 18px; }
.card .body li { margin-bottom: 6px; }
.card .body code, .qtext code {
  background: var(--code-bg); border-radius: 6px; padding: 2px 6px;
  font-family: "SF Mono", Menlo, monospace; font-size: 0.88em; color: #7ee0c8;
}

pre.codeblock {
  background: var(--code-bg); border: 1px solid #222232;
  border-radius: 14px; padding: 14px; margin: 12px 0;
  overflow-x: auto; font-family: "SF Mono", Menlo, monospace;
  font-size: 13.5px; line-height: 1.55;
  user-select: text; -webkit-user-select: text;
}
pre.codeblock code { background: none; padding: 0; color: #e8e8f0; font-size: inherit; }
.kw { color: #c792ea; } .str { color: #c3e88d; } .com { color: #5c6370; font-style: italic; } .num { color: #f78c6c; }

.qtext { font-size: 18px; font-weight: 700; line-height: 1.5; margin-bottom: 16px; }

.choices { display: flex; flex-direction: column; gap: 10px; }
.choices button {
  background: var(--card2); color: var(--text);
  border: 1.5px solid #2c2c40; border-radius: 14px;
  padding: 14px 16px; font-size: 15.5px; font-weight: 600;
  text-align: left; cursor: pointer; transition: transform 0.1s, border-color 0.15s;
  font-family: inherit; line-height: 1.4;
}
.choices button:active { transform: scale(0.97); }
.choices button.correct { background: rgba(0,212,160,0.18); border-color: var(--accent2); }
.choices button.wrong { background: rgba(255,84,112,0.18); border-color: var(--wrong); }
.choices button:disabled { cursor: default; opacity: 0.85; }
.choices.tf { flex-direction: row; }
.choices.tf button { flex: 1; text-align: center; font-size: 20px; padding: 18px; }

.explain {
  margin-top: 16px; background: var(--card2); border-radius: 14px;
  padding: 14px; font-size: 14.5px; line-height: 1.6; color: #c9c9da;
  border-left: 3px solid var(--accent);
  animation: slideup 0.3s ease;
}
.explain b { color: var(--text); }
.explain.ok { border-left-color: var(--accent2); }
.explain.ng { border-left-color: var(--wrong); }

.gotit {
  display: block; width: 100%; margin-top: 20px;
  background: linear-gradient(90deg, var(--accent), #9d7bff);
  color: #fff; border: none; border-radius: 14px;
  padding: 15px; font-size: 16px; font-weight: 800; cursor: pointer;
  font-family: inherit;
}
.gotit:active { transform: scale(0.97); }
.gotit:disabled { background: var(--card2); color: var(--muted); }
.gotit.done { background: var(--card2); color: var(--accent2); }

.swipe-hint {
  position: absolute; bottom: 14px; left: 0; right: 0;
  text-align: center; font-size: 12px; color: var(--muted);
  animation: bounce 1.5s infinite;
}

/* molip card */
.molip-q { font-size: 17px; line-height: 1.6; margin: 10px 0; padding: 14px; background: var(--card2); border-radius: 14px; }

/* ---- xp float ---- */
.xpfloat {
  position: fixed; font-size: 20px; font-weight: 900; color: var(--gold);
  pointer-events: none; z-index: 100; animation: floatup 1s ease forwards;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
}

/* ---- toast ---- */
#toast {
  position: fixed; top: calc(60px + var(--safe-top)); left: 50%; transform: translateX(-50%) translateY(-20px);
  background: var(--card2); border: 1px solid #33334a; border-radius: 20px;
  padding: 10px 20px; font-size: 15px; font-weight: 700;
  opacity: 0; transition: all 0.25s; z-index: 100; pointer-events: none;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- tab bar ---- */
#tabbar {
  display: flex; background: rgba(13,13,20,0.9); backdrop-filter: blur(12px);
  border-top: 1px solid #1e1e2c;
  padding-bottom: var(--safe-bot);
}
#tabbar button {
  flex: 1; background: none; border: none; color: var(--muted);
  padding: 10px 0 8px; font-size: 11px; font-weight: 700; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: inherit; position: relative;
}
#tabbar button .ico { font-size: 20px; }
#tabbar button.active { color: var(--text); }
#tabbar em {
  position: absolute; top: 6px; right: 28%;
  width: 8px; height: 8px; border-radius: 50%; background: var(--wrong);
}

/* ---- panels (review/progress/settings) ---- */
.panel { height: 100%; overflow-y: auto; padding: 20px 16px 40px; }
.panel h1 { font-size: 24px; margin-bottom: 16px; letter-spacing: -0.5px; }
.panel .sub { color: var(--muted); font-size: 14px; margin-bottom: 20px; line-height: 1.5; }

.bigstat {
  display: flex; gap: 10px; margin-bottom: 20px;
}
.bigstat > div {
  flex: 1; background: var(--card); border-radius: 18px; padding: 16px 12px;
  text-align: center; border: 1px solid #23233a;
}
.bigstat .num { font-size: 26px; font-weight: 900; }
.bigstat .lbl { font-size: 12px; color: var(--muted); margin-top: 4px; }

.chrow {
  background: var(--card); border-radius: 16px; padding: 14px 16px;
  margin-bottom: 10px; border: 1px solid #212132; cursor: pointer;
}
.chrow:active { transform: scale(0.98); }
.chrow .t { display: flex; justify-content: space-between; font-size: 14.5px; font-weight: 700; margin-bottom: 8px; }
.chrow .t .pct { color: var(--muted); font-weight: 600; }
.chrow .bar { height: 6px; background: #23233a; border-radius: 3px; overflow: hidden; }
.chrow .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 3px; }
.chrow.current { border-color: var(--accent); }

.btn {
  display: block; width: 100%; background: linear-gradient(90deg, var(--accent), #9d7bff);
  color: #fff; border: none; border-radius: 14px; padding: 15px;
  font-size: 16px; font-weight: 800; cursor: pointer; margin-bottom: 12px;
  font-family: inherit; text-align: center;
}
.btn.ghost { background: var(--card2); color: var(--text); border: 1px solid #2c2c40; }
.btn.danger { background: var(--card2); color: var(--wrong); border: 1px solid #3a2030; }
.btn:active { transform: scale(0.98); }

select, textarea {
  width: 100%; background: var(--card2); color: var(--text);
  border: 1px solid #2c2c40; border-radius: 12px; padding: 12px;
  font-size: 15px; font-family: inherit; margin-bottom: 12px;
}
label.fieldlbl { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }

/* ---- overlay (recap) ---- */
#overlay {
  position: fixed; inset: 0; background: rgba(8,8,14,0.92); backdrop-filter: blur(8px);
  z-index: 50; overflow-y: auto; padding: calc(20px + var(--safe-top)) 20px 40px;
}
.recap-box h1 { font-size: 26px; margin-bottom: 6px; }
.recap-box .sub { color: var(--muted); margin-bottom: 20px; }
.recap-box h3 { font-size: 15px; color: var(--muted); margin: 18px 0 8px; }
.recap-box li { margin-left: 18px; margin-bottom: 6px; font-size: 15px; line-height: 1.5; }

/* ---- 읽기 모드 ---- */
.rd-h {
  font-size: 18px; font-weight: 800; margin: 18px 0 10px;
  border-left: 3px solid var(--accent); padding-left: 10px;
}
.card .body a { color: var(--accent2); text-decoration: none; border-bottom: 1px dotted var(--accent2); }
.rd-note {
  border-radius: 14px; padding: 12px 14px; margin: 12px 0;
  font-size: 14.5px; line-height: 1.6;
  background: var(--card2); border: 1px solid #2c2c40;
}
.rd-note p { margin-bottom: 8px; }
.rd-note p:last-child { margin-bottom: 0; }
.rd-note-t { font-weight: 800; font-size: 12.5px; margin-bottom: 8px; letter-spacing: 0.4px; text-transform: uppercase; }
.rd-note.green { border-color: rgba(0,212,160,0.4); }
.rd-note.green .rd-note-t { color: var(--accent2); }
.rd-note.blue { border-color: rgba(124,92,255,0.45); }
.rd-note.blue .rd-note-t { color: #a98fff; }
.rd-note.gray .rd-note-t { color: var(--muted); }
.rd-note.red, .rd-note.yellow { border-color: rgba(255,84,112,0.4); }
.rd-note.red .rd-note-t, .rd-note.yellow .rd-note-t { color: var(--wrong); }
.rd-img { max-width: 100%; border-radius: 10px; margin: 10px 0; background: #fff; }
.rd-tbl { overflow-x: auto; margin: 12px 0; }
.rd-tbl table { border-collapse: collapse; font-size: 13.5px; }
.rd-tbl td, .rd-tbl th { border: 1px solid #2c2c40; padding: 6px 10px; }
.rd-tbl th { background: var(--card2); }
#backChip {
  position: absolute; top: 10px; left: 16px; z-index: 5;
  background: rgba(22,22,31,0.92); border: 1px solid #2c2c40; color: var(--text);
  border-radius: 20px; padding: 8px 14px; font-weight: 700; font-size: 13px;
  cursor: pointer; font-family: inherit; backdrop-filter: blur(8px);
}
.badge.ref { cursor: pointer; }

/* ---- animations ---- */
@keyframes pop { 0% { transform: scale(1.5); } 100% { transform: scale(1); } }
@keyframes slideup { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes floatup { 0% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-70px); } }
@keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.shake { animation: shake 0.3s ease; }

@media (min-width: 700px) {
  .card { padding: 30px 0 50px; }
  .card-inner, .swipe-hint { max-width: 480px; margin: 0 auto; width: 100%; }
  .panel { max-width: 560px; margin: 0 auto; }
}
