:root {
  --bg: #f5f3ff;
  --ink: #1f1b3a;
  --ink-soft: #6b6489;
  --card: #ffffff;
  --line: #ece9fb;
  --violet: #7c5cff;
  --violet-dk: #5b3df0;
  --pink: #ff6b8b;
  --amber: #ffb648;
  --green: #22c58b;
  --red: #ff5c6c;
  --shadow: 0 10px 30px -12px rgba(91, 61, 240, 0.28);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Segoe UI", sans-serif;
  overscroll-behavior-y: none;
}

body {
  background:
    radial-gradient(1200px 500px at 50% -10%, #ede8ff 0%, transparent 60%),
    var(--bg);
}

button, input { font-family: inherit; }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-top: var(--safe-t);
  padding-bottom: calc(var(--safe-b) + 8px);
  display: flex;
  flex-direction: column;
}

a { color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px 8px;
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  z-index: 5;
}
.topbar h1 {
  font-size: 19px;
  margin: 0;
  flex: 1;
  font-weight: 800;
}
.iconbtn {
  width: 38px; height: 38px;
  border-radius: 12px;
  border: none;
  background: var(--card);
  box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  cursor: pointer;
}
.iconbtn:active { transform: scale(0.94); }

/* ---------- generic layout ---------- */
.screen {
  flex: 1;
  padding: 4px 18px 24px;
  animation: fadeUp 0.28s ease both;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--card);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  border: 1px solid var(--line);
}

.muted { color: var(--ink-soft); font-size: 13px; }

.btn {
  appearance: none;
  border: none;
  border-radius: 16px;
  padding: 15px 18px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  color: #fff;
  background: linear-gradient(135deg, var(--violet), var(--violet-dk));
  box-shadow: 0 10px 22px -8px rgba(91, 61, 240, 0.55);
  transition: transform 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn.secondary {
  background: var(--card);
  color: var(--violet-dk);
  border: 1.5px solid var(--line);
  box-shadow: none;
}
.btn.pink { background: linear-gradient(135deg, var(--pink), #ff9066); box-shadow: 0 10px 22px -8px rgba(255,107,139,0.55); }
.btn.ghost { background: transparent; color: var(--ink-soft); box-shadow: none; }
.btn.sm { padding: 10px 14px; font-size: 14px; border-radius: 12px; width: auto; }

.row { display: flex; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 10px; }
.spacer { flex: 1; }
.center { text-align: center; }

input[type=text], input[type=tel], input[type=password] {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: #faf9ff;
  font-size: 16px;
  color: var(--ink);
  outline: none;
}
input:focus { border-color: var(--violet); background: #fff; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #f0ecff;
  color: var(--violet-dk);
}
.chip.pink { background: #ffe9ee; color: #e0455f; }
.chip.green { background: #e3faf1; color: #0f9d6d; }
.chip.amber { background: #fff3e0; color: #b9770e; }

/* ---------- welcome / auth ---------- */
.hero {
  text-align: center;
  padding: 34px 6px 8px;
}
.hero .logo {
  font-size: 52px;
  line-height: 1;
  margin-bottom: 10px;
}
.hero h1 {
  font-size: 26px;
  margin: 6px 0 4px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--violet-dk), var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p { color: var(--ink-soft); font-size: 14px; margin: 0; }

.tabs {
  display: flex;
  background: #efecff;
  border-radius: 14px;
  padding: 4px;
  margin: 18px 0 16px;
}
.tabs button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px;
  border-radius: 11px;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
}
.tabs button.active {
  background: #fff;
  color: var(--violet-dk);
  box-shadow: 0 4px 12px -4px rgba(91,61,240,0.35);
}

.pick {
  display: flex;
  gap: 10px;
}
.pick .opt {
  flex: 1;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 16px 8px;
  text-align: center;
  cursor: pointer;
  background: #fff;
}
.pick .opt.sel {
  border-color: var(--violet);
  background: #f4f1ff;
}
.pick .opt .big { font-size: 26px; display: block; margin-bottom: 4px; }
.pick .opt .lbl { font-size: 13px; font-weight: 700; }

/* ---------- home ---------- */
.greet {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 18px;
}
.avatar {
  width: 50px; height: 50px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--violet), var(--pink));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 20px;
  flex-shrink: 0;
}
.greet .name { font-weight: 800; font-size: 17px; }

.streak-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.flame {
  font-size: 34px;
}
.streak-num { font-size: 28px; font-weight: 900; }

.progress-ring {
  position: relative;
  width: 54px; height: 54px;
  flex-shrink: 0;
}
.progress-ring svg { transform: rotate(-90deg); }
.progress-ring .pct {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: var(--violet-dk);
}

.section-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 18px 4px 8px;
}

.partner-card .ptop { display: flex; align-items: center; gap: 10px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex-shrink: 0; }
.dot.on { background: var(--green); box-shadow: 0 0 0 4px rgba(34,197,139,0.15); }

/* ---------- feed / chat ---------- */
.react-row { display: flex; gap: 8px; margin-bottom: 10px; }
.react-btn {
  flex: 1;
  border: none;
  border-radius: 14px;
  background: #f7f5ff;
  font-size: 22px;
  padding: 10px 0;
  cursor: pointer;
}
.react-btn:active { transform: scale(0.9); }

.msg-input-row { display: flex; gap: 8px; }
.msg-input-row input { flex: 1; }

.feed-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; max-height: 260px; overflow-y: auto; }
.bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
}
.bubble .who { font-size: 11px; opacity: 0.6; margin-bottom: 2px; }
.bubble.me { align-self: flex-end; background: linear-gradient(135deg, var(--violet), var(--violet-dk)); color: #fff; border-bottom-right-radius: 4px; }
.bubble.them { align-self: flex-start; background: #f1eefe; color: var(--ink); border-bottom-left-radius: 4px; }
.bubble.emo { font-size: 22px; padding: 6px 12px; background: transparent; }

/* ---------- quiz ---------- */
.quiz-top { display: flex; align-items: center; gap: 10px; margin: 6px 0 20px; }
.bar {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--violet), var(--pink));
  border-radius: 999px;
  transition: width 0.25s ease;
}
.qcount { font-size: 13px; font-weight: 800; color: var(--ink-soft); white-space: nowrap; }

.prompt-card {
  text-align: center;
  padding: 40px 16px;
  border-radius: 24px;
  background: linear-gradient(160deg, #fff, #f6f3ff);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.prompt-main { font-size: 34px; font-weight: 900; word-break: break-word; }
.prompt-sub { font-size: 16px; color: var(--violet-dk); margin-top: 8px; font-weight: 600; }

.opt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt-btn {
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 16px;
  padding: 16px 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  min-height: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}
.opt-btn .sub { font-size: 12px; font-weight: 500; color: var(--ink-soft); }
.opt-btn:active { transform: scale(0.96); }
.opt-btn.correct { border-color: var(--green); background: #eafbf3; }
.opt-btn.correct .sub { color: #0f9d6d; }
.opt-btn.wrong { border-color: var(--red); background: #ffefee; }
.opt-btn[disabled] { pointer-events: none; }
.opt-btn.dim { opacity: 0.45; }

/* ---------- battle ---------- */
.vs-row { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.vs-side { flex: 1; }
.vs-name { font-size: 13px; font-weight: 800; margin-bottom: 4px; }
.vs-mid { font-size: 12px; font-weight: 900; color: var(--ink-soft); }
.vs-bar { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.vs-bar > i { display: block; height: 100%; border-radius: 999px; }
.vs-bar.mine > i { background: linear-gradient(90deg, var(--violet), var(--violet-dk)); }
.vs-bar.opp > i { background: linear-gradient(90deg, var(--pink), var(--amber)); }

.code-box {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-align: center;
  padding: 20px 0;
  border-radius: 18px;
  background: linear-gradient(135deg, #f4f1ff, #ffe9ee);
  color: var(--violet-dk);
}

.spin {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--violet);
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- result ---------- */
.result-hero {
  text-align: center;
  padding: 20px 0 10px;
}
.result-score {
  font-size: 58px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--violet-dk), var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.coach-bubble {
  background: #fff8ea;
  border: 1.5px solid #ffe3a8;
  border-radius: 16px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.6;
  margin: 14px 0;
}

.win-badge {
  display: inline-block;
  font-size: 15px;
  font-weight: 900;
  padding: 8px 20px;
  border-radius: 999px;
  margin-bottom: 10px;
}
.win-badge.win { background: #e3faf1; color: #0f9d6d; }
.win-badge.lose { background: #f1eefe; color: var(--violet-dk); }
.win-badge.tie { background: #fff3e0; color: #b9770e; }

/* ---------- bottom nav ---------- */
.tabbar {
  position: sticky;
  bottom: 0;
  display: flex;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 8px 10px calc(8px + var(--safe-b));
  gap: 4px;
}
.tabbar button {
  flex: 1;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  cursor: pointer;
}
.tabbar button .ic { font-size: 20px; }
.tabbar button.active { color: var(--violet-dk); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-b));
  transform: translateX(-50%) translateY(20px);
  background: #1f1b3a;
  color: #fff;
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 999;
  max-width: 86vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- confetti ---------- */
.confetti-piece {
  position: fixed;
  top: -10px;
  width: 8px; height: 14px;
  z-index: 998;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(540deg); opacity: 0.3; }
}

/* ---------- misc ---------- */
.empty {
  text-align: center;
  padding: 30px 10px;
  color: var(--ink-soft);
  font-size: 14px;
}
.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 60vh;
}
::-webkit-scrollbar { display: none; }
