:root {
  --bg: #eef6f8;
  --card: #ffffff;
  --text: #1f2d3a;
  --muted: #6b7c8c;
  --primary: #1a9e8f;
  --primary-dark: #137a6e;
  --doctor: #d9f2ee;
  --patient: #ffffff;
  --good: #2e9d4f;
  --bad: #d64545;
  --warn: #f2a33a;
  --border: #d5e3e8;
  --shadow: 0 2px 10px rgba(30, 60, 80, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121a20;
    --card: #1c2730;
    --text: #e6eef2;
    --muted: #93a6b4;
    --primary: #2bbfac;
    --primary-dark: #22a191;
    --doctor: #1d3a37;
    --patient: #24323d;
    --border: #2c3d49;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }

/* ---- 上方列 ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--card);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
.tools { display: flex; gap: 6px; }
.icon-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  width: 38px;
  height: 38px;
  font-size: 1rem;
}
.icon-btn.off { opacity: 0.45; text-decoration: line-through; }

/* ---- 畫面 ---- */
.screen {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
[hidden] { display: none !important; }

.title-card {
  background: var(--card);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
  margin-top: 4vh;
}
.big-emoji { font-size: 3.5rem; }
.title-card h1 { margin: 8px 0 0; font-size: 2rem; }
.subtitle { margin: 0 0 12px; color: var(--muted); letter-spacing: 0.1em; }
.howto { text-align: left; max-width: 420px; margin: 16px auto; line-height: 1.8; padding-left: 1.4em; }
.hint { color: var(--muted); font-size: 0.9rem; }
.record-line { color: var(--muted); font-size: 0.9rem; min-height: 1em; }

.primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 28px;
  font-size: 1.1rem;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
}
.primary:hover { background: var(--primary-dark); }
.primary:active { transform: scale(0.97); }
.secondary {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: 12px;
  padding: 10px 20px;
  font-weight: 600;
}

/* ---- 病人卡 ---- */
.patient-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: 16px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
}
.avatar { font-size: 2.6rem; line-height: 1; }
.avatar.shake { animation: shake 0.4s; }
.p-name { font-weight: 700; font-size: 1.15rem; }
.p-age { color: var(--muted); font-size: 0.85rem; }
.patience { margin-left: auto; font-size: 1.3rem; letter-spacing: 2px; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px) rotate(-5deg); }
  75% { transform: translateX(6px) rotate(5deg); }
}

/* ---- 對話 ---- */
.chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 160px;
}
.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  animation: pop 0.2s ease-out;
}
.msg.patient { background: var(--patient); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.doctor { background: var(--doctor); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.system {
  align-self: center;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  max-width: 100%;
}
.msg .who { font-size: 0.75rem; color: var(--muted); margin-bottom: 2px; }
.msg .en { display: flex; gap: 6px; align-items: flex-start; }
.msg .zh { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }
.speak {
  border: none;
  background: transparent;
  padding: 0 2px;
  font-size: 0.95rem;
  line-height: 1.4;
  flex-shrink: 0;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

body.hide-zh .zh { display: none; }

/* ---- 操作面板 ---- */
.panel {
  background: var(--card);
  border-radius: 16px;
  padding: 14px 16px 16px;
  box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 4px; font-size: 1rem; }
.panel .step { color: var(--muted); font-size: 0.8rem; margin-bottom: 10px; }
.choices { display: grid; gap: 8px; }
.choices.grid2 { grid-template-columns: 1fr 1fr; }
.choice {
  text-align: left;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  transition: border-color 0.15s, background 0.15s;
}
.choice:hover:not(:disabled) { border-color: var(--primary); }
.choice:disabled { opacity: 0.5; }
.choice.correct { border-color: var(--good); background: rgba(46, 157, 79, 0.12); opacity: 1; }
.choice.wrong { border-color: var(--bad); background: rgba(214, 69, 69, 0.12); opacity: 1; }
.choice .zh { display: block; color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.panel-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.explain {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(242, 163, 58, 0.14);
  font-size: 0.9rem;
  line-height: 1.6;
}

.record-sentence { font-size: 1.05rem; line-height: 2; }
.record-input {
  font: inherit;
  font-size: 1rem;
  width: 9em;
  padding: 4px 8px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  text-align: center;
}
.record-input:focus { outline: none; border-color: var(--primary); }
.record-input.correct { border-color: var(--good); }
.record-input.wrong { border-color: var(--bad); animation: shake 0.3s; }

/* ---- 結算 ---- */
.result { text-align: center; }
.stars { font-size: 2.2rem; letter-spacing: 6px; margin: 6px 0; }
.score-big { font-size: 1.4rem; font-weight: 700; }
.breakdown { list-style: none; padding: 0; margin: 10px auto; max-width: 320px; text-align: left; }
.breakdown li { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--border); }
.new-words { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 10px 0; }
.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--text);
}

/* ---- 單字本 ---- */
dialog {
  border: none;
  border-radius: 16px;
  padding: 16px;
  width: min(480px, calc(100vw - 32px));
  max-height: 80vh;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-head h2 { margin: 0; font-size: 1.2rem; }
.vocab-list { list-style: none; padding: 0; margin: 12px 0 0; }
.vocab-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}
.vocab-list .v-en { font-weight: 600; }
.vocab-list .v-zh { color: var(--muted); margin-left: auto; }

/* ---- 浮動提示 ---- */
.toast-layer {
  position: fixed;
  top: 64px;
  left: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 20;
}
.toast {
  background: var(--card);
  border-radius: 999px;
  padding: 6px 16px;
  font-weight: 700;
  font-size: 1rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  text-align: center;
  animation: floatUp 1.4s ease-out forwards;
}
.toast.good { color: var(--good); }
.toast.bad { color: var(--bad); }
@keyframes floatUp {
  0% { opacity: 0; transform: translateY(8px); }
  15% { opacity: 1; transform: none; }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-16px); }
}

@media (max-width: 520px) {
  .brand span { display: none; }
  .choices.grid2 { grid-template-columns: 1fr; }
  .msg { max-width: 92%; }
}

/* ===================== 養成系統 ===================== */
body { padding-bottom: 76px; }
.hud { display: flex; gap: 10px; flex: 1; justify-content: center; flex-wrap: wrap; font-size: 0.9rem; }
.hud span { background: var(--bg); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.title-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.secondary:disabled, .primary:disabled { opacity: 0.5; }
.primary.small { padding: 6px 14px; font-size: 0.9rem; }
.patient-side { margin-left: auto; text-align: right; }
.visit-score { color: var(--muted); font-size: 0.85rem; }
.reward-line { font-weight: 600; margin: 8px 0; }
.sprite-note {
  margin: 8px auto;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(26, 158, 143, 0.12);
  max-width: 420px;
}
.card {
  background: var(--card);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.center { text-align: center; justify-content: center; }
h2 { font-size: 1.15rem; margin: 6px 0; }

/* 下方分頁列 */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--card);
  box-shadow: 0 -2px 10px rgba(30, 60, 80, 0.1);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  z-index: 10;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.75rem;
  padding: 6px 0;
  border-radius: 12px;
  position: relative;
}
.tab span { font-size: 1.4rem; line-height: 1.2; }
.tab.active { color: var(--primary); background: var(--bg); font-weight: 700; }
.tab.badge::after {
  content: "";
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bad);
}

/* 我家 */
.home-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.room {
  position: relative;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(5, 1fr);
  aspect-ratio: 6 / 5;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: linear-gradient(var(--wall) 40%, var(--floor) 40%);
  border: 6px solid rgba(120, 80, 40, 0.35);
}
.tile {
  border: none;
  background: transparent;
  font-size: clamp(1.4rem, 6vw, 2.4rem);
  padding: 0;
  z-index: 1;
}
.room.editing .tile { outline: 1px dashed rgba(0, 0, 0, 0.18); }
.room.editing .tile:hover { background: rgba(255, 255, 255, 0.35); }
.actor {
  position: absolute;
  font-size: clamp(1.2rem, 5vw, 2rem);
  transform: translate(-50%, -50%);
  transition: left 2.2s ease-in-out, top 2.2s ease-in-out;
  pointer-events: none;
  z-index: 2;
  animation: bob 1.6s ease-in-out infinite;
}
.actor.big { font-size: clamp(1.8rem, 7vw, 2.8rem); }
.shiny { filter: drop-shadow(0 0 6px gold); }
.room.editing .actor { opacity: 0.35; }
.inventory {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border-radius: 14px;
  padding: 10px;
  box-shadow: var(--shadow);
}
.inv-item {
  border: 2px solid var(--border);
  background: var(--bg);
  border-radius: 10px;
  font-size: 1.5rem;
  padding: 2px 8px;
  color: var(--text);
}
.inv-item small { font-size: 0.7rem; margin-left: 2px; }
.inv-item.selected { border-color: var(--primary); background: rgba(26, 158, 143, 0.15); }

@keyframes bob {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -6px; }
}

/* 寵物 */
.pet-hero {
  position: relative;
  width: 180px;
  height: 180px;
  margin: 10px auto;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(26, 158, 143, 0.18), transparent 70%);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.hero-emoji { font-size: 6rem; line-height: 1; }
.bob { animation: bob 1.6s ease-in-out infinite; }
.mood-sad .hero-emoji, .mood-hungry .hero-emoji { filter: grayscale(0.4); animation-duration: 3s; }
.pet-accessory { position: absolute; top: 14px; right: 30px; font-size: 2.4rem; }
.pet-name { margin-bottom: 0; }
.pet-bubble {
  display: inline-block;
  background: var(--doctor);
  border-radius: 16px;
  padding: 8px 14px;
  position: relative;
  max-width: 90%;
}
.pet-bubble .en { display: flex; gap: 6px; justify-content: center; }
.pet-bubble .zh { color: var(--muted); font-size: 0.85rem; }
.stat { max-width: 320px; margin: 8px auto; text-align: left; }
.bar-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 3px; }
.bar { height: 10px; border-radius: 999px; background: var(--bg); overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; background: var(--primary); border-radius: 999px; transition: width 0.4s; }
.bar-fill.low { background: var(--bad); }
.bar-fill.mid { background: var(--warn); }
.adopt-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.adopt-card {
  border: 2px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 4px;
  font-size: 0.85rem;
}
.adopt-card.selected { border-color: var(--primary); background: rgba(26, 158, 143, 0.12); }
.field { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 10px 0; }
.text-input {
  font: inherit;
  padding: 6px 10px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  width: 10em;
}

/* 圖鑑 */
.dex-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.dex-card {
  border: none;
  border-radius: 16px;
  padding: 12px 4px;
  background: var(--sprite-bg, var(--card));
  color: #1f2d3a;
  box-shadow: var(--shadow);
}
.dex-card.locked { background: var(--card); color: var(--muted); opacity: 0.7; }
.dex-card.shiny { box-shadow: 0 0 0 3px gold, var(--shadow); }
.dex-emoji { font-size: 2.4rem; line-height: 1.2; }
.dex-name { font-weight: 700; font-size: 0.9rem; }
.dex-sub { font-size: 0.75rem; color: var(--muted); }
.dex-card .dex-sub { color: inherit; opacity: 0.75; }
.sprite-hero {
  margin: 8px auto 12px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: var(--sprite-bg);
  display: grid;
  place-items: center;
}
.sprite-hero .hero-emoji { font-size: 4.5rem; }
.sprite-hero.shiny { box-shadow: 0 0 24px gold; }
.achievement-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.achievement-list li {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--card);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  opacity: 0.7;
}
.achievement-list li.done { opacity: 1; }
.ach-icon { font-size: 1.5rem; }
.ach-name { font-weight: 600; }

/* 商店 */
.shop-tabs { display: flex; gap: 6px; overflow-x: auto; }
.shop-tab {
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  white-space: nowrap;
}
.shop-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.shop-item {
  background: var(--card);
  border-radius: 14px;
  padding: 12px 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}
.shop-item.locked { opacity: 0.65; }
.shop-item button { margin-top: auto; }
.shop-emoji { font-size: 2.2rem; }
.shop-emoji.swatch { width: 56px; height: 56px; border-radius: 12px; border: 1px solid var(--border); }
.shop-name { font-weight: 600; font-size: 0.9rem; }
.en-word { color: var(--primary); font-weight: 500; }
.price { font-weight: 600; font-size: 0.9rem; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.tag { font-size: 0.68rem; border-radius: 999px; padding: 1px 8px; color: #fff; }
.tag.study { background: #3a7bd5; }
.tag.ach { background: #c9902c; }
.tag.gem { background: #8a4fd6; }
.gem-card { grid-column: 1 / -1; text-align: center; }
.quiz-q { font-size: 1.15rem; font-weight: 600; text-align: center; }
.todo { text-align: left; line-height: 1.9; }

@media (max-width: 520px) {
  .hud { gap: 4px; font-size: 0.8rem; }
  .hud span { padding: 2px 6px; }
  .dex-grid { grid-template-columns: repeat(3, 1fr); }
  .adopt-grid { grid-template-columns: repeat(2, 1fr); }
  .shop-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===================== 圖片素材 ===================== */
.icon { width: 1.35em; height: 1.35em; object-fit: contain; vertical-align: -0.3em; }
.icon.big { width: 1.8em; height: 1.8em; }
.line, .price-tag { display: inline-flex; align-items: center; gap: 3px; vertical-align: middle; }
.price-tag { gap: 10px; }
.brand { display: flex; align-items: center; gap: 6px; }
.hud span { display: inline-flex; align-items: center; gap: 4px; }
.icon-btn { display: inline-grid; place-items: center; padding: 0; }
.icon-btn .icon { width: 24px; height: 24px; }
.tab img { width: 30px; height: 30px; object-fit: contain; }
.shop-tab { display: inline-flex; align-items: center; gap: 4px; }
.title-art { display: flex; justify-content: center; align-items: flex-end; gap: 4px; }
.title-art img { width: 96px; height: 96px; object-fit: contain; }
.title-art .title-hospital { width: 80px; height: 80px; }
#btn-gift, #btn-edit { display: inline-flex; align-items: center; gap: 4px; }

/* 小精靈 */
.sprite-fig { position: relative; display: inline-block; width: 72px; height: 72px; }
.sprite-fig > img:first-child, .sprite-fig.small { width: 100%; height: 100%; object-fit: contain; }
.sprite-fig.small { width: 52px; height: 52px; flex-shrink: 0; }
.sprite-fig .crown { position: absolute; top: -10px; right: -6px; width: 34%; height: auto; transform: rotate(14deg); }
.sprite-fig.shiny > img:first-child { filter: drop-shadow(0 0 6px gold) drop-shadow(0 0 2px gold); }
.sprite-fig.silhouette img { filter: brightness(0) opacity(0.22); }
.dex-card .sprite-fig { width: 80px; height: 80px; }
.dex-card.locked { opacity: 1; }
.sprite-hero { width: 190px; height: 190px; }
.sprite-hero .sprite-fig { width: 170px; height: 170px; }
.sprite-reward {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  margin: 10px auto;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(26, 158, 143, 0.12);
  max-width: 440px;
}
.sprite-reward .sprite-fig:not(.small) { width: 90px; height: 90px; flex-shrink: 0; }
.pop-in { animation: popIn 0.6s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes popIn {
  from { transform: scale(0.2) rotate(-20deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* 寵物 */
.hero-img { width: 140px; height: 140px; object-fit: contain; }
.pet-accessory { position: absolute; top: 8px; right: 18px; width: 48px; height: 48px; object-fit: contain; transform: rotate(12deg); }
.adopt-img { width: 60px; height: 60px; object-fit: contain; }
.adopt-grid { grid-template-columns: repeat(3, 1fr); }

/* 我家 */
.tile-img { width: 88%; height: 88%; object-fit: contain; pointer-events: none; }
.tile { display: grid; place-items: center; }
.actor { animation: bob 1.6s ease-in-out infinite; }
.actor .sprite-fig { width: clamp(50px, 15vw, 84px); height: clamp(50px, 15vw, 84px); }
.actor-img { width: clamp(46px, 13vw, 76px); height: clamp(46px, 13vw, 76px); object-fit: contain; }
.inv-item { display: inline-flex; align-items: center; gap: 2px; }
.inv-item .icon { width: 34px; height: 34px; }

/* 商店、成就 */
.shop-img { width: 64px; height: 64px; object-fit: contain; }
.shop-img.swatch { border-radius: 12px; border: 1px solid var(--border); width: 56px; height: 56px; }
.ach-icon { width: 40px; height: 40px; object-fit: contain; flex-shrink: 0; }
.breakdown .price-tag { font-weight: 600; }

@media (max-width: 520px) {
  .hud .icon { width: 1.15em; height: 1.15em; }
  .title-art img { width: 76px; height: 76px; }
}

/* ===================== 地圖與角色 ===================== */
.map-banner { position: relative; border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.map-banner img { display: block; width: 100%; height: auto; min-height: 110px; object-fit: cover; object-position: 30% 50%; }
.map-chip {
  position: absolute;
  top: 4px;
  left: 4px;
  background: var(--card);
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 6px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.map-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.map-head h2 { margin: 0; }
#map-stars { display: inline-flex; align-items: center; gap: 4px; }
.howto-card summary { cursor: pointer; font-weight: 600; }
.staff-row { display: flex; justify-content: center; gap: 8px; margin-top: 10px; }
.staff-row img { width: 84px; height: 84px; object-fit: contain; }

/* 病人卡：場景當背景 */
.patient-card {
  background-size: cover;
  background-position: center 40%;
  min-height: 130px;
  position: relative;
  overflow: hidden;
}
.patient-card::before { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(255,255,255,0.15), rgba(255,255,255,0.85) 65%); }
.patient-card > * { position: relative; }
.avatar { width: 110px; height: 110px; display: grid; place-items: center; }
.person { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.25)); }
.p-info, .patient-side { color: #1f2d3a; }
.p-info .p-age, .patient-side .visit-score { color: #4b5b6a; }
.who { display: flex; align-items: center; gap: 6px; }
.who-img { width: 28px; height: 28px; object-fit: contain; border-radius: 50%; background: var(--bg); }
.panel-title { display: flex; align-items: center; gap: 8px; }
.staff-img { width: 52px; height: 52px; object-fit: contain; }

/* 房間：真的地板、窗戶和門 */
.room {
  background:
    var(--wall-img, none) left top / auto 40% repeat-x,
    linear-gradient(var(--wall) 40%, transparent 40%),
    url(assets/scenes/floor.webp) center bottom / 100% 60% no-repeat,
    var(--floor);
}
.room::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 40%;
  bottom: 0;
  background: var(--floor);
  mix-blend-mode: multiply;
  opacity: 0.18;
  pointer-events: none;
}
.room-deco { position: absolute; pointer-events: none; z-index: 0; }
.room-deco.window { left: 30%; top: 3%; width: 26%; }
.room-deco.door { right: 5%; top: 6%; width: 14%; }
.room .tile { position: relative; z-index: 1; }

@media (max-width: 520px) {
  .avatar { width: 90px; height: 90px; }
  .staff-img { width: 44px; height: 44px; }
}
.login-art { width: 100%; border-radius: 12px; display: block; margin-top: 8px; }

/* ===================== 多層房子、拖拉 ===================== */
.floor-bar { display: flex; gap: 6px; overflow-x: auto; padding: 2px; }
.floor-tab {
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 2px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  padding: 6px 12px;
  transition: transform 0.15s, border-color 0.15s;
}
.floor-tab b { font-size: 1.05rem; }
.floor-tab.active { border-color: var(--primary); background: rgba(26, 158, 143, 0.12); }
.floor-tab.build { border-style: dashed; color: var(--primary); }
.floor-tab.drop-target { transform: scale(1.12); border-color: var(--warn); background: rgba(242, 163, 58, 0.2); }
.floor-count {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  font-size: 0.7rem;
  min-width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
}

.actor { pointer-events: auto; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.actor img { -webkit-user-drag: none; }
.room.editing .actor { pointer-events: none; }
.actor.dragging { transition: none; animation: none; z-index: 5; transform: translate(-50%, -60%) scale(1.2); cursor: grabbing; filter: drop-shadow(0 8px 8px rgba(0, 0, 0, 0.3)); }
.actor.hop { animation: hop 0.5s ease-out; }
@keyframes hop {
  0%, 100% { margin-top: 0; }
  40% { margin-top: -22px; }
}
.tile.movable { cursor: grab; touch-action: none; }
.inv-item { touch-action: none; }
.drag-ghost {
  position: fixed;
  width: 64px;
  height: 64px;
  object-fit: contain;
  transform: translate(-50%, -50%) scale(1.1);
  pointer-events: none;
  z-index: 50;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.3));
}
.room-deco.window-right { right: 8%; top: 3%; width: 26%; }
.room-deco.window-center { left: 37%; top: 8%; width: 26%; }
.room.basement::before {
  content: "";
  position: absolute;
  inset: 0 0 60% 0;
  background: repeating-linear-gradient(0deg, rgba(90, 70, 50, 0.18) 0 2px, transparent 2px 22px),
    repeating-linear-gradient(90deg, rgba(90, 70, 50, 0.12) 0 2px, transparent 2px 44px);
  pointer-events: none;
}
.room.attic::before {
  content: "";
  position: absolute;
  inset: 0 0 60% 0;
  background: linear-gradient(135deg, rgba(120, 80, 40, 0.45) 0 22%, transparent 22% 78%, rgba(120, 80, 40, 0.45) 78%);
  pointer-events: none;
}
.build-art { text-align: center; }
.build-house { width: 110px; height: 110px; object-fit: contain; }
.build-list li { align-items: center; gap: 6px; }
.build-list li.done { opacity: 0.6; }
.floor-status { margin-left: auto; }

/* 升級慶祝 */
.levelup { text-align: center; }
.levelup-num { font-size: 1.8rem; font-weight: 800; color: var(--primary); }
.jump { animation: jump 0.9s ease-in-out infinite; }
@keyframes jump {
  0%, 100% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-24px) scale(1.05, 0.95); }
  60% { transform: translateY(0) scale(1.05, 0.95); }
}

/* 拼字、聽力題 */
.spell-box { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.spell-hint { font-family: ui-monospace, Menlo, monospace; font-size: 1.3rem; letter-spacing: 2px; color: var(--muted); }
.record-input.wide { width: min(260px, 100%); }
.quiz-q button { margin-top: 4px; }

/* ===================== 情境與通關地圖 ===================== */
.theme-bar { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; }
.theme-chip {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 74px;
  border: 2px solid transparent;
  border-radius: 16px;
  padding: 8px 10px;
  background: var(--theme);
  color: #1f2d3a;
  box-shadow: var(--shadow);
}
.theme-chip.active { border-color: var(--primary); transform: translateY(-2px); }
.theme-chip.done small::after { content: " ✓"; }
.theme-emoji { font-size: 1.6rem; line-height: 1; }
.theme-chip small { color: #4b5b6a; }
#total-progress { display: inline-flex; align-items: center; gap: 4px; }
.theme-card #theme-desc { margin: 4px 0 8px; }

/* 橫向通關地圖 */
.level-track {
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: 16px;
  margin: 0 -4px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.level-strip {
  position: relative;
  height: 280px;
  background:
    radial-gradient(ellipse at 20% 110%, rgba(120, 190, 110, 0.55), transparent 60%),
    radial-gradient(ellipse at 80% 110%, rgba(120, 190, 110, 0.5), transparent 60%),
    linear-gradient(#cfeaff 0%, var(--theme) 55%, #d9efc9 100%);
}
.level-strip.clinic { background: url(assets/scenes/map.webp) left top / auto 100% no-repeat; }
/* 看病地圖的圓點在下半部，所以名牌放在圓圈上方 */
.level-strip.clinic .level-node { flex-direction: column-reverse; transform: translate(-50%, calc(-100% + 30px)); }
.level-strip.clinic .node-circle { width: 60px; height: 60px; }
.level-strip.clinic .node-info { margin: 0 0 6px; }
.far-land {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 110px;
  background-repeat: repeat-x;
  background-size: auto 100%;
  opacity: 0.85;
  -webkit-mask-image: linear-gradient(#000 60%, transparent);
  mask-image: linear-gradient(#000 60%, transparent);
  pointer-events: none;
}
.scenery { position: absolute; transform: translateX(-50%); object-fit: contain; pointer-events: none; }
.scenery.front { bottom: 0; height: 78px; max-width: 100px; }
.scenery.back { bottom: 48px; height: 56px; max-width: 80px; opacity: 0.9; }
.path-line { position: absolute; inset: 0; width: 100%; height: 100%; color: #fff; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.25)); pointer-events: none; }
.level-node {
  position: absolute;
  transform: translate(-50%, -32px);
  width: 150px;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 1;
}
.node-circle {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #fff;
  border: 4px solid #fff;
  box-shadow: 0 0 0 3px var(--primary), var(--shadow);
  font-size: 1.5rem;
  font-weight: 800;
  color: #1f2d3a;
  transition: transform 0.15s;
}
.node-circle img { width: 90%; height: 90%; object-fit: contain; }
.level-node.cleared .node-circle { box-shadow: 0 0 0 3px gold, var(--shadow); }
.level-node.locked .node-circle { filter: grayscale(1); opacity: 0.75; box-shadow: 0 0 0 3px #bbb; }
.level-node.paywall .node-circle { box-shadow: 0 0 0 3px #8a4fd6, var(--shadow); }
.level-node.open .node-circle { animation: pulse 1.6s ease-in-out infinite; }
.level-node:hover:not(:disabled) .node-circle { transform: scale(1.08); }
.node-lock { position: absolute; width: 28px; height: 28px; right: -8px; bottom: -6px; }
.node-info {
  margin-top: 6px;
  background: rgba(255, 255, 255, 0.94);
  color: #1f2d3a;
  border-radius: 12px;
  padding: 4px 8px;
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 150px;
}
.level-node.locked .node-info { opacity: 0.75; }
.node-title { font-weight: 700; font-size: 0.85rem; line-height: 1.3; }
.node-en { color: #6b7c8c; font-size: 0.72rem; }
.node-status { font-size: 0.75rem; margin-top: 1px; }
.you-are-here {
  position: absolute;
  top: -58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: bob 1.4s ease-in-out infinite;
  pointer-events: none;
}
.here-img { width: 44px; height: 44px; object-fit: contain; }
.you-are-here small { font-size: 0.65rem; background: var(--primary); color: #fff; border-radius: 999px; padding: 0 6px; white-space: nowrap; }
.goal-flag { position: absolute; transform: translate(-50%, -50%); width: 52px; height: 52px; object-fit: contain; pointer-events: none; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.25)); }
.swipe-hint { text-align: center; margin: 6px 0 0; font-size: 0.8rem; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--primary), var(--shadow); }
  50% { box-shadow: 0 0 0 7px rgba(26, 158, 143, 0.35), var(--shadow); }
}

.clear-note { margin: 10px auto; padding: 10px 12px; border-radius: 12px; font-weight: 700; max-width: 440px; }
.clear-note.good { background: rgba(46, 157, 79, 0.14); color: var(--good); }
.clear-note.bad { background: rgba(214, 69, 69, 0.12); color: var(--bad); }
.npc-emoji {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 4.2rem;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
}
.who-emoji { font-size: 1.1rem; }

/* ===================== 登入與購買 ===================== */
.login-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; }
.login-or { text-align: center; color: var(--muted); font-size: 0.85rem; margin: 8px 0; }
.email-form { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.text-input.wide { width: min(260px, 100%); }
.product-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
  text-align: left;
}
.product-row button { flex-shrink: 0; }
#btn-account { font-size: 1.1rem; }

/* ===================== 換裝 ===================== */
.dress-fig { position: relative; display: inline-block; width: 90px; }
.dress-base { display: block; width: 100%; height: auto; position: relative; }
.dress-layer { position: absolute; transform: translate(-50%, -50%); height: auto; pointer-events: none; }
.dress-fig.big { width: 150px; }
.dress-fig.card-fig { width: 96px; flex-shrink: 0; }
.dress-fig.here-fig { width: 46px; }
.dress-fig.actor-dress { width: clamp(52px, 15vw, 88px); }
.dress-preview { text-align: center; padding: 10px; border-radius: 16px; background: radial-gradient(circle, rgba(26, 158, 143, 0.15), transparent 70%); margin-bottom: 8px; }
.dress-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 10px; max-height: 42vh; overflow-y: auto; padding: 2px; }
.dress-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border: 2px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 14px;
  padding: 8px 4px;
  text-align: center;
  font-size: 0.85rem;
}
.dress-card.worn { border-color: var(--primary); background: rgba(26, 158, 143, 0.1); }
.dress-thumb { width: 56px; height: 56px; object-fit: contain; }
.dress-thumb.big { width: 96px; height: 120px; }
.my-fairy { display: flex; align-items: center; gap: 14px; }
.my-fairy h3 { margin: 0 0 4px; }

/* ===================== 廣告 ===================== */
.ad-slot { margin: 12px 0; text-align: center; min-height: 60px; }
.ad-label { font-size: 0.7rem; color: var(--muted); text-align: left; margin-bottom: 2px; }
.ad-slot.preview {
  display: grid;
  place-items: center;
  min-height: 90px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 8px;
}
.center { text-align: center; }
.site-footer { text-align: center; color: var(--muted); font-size: 0.8rem; line-height: 1.8; padding: 6px 0 2px; }
.site-footer a { color: var(--primary); }
/* 跟著畫面捲動、一直留在上方的返回按鈕 */
.back-btn {
  position: sticky;
  top: 66px;
  align-self: flex-start;
  margin-bottom: -6px;
  z-index: 4;
  border: none;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.92);
  color: #1f2d3a;
  box-shadow: var(--shadow);
}
