/* 手機優先的樣式 */
:root {
  --bg: #f4f8fb;
  --card: #ffffff;
  --text: #1d2a33;
  --muted: #5f6f7a;
  --primary: #0b6e99;
  --primary-dark: #08587a;
  --secondary: #e3f1f8;
  --danger: #c0392b;
  --border: #d8e3ea;
  --marker: #e53935;
  --radius: 14px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 17px;
  line-height: 1.6;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

a { color: var(--primary); }

h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.2rem; margin: 0 0 .75rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 .25rem; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  background: var(--primary); color: #fff;
}
.topbar .brand { color: #fff; font-weight: 700; font-size: 1.15rem; text-decoration: none; }
.topbar form { margin: 0; }
.link-btn { background: none; border: 0; color: #fff; font: inherit; padding: 6px 4px; cursor: pointer; }

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

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
}

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

.note {
  background: #fff7e0; border-left: 4px solid #f0b400;
  padding: 10px 12px; border-radius: 8px; font-size: .92rem;
}

.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; }
.flash-error { background: #fdecea; color: #8a1f14; }
.flash-success { background: #e6f6ec; color: #1e6b3a; }

/* 表單 */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.form small { font-weight: 400; }
input[type=text], input:not([type]), input[type=password] {
  font: inherit; font-size: 16px; /* 16px 以上 iPhone 才不會自動放大 */
  padding: 12px; border: 1px solid var(--border); border-radius: 10px; width: 100%;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* 按鈕 */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 48px; padding: 12px 16px;
  border: 0; border-radius: 12px; font: inherit; font-weight: 700;
  text-decoration: none; cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-outline { background: #fff; color: var(--danger); border: 1px solid var(--danger); margin-top: 12px; }
.btn-big { min-height: 64px; font-size: 1.15rem; margin-top: 12px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.tips ol { padding-left: 1.3rem; margin: 0; }

/* 辨識中 */
.loading {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .92); font-weight: 700;
}
.loading[hidden] { display: none; }
.spinner {
  width: 52px; height: 52px; border-radius: 50%;
  border: 5px solid var(--secondary); border-top-color: var(--primary);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 結果頁 */
.result-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.result-head h1 { margin: 0; margin-right: 4px; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  background: var(--secondary); color: var(--primary-dark); font-size: .85rem; font-weight: 600;
}
.badge-high { background: #e6f6ec; color: #1e6b3a; }
.badge-mid { background: #fff7e0; color: #7a5a00; }
.badge-low { background: #fdecea; color: #8a1f14; }

.photo-wrap { position: relative; border-radius: 10px; overflow: hidden; line-height: 0; }
.photo-wrap img { width: 100%; height: auto; display: block; }
.marker {
  position: absolute; transform: translate(-50%, -50%);
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--marker); color: #fff; border: 2px solid #fff;
  font: 700 14px/1 system-ui, sans-serif; cursor: pointer;
  box-shadow: 0 0 0 3px rgba(229, 57, 53, .35);
  animation: pulse 1.8s ease-in-out infinite;
}
.marker.selected { background: #ffb300; color: #1d2a33; box-shadow: 0 0 0 5px rgba(255, 179, 0, .5); animation: none; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(229, 57, 53, .15); } }

.bone-list { padding-left: 1.4rem; margin: 12px 0 0; }
.bone-list li { padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.bone-list li.selected { background: #fff3cd; }

.recipe { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; padding: 0 14px; }
.recipe summary {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 0; cursor: pointer; list-style: none; font-weight: 700;
}
.recipe summary::-webkit-details-marker { display: none; }
.recipe .rank {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: #fff; display: grid; place-items: center; font-size: .9rem;
}
.recipe .recipe-name { flex: 1; }
.recipe .stars { color: #f0a500; letter-spacing: 1px; }
.recipe .reason { margin: 0 0 6px; color: var(--muted); }
.recipe ol { margin: 0 0 12px; padding-left: 1.3rem; }

.actions { display: flex; flex-direction: column; gap: 4px; }
.actions form { margin: 0; }

/* 歷史紀錄 */
.history { list-style: none; padding: 0; margin: 0 0 8px; }
.history li { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); }
.history form { margin: 0; }
.history-item { flex: 1; display: flex; align-items: center; gap: 12px; padding: 10px 0; color: inherit; text-decoration: none; }
.history-item img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; flex: none; }
.history-item span { display: flex; flex-direction: column; }
.icon-btn { background: none; border: 0; font-size: 1.3rem; padding: 12px; cursor: pointer; }

/* 設定 */
.help { margin: 14px 0; }
.help summary { cursor: pointer; color: var(--primary); }
.danger-zone { border: 1px solid #f3c2bc; }
code { background: var(--secondary); padding: 2px 6px; border-radius: 6px; }

/* 底部導覽列 */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: #fff; border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 8px 0 10px; color: var(--muted); text-decoration: none; font-size: .8rem;
}
.bottom-nav a span { font-size: 1.35rem; line-height: 1.2; }
.bottom-nav a.active { color: var(--primary); font-weight: 700; }
