/* 設計 token 與通用元件沿用姊妹站 archero2，讓兩站看起來是同一個作者。
   本站沒有 Noto Sans TC 字型檔，因此不引入 @font-face，改用系統字型堆疊。 */

:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #12151a;
  --panel2: #181c22;
  --line: #2a2d2f;
  --line-strong: #4c4434;
  --text: #f1eee7;
  --muted: #99968f;
  --gold: #b8954f;
  --gold-bright: #d6b568;
  --green: #72b89a;
  --red: #c87979;
  --violet: #aa91c8;

  /* 盤面標示用色：canvas 由 JS 繪製，這裡集中定義好讓兩邊同色。 */
  --mark-suggest: #d6b568;
  --mark-crown: #72b89a;
  --mark-piece: rgba(241, 238, 231, 0.55);
  --mark-unexplained: #c87979;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(rgba(184, 149, 79, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(184, 149, 79, 0.025) 1px, transparent 1px),
    var(--bg);
  background-size: 48px 48px;
  color: var(--text);
  font:
    15px/1.55 system-ui,
    "Noto Sans TC",
    "PingFang TC",
    "Microsoft JhengHei",
    sans-serif;
  min-height: 100vh;
}

a {
  color: inherit;
}

/* 四個階段用 hidden 切換，而版面元件多半設了 display，需要蓋過去。 */
[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  transform: translateY(-160%);
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--gold-bright);
  color: #12100c;
  font-weight: 800;
}
.skip-link:focus { transform: translateY(0); }

:where(a, button, input, select, [tabindex]):focus-visible {
  outline: 3px solid var(--gold-bright);
  outline-offset: 3px;
}

/* 只給螢幕閱讀器與鍵盤使用：display:none 會讓元素不可聚焦，故用裁切法。 */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: auto;
  padding: 22px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 48px;
  margin-bottom: 42px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 800;
  text-decoration: none;
}
.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  object-fit: contain;
}

.nav {
  display: flex;
  align-self: stretch;
  gap: 24px;
  color: var(--muted);
  font-size: 14px;
  flex-wrap: wrap;
}
.nav a {
  display: inline-flex;
  align-items: center;
  border-bottom: 1px solid transparent;
  text-decoration: none;
}
.nav a:hover,
.nav a.active {
  color: var(--text);
}
.nav a.active {
  border-bottom-color: var(--gold);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}
h1 {
  font-size: clamp(30px, 4.6vw, 52px);
  line-height: 1.12;
  letter-spacing: -0.025em;
  max-width: 850px;
}
h2 {
  font-size: 22px;
}
h3 {
  font-size: 17px;
}

.eyebrow {
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 12px;
  font-weight: 850;
}
.lede,
.muted {
  color: var(--muted);
}
.lede {
  max-width: 720px;
  font-size: 17px;
}

.panel {
  background: rgba(18, 21, 26, 0.96);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
}
.hero {
  padding: clamp(24px, 5vw, 50px);
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 24px;
}
.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  padding: 0 17px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  background: var(--panel2);
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  color: var(--text);
  transition: background-color 150ms, border-color 150ms, color 150ms, transform 150ms;
}
.button:hover:not(:disabled) { border-color: var(--gold); }
.button:active:not(:disabled) { transform: translateY(1px); }
.button.primary {
  background: var(--gold);
  border-color: var(--gold);
  color: #12100c;
}
.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.grid {
  display: grid;
  gap: 14px;
}
.metric strong {
  display: block;
  font-size: 23px;
  margin-top: 5px;
}
.metric span {
  color: var(--muted);
  font-size: 12px;
}

.section {
  margin-top: 36px;
}
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 14px;
}
.section-head h2,
.section-head p {
  margin-bottom: 0;
}
.section-head > a {
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}
.section-head > a:hover {
  color: var(--gold-bright);
}
/* 窄螢幕改直排：並排時按鈕會被擠到只剩兩三個字寬，中文標籤直接折行。 */
@media (max-width: 560px) {
  .section-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .section-head > .button {
    align-self: flex-start;
  }
}

.status {
  display: inline-flex;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel2);
  font-size: 12px;
  color: var(--muted);
}

/* 一格一格的統計磚，中間靠 1px gap 露出底色當分隔線。 */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--line);
}
.compact-stat {
  padding: 18px;
  background: var(--panel2);
}
.compact-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.compact-stat strong {
  display: block;
  margin-top: 4px;
  color: var(--gold-bright);
  font-size: 23px;
  font-variant-numeric: tabular-nums;
}
.compact-stat p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.notice {
  border-left: 3px solid var(--gold);
  padding: 12px 15px;
  background: #2b2412;
  color: #e7dba8;
  border-radius: 8px;
}

.site-footer {
  margin-top: 52px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  color: #aaa69d;
  font-size: 12px;
}
.site-footer p {
  margin-bottom: 4px;
}
.site-footer a {
  color: var(--muted);
}

/* ── 隱私訊息 ───────────────────────────────────────────────
   「圖片不會上傳」是這個工具唯一要求玩家信任的地方，
   因此不藏在 lede 裡，用綠色標記獨立成塊。 */
.privacy-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 720px;
  margin: 0 0 24px;
  padding: 13px 16px;
  border: 1px solid rgba(114, 184, 154, 0.42);
  border-left: 3px solid var(--green);
  border-radius: 8px;
  background: rgba(114, 184, 154, 0.08);
  font-size: 14px;
}
.privacy-note strong {
  color: var(--green);
}
/* 內嵌 SVG 而非 emoji：這是全站最重要的信任訊息，
   不該在缺 emoji 字型的裝置上變成一個空白方框。 */
.privacy-note-icon {
  flex: 0 0 auto;
  margin-top: 2px;
  color: var(--green);
}

/* ── 拖放區 ────────────────────────────────────────────── */
.dropzone {
  margin-top: 4px;
  padding: clamp(22px, 4vw, 34px) 20px;
  border: 2px dashed var(--line-strong);
  border-radius: 14px;
  background: rgba(24, 28, 34, 0.55);
  text-align: center;
  transition: border-color 150ms, background-color 150ms;
}
.dropzone.is-dragover {
  border-color: var(--gold-bright);
  background: rgba(184, 149, 79, 0.12);
}
.dropzone-title {
  margin-bottom: 6px;
  font-size: 17px;
  font-weight: 750;
}
.dropzone-hint {
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 13px;
}
.dropzone-hint kbd {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel2);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
}
.dropzone-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.dropzone-formats {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 12px;
}
/* input 視覺隱藏後看不到自己的 focus ring，改把焦點狀態映射到旁邊的按鈕上。 */
#file-input:focus-visible ~ .dropzone-actions #pick-button {
  outline: 3px solid var(--gold-bright);
  outline-offset: 3px;
}

/* ── 三步驟 ────────────────────────────────────────────── */
.steps {
  counter-reset: step;
  margin: 0;
  padding: 0;
  list-style: none;
}
.steps .compact-stat {
  counter-increment: step;
}
.steps .compact-stat span::before {
  content: counter(step) "／3";
  display: block;
  margin-bottom: 6px;
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0.08em;
}
.steps .compact-stat strong {
  color: var(--text);
  font-size: 17px;
}

/* ── 分析中 ────────────────────────────────────────────── */
.busy-panel {
  display: grid;
  gap: 16px;
  place-items: center;
  padding: clamp(32px, 7vw, 64px) 20px;
  text-align: center;
}
.busy-panel #status {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}
.progress-track {
  overflow: hidden;
  width: min(320px, 100%);
  height: 6px;
  border-radius: 999px;
  background: var(--panel2);
}
.progress-bar {
  width: 40%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  animation: progress-slide 1.4s ease-in-out infinite;
}
@keyframes progress-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

/* ── 錯誤 ──────────────────────────────────────────────── */
.error-panel {
  max-width: 640px;
  border-color: rgba(200, 121, 121, 0.45);
  box-shadow: inset 3px 0 var(--red);
}
.error-panel h2 {
  margin-bottom: 8px;
  color: var(--red);
}
.error-panel p {
  margin-bottom: 20px;
  color: var(--muted);
}

/* ── 結果 ──────────────────────────────────────────────── */
.result-layout {
  display: grid;
  /* 盤面是 10×12 的直式圖，給它較窄的一欄；建議與摘要是文字，需要較寬。 */
  grid-template-columns: minmax(0, 0.88fr) minmax(0, 1.12fr);
  gap: 18px;
  align-items: start;
}
.board-panel {
  position: sticky;
  top: 16px;
  padding: 16px;
}
#board-canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
  background: var(--panel2);
}
#board-caption {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.board-toggles {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel2);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.toggle:hover {
  border-color: var(--gold);
}
.toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--gold-bright);
  cursor: pointer;
}
.toggle:has(input:checked) {
  color: var(--text);
  border-color: var(--line-strong);
}

.result-info {
  display: grid;
  gap: 18px;
}

/* ── 建議清單 ──────────────────────────────────────────── */
#suggestions {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.suggestion {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel2);
}
.suggestion-rank {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.suggestion-body {
  min-width: 0;
}
.suggestion-cell {
  font-size: 17px;
  line-height: 1.3;
}
.suggestion-chance {
  margin-left: 8px;
  color: var(--gold-bright);
  font-size: 14px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.suggestion-reason {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}
/* 第 1 名是玩家真正要看的那一格，用金色框與內側金條拉開層級。 */
.suggestion[data-rank="1"] {
  border-color: var(--gold);
  background: linear-gradient(90deg, rgba(184, 149, 79, 0.14), var(--panel2) 60%);
  box-shadow: inset 3px 0 var(--gold);
}
.suggestion[data-rank="1"] .suggestion-rank {
  border-color: var(--gold);
  background: var(--gold);
  color: #12100c;
}
.suggestion[data-rank="1"] .suggestion-cell {
  font-size: 20px;
}
/* 三格同分時全部套 .is-tied：一起升級成金框，而不是只讓第 1 名亮起來。
   同分的排序是座標決定的，把第 1 名畫得比較有把握等於誤導玩家。 */
.suggestion.is-tied {
  border-color: var(--gold);
  background: linear-gradient(90deg, rgba(184, 149, 79, 0.14), var(--panel2) 60%);
  box-shadow: inset 3px 0 var(--gold);
}
.suggestion.is-tied .suggestion-rank {
  border-color: var(--gold);
  background: var(--gold);
  color: #12100c;
}
/* 字級一律回到基準：放大第 1 名就是在暗示它比較準。 */
.suggestion.is-tied .suggestion-cell {
  font-size: 17px;
}
/* 已確認的皇冠不是機率而是事實，用綠色與金色的建議區隔開。 */
.suggestion.is-confirmed {
  border-color: var(--green);
  background: linear-gradient(90deg, rgba(114, 184, 154, 0.14), var(--panel2) 60%);
  box-shadow: inset 3px 0 var(--green);
}
.suggestion.is-confirmed .suggestion-rank {
  border-color: var(--green);
  background: var(--green);
  color: #0d1a15;
}
.suggestion.is-confirmed .suggestion-chance {
  color: var(--green);
}

/* ── 盤面摘要 ──────────────────────────────────────────── */
#summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1px;
  overflow: hidden;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--line);
}
#summary > div {
  padding: 13px 14px;
  background: var(--panel2);
}
#summary dt {
  color: var(--muted);
  font-size: 12px;
}
#summary dd {
  margin: 4px 0 0;
  color: var(--gold-bright);
  font-size: 20px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

/* ── 物件統計 ──────────────────────────────────────────── */
#piece-tally {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
#piece-tally li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel2);
  font-size: 13px;
}
/* 精靈圖不是正方形單格（bow 是 3×3 的完整物件圖），縮進固定框內即可。 */
#piece-tally img {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  object-fit: contain;
}
#piece-tally span {
  flex: 1;
  min-width: 0;
  color: var(--muted);
}
#piece-tally strong {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

#accuracy-note {
  margin: 0;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(24, 28, 34, 0.6);
  color: var(--muted);
  font-size: 12.5px;
}
#accuracy-note strong {
  color: var(--text);
}
#accuracy-note a {
  color: var(--gold-bright);
  white-space: nowrap;
}

/* 標題與其下的說明擠在同一列會太滿，section-head 內若包了一層就改直排。 */
.section-head > div > h2 {
  margin-bottom: 4px;
}
.section-head > div > p {
  margin-bottom: 0;
  font-size: 13px;
}

/* ── 原理頁 ────────────────────────────────────────────── */
.prose {
  max-width: 760px;
}
.prose p,
.prose ul,
.prose ol {
  margin-bottom: 14px;
}
.prose ul,
.prose ol {
  padding-left: 20px;
}
.prose li {
  margin-bottom: 7px;
}
.prose li::marker {
  color: var(--gold);
}
.prose strong {
  color: var(--text);
}
.shape-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}
.shape-grid li {
  display: grid;
  gap: 6px;
  place-items: center;
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel2);
  text-align: center;
}
.shape-grid img {
  width: 46px;
  height: 46px;
  object-fit: contain;
}
.shape-grid strong {
  font-size: 13px;
}
.shape-grid span {
  color: var(--muted);
  font-size: 11px;
}
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}
td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 900px) {
  .result-layout {
    grid-template-columns: 1fr;
  }
  .board-panel {
    position: static;
  }
}

@media (max-width: 780px) {
  .stat-strip {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .shell {
    width: min(100% - 22px, 1120px);
    padding-top: 20px;
  }
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding-bottom: 10px;
    margin-bottom: 24px;
  }
  .nav {
    width: 100%;
    gap: 18px;
    overflow-x: auto;
    scrollbar-width: thin;
    overscroll-behavior-inline: contain;
  }
  .nav a {
    flex: 0 0 auto;
    padding-bottom: 8px;
  }
  .hero {
    padding: 22px 18px;
  }
  h1 {
    font-size: 30px;
  }
  .lede {
    font-size: 16px;
  }
  .panel {
    padding: 16px;
  }
  .dropzone {
    padding: 22px 14px;
  }
  /* 390px 寬時兩顆按鈕並排會擠成兩行字，改成上下各佔滿一列。 */
  .dropzone-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
  .suggestion {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
  }
  .suggestion-rank {
    width: 30px;
    height: 30px;
  }
  #summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #piece-tally {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .shape-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
  /* 動畫被停掉後跑馬燈會停在畫面外，改成靜態的滿版條，仍看得出「進行中」。 */
  .progress-bar {
    width: 100%;
    animation: none !important;
    opacity: 0.55;
  }
}
