:root {
  --bg: #080d1d;
  --bg-elev: #111833;
  --bg-card: rgba(20, 29, 58, 0.88);
  --bg-card-hover: rgba(28, 40, 78, 0.94);
  --border: rgba(125, 211, 252, 0.16);
  --border-strong: rgba(56, 189, 248, 0.38);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --cyan: #38bdf8;
  --cyan-bright: #67e8f9;
  --gold: #fbbf24;
  --emerald: #34d399;
  --rose: #fb7185;
  --purple: #c084fc;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 12px 32px rgba(2, 6, 23, 0.45);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 50% 0%, #172554 0%, #0b1024 45%, #070b18 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: "Noto Sans CJK TC", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
}

body.has-tabbar {
  padding-bottom: calc(82px + env(safe-area-inset-bottom));
}

a {
  color: var(--cyan);
  text-decoration: none;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 15px;
}

.app-shell {
  max-width: 520px;
  margin: 0 auto;
  padding: 14px 14px 24px;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 4px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-badge {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.25), rgba(168, 85, 247, 0.25));
  border: 1px solid var(--border-strong);
  display: grid;
  place-items: center;
  font-size: 20px;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.pill-btn:active {
  transform: scale(0.97);
}

.coin-pill {
  background: rgba(251, 191, 36, 0.14);
  border-color: rgba(251, 191, 36, 0.42);
  color: #fde68a;
  font-weight: 700;
  font-size: 14px;
  padding: 7px 13px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.card + .card {
  margin-top: 12px;
}

/* Slime Hero Sanctuary */
.slime-hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(165deg, rgba(14, 34, 72, 0.92) 0%, rgba(16, 22, 48, 0.96) 100%);
  border: 1px solid rgba(56, 189, 248, 0.32);
}

.slime-hero::before {
  content: "";
  position: absolute;
  inset: -40% -20% auto -20%;
  height: 220px;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.18) 0%, transparent 70%);
  pointer-events: none;
}

.slime-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stage-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--cyan-bright);
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.35);
  padding: 4px 10px;
  border-radius: 999px;
}

.slime-stage-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0 4px;
  cursor: pointer;
  user-select: none;
}

.slime-svg {
  width: 176px;
  height: 148px;
  display: block;
  animation: slimeFloat 3.4s ease-in-out infinite;
  transition: transform 0.18s ease;
}

.mini-slime .slime-svg {
  width: 100%;
  height: 100%;
}

.slime-stage-area.squish .slime-svg {
  animation: slimeSquish 0.45s ease;
}

@keyframes slimeFloat {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  50% { transform: translateY(-6px) scale(0.985, 1.02); }
}

@keyframes slimeSquish {
  0% { transform: scale(1, 1); }
  30% { transform: scale(1.13, 0.86); }
  65% { transform: scale(0.93, 1.08); }
  100% { transform: scale(1, 1); }
}

.slime-name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 2px;
}

.slime-name {
  font-size: 19px;
  font-weight: 800;
}

.slime-level {
  font-size: 13px;
  font-weight: 700;
  color: var(--gold);
  background: rgba(251, 191, 36, 0.15);
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid rgba(251, 191, 36, 0.32);
}

.xp-bar-wrap {
  margin-top: 10px;
}

.xp-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.progress-track {
  width: 100%;
  height: 9px;
  background: rgba(15, 23, 42, 0.85);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.16);
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #0ea5e9, #67e8f9, #a855f7);
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Great Sage Dialogue Box */
.sage-box {
  margin-top: 12px;
  background: rgba(8, 15, 36, 0.78);
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-left: 3px solid var(--cyan-bright);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  color: #e0f2fe;
}

.sage-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: var(--cyan-bright);
  letter-spacing: 0.6px;
  margin-bottom: 3px;
}

/* Feed actions */
.feed-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.feed-btn {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 6px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: border-color 0.15s, background 0.15s;
}

.feed-btn:hover {
  border-color: var(--border-strong);
  background: rgba(30, 41, 78, 0.85);
}

.feed-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.feed-btn .emoji { font-size: 20px; }
.feed-btn .fname { font-size: 12px; font-weight: 700; }
.feed-btn .fcost { font-size: 11px; color: var(--gold); font-weight: 600; }

/* Section header & filter chips */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 2px 10px;
}

.section-title {
  font-size: 16px;
  font-weight: 700;
}

.filter-scroll {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 10px;
  scrollbar-width: none;
}

.filter-scroll::-webkit-scrollbar { display: none; }

.chip {
  white-space: nowrap;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
}

.chip.active {
  background: rgba(56, 189, 248, 0.2);
  border-color: var(--cyan);
  color: var(--cyan-bright);
}

/* Quest Cards */
.quest-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quest-card.is-rejected {
  border-color: rgba(251, 113, 133, 0.55);
  background: rgba(44, 20, 42, 0.75);
}

.quest-card.is-pending {
  border-color: rgba(251, 191, 36, 0.35);
}

.quest-card.is-completed {
  opacity: 0.65;
}

.quest-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge-recur {
  background: rgba(148, 163, 184, 0.14);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.22);
}

.badge-status-open { background: rgba(56, 189, 248, 0.15); color: #7dd3fc; }
.badge-status-pending { background: rgba(251, 191, 36, 0.16); color: #fde68a; }
.badge-status-rejected { background: rgba(251, 113, 133, 0.2); color: #fda4af; }
.badge-status-approved, .badge-status-completed, .badge-status-fulfilled {
  background: rgba(52, 211, 153, 0.16);
  color: #6ee7b7;
}

.quest-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.quest-desc {
  font-size: 13px;
  color: var(--text-muted);
}

.quest-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 2px;
}

.reward-tags {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 700;
}

.tag-coins { color: var(--gold); }
.tag-xp { color: var(--cyan-bright); }
.tag-due { color: var(--text-muted); font-size: 12px; font-weight: 500; }

.feedback-banner {
  background: rgba(251, 113, 133, 0.14);
  border: 1px solid rgba(251, 113, 133, 0.35);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  color: #fecdd3;
}

.note-preview {
  background: rgba(15, 23, 42, 0.65);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  color: #cbd5e1;
}

.photo-thumb {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-top: 6px;
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 9px 16px;
  border-radius: 12px;
  border: none;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #041322;
}

.btn-gold {
  background: linear-gradient(135deg, #d97706, #fbbf24);
  color: #1c1002;
}

.btn-emerald {
  background: linear-gradient(135deg, #059669, #34d399);
  color: #032217;
}

.btn-danger {
  background: rgba(251, 113, 133, 0.18);
  border: 1px solid rgba(251, 113, 133, 0.45);
  color: #fda4af;
}

.btn-ghost {
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 10px;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-row > .btn {
  flex: 1;
}

/* Skills & Roadmap */
.skills-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.skill-item {
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}

.skill-item.locked {
  opacity: 0.48;
  filter: grayscale(0.7);
}

.skill-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--cyan-bright);
}

.skill-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

.roadmap-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.roadmap-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border);
}

.roadmap-item.current {
  border-color: var(--cyan);
  background: rgba(14, 116, 144, 0.24);
}

.roadmap-item.locked {
  opacity: 0.5;
}

/* Bottom Tab Bar */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(8, 13, 29, 0.94);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  z-index: 40;
}

.tabbar-inner {
  max-width: 520px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.tabbar-inner.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
}

.tab-btn.active {
  color: var(--cyan-bright);
  background: rgba(56, 189, 248, 0.12);
}

.tab-btn .ticon { font-size: 19px; line-height: 1.1; }

.tab-badge {
  position: absolute;
  top: 2px;
  right: 18%;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--rose);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: grid;
  place-items: center;
}

/* Forms & Inputs */
.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #cbd5e1;
  margin-bottom: 5px;
}

.input, .select, .textarea {
  width: 100%;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--cyan);
}

.textarea {
  min-height: 82px;
  resize: vertical;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Login Screen */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 20px 16px;
  max-width: 420px;
  margin: 0 auto;
}

.pin-input {
  text-align: center;
  font-size: 24px;
  letter-spacing: 8px;
  font-weight: 800;
  padding: 14px;
}

/* Modal / Bottom Sheet */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 80;
  padding: 12px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-sheet {
  width: 100%;
  max-width: 500px;
  max-height: 88dvh;
  overflow-y: auto;
  background: #0f1733;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 17px;
  font-weight: 800;
}

/* Toast */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-16px);
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid var(--cyan);
  color: #e0f2fe;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.empty-state {
  text-align: center;
  padding: 28px 14px;
  color: var(--text-muted);
  font-size: 14px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.history-item:last-child {
  border-bottom: none;
}

.hidden { display: none !important; }

/* Quest presets */
.preset-block { margin-bottom: 14px; }
.preset-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin: 0 0 7px;
  letter-spacing: 0.3px;
}
.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 11px;
  color: var(--text);
  cursor: pointer;
}
.preset-btn:hover, .preset-btn.active {
  border-color: var(--cyan);
  background: rgba(14, 116, 144, 0.22);
}
.preset-btn .ptitle { font-size: 14px; font-weight: 800; }
.preset-btn .pmeta { font-size: 11px; color: var(--gold); font-weight: 700; }
.preset-btn .phint { font-size: 11px; color: var(--text-muted); }

/* Grammar settings */
.lock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}
.lock-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #cbd5e1;
}
.level-pills { display: flex; gap: 6px; flex-wrap: wrap; }

/* Quiz */
.quiz-progress {
  font-size: 12px;
  font-weight: 700;
  color: var(--cyan-bright);
  margin-bottom: 8px;
}
.quiz-prompt {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.45;
  margin: 8px 0 14px;
}
.quiz-choice {
  width: 100%;
  text-align: left;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 14px;
  margin-bottom: 8px;
  font-weight: 600;
  cursor: pointer;
}
.quiz-choice.selected {
  border-color: var(--cyan);
  background: rgba(14, 116, 144, 0.28);
  color: var(--cyan-bright);
}
.quiz-choice.correct {
  border-color: var(--emerald);
  background: rgba(5, 150, 105, 0.22);
  color: #6ee7b7;
}
.quiz-choice.wrong {
  border-color: var(--rose);
  background: rgba(251, 113, 133, 0.16);
  color: #fda4af;
}

.score-banner {
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 6px 0 10px;
}
.score-banner .score-num {
  font-size: 22px;
  font-weight: 800;
  color: var(--cyan-bright);
}
.wrong-item {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(251, 113, 133, 0.25);
  border-radius: 12px;
  padding: 10px 12px;
  margin-top: 8px;
  font-size: 13px;
}
.wrong-item .wprompt { font-weight: 700; margin-bottom: 4px; }
.wrong-item .wans { color: #fda4af; }
.wrong-item .cok { color: #6ee7b7; }
.wrong-item .wexp { color: var(--text-muted); margin-top: 4px; }
