/* ===== 比例消除 樣式 ===== */
:root {
  --bg: #F8F4E8;
  --card: #FFFFFF;
  --ink: #2B2722;
  --line: #E8DFC8;
  --red: #E85A5A;
  --blue: #4A90D9;
  --gold: #D4A82C;
  --accent: #14427a;
  --warn: #C75B1E;
  --ok: #1E7A42;
  --cell-size: 64px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  user-select: none;
  -webkit-user-select: none;
}

html.play-lock,
body.play-lock {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100svh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

.screen {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px;
}
#screen-play {
  min-height: 100svh;
  overflow: hidden;
}
.hidden { display: none !important; }

h1 { font-size: 2em; color: var(--accent); margin: 8px 0; }
h2 { color: var(--accent); }
h3 { color: var(--accent); margin-top: 14px; margin-bottom: 4px; }
.subtitle { color: #666; margin: 0 0 20px; }

/* 首頁 hero 區 — 短招牌（裁中心帶，避免佔版面） */
.hero {
  margin: -4px 0 12px;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 6px 18px rgba(20, 66, 122, 0.18);
  background: #F5EDDD;
  height: 140px;
}
.hero-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 45%;
}
@media (max-width: 480px) {
  .hero { height: 110px; }
}

/* 結束畫面情緒圖 */
.end-image-wrap {
  margin: -8px -8px 16px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(20, 66, 122, 0.2);
  max-height: 280px;
}
.end-image {
  display: block;
  width: 100%;
  height: auto;
  object-fit: cover;
  animation: end-image-in 0.5s ease-out;
}
@keyframes end-image-in {
  from { transform: scale(1.08); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@media (max-width: 480px) {
  .hero { max-height: 200px; margin: -4px -16px 10px; }
  .end-image-wrap { max-height: 200px; }
}

.card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  margin: 12px 0;
  box-shadow: 0 2px 6px rgba(20,66,122,0.05);
}
.card .hint { color: #888; font-size: 0.9em; margin-top: 10px; }

button {
  font-family: inherit;
  font-size: 1em;
  padding: 10px 18px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: #fff;
  color: var(--accent);
  cursor: pointer;
  margin: 4px 6px 4px 0;
  transition: all 0.15s;
}
button:hover { background: #eef5ff; }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: #0f3460; }
button.primary.big { font-size: 1.2em; padding: 14px 30px; width: 100%; }
button.link { border: none; background: none; color: #777; }

.rules ul, .rules ol { padding-left: 20px; margin: 6px 0; }
.rules li { margin: 4px 0; }
.rules code { background: #F3EDDE; padding: 1px 6px; border-radius: 4px; font-family: "Consolas", monospace; }

/* ===== 規則頁資訊圖表 ===== */
.info-card {
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin: 14px 0;
  box-shadow: 0 2px 6px rgba(20,66,122,0.05);
}
.info-card > p { line-height: 1.6; margin: 8px 0; }
.info-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.info-card-header h3 { margin: 0; color: var(--accent); }
.info-icon {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  background: #FFF8E8;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5em;
  border: 2px solid var(--gold);
}
.info-icon.unknown-icon {
  background: #F5E8FC;
  border-color: #B78CD6;
  color: #8E44AD;
  font-family: "Consolas", monospace;
  font-style: italic;
  font-weight: bold;
}

.sub-head {
  margin: 14px 0 8px;
  color: var(--accent);
  font-size: 1em;
}

.mini {
  font-size: 0.85em;
  color: #666;
  margin: 8px 0 0;
  padding: 8px 12px;
  background: #FAF7EE;
  border-radius: 8px;
  border-left: 3px solid var(--gold);
}
.mini code {
  background: #F3EDDE;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: "Consolas", monospace;
}

/* 數字球 */
.rule-ball {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid currentColor;
  font-family: "Consolas", "Microsoft JhengHei", monospace;
  font-weight: bold;
  font-size: 1.15em;
  vertical-align: middle;
  margin: 2px 1px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}
.rule-ball.v-1 { color: #C04040; }
.rule-ball.v-2 { color: #D97A00; }
.rule-ball.v-3 { color: #B89500; }
.rule-ball.v-4 { color: #3E8E3E; }
.rule-ball.v-5 { color: #2E8B99; }
.rule-ball.v-6 { color: #3B6ABF; }
.rule-ball.v-8 { color: #7B4AB7; }
.rule-ball.v-9 { color: #B03A80; }
.rule-ball.unknown {
  color: #8E44AD;
  background: linear-gradient(135deg, #F5E8FC 0%, #E8D4F5 100%);
  font-style: italic;
}
.rule-arrow {
  display: inline-block;
  color: #B8A58E;
  margin: 0 2px;
  font-weight: normal;
  font-size: 1em;
  vertical-align: middle;
}
.colon {
  font-family: monospace;
  color: #666;
  margin: 0 3px;
  font-weight: bold;
  vertical-align: middle;
}
.big-eq {
  font-family: monospace;
  font-size: 1.5em;
  color: var(--gold);
  font-weight: bold;
  margin: 0 10px;
  vertical-align: middle;
}

/* 目標視覺 */
.goal-visual {
  text-align: center;
  padding: 16px;
  background: #FAF7EE;
  border-radius: 12px;
  margin: 10px 0;
}

/* 操作步驟 */
.steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  margin: 12px 0;
}
.step {
  background: #FAF7EE;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 12px 10px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.step p { margin: 0; line-height: 1.4; font-size: 0.92em; }
.step small { font-size: 0.85em; color: #888; }
.step-num {
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.9em;
  font-family: monospace;
}

/* 範例卡 */
.example {
  background: #FAF7EE;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 8px 0;
  border-left: 5px solid var(--line);
}
.example-ok { border-left-color: var(--ok); background: #F0F7F0; }
.example-bad { border-left-color: var(--warn); background: #FBEEE5; }
.example-balls {
  line-height: 1.6em;
  font-size: 1em;
  margin-bottom: 6px;
  flex-wrap: wrap;
  display: flex;
  align-items: center;
  gap: 2px;
}
.example-eq {
  font-family: "Consolas", monospace;
  font-weight: bold;
  color: var(--accent);
  font-size: 1.1em;
  margin: 4px 0 2px;
}
.example-note { font-size: 0.88em; }
.example-ok .example-note { color: var(--ok); font-weight: bold; }
.example-bad .example-note { color: var(--warn); font-weight: bold; }

/* 未知數 demo */
.unknown-demo {
  padding: 14px;
  background: #FAF7EE;
  border-radius: 12px;
  margin: 10px 0;
  text-align: center;
}
.unknown-demo .example-balls { justify-content: center; margin-bottom: 0; }
.arrow-down {
  text-align: center;
  font-size: 1.2em;
  color: var(--accent);
  opacity: 0.6;
  margin: 6px 0;
}
.quiz-preview {
  background: #FFF8E8;
  border: 2px dashed var(--gold);
  border-radius: 10px;
  padding: 12px;
  margin-top: 4px;
}
.quiz-eq {
  font-family: "Consolas", monospace;
  font-size: 1.5em;
  font-weight: bold;
  color: var(--accent);
  margin: 0 0 8px;
  letter-spacing: 0.03em;
}
.quiz-eq .blank {
  display: inline-block;
  background: var(--gold);
  color: #fff;
  padding: 0 10px;
  border-radius: 6px;
  margin: 0 4px;
}
.quiz-opts {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 8px 0;
  flex-wrap: wrap;
}
.quiz-opts span {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-weight: bold;
  font-family: "Consolas", monospace;
}
.quiz-opts span.correct {
  background: var(--ok);
  color: #fff;
  border-color: var(--ok);
  box-shadow: 0 0 0 3px rgba(30,122,66,0.25);
}
.tiny-hint {
  font-size: 0.85em;
  color: #666;
  margin: 6px 0 0;
}

/* 兩欄對比（成功 vs 失敗） */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.two-col-item {
  padding: 10px;
  border-radius: 8px;
  text-align: center;
  font-weight: bold;
  font-size: 0.95em;
}
.ok-item { background: #E8F4EC; color: var(--ok); border: 2px solid #A7D5B9; }
.bad-item { background: #FDEFE4; color: var(--warn); border: 2px solid #F0C9A8; }

/* 分數柱 */
.score-bars { margin: 8px 0 14px; }
.score-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
}
.score-bar {
  background: linear-gradient(90deg, #FFD966 0%, var(--gold) 100%);
  padding: 7px 14px;
  border-radius: 6px;
  color: #7A5600;
  font-weight: bold;
  font-family: monospace;
  font-size: 0.95em;
  text-align: center;
  min-width: 60px;
}
.score-val {
  color: var(--gold);
  font-weight: bold;
  font-size: 1em;
  font-family: monospace;
}

/* 連擊倍率 */
.combo-chart {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 8px 0;
}
.combo-pill {
  background: #fff;
  border: 2px solid var(--line);
  color: #666;
  padding: 5px 12px;
  border-radius: 16px;
  font-size: 0.9em;
  font-family: monospace;
  font-weight: bold;
}
.combo-pill.hot {
  background: #FF6B4A;
  color: #fff;
  border-color: #FF6B4A;
  box-shadow: 0 2px 6px rgba(255,107,74,0.3);
}

.warn-box {
  background: #FDEFE4;
  color: var(--warn);
  border: 2px solid #F0C9A8;
  padding: 10px 14px;
  border-radius: 8px;
  margin-top: 12px;
  font-size: 0.92em;
  text-align: center;
}

/* 模式卡（規則頁用） */
.modes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 10px 0;
}
.mode-item {
  background: #FAF7EE;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 12px 8px;
  text-align: center;
}
.mode-item img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  margin: 0 auto 6px;
  display: block;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.mode-item h4 { margin: 4px 0 2px; font-size: 0.95em; color: var(--accent); }
.mode-item p { margin: 0; font-size: 0.8em; color: #666; line-height: 1.3; }

/* 石頭流程 */
.stone-flow { margin: 14px 0; }
.stone-step {
  background: #F0EADC;
  border: 2px solid #D8CDA8;
  border-radius: 12px;
  padding: 12px 16px;
}
.stone-step p { margin: 0; font-size: 0.95em; line-height: 1.5; }
.stone-step-head {
  font-weight: bold;
  color: var(--accent);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.stone-step-head .step-num { background: #7A6F61; }

@media (max-width: 480px) {
  .info-card { padding: 14px; }
  .modes-grid { grid-template-columns: 1fr; }
  .rule-ball { width: 32px; height: 32px; font-size: 1em; }
  .steps { grid-template-columns: 1fr 1fr; }
  .quiz-eq { font-size: 1.2em; }
  .two-col { grid-template-columns: 1fr; }
}

/* ===== HUD ===== */
.hud {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 12px;
  margin-bottom: 10px;
}
.hud-item { display: flex; flex-direction: column; align-items: center; }
.hud-label { font-size: 0.72em; color: #888; }
.hud-value {
  font-family: "Consolas", monospace;
  font-size: 1.5em;
  font-weight: bold;
  color: var(--accent);
}
.hud-value.gold { color: var(--gold); }
.hud-item.small .hud-value { font-size: 1.1em; color: #555; }

.hint-toggle {
  padding: 6px 12px;
  font-size: 0.9em;
  border: 2px solid var(--gold);
  background: #FFF5D4;
  color: #8A6B00;
  border-radius: 8px;
  cursor: pointer;
  margin: 0;
}
.hint-toggle:hover { background: #FFE9A8; }
.hint-toggle.off {
  border-color: #BBB;
  background: #EEE;
  color: #777;
}

/* 連擊 HUD 高亮 */
#comboHudItem.hot .hud-value {
  color: #FF6B4A;
  font-size: 1.4em;
  animation: combo-pulse 0.6s ease-in-out infinite;
}
@keyframes combo-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* Quiz Modal */
.quiz-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 50, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fade-in 0.18s ease-out;
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.quiz-card {
  background: #fff;
  border-radius: 18px;
  padding: 28px 24px;
  max-width: 520px;
  width: 92%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  animation: card-pop 0.22s cubic-bezier(0.34, 1.4, 0.64, 1);
}
@keyframes card-pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.quiz-card h3 {
  margin: 0 0 14px;
  color: var(--accent);
}
.quiz-equation {
  font-family: "Consolas", monospace;
  font-size: 2em;
  font-weight: bold;
  color: var(--accent);
  background: #FFF8E8;
  padding: 14px 10px;
  border-radius: 10px;
  border: 2px dashed var(--gold);
  margin: 10px 0;
  letter-spacing: 0.05em;
}
.quiz-hint {
  color: #888;
  font-size: 0.9em;
  margin: 8px 0 16px;
}
.quiz-choices {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-top: 10px;
}
.quiz-choice {
  padding: 16px 0;
  font-size: 1.6em;
  font-family: "Consolas", monospace;
  font-weight: bold;
  border: 3px solid var(--accent);
  border-radius: 12px;
  background: #fff;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.1s;
  margin: 0;
}
.quiz-choice:hover:not(:disabled) {
  background: #eef5ff;
  transform: translateY(-3px);
  box-shadow: 0 4px 10px rgba(20, 66, 122, 0.25);
}
.quiz-choice:disabled {
  cursor: default;
  opacity: 1;             /* 抵銷 iOS/Safari 對 disabled 按鈕預設的 opacity:0.4 */
  -webkit-appearance: none;
  appearance: none;
}
.quiz-choice.correct {
  background: #56B38A !important;
  color: #fff !important;
  border-color: #2E7A52 !important;
  box-shadow: 0 0 0 4px rgba(86, 179, 138, 0.4);
  animation: choice-correct 0.4s ease-out;
}
.quiz-choice.wrong {
  background: #E85A5A !important;
  color: #fff !important;
  border-color: #A83030 !important;
  animation: choice-wrong 0.4s;
}
@keyframes choice-correct {
  0% { transform: scale(1); }
  30% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
@keyframes choice-wrong {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@media (max-width: 480px) {
  .quiz-card { padding: 20px 14px; }
  .quiz-equation { font-size: 1.5em; padding: 10px 6px; }
  .quiz-choice { padding: 12px 0; font-size: 1.3em; }
}

/* ===== 模式選擇卡片 ===== */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin: 20px 0;
}
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 14px;
  border: 3px solid var(--accent);
  border-radius: 14px;
  background: #fff;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.15s;
  margin: 0;
  font-family: inherit;
}
.mode-card:hover:not(:disabled) {
  background: #eef5ff;
  transform: translateY(-4px);
  box-shadow: 0 6px 16px rgba(20, 66, 122, 0.2);
}
.mode-card.disabled,
.mode-card:disabled {
  border-color: #CCC;
  color: #999;
  cursor: not-allowed;
  background: #F5F5F5;
}
.mode-icon {
  width: 88px;
  height: 88px;
  display: block;
  margin: 0 auto 8px;
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(20, 66, 122, 0.15);
  transition: transform 0.15s;
}
.mode-card:hover:not(:disabled) .mode-icon { transform: scale(1.06); }
.mode-title { font-size: 1.15em; font-weight: bold; margin-bottom: 4px; }
.mode-desc { font-size: 0.82em; color: #666; text-align: center; line-height: 1.4; }
.mode-card.disabled .mode-desc { color: #AAA; }

@media (max-width: 480px) {
  .mode-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .mode-card { padding: 18px 10px; }
  .mode-icon { width: 68px; height: 68px; }
  .mode-title { font-size: 1em; }
}

/* ===== 名字輸入 ===== */
.name-input-block {
  margin: 20px 0;
  padding: 18px;
  border: 2px dashed var(--gold);
  border-radius: 12px;
  background: #FFF8E8;
  text-align: center;
}
.name-input-block label {
  display: block;
  margin-bottom: 8px;
  color: var(--accent);
  font-weight: bold;
}
.name-input-block input {
  font-family: "Consolas", monospace;
  font-size: 1.4em;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: 8px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  width: 240px;
  max-width: 100%;
  margin: 8px 0;
}
.name-input-block input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212, 168, 44, 0.25);
}
.name-error {
  color: var(--warn);
  font-size: 0.9em;
  margin-top: 6px;
  min-height: 1.2em;
}
.submitted-block .success-msg {
  color: var(--ok);
  font-weight: bold;
  font-size: 1.2em;
  padding: 14px;
  background: #E8F4EC;
  border: 2px solid #A7D5B9;
  border-radius: 10px;
  margin: 16px 0;
}

/* ===== 排行榜 ===== */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.tab {
  flex: 1;
  padding: 10px 8px;
  border: 2px solid var(--line);
  background: #fff;
  color: #888;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-weight: bold;
  margin: 0;
}
.tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.loading {
  padding: 30px;
  text-align: center;
  color: #888;
}
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Consolas", monospace;
}
.leaderboard-table th,
.leaderboard-table td {
  padding: 8px 6px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  font-size: 0.95em;
}
.leaderboard-table th {
  background: #FAF7EE;
  color: var(--accent);
  font-weight: bold;
}
.leaderboard-table tr.top-rank { background: #FFF8E0; }
.leaderboard-table tr.top-rank td:first-child { font-size: 1.3em; }

@media (max-width: 480px) {
  .leaderboard-table th,
  .leaderboard-table td { padding: 6px 3px; font-size: 0.82em; }
}

/* ===== 對戰：登入、大廳、等待 ===== */
.mono { font-family: "Consolas", monospace; }

/* Namespace badge */
.ns-badge {
  display: inline-block;
  background: linear-gradient(135deg, #7B5EA7 0%, #5D3A8C 100%);
  color: #fff;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.85em;
  font-weight: bold;
  margin-bottom: 8px;
  box-shadow: 0 2px 6px rgba(93, 58, 140, 0.3);
}

/* 大廳：房間數 */
.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.lobby-header h3 { margin: 0; }
.room-count {
  font-size: 0.9em;
  color: #666;
  background: #F5E8E0;
  padding: 4px 10px;
  border-radius: 12px;
}

.id-label { display: block; margin: 10px 0 4px; font-weight: bold; color: var(--accent); }
.id-input {
  font-family: "Consolas", monospace;
  font-size: 1.3em;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: 8px;
  width: 260px;
  max-width: 100%;
  text-align: center;
  letter-spacing: 0.05em;
}
.id-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212, 168, 44, 0.25);
}

.lobby-actions { margin: 14px 0; }
.lobby-join-by-code { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.lobby-join-by-code input {
  flex: 1;
  padding: 8px 10px;
  font-size: 1.1em;
  border: 2px solid var(--line);
  border-radius: 8px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}
.lobby-join-by-code input:focus { outline: none; border-color: var(--gold); }
button.link.small { font-size: 0.85em; padding: 2px 6px; }

.room-list { max-height: 360px; overflow-y: auto; }
.room-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  margin-bottom: 6px;
  background: #FAF7EE;
}
.room-info { text-align: left; }
.room-code { font-size: 1.3em; font-weight: bold; color: var(--accent); letter-spacing: 0.05em; }
.room-host { font-size: 0.85em; color: #666; }
.room-actions button { margin: 0; }

/* 等待畫面 */
.waiting-card { text-align: center; }
.waiting-img {
  display: block;
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  object-position: center;
  border-radius: 12px;
  margin: -8px -8px 14px;
  box-shadow: 0 4px 12px rgba(20, 66, 122, 0.15);
}

/* 空大廳插畫 */
.empty-lobby {
  text-align: center;
  padding: 10px 0;
}
.empty-lobby img {
  display: block;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  margin: 10px auto;
  box-shadow: 0 3px 10px rgba(20, 66, 122, 0.15);
}
.empty-lobby .hint {
  margin-top: 10px;
}
.big-code {
  font-size: 3em;
  font-weight: bold;
  color: var(--gold);
  letter-spacing: 0.2em;
  padding: 20px;
  background: #FFF8E8;
  border: 3px dashed var(--gold);
  border-radius: 14px;
  margin: 14px 0;
}
.loading-dots span {
  opacity: 0.3;
  animation: dot-pulse 1.4s infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-pulse {
  0%, 60%, 100% { opacity: 0.3; }
  30% { opacity: 1; }
}

/* 對手 HUD */
.opponent-hud {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  padding: 8px 12px;
  background: #FDE8E0;
  border: 2px solid #F0B4A0;
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 0.95em;
}
.opp-label { font-weight: bold; color: #C04F2A; }
.opp-sep { color: #D0A090; }

/* 對戰結束 */
.battle-result {
  font-size: 1.3em;
  font-weight: bold;
  padding: 14px;
  border-radius: 10px;
  margin: 14px 0;
}
.battle-result.win { background: #E8F4EC; color: var(--ok); border: 2px solid #A7D5B9; }
.battle-result.lose { background: #FDEFE4; color: var(--warn); border: 2px solid #F0C9A8; }
.battle-result.tie { background: #E8F0FA; color: var(--accent); border: 2px solid #BBD3EC; }

.battle-final-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Consolas", monospace;
  margin: 10px 0 16px;
}
.battle-final-table th,
.battle-final-table td {
  padding: 8px 10px;
  text-align: center;
  border-bottom: 1px solid var(--line);
}
.battle-final-table th { background: #FAF7EE; color: var(--accent); }
.battle-final-table td:first-child {
  text-align: left;
  color: #666;
  font-family: inherit;
  font-size: 0.9em;
}

/* ===== 當前比例式顯示 ===== */
.equation {
  text-align: center;
  font-family: "Consolas", monospace;
  font-size: 1.6em;
  font-weight: bold;
  padding: 10px;
  min-height: 50px;
  margin: 6px 0;
  border-radius: 10px;
  background: #FFF8E8;
  border: 2px dashed #D8CDA8;
  color: #555;
  transition: all 0.15s;
}
.equation.hint {
  font-size: 0.95em;
  font-weight: normal;
  color: #999;
  border-style: dashed;
  background: transparent;
}
.equation.valid {
  background: #E8F7EE;
  border-color: var(--ok);
  color: var(--ok);
  box-shadow: 0 0 0 3px rgba(30, 122, 66, 0.15);
}
.equation.invalid {
  background: #FDEFE4;
  border-color: var(--warn);
  color: var(--warn);
}
.tap-mode-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 8px 0 10px;
  flex-wrap: wrap;
}
.tap-mode-label {
  padding: 6px 10px;
  border-radius: 8px;
  background: #E8F0FA;
  color: var(--accent);
  font-weight: 800;
}
.tap-mode-bar button {
  margin: 0;
}

/* ===== 棋盤 ===== */
.board-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  margin: 8px 0 14px;
}
.game-board {
  display: grid;
  gap: 2px;
  padding: 6px;
  background: #EFE5CA;
  border-radius: 10px;
  border: 2px solid var(--line);
  touch-action: none;
  position: relative;
  overflow: hidden;
}
.path-overlay {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 3;
}

/* 每個數字一個顏色（區辨用） */
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #FFFFFF;
  border: 2px solid #E0D6B8;
  border-radius: 50%;
  font-size: 1.8em;
  font-weight: bold;
  font-family: "Consolas", "Microsoft JhengHei", monospace;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  position: relative;
}
.cell.empty {
  background: transparent;
  border: 2px dashed #D8CDA8;
  box-shadow: none;
  cursor: default;
}
.cell.val-1  { color: #C04040; }
.cell.val-2  { color: #D97A00; }
.cell.val-3  { color: #B89500; }
.cell.val-4  { color: #3E8E3E; }
.cell.val-5  { color: #2E8B99; }
.cell.val-6  { color: #3B6ABF; }
.cell.val-8  { color: #7B4AB7; }
.cell.val-9  { color: #B03A80; }
.cell.val-10 { color: #A14040; font-size: 1.35em; }
.cell.val-12 { color: #AA6400; font-size: 1.35em; }
.cell.val-15 { color: #8A7500; font-size: 1.35em; }
.cell.val-18 { color: #2E6E2E; font-size: 1.35em; }
.cell.val-20 { color: #246B76; font-size: 1.35em; }
.cell.val-24 { color: #2C519C; font-size: 1.35em; }
.cell.val-36 { color: #5E3E97; font-size: 1.35em; }

/* 石頭 */
.cell.stone {
  color: #444;
  background: linear-gradient(135deg, #B8ADA1 0%, #7A6F61 100%);
  font-size: 1.9em;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.3), inset 0 -3px 6px rgba(0,0,0,0.35), 0 3px 6px rgba(0,0,0,0.3);
  border-color: #6A5A48;
  cursor: not-allowed;
  filter: saturate(0.6);
}
.cell.stone-incoming {
  animation: stone-drop 0.5s ease-out;
  z-index: 4;
}
@keyframes stone-drop {
  0% { transform: translateY(-260px) scale(0.6) rotate(-120deg); opacity: 0.4; }
  65% { transform: translateY(10px) scale(1.12) rotate(12deg); opacity: 1; }
  85% { transform: translateY(-4px) scale(0.96) rotate(-4deg); }
  100% { transform: translateY(0) scale(1) rotate(0); }
}
.cell.stone-release {
  animation: stone-crack 0.4s ease-out;
  z-index: 4;
}
@keyframes stone-crack {
  0% { transform: scale(1); filter: saturate(0.6); }
  40% { transform: scale(1.25) rotate(8deg); filter: saturate(1.5) brightness(1.3); box-shadow: 0 0 24px rgba(212,168,44,0.8); }
  100% { transform: scale(1); filter: saturate(1) brightness(1); }
}

/* 未知數 */
.cell.unknown {
  color: #8E44AD;
  background: linear-gradient(135deg, #F5E8FC 0%, #E8D4F5 100%);
  font-size: 2em;
  font-weight: bold;
  font-style: italic;
  box-shadow: 0 2px 6px rgba(142, 68, 173, 0.3);
  border-color: #B78CD6;
  animation: unknown-pulse 2s ease-in-out infinite;
}
@keyframes unknown-pulse {
  0%, 100% { box-shadow: 0 2px 6px rgba(142, 68, 173, 0.3); }
  50% { box-shadow: 0 2px 12px rgba(142, 68, 173, 0.6); }
}

.cell:hover:not(.empty) { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.15); }
.cell.chained {
  transform: scale(1.1);
  box-shadow: 0 0 0 4px var(--gold), 0 4px 10px rgba(212, 168, 44, 0.4);
  background: #FFF8E0;
  z-index: 2;
}
/* 消除爆炸特效 */
@keyframes pop-out {
  0% {
    transform: scale(1);
    opacity: 1;
    background: #FFF8E0;
  }
  25% {
    transform: scale(1.35) rotate(-8deg);
    opacity: 1;
    background: #FFE066;
    box-shadow: 0 0 24px #FFD966, 0 0 48px rgba(255, 217, 102, 0.6);
  }
  55% {
    transform: scale(1.2) rotate(6deg);
    opacity: 0.8;
    background: #FFD4A0;
    box-shadow: 0 0 32px #D4A82C, 0 0 60px rgba(212, 168, 44, 0.4);
  }
  100% {
    transform: scale(1.6) rotate(-4deg);
    opacity: 0;
    background: #FFCC66;
    box-shadow: 0 0 0 transparent;
  }
}
.cell.exploding {
  animation: pop-out 320ms ease-out forwards;
  z-index: 5;
  pointer-events: none;
}

.cell.hint:not(.chained) {
  outline: 4px dashed #FF6B4A;
  outline-offset: -3px;
  animation: hint-pulse 0.9s ease-in-out infinite;
  background: #FFE5D4;
  box-shadow: 0 0 16px rgba(255, 107, 74, 0.6);
  z-index: 4;
}
@keyframes hint-pulse {
  0%, 100% {
    outline-color: #FF6B4A;
    background: #FFE5D4;
    transform: scale(1);
    box-shadow: 0 0 16px rgba(255, 107, 74, 0.6);
  }
  50% {
    outline-color: #FF9373;
    background: #FFF2E0;
    transform: scale(1.08);
    box-shadow: 0 0 24px rgba(255, 107, 74, 0.9);
  }
}
/* 提示編號徽章（置於 cell 內部右上角，避免被 board overflow 剪裁） */
.cell.hint[data-hint-num]::after {
  content: attr(data-hint-num);
  position: absolute;
  top: 1px;
  right: 1px;
  width: 22px;
  height: 22px;
  background: #FF6B4A;
  color: #fff;
  border-radius: 50%;
  font-size: 0.65em;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3), 0 0 0 2px #fff;
  font-family: "Microsoft JhengHei", sans-serif;
  pointer-events: none;
  z-index: 5;
}

.cell.chain-first::before {
  content: '1';
  position: absolute;
  top: -6px;
  left: -6px;
  width: 18px;
  height: 18px;
  background: var(--gold);
  color: #fff;
  border-radius: 50%;
  font-size: 0.7em;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== 訊息 ===== */
.message {
  text-align: center;
  min-height: 30px;
  padding: 6px 10px;
  font-weight: bold;
  border-radius: 8px;
  transition: all 0.2s;
}
.message.ok { background: #E8F4EC; color: var(--ok); border: 1px solid #A7D5B9; }
.message.warn { background: #FDEFE4; color: var(--warn); border: 1px solid #F0C9A8; }
.message.info { background: #E8F0FA; color: var(--accent); border: 1px solid #BBD3EC; }

/* ===== RWD ===== */
@media (max-width: 480px) {
  :root { --cell-size: 48px; }
  .cell { font-size: 1.4em; }
  .equation { font-size: 1.3em; }
}

/* ===== v4：首頁 QR + 房間 QR + iPad RWD ===== */
.home-qr-card {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 18px;
  margin: 16px 0 8px;
  background: #fff;
  border: 2px solid var(--accent, #4A90E2);
  border-radius: 14px;
  flex-wrap: wrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.home-qr-text { flex: 1; min-width: 220px; }
.home-qr-title {
  font-size: 1.05em;
  font-weight: 800;
  color: var(--accent, #4A90E2);
  margin-bottom: 6px;
}
.home-qr-sub {
  font-size: 0.92em;
  color: #555;
  margin-bottom: 8px;
  line-height: 1.5;
}
.home-qr-url {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.78em;
  color: #888;
  word-break: break-all;
}
.home-qr-canvas {
  flex: 0 0 auto;
  background: #fff;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid #ddd;
  line-height: 0;
}
.home-qr-canvas canvas { display: block; }

.waiting-qr-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
}
.waiting-qr {
  background: #fff;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #ddd;
  line-height: 0;
}
.waiting-qr canvas { display: block; }
.waiting-qr-hint {
  font-size: 0.9em;
  color: #555;
  max-width: 360px;
  line-height: 1.55;
  text-align: center;
}

/* 觸控:加大按鈕區域 */
@media (pointer: coarse) {
  button { min-height: 44px; }
  .id-input, .lobby-join-by-code input { min-height: 48px; }
  button, .room-row, .mode-card { touch-action: manipulation; }
  .game-board, .cell { touch-action: none; }
}

/* iPad Portrait */
@media (min-width: 700px) and (max-width: 1100px) and (orientation: portrait) {
  :root { --cell-size: 64px; }
  .home-qr-canvas canvas { width: 200px !important; height: 200px !important; }
  .waiting-qr canvas { width: 240px !important; height: 240px !important; }
  .big-code { font-size: 3em; }
}

/* iPad Landscape */
@media (min-width: 1000px) and (max-width: 1300px) and (orientation: landscape) {
  :root { --cell-size: 64px; }
  .home-qr-canvas canvas { width: 200px !important; height: 200px !important; }
  .waiting-qr canvas { width: 220px !important; height: 220px !important; }
}

/* 手機/小平板:首頁 QR 直排 */
@media (max-width: 700px) {
  .home-qr-card { flex-direction: column; align-items: stretch; text-align: center; }
  .home-qr-canvas { align-self: center; }
  .home-qr-canvas canvas { width: 170px !important; height: 170px !important; }
  .waiting-qr canvas { width: 200px !important; height: 200px !important; }
}
