:root {
  --bg: #ffffff;
  --panel: #f4f5f7;
  --border: #dde1e7;
  --text: #1b2330;
  --muted: #5b6472;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.10);
  --danger: #dc2626;
  --success: #15803d;
  --highlight: #b45309;
  --grade-a: #dc2626; --grade-a-bg: rgba(220, 38, 38, 0.10);
  --grade-b: #b45309; --grade-b-bg: rgba(180, 83, 9, 0.12);
  --grade-c: #15803d; --grade-c-bg: rgba(21, 128, 61, 0.10);
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 4px 14px rgba(16, 24, 40, 0.08);
  --mono: "SFMono-Regular", ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Noto Sans TC", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 24px 16px;
}

.site-header {
  border-bottom: 1px solid var(--border);
  padding: 20px 24px;
}

.logo-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 20px;
  max-width: 960px;
  margin: 0 auto;
}

.logo-img {
  height: 67px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  padding: 6px 10px;
}

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 1rem;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.site-footer p {
  margin: 2px 0;
}

h1 { margin-top: 0; text-align: center; }

.subtitle {
  text-align: center;
  color: var(--muted);
  margin-top: -8px;
  margin-bottom: 24px;
}

/* 上傳表單 */
.predict-form {
  margin: 24px auto 0;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 16px;
  max-width: 480px;
  text-align: center;
}

.field {
  flex: 1;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
}

.field select {
  width: 100%;
  height: 56px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--panel);
  color: var(--text);
  font-size: 1.5rem;
}

.file-upload-btn {
  flex: 1;
  min-width: 140px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
  text-align: center;
  color: var(--text);
  font-size: 1.5rem;
}

.file-upload-btn:hover { border-color: var(--accent); }

.file-upload-btn input { display: none; }

/* Flash 訊息 */
.flash-list { margin-bottom: 16px; }

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 1.8rem;
}

.flash-error { background: rgba(255, 107, 107, 0.15); color: var(--danger); }
.flash-success { background: rgba(67, 193, 123, 0.15); color: var(--success); }

/* 結果頁 */
.result-layout {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 16px;
  margin-top: 24px;
  align-items: stretch;
}

.result-image {
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.result-image img {
  max-width: 120px;
  max-height: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.prob-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1.5rem;
}

.prob-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
}

.prob-table tr.is-top td:first-child,
.prob-table tr.is-top td:nth-child(2) {
  color: var(--highlight);
  font-weight: 600;
}

.bar-cell { width: 20%; }

.bar-track {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

/* A/B/C 分級卡片（介面 B） */
.grade-chip {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: 8px;
  font-weight: 800;
  letter-spacing: 0.06em;
  font-size: 1.5rem;
}

.grade-chip .g {
  font-size: 1.8rem;
  line-height: 1;
  font-family: "SFMono-Regular", ui-monospace, Consolas, monospace;
}

.grade-A { background: var(--grade-a-bg); color: var(--grade-a); border: 1.5px solid var(--grade-a); }
.grade-B { background: var(--grade-b-bg); color: var(--grade-b); border: 1.5px solid var(--grade-b); }
.grade-C { background: var(--grade-c-bg); color: var(--grade-c); border: 1.5px solid var(--grade-c); }

.rc-meaning {
  margin: 12px 0;
  font-size: 1.25rem;
}

.rc-actions {
  margin: 8px 0 0;
  padding-left: 1.2em;
  font-size: 1.25rem;
}

.rc-actions li {
  margin: 6px 0;
}

/* 免責聲明彈窗 */
.gate-shell {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(27, 35, 48, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.gate-shell[hidden] { display: none; }

.gate-panel {
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 640px;
  width: 100%;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.gate-heading { margin: 0 0 12px; font-size: 1.25rem; text-align: center; }

.gate-text {
  overflow-y: auto;
  font-size: 1.125rem;
  line-height: 1.7;
  padding-right: 4px;
  color: var(--text);
}

.gate-text p { margin: 0 0 12px; }
.gate-text h3 { margin: 16px 0 6px; font-size: 1.125rem; color: var(--accent); }
.gate-text ul { margin: 0 0 4px; padding-left: 1.3em; }
.gate-text li { margin: 6px 0; }

.gate-confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  font-size: 1.125rem;
  cursor: pointer;
}

.btn {
  border-radius: 8px;
  padding: 11px 18px;
  font-weight: 700;
  letter-spacing: 0.04em;
  border: 1.5px solid transparent;
  font-size: 1.25rem;
  cursor: pointer;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:disabled { background: #d7dbe0; color: #8b93a0; cursor: not-allowed; }
.btn-ghost { background: var(--panel); border-color: var(--accent); color: var(--accent); }
.btn-ghost:active { background: var(--accent-soft); }
.btn-sm { padding: 8px 14px; font-size: 1.25rem; border-radius: 7px; }

.gate-panel .btn {
  margin-top: 14px;
  align-self: center;
  padding: 11px 32px;
}

/* 歷史紀錄（介面 B） */
.history-section {
  margin-top: 32px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.history-heading {
  margin: 0;
  font-size: 1.5rem;
}

.rc-summary .btn { margin-left: auto; }

.results-list {
  display: grid;
  gap: 14px;
}

.result-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.rc-summary {
  cursor: pointer;
  list-style: none;
  padding: 12px 14px;
  font-weight: 600;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rc-summary::-webkit-details-marker { display: none; }
.rc-summary::before { content: "▸ "; display: inline-block; transition: transform .15s; }
.result-card[open] .rc-summary::before { transform: rotate(90deg); }
.result-card[open] .rc-summary { border-bottom: 1px solid var(--border); }

.g-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 6px;
  font-family: var(--mono);
  font-weight: 800;
  font-size: 1.25rem;
  flex: none;
}

.rc-body { padding: 14px; }

.rc-top {
  display: flex;
  gap: 14px;
  margin-top: 10px;
  align-items: flex-start;
}

.rc-photo {
  width: 110px;
  flex: none;
  border-radius: 8px;
  overflow: hidden;
  background: var(--border);
}

.rc-photo img { width: 100%; height: auto; display: block; }

.rc-main { flex: 1; min-width: 0; }
