/* 單字麻將配色：象牙白牌面、翡翠綠牌背、紅中紅；深色模式是綠色牌桌 */
:root {
  --bg: #efe7d4;            /* 牌面象牙白 */
  --fg: #1c2b23;
  --muted: #6d776e;
  --line: #d8ccb2;
  --soft: #e6dcc4;
  --inv-bg: #16643f;        /* 翡翠綠 */
  --inv-fg: #fbf7ec;
  --red: #c0322b;           /* 紅中 */
  --tile: #fbf7ec;
  --tile-fg: #1c2b23;
  --tile-muted: #7a8278;
  --tile-line: #e3d8bf;
  --tile-edge: #1d7a4e;     /* 牌背綠 */
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c3324;          /* 牌桌絨布綠 */
    --fg: #f1e9d6;
    --muted: #93b8a4;
    --line: #1f5039;
    --soft: #114030;
    --inv-bg: #237e52;      /* 翡翠綠 */
    --inv-fg: #fbf7ec;
    --red: #ef6a5f;         /* 紅中 */
    --tile: #f1e9d6;        /* 牌面象牙白 */
    --tile-fg: #13261d;
    --tile-muted: #66756b;
    --tile-line: #ddd1b6;
    --tile-edge: #17603e;   /* 牌背綠 */
  }
}
:root[data-theme="dark"] {
  --bg: #0c3324;          /* 牌桌絨布綠 */
  --fg: #f1e9d6;
  --muted: #93b8a4;
  --line: #1f5039;
  --soft: #114030;
  --inv-bg: #237e52;      /* 翡翠綠 */
  --inv-fg: #fbf7ec;
  --red: #ef6a5f;         /* 紅中 */
  --tile: #f1e9d6;        /* 牌面象牙白 */
  --tile-fg: #13261d;
  --tile-muted: #66756b;
  --tile-line: #ddd1b6;
  --tile-edge: #17603e;   /* 牌背綠 */
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  line-height: 1.5;
  min-height: 100dvh;
  transition: background .2s, color .2s;
}
a { color: inherit; }
button { font: inherit; color: inherit; }

.wrap { max-width: 640px; margin: 0 auto; padding: 8px 16px 64px; }

/* 頂欄 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  max-width: 640px; margin: 0 auto;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bg);
}
.brand { font-weight: 800; font-size: 18px; text-decoration: none; letter-spacing: .02em; }
.icon-btn {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  border: 1.5px solid var(--line); border-radius: 50%;
  background: transparent; cursor: pointer;
}
.icon-btn:hover { border-color: var(--fg); }
.icon-btn svg { width: 18px; height: 18px; }

/* 共用 */
h1 { font-size: 28px; line-height: 1.2; margin: 16px 0 4px; }
.sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.section-title { font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .06em; margin: 32px 0 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  border: 1.5px solid var(--fg); border-radius: var(--radius);
  background: transparent; cursor: pointer; text-decoration: none;
  font-weight: 600; font-size: 15px;
  transition: transform .08s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--inv-bg); color: var(--inv-fg); border-color: var(--inv-bg); }
.btn.ghost { border-color: var(--line); }
.btn.ghost:hover { border-color: var(--fg); }
.btn[disabled] { opacity: .35; pointer-events: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row .btn { flex: 1 1 0; }

/* 首頁的天數列表 */
.day-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.day-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  text-decoration: none;
  transition: border-color .15s;
}
.day-card:hover { border-color: var(--fg); }
.day-card .name { font-weight: 700; font-size: 17px; }
.day-card .meta { color: var(--muted); font-size: 13px; }
.day-card .best { font-family: var(--mono); font-size: 13px; color: var(--muted); white-space: nowrap; }
.day-card.all { background: var(--soft); }

/* 模式選擇 */
.modes { display: grid; gap: 10px; }
.mode {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px; text-align: left;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: transparent; cursor: pointer;
}
.mode:hover { border-color: var(--fg); }
.mode .tag {
  flex: none; display: grid; place-items: center;
  width: 54px; height: 40px; border-radius: 10px;
  background: var(--inv-bg); color: var(--inv-fg);
  font-weight: 700; font-size: 13px;
}
.mode .title { font-weight: 700; }
.mode .desc { color: var(--muted); font-size: 13px; }

.toggle { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 14px; color: var(--muted); cursor: pointer; user-select: none; }
.toggle input { width: 18px; height: 18px; accent-color: var(--fg); }

/* 單字表 */
.word-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.word-table td { padding: 11px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.word-table td:first-child { font-weight: 600; width: 45%; }
.word-table .pos { color: var(--muted); font-size: 12px; font-style: italic; margin-left: 4px; font-weight: 400; }
.word-table .note { display: block; color: var(--muted); font-size: 13px; }
.speak { border: 0; background: none; padding: 0 0 0 6px; cursor: pointer; color: var(--muted); vertical-align: -3px; }
.speak:hover { color: var(--fg); }
.speak svg { width: 16px; height: 16px; }

/* 測驗 */
.quiz-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 10px; font-size: 14px; color: var(--muted); }
.quiz-head .count { font-family: var(--mono); }
.quiz-head a { text-decoration: none; }
.quiz-head a:hover { color: var(--fg); }
.progress { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--fg); transition: width .25s; }

.prompt {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  min-height: 200px; margin: 20px 0;
  padding: 28px 20px;
  border: 1.5px solid var(--line); border-radius: 20px;
}
.prompt .label { font-size: 12px; color: var(--muted); letter-spacing: .08em; margin-bottom: 10px; }
.prompt .word { font-size: clamp(28px, 8vw, 44px); font-weight: 800; line-height: 1.2; word-break: break-word; }
.prompt .pos { color: var(--muted); font-style: italic; margin-top: 6px; font-size: 14px; }
.prompt .speak { margin-top: 10px; padding: 6px; }
.prompt .speak svg { width: 22px; height: 22px; }

.options { display: grid; gap: 10px; }
.option {
  display: flex; align-items: center; gap: 14px;
  width: 100%; min-height: 60px; padding: 12px 16px; text-align: left;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: transparent; cursor: pointer; font-size: 17px;
  transition: border-color .12s, background .12s, color .12s;
}
.option:hover:not([disabled]) { border-color: var(--fg); }
.option .key {
  flex: none; display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 8px;
  border: 1.5px solid var(--line); font-family: var(--mono); font-size: 13px; color: var(--muted);
}
.option .mark { margin-left: auto; font-weight: 800; }
.option[disabled] { cursor: default; }
.option.correct { background: var(--inv-bg); color: var(--inv-fg); border-color: var(--inv-bg); }
.option.correct .key { border-color: currentColor; color: inherit; }
.option.wrong { border-style: dashed; border-color: var(--fg); color: var(--muted); text-decoration: line-through; }
.option.dim { opacity: .4; }

.feedback { min-height: 24px; margin: 14px 0; text-align: center; font-weight: 600; }
.hint { text-align: center; color: var(--muted); font-size: 12px; margin-top: 18px; }
@media (hover: none) { .hint { display: none; } }

@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.shake { animation: shake .3s; }

/* 結果 */
.score-big { font-size: 72px; font-weight: 900; line-height: 1; margin: 28px 0 6px; font-family: var(--mono); letter-spacing: -.03em; }
.score-big small { font-size: 28px; color: var(--muted); font-weight: 600; }

.empty { color: var(--muted); padding: 24px 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

/* 後台 /upload */
.foot { margin-top: 32px; font-size: 13px; color: var(--muted); }
.foot a, .empty a { color: inherit; }
.admin-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.link-btn { border: 0; background: none; padding: 0; color: var(--muted); cursor: pointer; text-decoration: underline; font-size: 14px; }
.link-btn:hover { color: var(--fg); }
kbd { font-family: var(--mono); font-size: 12px; padding: 1px 5px; border: 1px solid var(--line); border-radius: 5px; }

.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field textarea {
  width: 100%; min-height: 46px; padding: 10px 14px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--fg); font: inherit; font-size: 16px;
}
.field textarea { font-family: var(--mono); font-size: 14px; line-height: 1.6; resize: vertical; tab-size: 12; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--fg); }
.field input:user-invalid { border-style: dashed; border-color: var(--fg); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .field-row { grid-template-columns: 1fr; } }
.slug-input { display: flex; align-items: center; border: 1.5px solid var(--line); border-radius: 12px; padding-left: 14px; }
.slug-input:focus-within { border-color: var(--fg); }
.slug-input em { font-style: normal; color: var(--muted); font-family: var(--mono); }
.slug-input input { border: 0 !important; padding-left: 2px; font-family: var(--mono); }

.drop {
  display: grid; place-items: center; gap: 2px; text-align: center;
  padding: 22px 16px; cursor: pointer;
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--fg); background: var(--soft); }
.drop-title { font-weight: 700; }
.drop-sub { font-size: 13px; color: var(--muted); word-break: break-all; }

.form-error { margin: 0; min-height: 0; color: var(--fg); font-weight: 600; font-size: 14px; }
.form-error:empty { display: none; }
.preview-scroll { max-height: 320px; overflow-y: auto; border: 1.5px solid var(--line); border-radius: 12px; padding: 0 12px; }
.preview-scroll .word-table tr:last-child td { border-bottom: 0; }
.word-table tr.unsure td { background: var(--soft); }
.parse-errors { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); display: grid; gap: 4px; }
.parse-errors code { font-family: var(--mono); color: var(--fg); word-break: break-all; }

.admin-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.admin-list li { display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 16px; border: 1.5px solid var(--line); border-radius: var(--radius); }
.admin-list a { flex: 1; min-width: 0; text-decoration: none; display: grid; }
.admin-list a span { font-size: 13px; color: var(--muted); font-family: var(--mono); }
.btn.danger { min-height: 38px; padding: 0 14px; font-size: 14px; flex: none; }
.btn.danger.armed { background: var(--inv-bg); color: var(--inv-fg); border-color: var(--inv-bg); }

/* 發音聲音選擇 */
.voice-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 14px; color: var(--muted); }
.voice-row select {
  min-height: 38px; padding: 0 30px 0 12px; font: inherit; font-size: 14px;
  color: var(--fg); background: var(--bg); border: 1.5px solid var(--line); border-radius: 10px;
}
.voice-row select:focus { outline: none; border-color: var(--fg); }

/* 從主畫面開啟（standalone）時，避開瀏海 */
@media (display-mode: standalone) {
  .wrap { padding-bottom: max(64px, env(safe-area-inset-bottom)); }
}

/* 開始測驗按鈕 */
.btn.block { display: flex; width: 100%; }
.best-line { margin: 10px 0 0; font-size: 13px; color: var(--muted); font-family: var(--mono); }

/* 開始測驗 popup：手機是底部抽屜，桌面置中 */
dialog.sheet {
  width: 100%; max-width: 520px; max-height: min(88dvh, 760px);
  margin: auto auto 0; padding: 0;
  border: 1.5px solid var(--line); border-bottom: 0; border-radius: 22px 22px 0 0;
  background: var(--bg); color: var(--fg);
  overflow: hidden;
}
@media (min-width: 600px) {
  dialog.sheet { margin: auto; border-bottom: 1.5px solid var(--line); border-radius: 22px; }
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, .55); }
dialog.sheet[open] { animation: sheet-in .22s ease-out; }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }

.sheet-body {
  display: grid; gap: 20px;
  max-height: inherit; overflow-y: auto;
  padding: 18px 18px max(18px, env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-section { display: grid; gap: 10px; }
.sheet-label { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .04em; }
.sheet-label #qd-avail { font-family: var(--mono); font-weight: 400; letter-spacing: 0; }
.sheet-actions { display: flex; gap: 14px; }
.sheet-actions .link-btn { font-size: 13px; }
.scope-fixed { margin: 0; font-weight: 600; }

.day-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; max-height: 196px; overflow-y: auto; }
.day-opt, .mode-opt {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; cursor: pointer; user-select: none;
  border: 1.5px solid var(--line); border-radius: 12px;
  transition: border-color .12s, background .12s, color .12s;
}
.day-opt input, .mode-opt input { position: absolute; opacity: 0; pointer-events: none; }
.day-opt .t { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-opt .c { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.day-opt:has(input:checked), .mode-opt:has(input:checked) { background: var(--inv-bg); color: var(--inv-fg); border-color: var(--inv-bg); }
.day-opt:has(input:checked) .c { color: inherit; opacity: .7; }
.day-opt:has(input:focus-visible), .mode-opt:has(input:focus-visible) { outline: 2px solid var(--fg); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 0 16px; cursor: pointer;
  border: 1.5px solid var(--line); border-radius: 999px; background: transparent;
  font-family: var(--mono); font-size: 14px;
}
.chip:hover { border-color: var(--fg); }
.chip.on { background: var(--inv-bg); color: var(--inv-fg); border-color: var(--inv-bg); }

.mode-pick { display: grid; gap: 8px; }
.mode-opt .tag {
  flex: none; display: grid; place-items: center; width: 52px; height: 30px; border-radius: 8px;
  border: 1.5px solid currentColor; font-weight: 700; font-size: 12px;
}
.mode-opt .desc { font-size: 14px; }
.sheet .voice-row { margin-top: 0; }
.sheet-head h2:focus { outline: none; }

/* 底部 toolbar */
.wrap { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
body.in-quiz .wrap { padding-bottom: 64px; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  max-width: 640px; margin: 0 auto;
  padding: 6px 8px max(8px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--line);
}
@media (min-width: 640px) {
  .tabbar { bottom: 12px; border: 1px solid var(--line); border-radius: 20px; padding-bottom: 8px; }
}
body.in-quiz .tabbar { display: none; }
.tabbar a {
  display: grid; justify-items: center; gap: 2px;
  padding: 6px 0 2px; text-decoration: none;
  color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .04em;
  -webkit-tap-highlight-color: transparent;
}
.tabbar a:hover { color: var(--fg); }
.tabbar a.on { color: var(--fg); }
.tab-icon {
  position: relative; display: grid; place-items: center;
  width: 52px; height: 30px; border-radius: 999px;
  transition: background .15s, color .15s;
}
.tabbar a.on .tab-icon { background: var(--inv-bg); color: var(--inv-fg); }
.tab-icon svg { width: 22px; height: 22px; }
.badge {
  position: absolute; top: -3px; right: 4px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  display: grid; place-items: center;
  background: var(--fg); color: var(--bg);
  border: 2px solid var(--bg);
  font: 700 10px/1 var(--mono);
}
.tabbar a.on .badge { background: var(--bg); color: var(--fg); border-color: var(--inv-bg); }

/* 設定頁 */
.settings-group { display: grid; gap: 4px; }
.settings-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 12px 12px 16px; border: 1.5px solid var(--line); border-radius: var(--radius); font-size: 14px; }

/* ---------- 麻將牌 ---------- */
/* 牌：象牙白牌面＋底下一截綠色牌背。牌裡面的文字顏色另外定，深色模式時牌還是白的 */
.prompt, .option, .day-card, .mode-opt, .day-opt, .chip, .admin-list li, .settings-line {
  --muted: var(--tile-muted);
  --line: var(--tile-line);
  background: var(--tile);
  color: var(--tile-fg);
  border-color: var(--tile-line);
  box-shadow: 0 3px 0 var(--tile-edge), 0 4px 10px rgba(0, 0, 0, .08);
}
.prompt { box-shadow: 0 6px 0 var(--tile-edge), 0 8px 18px rgba(0, 0, 0, .10); }
.day-card.all { background: var(--tile); }
.day-card:hover, .option:hover:not([disabled]), .mode-opt:hover, .day-opt:hover, .chip:hover { border-color: var(--tile-edge); }
.day-card:active, .option:active:not([disabled]), .mode-opt:active, .chip:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--tile-edge); }
.option, .day-card, .mode-opt, .chip { transition: transform .08s, box-shadow .08s, border-color .12s, background .12s; }

/* 選中、答對：整張變翡翠綠 */
.option.correct, .chip.on, .day-opt:has(input:checked), .mode-opt:has(input:checked) {
  background: var(--inv-bg); color: var(--inv-fg); border-color: var(--inv-bg);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--inv-bg) 60%, #000);
}
/* 答錯：紅中紅 */
.option.wrong { color: var(--red); border: 1.5px dashed var(--red); background: var(--tile); opacity: .9; }
.option.wrong .key { border-color: var(--red); color: var(--red); }
.option.dim { opacity: .5; }
.badge { background: var(--red); color: #fff; }
.tabbar a.on .badge { background: var(--red); color: #fff; border-color: var(--bg); }
.form-error { color: var(--red); }
.btn.danger.armed { background: var(--red); border-color: var(--red); color: #fff; }
.spell-input.wrong-input { border-color: var(--red); }
.word-table tr.unsure td { background: color-mix(in srgb, var(--red) 10%, transparent); }

/* 首頁標題旁的紅中點綴 */
.brand::before {
  content: "中"; display: inline-grid; place-items: center;
  width: 24px; height: 30px; margin-right: 8px; vertical-align: -6px;
  border-radius: 5px; background: var(--tile); color: var(--red);
  font-size: 16px; font-weight: 900;
  box-shadow: 0 2px 0 var(--tile-edge), inset 0 0 0 1px var(--tile-line);
}

/* ---------- 邊框統一：牌只用內描邊＋牌背厚度，不再疊 border ---------- */
.prompt, .option, .day-card, .mode-opt, .day-opt, .chip, .admin-list li, .settings-line {
  border: 0;
  box-shadow: inset 0 0 0 1px var(--tile-line), 0 3px 0 var(--tile-edge), 0 5px 10px rgba(0, 0, 0, .07);
}
.prompt { box-shadow: inset 0 0 0 1px var(--tile-line), 0 5px 0 var(--tile-edge), 0 8px 16px rgba(0, 0, 0, .08); }
.day-card:hover, .option:hover:not([disabled]), .mode-opt:hover, .day-opt:hover, .chip:hover {
  box-shadow: inset 0 0 0 1.5px var(--tile-edge), 0 3px 0 var(--tile-edge), 0 5px 10px rgba(0, 0, 0, .07);
}
.option.correct, .chip.on, .day-opt:has(input:checked), .mode-opt:has(input:checked) {
  box-shadow: 0 3px 0 color-mix(in srgb, var(--inv-bg) 55%, #000);
}
.option.wrong { border: 0; box-shadow: inset 0 0 0 2px var(--red), 0 3px 0 #8f2a24; }
.option .key { border-width: 1px; }
.mode-opt .tag { border-width: 1px; }



/* 輸入框、空心按鈕、分隔線統一 1px */
.field input, .field textarea, .slug-input, .voice-row select, .btn.ghost, .icon-btn { border-width: 1px; }
.slug-input input { border: 0 !important; }

/* logo：中牌＋兩行字 */
.brand { gap: 10px; }
.brand::before { width: 26px; height: 34px; margin-right: 0; font-size: 17px; border-radius: 6px; }
.brand-text { display: grid; line-height: 1.15; }
.brand-text b { font-size: 18px; font-weight: 800; }
.brand-text small { font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: .03em; }

/* ================= 測驗畫面：麻將桌 ================= */
/* 結構：木框 .mj-table ＞ 絨布 .mj-felt ＞ 對家的蓋牌、中央控制台（題目）、自己的三張牌 */

.mj-table {
  position: relative;
  margin: 16px -6px 8px;
  padding: 11px;
  border-radius: 30px;
  /* 木框：底色漸層＋細木紋＋上緣受光 */
  background:
    repeating-linear-gradient(100deg, rgba(255, 255, 255, .035) 0 2px, transparent 2px 7px),
    repeating-linear-gradient(80deg, rgba(0, 0, 0, .05) 0 1px, transparent 1px 11px),
    linear-gradient(160deg, #9a6a3d 0%, #7a4b25 45%, #5c3518 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 228, 190, .45),
    inset 0 -2px 0 rgba(0, 0, 0, .35),
    0 2px 0 #3f230e,
    0 18px 34px rgba(30, 18, 6, .35);
}
.mj-felt {
  position: relative; overflow: hidden;
  display: grid; gap: 14px;
  padding: 14px 12px 26px;
  border-radius: 21px;
  background:
    radial-gradient(ellipse 70% 55% at 50% 42%, rgba(255, 255, 255, .12), transparent 70%),
    radial-gradient(ellipse at 50% 50%, #237f53 0%, #17603e 55%, #0f4a2f 100%);
  /* 絨布邊緣被木框壓住的陰影 */
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, .35),
    inset 0 6px 14px rgba(0, 0, 0, .45),
    inset 0 -4px 10px rgba(0, 0, 0, .25);
  color: #fbf7ec;
}
/* 絨布織紋（SVG 雜訊） */
.mj-felt::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .22; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.mj-felt > * { position: relative; }

/* 對家的蓋牌 */
.mj-opp { display: flex; justify-content: center; gap: 2px; padding-top: 2px; }
.mj-opp i {
  width: clamp(12px, 3.6vw, 17px); aspect-ratio: 3 / 4; border-radius: 3px;
  background: linear-gradient(180deg, #2c9a65, #1b734a);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3), 0 2px 0 #efe6d0, 0 3px 0 #cbbd98, 0 4px 5px rgba(0, 0, 0, .35);
}

/* 中央控制台：題目 */
.mj-console {
  position: relative; margin: 0 auto; width: min(100%, 380px);
  padding: 20px 18px 16px; border-radius: 18px; text-align: center;
  background: linear-gradient(180deg, rgba(4, 30, 19, .38), rgba(4, 30, 19, .22));
  box-shadow: inset 0 0 0 1px rgba(251, 247, 236, .14), inset 0 2px 6px rgba(0, 0, 0, .35), 0 1px 0 rgba(255, 255, 255, .08);
}
.mj-console .wind { position: absolute; font: 700 12px/1 "Noto Serif TC", "Songti TC", serif; color: rgba(251, 247, 236, .38); }
.mj-console .wind.on { color: #ff8a7d; }
.mj-console .w-e { top: 9px; left: 11px; }
.mj-console .w-s { top: 9px; right: 11px; }
.mj-console .w-w { bottom: 9px; right: 11px; }
.mj-console .w-n { bottom: 9px; left: 11px; }
.mj-console .prompt {
  --muted: rgba(251, 247, 236, .66);
  min-height: 0; margin: 0; padding: 0;
  background: none; border: 0; box-shadow: none; color: #fbf7ec;
}
.mj-console .prompt .label { font-size: 11px; letter-spacing: .14em; margin-bottom: 8px; }
.mj-console .prompt .word {
  font-size: clamp(26px, 7.4vw, 40px); letter-spacing: .01em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .35), 0 6px 18px rgba(0, 0, 0, .25);
}
.mj-console .prompt .pos { margin-top: 4px; }
.mj-console .prompt .speak { margin-top: 6px; color: rgba(251, 247, 236, .75); }
.mj-console .prompt .speak:hover { color: #fff; }
.mj-wall { margin-top: 10px; font: 600 11px/1 var(--mono); letter-spacing: .08em; color: rgba(251, 247, 236, .5); }

/* 自己的三張牌 */
.hand { display: grid; grid-template-columns: repeat(3, minmax(0, 124px)); justify-content: center; gap: clamp(8px, 2.6vw, 14px); padding-bottom: 4px; }
.option.tile {
  position: relative;
  flex-direction: column; justify-content: center; gap: 0;
  aspect-ratio: 3 / 4; min-height: 0; height: auto;
  padding: 24px 8px 14px; border: 0; border-radius: 13px 13px 11px 11px;
  background:
    radial-gradient(ellipse 80% 40% at 50% 0%, rgba(255, 255, 255, .9), transparent 70%),
    linear-gradient(180deg, #fffdf8 0%, #f8f2e2 55%, #ede3ca 100%);
  color: #1f2b24;
  /* 牌面描邊／白色牌身兩層／綠色牌背兩層／落地陰影 */
  box-shadow:
    inset 0 1px 0 #fff,
    inset 0 0 0 1px rgba(150, 128, 86, .28),
    inset 0 -4px 8px rgba(120, 96, 52, .10),
    0 2px 0 #e7dcc0,
    0 4px 0 #d3c49f,
    0 7px 0 #22865a,
    0 11px 0 #165d3b,
    0 16px 16px rgba(0, 0, 0, .38);
  font-family: "Noto Serif TC", "Songti TC", "PMingLiU", Georgia, serif;
  font-size: 19px; font-weight: 700; line-height: 1.28; text-align: center;
  transition: transform .14s cubic-bezier(.3, .7, .4, 1), box-shadow .14s, background .14s, color .14s;
  animation: deal .32s cubic-bezier(.2, .8, .3, 1) both;
}
.option.tile:nth-child(2) { animation-delay: .06s; }
.option.tile:nth-child(3) { animation-delay: .12s; }
@keyframes deal { from { transform: translateY(26px) scale(.96); opacity: 0; } }
.option.tile.long { font-size: 15px; }
.option.tile .txt { overflow-wrap: anywhere; hyphens: auto; }
.option.tile .key {
  position: absolute; top: 7px; left: 9px; width: auto; height: auto; border: 0; border-radius: 0;
  font: 900 14px/1 "Noto Serif TC", "Songti TC", serif; color: #c0322b;
}
.option.tile .mark { position: absolute; top: 6px; right: 9px; margin: 0; font: 900 15px/1 var(--font); }
.option.tile:hover:not([disabled]) {
  transform: translateY(-6px);
  box-shadow:
    inset 0 1px 0 #fff, inset 0 0 0 1px rgba(150, 128, 86, .28), inset 0 -4px 8px rgba(120, 96, 52, .10),
    0 2px 0 #e7dcc0, 0 4px 0 #d3c49f, 0 7px 0 #22865a, 0 11px 0 #165d3b, 0 22px 22px rgba(0, 0, 0, .34);
}
.option.tile:active:not([disabled]) { transform: translateY(2px); }

/* 答對：抬起、金色光暈、字變翡翠綠 */
.option.tile.correct {
  transform: translateY(-14px);
  color: #0f5a37;
  background: linear-gradient(180deg, #ffffff 0%, #eef8ef 60%, #dcefdf 100%);
  box-shadow:
    inset 0 1px 0 #fff, inset 0 0 0 2px #2a9562,
    0 2px 0 #e7dcc0, 0 4px 0 #d3c49f, 0 7px 0 #22865a, 0 11px 0 #165d3b,
    0 0 0 3px rgba(240, 200, 96, .9), 0 0 22px 6px rgba(240, 200, 96, .45), 0 26px 26px rgba(0, 0, 0, .35);
}
.option.tile.correct .key { color: #0f5a37; }
/* 答錯：壓低、紅框、字變紅 */
.option.tile.wrong {
  transform: translateY(4px);
  color: #b3261e;
  background: linear-gradient(180deg, #fff8f5 0%, #f7e7e0 100%);
  box-shadow:
    inset 0 0 0 2px #c0322b,
    0 2px 0 #e7dcc0, 0 3px 0 #d3c49f, 0 5px 0 #22865a, 0 7px 10px rgba(0, 0, 0, .35);
  opacity: 1;
}
.option.tile.wrong .key { color: #b3261e; }
.option.tile.dim { opacity: .5; transform: translateY(2px); }

.mj-table + .feedback { margin-top: 18px; }
@media (max-width: 360px) {
  .mj-felt { padding: 12px 8px 22px; }
  .option.tile { font-size: 16px; padding: 22px 5px 12px; }
  .option.tile.long { font-size: 13px; }
}
.option.tile.wrong { text-decoration: none; }
.option.tile.wrong .txt { opacity: .85; }

/* 建立／編輯頁 */
.sub a { color: inherit; }
.admin-list li { gap: 8px; }
.admin-list li.editing { box-shadow: inset 0 0 0 2px var(--inv-bg), 0 3px 0 var(--tile-edge); }
.editing-tag { font-size: 12px; font-weight: 700; color: var(--inv-bg); padding: 0 8px; white-space: nowrap; }
a.btn.danger { text-decoration: none; }

/* logo：中牌在左、兩行字在右（之前被誤刪，補回來） */
.brand { display: inline-flex; align-items: center; gap: 10px; }

/* 鍵盤提示 */
.hint kbd {
  display: inline-block; min-width: 22px; padding: 1px 6px; margin: 0 1px;
  font: 600 11px/18px var(--mono); text-align: center; color: var(--fg);
  background: var(--tile); border-radius: 5px; border: 0;
  box-shadow: inset 0 0 0 1px var(--tile-line), 0 2px 0 var(--tile-edge);
}

/* 答錯後牌上的小字翻譯 */
.option.tile .gloss { display: none; }
.hand.reveal .option.tile .gloss, .option.tile.reveal .gloss {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  margin-top: 6px; padding-top: 6px; max-width: 100%;
  border-top: 1px solid rgba(120, 96, 52, .2);
  font: 500 12px/1.35 var(--font); color: #5d6a61; letter-spacing: 0;
}
.option.tile.correct .gloss { color: #2a6e4b; border-top-color: rgba(42, 149, 98, .3); }
.option.tile.wrong .gloss { color: #a3433c; border-top-color: rgba(192, 50, 43, .25); }

/* ================= 多人版：登入、帳號、方案、分享 ================= */

body.signed-out .tabbar { display: none; }
body.signed-out .wrap { padding-bottom: 48px; }

/* 右上角頭像 */
.topbar { gap: 12px; }
.me-chip { display: grid; place-items: center; border-radius: 50%; text-decoration: none; }
.avatar { display: block; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 2px var(--tile), 0 2px 0 3px var(--tile-edge); }
.avatar-text { display: grid; place-items: center; background: var(--inv-bg); color: var(--inv-fg); font-weight: 800; font-size: 14px; }

/* 登入頁 */
.auth { max-width: 400px; margin: 4vh auto 0; }
.auth-hero { text-align: center; margin-bottom: 22px; }
.auth-hero h1 { margin: 14px 0 4px; font-size: 30px; }
.auth-hero .sub { margin: 0; }
.hero-tile {
  display: inline-grid; place-items: center; width: 58px; height: 76px; border-radius: 10px;
  background: linear-gradient(#fefcf6, #efe6d0); color: var(--red);
  font: 900 36px/1 "Noto Serif TC", "Songti TC", serif;
  box-shadow: inset 0 0 0 1px var(--tile-line), 0 2px 0 #e7dcc0, 0 4px 0 #d3c49f, 0 8px 0 var(--tile-edge), 0 14px 20px rgba(0, 0, 0, .18);
  transform: rotate(-4deg);
}
.auth-card {
  display: grid; gap: 14px; padding: 22px 20px;
  background: var(--tile); color: var(--tile-fg); border-radius: 20px;
  --muted: var(--tile-muted); --line: var(--tile-line);
  box-shadow: inset 0 0 0 1px var(--tile-line), 0 4px 0 var(--tile-edge), 0 12px 24px rgba(0, 0, 0, .08);
}
.auth-card h2 { margin: 0; font-size: 20px; }
.auth-text { margin: 0; font-size: 14px; line-height: 1.6; color: var(--tile-muted); }
.auth-text b { color: var(--tile-fg); word-break: break-all; }
.auth-card .field input { background: #fffdf8; color: var(--tile-fg); border-color: var(--tile-line); }
.auth-card .field input:focus { border-color: var(--inv-bg); }
.auth-switch { justify-self: center; font-size: 13px; }
.auth-fine { margin: 14px 4px 0; font-size: 12px; line-height: 1.6; color: var(--muted); text-align: center; }

.google-btn {
  gap: 10px; background: #fff; color: #1f1f1f; border: 1px solid #dadce0 !important;
  font-family: Roboto, var(--font); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}
.google-btn:hover { background: #f8faff; }
.google-btn svg { width: 18px; height: 18px; flex: none; }
.or { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--tile-muted); }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--tile-line); }

.seg { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 12px; background: color-mix(in srgb, var(--tile-line) 55%, transparent); }
.seg button { min-height: 38px; border: 0; border-radius: 9px; background: transparent; color: var(--tile-muted); font-weight: 700; cursor: pointer; }
.seg button.on { background: #fffdf8; color: var(--tile-fg); box-shadow: 0 1px 0 var(--tile-edge), 0 1px 3px rgba(0, 0, 0, .08); }
.ts-box:empty { display: none; }
.ts-box { min-height: 65px; }

/* 方案 */
.plan-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: -12px 0 18px; font-size: 13px; color: var(--muted); }
.plan-line a { color: var(--inv-bg); font-weight: 700; }
.plan-tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; letter-spacing: .04em; }
.plan-free { background: var(--soft); color: var(--fg); box-shadow: inset 0 0 0 1px var(--line); }
.plan-premium { background: linear-gradient(135deg, #f3d27a, #d9a93a); color: #3d2a05; }
.plan-card { align-items: flex-start; flex-wrap: wrap; }
.plan-card .best-line { margin-top: 6px; }

/* 帳號 */
.account-card { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--radius); background: var(--tile); color: var(--tile-fg);
  box-shadow: inset 0 0 0 1px var(--tile-line), 0 3px 0 var(--tile-edge); --muted: var(--tile-muted); }
.account-info { min-width: 0; flex: 1; display: grid; gap: 2px; }
.name-form { display: flex; gap: 8px; align-items: center; }
.name-form input { min-width: 0; flex: 1; border: 0; background: transparent; color: inherit; font: 800 17px/1.3 var(--font); padding: 2px 0; border-bottom: 1px dashed transparent; }
.name-form input:focus { outline: none; border-bottom-color: var(--tile-edge); }
.account-email { font-size: 13px; color: var(--tile-muted); overflow: hidden; text-overflow: ellipsis; }
.account-methods { display: flex; gap: 6px; margin-top: 4px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: color-mix(in srgb, var(--tile-edge) 14%, transparent); color: var(--tile-edge); }
.pill-red { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }

/* 管理員：使用者列表 */
.admin-users { display: grid; gap: 8px; }
.admin-user { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 10px 14px; border-radius: 12px;
  background: var(--tile); color: var(--tile-fg); box-shadow: inset 0 0 0 1px var(--tile-line); font-size: 13px; }
.au-main { display: grid; min-width: 0; }
.au-mail, .au-meta { color: var(--tile-muted); overflow: hidden; text-overflow: ellipsis; }
.au-meta { font-size: 12px; }
.au-plan { display: flex; align-items: center; gap: 8px; }
.au-plan select, .au-plan input { min-height: 34px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--tile-line); background: #fffdf8; color: var(--tile-fg); font: inherit; font-size: 13px; }

/* 分享 */
.share-box { margin-top: 12px; }
.share-off, .share-on { display: grid; gap: 8px; padding: 12px 14px; border-radius: 12px; font-size: 13px; color: var(--muted); background: var(--soft); }
.share-off { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.share-label { color: var(--fg); font-weight: 600; }
.share-row { display: flex; gap: 8px; }
.share-row input { flex: 1; min-width: 0; min-height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg); font: 13px var(--mono); }
.share-row .btn { min-height: 40px; padding: 0 16px; flex: none; }
.share-on .link-btn { justify-self: start; font-size: 12px; }
.kicker { margin: 16px 0 -8px; font-size: 13px; font-weight: 700; color: var(--inv-bg); }

/* 首頁空狀態 */
.empty-hand { display: grid; justify-items: center; gap: 10px; padding: 28px 16px 8px; text-align: center; }
.empty-hand h2 { margin: 6px 0 0; font-size: 20px; }
.empty-hand p { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.mini-tiles { display: flex; gap: 6px; }
.mini-tiles i {
  display: grid; place-items: center; width: 40px; height: 54px; border-radius: 7px; font-style: normal;
  background: linear-gradient(#fefcf6, #efe6d0); color: #1f2b24; font: 900 22px/1 "Noto Serif TC", "Songti TC", serif;
  box-shadow: inset 0 0 0 1px var(--tile-line), 0 2px 0 #d3c49f, 0 5px 0 var(--tile-edge), 0 8px 12px rgba(0, 0, 0, .15);
}
.mini-tiles i:nth-child(odd) { transform: translateY(-4px) rotate(-3deg); }
.mini-tiles i:nth-child(4) { color: var(--red); }
