/* ===== 和風配色：和紙底 / 墨 / 縹 / 朱 ===== */
:root {
  --washi:    #f4efe6;  /* 和紙背景 */
  --washi-2:  #ece4d6;  /* 較深紙色 */
  --card:     #fbf8f2;  /* 卡面 */
  --sumi:     #2e2a26;  /* 墨色 文字 */
  --sumi-soft:#6b6359;  /* 次要文字 */
  --ai:       #5b7b8a;  /* 縹（藍鼠）主色 */
  --ai-deep:  #45616e;
  --shu:      #b5654c;  /* 朱（柔和朱色）強調 */
  --matcha:   #8a9a5b;  /* 抹茶綠 — 會了 */
  --line:     #e0d8c8;
  --shadow:   rgba(70, 60, 45, 0.12);
  --r-lg: 26px;
  --r-md: 16px;
}

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

html, body {
  height: 100%;
  overflow-x: hidden;
  background: var(--washi);
  color: var(--sumi);
  font-family: 'Noto Sans JP', system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
}

body {
  /* 細緻和紙紋理（純 CSS） */
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,0.5) 0, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(236,228,214,0.6) 0, transparent 45%);
}

.app {
  max-width: 460px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  /* 卡片主題變數（預設 Lv1 和紙） */
  --c-bg: var(--card);
  --c-ink: var(--sumi);
  --c-kana: var(--ai-deep);
  --c-accent: var(--ai-deep);
  --c-border: var(--line);
  --c-reveal: var(--shu);
  --c-chip-bg: rgba(91,123,138,0.10);
  --c-frame: transparent;
  --c-frame-w: 1px;
  --c-frame-inset: 11px;
  --c-mark: var(--ai);
}

/* ===== 五級主題：越級越高級 ===== */
.app[data-level="2"] {          /* 若竹 — 竹綠清新 */
  --c-bg: linear-gradient(160deg, #fcfbf3, #f0f5ea);
  --c-ink: #2c3326;
  --c-kana: #5f7d57;
  --c-accent: #5f7d57;
  --c-border: #cfdcc4;
  --c-reveal: #a8603f;
  --c-chip-bg: rgba(95,125,87,0.12);
  --c-frame: rgba(95,125,87,0.35);
  --c-mark: #6f8f63;
}
.app[data-level="3"] {          /* 藍染 — 靛藍沉穩 + 細框 */
  --c-bg: linear-gradient(160deg, #f7f9fc, #eaf0f7);
  --c-ink: #22303f;
  --c-kana: #3f5d7a;
  --c-accent: #34516e;
  --c-border: #c2d2e3;
  --c-reveal: #a8603f;
  --c-chip-bg: rgba(63,93,122,0.13);
  --c-frame: rgba(52,81,110,0.5);
  --c-frame-inset: 9px;
  --c-mark: #3f5d7a;
}
.app[data-level="4"] {          /* 紺金 — 深藍底 + 金線（深色卡） */
  --c-bg: linear-gradient(160deg, #2c3b54, #1e2a3f);
  --c-ink: #f3ede0;
  --c-kana: #c9a96a;
  --c-accent: #c9a96a;
  --c-border: #3a4a64;
  --c-reveal: #e3c386;
  --c-chip-bg: rgba(201,169,106,0.16);
  --c-frame: rgba(201,169,106,0.55);
  --c-frame-w: 1.5px;
  --c-frame-inset: 9px;
  --c-mark: #c9a96a;
}
.app[data-level="5"] {          /* 漆黒蒔絵 — 墨黑 + 鎏金雙框（頂級） */
  --c-bg: linear-gradient(160deg, #232019, #131110);
  --c-ink: #f0e6cf;
  --c-kana: #d4af6a;
  --c-accent: #d4af6a;
  --c-border: #3a3024;
  --c-reveal: #e6c884;
  --c-chip-bg: rgba(212,175,106,0.16);
  --c-frame: rgba(212,175,106,0.7);
  --c-frame-w: 1.5px;
  --c-frame-inset: 7px;
  --c-mark: #d4af6a;
}
.app[data-level="5"] .card { box-shadow: 0 12px 36px rgba(0,0,0,0.35); }
.app[data-level="4"] .card { box-shadow: 0 12px 34px rgba(20,30,50,0.3); }

/* ===== 頂部列 ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 4px 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-family: 'Noto Serif JP', serif;
  font-weight: 700;
  font-size: 26px;
  color: #fff;
  background: var(--c-mark);
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 14px;
  box-shadow: 0 4px 12px var(--shadow);
  transition: background .3s;
}

/* ===== 等級選擇器 ===== */
.level-bar {
  display: flex;
  gap: 8px;
  padding: 4px 4px 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.level-bar::-webkit-scrollbar { display: none; }
.lv-chip {
  flex: 1 0 auto;
  min-width: 56px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 14px;
  padding: 8px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform .1s, border-color .2s;
}
.lv-chip:active { transform: scale(0.95); }
.lv-num { font-family: 'Noto Serif JP', serif; font-weight: 700; font-size: 17px; color: var(--sumi); }
.lv-name { font-size: 10px; color: var(--sumi-soft); letter-spacing: 1px; }
.lv-chip.active { border-color: var(--chip-accent); box-shadow: inset 0 0 0 1px var(--chip-accent); }
.lv-chip.active .lv-num { color: var(--chip-accent); }
.lv-chip.locked { opacity: 0.55; }
.lv-chip.locked .lv-num { font-size: 14px; }
/* 每個 chip 用該級主題色點綴 */
.lv-chip[data-level="1"] { --chip-accent: #5b7b8a; }
.lv-chip[data-level="2"] { --chip-accent: #6f8f63; }
.lv-chip[data-level="3"] { --chip-accent: #3f5d7a; }
.lv-chip[data-level="4"] { --chip-accent: #b18f54; }
.lv-chip[data-level="5"] { --chip-accent: #c9a96a; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%; bottom: 96px;
  transform: translateX(-50%) translateY(10px);
  background: rgba(46,42,38,0.92);
  color: #fff;
  font-size: 13px;
  padding: 9px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.brand-text h1 { font-size: 19px; font-weight: 700; letter-spacing: 1px; }
.brand-text p { font-size: 12px; color: var(--sumi-soft); margin-top: 2px; }

.stats { display: flex; gap: 8px; }
.stat {
  font-size: 11px;
  color: var(--sumi-soft);
  background: var(--card);
  border: 1px solid var(--line);
  padding: 6px 10px;
  border-radius: 999px;
  display: flex; align-items: baseline; gap: 3px;
}
.stat b { font-size: 14px; color: var(--ai-deep); }

/* ===== 語音橫幅 ===== */
.voice-banner {
  background: #fbeee9;
  border: 1px solid #e7c4b8;
  color: #8a4634;
  font-size: 12.5px;
  line-height: 1.5;
  padding: 10px 36px 10px 14px;
  border-radius: var(--r-md);
  margin: 4px 4px 0;
  position: relative;
}
.banner-close {
  position: absolute; top: 6px; right: 8px;
  background: none; border: none; font-size: 20px;
  color: #8a4634; cursor: pointer; line-height: 1;
}

/* ===== 卡片舞台 ===== */
.stage {
  flex: 1;
  position: relative;
  display: grid;
  place-items: center;
  padding: 16px 0;
}
.card-deck {
  position: relative;
  width: 100%;
  height: 100%;
  max-height: 540px;
}

.card {
  position: absolute;
  inset: 0;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: 0 10px 30px var(--shadow);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  cursor: grab;
  transform-origin: center;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
}
/* 高級框：依等級顯現的內框（Lv1 透明） */
.card::after {
  content: '';
  position: absolute;
  inset: var(--c-frame-inset, 11px);
  border: var(--c-frame-w, 1px) solid var(--c-frame, transparent);
  border-radius: 17px;
  pointer-events: none;
}
.card:active { cursor: grabbing; }
.card.dragging { transition: none; }
.card.settle { transition: transform 0.28s cubic-bezier(.2,.8,.3,1); }
.card.fly { transition: transform 0.32s ease-in, opacity 0.32s ease-in; }

/* 卡片正面 */
.card-group {
  align-self: flex-start;
  font-size: 11px;
  color: var(--c-accent);
  background: var(--c-chip-bg);
  padding: 4px 11px;
  border-radius: 999px;
  letter-spacing: 1px;
  position: relative;
  z-index: 1;
}
.card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}
.card-body { position: relative; z-index: 1; }
.card-jp {
  font-family: 'Noto Serif JP', serif;
  font-weight: 700;
  font-size: clamp(46px, 13vw, 64px);
  line-height: 1.1;
  color: var(--c-ink);
}
.card-kana {
  font-size: 19px;
  color: var(--c-kana);
  letter-spacing: 2px;
}
.card-ex {
  margin-top: 18px;
  font-size: 17px;
  color: var(--c-ink);
  line-height: 2.4;   /* 留空間給上方振假名 */
}
.card-ex ruby { ruby-align: center; }
.card-ex rt {
  font-size: 0.5em;
  color: var(--c-kana);
  font-weight: 400;
  letter-spacing: 0;
  user-select: none;
}

/* 中文（恆顯示） */
.reveal {
  border-top: 1px dashed var(--c-border);
  margin-top: 20px;
  padding-top: 16px;
  text-align: center;
}
.reveal-zh { font-size: 22px; font-weight: 700; color: var(--c-reveal); }
.reveal-exzh { font-size: 14px; color: var(--c-kana); margin-top: 8px; }

.flip-hint {
  text-align: center;
  font-size: 12px;
  color: var(--c-kana);
  opacity: 0.7;
  margin-top: 14px;
  transition: opacity .2s;
}

/* 朗讀聚焦：唸時藏中文/提示，放大置中例句 */
.card-ex { transition: font-size .2s, color .2s; }
.card.reading .reveal,
.card.reading .flip-hint { display: none; }
.card.reading .card-ex {
  font-size: clamp(22px, 6.5vw, 30px);
  font-weight: 700;
  color: var(--c-accent);
  margin-top: 24px;
}

/* 滑動方向標記 */
.swipe-tag {
  position: absolute;
  top: 22px;
  font-weight: 700;
  font-size: 18px;
  padding: 6px 14px;
  border-radius: 10px;
  border: 2.5px solid;
  opacity: 0;
  transition: opacity .1s;
}
.swipe-tag.got { right: 22px; color: var(--matcha); border-color: var(--matcha); transform: rotate(8deg); }
.swipe-tag.again { left: 22px; color: var(--shu); border-color: var(--shu); transform: rotate(-8deg); }

@keyframes pulse { 0%,100%{ transform: scale(1);} 50%{ transform: scale(1.12);} }

/* ===== 完成畫面 ===== */
.done-screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px; text-align: center;
}
.done-mark {
  width: 76px; height: 76px;
  border-radius: 50%;
  background: var(--matcha);
  color: #fff; font-size: 40px;
  display: grid; place-items: center;
  box-shadow: 0 8px 20px rgba(138,154,91,0.4);
}
.done-screen h2 { font-size: 22px; }
.done-screen p { color: var(--sumi-soft); font-size: 14px; }
.btn-ghost {
  margin-top: 10px;
  background: none;
  border: 1.5px solid var(--ai);
  color: var(--ai-deep);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 14px; font-weight: 500;
  cursor: pointer;
}
.btn-ghost:active { background: rgba(91,123,138,0.08); }

/* ===== 操作列 ===== */
.actionbar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  padding: 14px 0 22px;
}
.act {
  border: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  box-shadow: 0 3px 10px var(--shadow);
  transition: transform .1s;
}
.act:active { transform: scale(0.94); }
.act-ico { font-size: 22px; line-height: 1; }
.act-label { font-size: 11px; color: var(--sumi-soft); }
.act-again { flex: 1; max-width: 130px; }
.act-got   { flex: 1; max-width: 130px; }
.act-again .act-ico { color: var(--shu); }
.act-got .act-ico { color: var(--matcha); }
.act-hear {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--ai);
  border: none;
  justify-content: center;
}
.act-hear .act-ico { font-size: 26px; }
.act-hear .act-label { color: rgba(255,255,255,0.85); }
.act-hear.speaking { animation: pulse 0.8s ease-in-out infinite; }

.hidden { display: none !important; }

/* ===== 模式切換頁籤 ===== */
.mode-tabs {
  display: flex;
  gap: 6px;
  padding: 2px 4px 10px;
}
.mode-tab {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--sumi-soft);
  border-radius: 12px;
  padding: 9px 0;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
}
.mode-tab.active { background: var(--ai); border-color: var(--ai); color: #fff; }

/* ===== 對話：場景清單 ===== */
.dialog-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 4px 0 8px;
}
.dlg-list {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 4px;
}
.dlg-card {
  text-align: left;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  cursor: pointer;
  box-shadow: 0 4px 14px var(--shadow);
  transition: transform .1s;
}
.dlg-card:active { transform: scale(0.98); }
.dlg-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dlg-card-title { font-family: 'Noto Serif JP', serif; font-weight: 700; font-size: 16px; color: var(--c-ink); }
.dlg-card-prof { font-size: 11px; color: var(--c-kana); letter-spacing: 1px; white-space: nowrap; }
.dlg-card-prof.done { color: var(--c-accent); }
.dlg-card-sit { font-size: 12.5px; color: var(--c-kana); margin-top: 6px; line-height: 1.5; }

/* ===== 對話：會話串 ===== */
.dlg-conv { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 2px; }
.dlg-conv-top { display: flex; align-items: center; gap: 10px; padding: 2px 2px 8px; }
.dlg-back {
  background: none; border: none; cursor: pointer;
  color: var(--c-accent); font-size: 14px; font-weight: 500; padding: 4px 2px;
}
.dlg-conv-title {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: 'Noto Serif JP', serif; font-weight: 700; font-size: 16px; color: var(--c-ink);
}
.dlg-progress { flex: 0 0 auto; font-size: 12px; color: var(--c-kana); white-space: nowrap; }
.dlg-auto {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--c-border);
  background: var(--c-bg);
  font-size: 15px;
  cursor: pointer;
  opacity: .4;
  transition: opacity .2s, border-color .2s;
}
.dlg-auto.on { opacity: 1; border-color: var(--c-accent); }
.dlg-sit {
  font-size: 12.5px; color: var(--c-kana); line-height: 1.5;
  background: var(--c-chip-bg); border-radius: 12px; padding: 8px 12px; margin-bottom: 10px;
}
.dlg-thread {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px; padding: 4px 2px 8px;
}
/* 手機捲動手感：慣性動量 + 邊界阻尼回彈，並隱藏桌面捲軸 */
.dlg-list, .dlg-thread {
  -webkit-overflow-scrolling: touch;   /* iOS 慣性動量 */
  overscroll-behavior: contain;        /* 阻尼回彈、不外溢到頁面 */
  scrollbar-width: none;               /* Firefox 隱藏捲軸 */
}
.dlg-list::-webkit-scrollbar,
.dlg-thread::-webkit-scrollbar { display: none; }  /* WebKit 隱藏捲軸 */
.dlg-line { display: flex; flex-direction: column; max-width: 86%; }
.dlg-line.me { align-self: flex-end; align-items: flex-end; }
.dlg-line.other { align-self: flex-start; align-items: flex-start; }
.dlg-role { font-size: 10.5px; color: var(--c-kana); margin: 0 8px 3px; letter-spacing: 1px; }
.dlg-bubble {
  border: 1px solid var(--c-border);
  border-radius: 16px;
  padding: 11px 14px;
  background: var(--c-bg);
  box-shadow: 0 3px 10px var(--shadow);
}
/* 我方氣泡：在 --c-bg 實底上疊一層 accent tint（避免半透明疊在米色頁面 → 深色級白字壓白底看不到） */
.dlg-line.me .dlg-bubble {
  background: linear-gradient(var(--c-chip-bg), var(--c-chip-bg)), var(--c-bg);
  border-color: var(--c-accent);
}
.dlg-jp { font-family: 'Noto Serif JP', serif; font-size: 19px; line-height: 2.2; color: var(--c-ink); }
.dlg-jp ruby { ruby-align: center; }
.dlg-jp rt { font-size: 0.5em; color: var(--c-kana); font-weight: 400; user-select: none; }
.dlg-zh { font-size: 13px; font-weight: 500; color: var(--c-reveal); margin-top: 5px; }
.dlg-zh-hint { font-size: 16px; font-weight: 700; color: var(--c-reveal); }
.dlg-tap { font-size: 11px; color: var(--c-kana); opacity: .7; margin-top: 7px; }
.dlg-line.hint .dlg-bubble { cursor: pointer; border-style: dashed; }
.dlg-line.revealed .dlg-bubble { cursor: pointer; }
.dlg-line.speaking .dlg-bubble { animation: pulse 0.8s ease-in-out infinite; }

.dlg-continue {
  align-self: center;
  margin-top: 10px;
  background: var(--c-accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 12px 30px;
  font-size: 15px; font-weight: 500;
  cursor: pointer;
  box-shadow: 0 4px 14px var(--shadow);
  transition: transform .1s;
}
.dlg-continue:active { transform: scale(0.96); }

/* 熟練度 1~5 */
.dlg-prof { text-align: center; padding: 12px 0 6px; }
.dlg-prof-q { font-size: 13px; color: var(--c-kana); margin-bottom: 10px; }
.dlg-prof-row { display: flex; justify-content: center; gap: 8px; margin-bottom: 12px; }
.dlg-prof-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--c-border);
  background: var(--c-bg);
  color: var(--c-ink);
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  transition: transform .1s, background .2s;
}
.dlg-prof-btn:active { transform: scale(0.92); }
.dlg-prof-btn.sel { background: var(--c-accent); color: #fff; border-color: var(--c-accent); }
.dlg-finish {
  background: none;
  border: 1.5px solid var(--c-accent);
  color: var(--c-accent);
  padding: 9px 22px;
  border-radius: 999px;
  font-size: 13px; cursor: pointer;
}
