/* 旅遊語音導覽 — 行動版優先、繁體中文 UI */

:root {
  --bg: #f7f6f3;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --accent: #c2410c;
  --accent-soft: #fde7dc;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
    "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

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

header.site {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(247, 246, 243, 0.92);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}

header.site .wrap {
  padding-top: 14px;
  padding-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

header.site h1 {
  font-size: 1.15rem;
  margin: 0;
  font-weight: 700;
}

header.site .back {
  font-size: 0.95rem;
  color: var(--accent);
  font-weight: 600;
}

.subtitle {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 4px 0 20px;
}

/* 行程卡片（首頁） */
.trip-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}

.trip-card:active {
  transform: scale(0.99);
}

.trip-card h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}

.trip-card .meta {
  color: var(--muted);
  font-size: 0.88rem;
}

/* 日分組 */
.day-group {
  margin-bottom: 28px;
}

.day-head {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.day-head::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

/* 景點卡片 */
.poi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.poi-photo {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: #eee;
}

.poi-body {
  padding: 16px;
}

.poi-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.poi-card h3 {
  margin: 0 0 6px;
  font-size: 1.1rem;
}

.poi-dist {
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

.poi-summary {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0 0 12px;
}

/* 播放器 */
.player {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn-play {
  background: var(--accent);
  color: #fff;
}

.btn-ghost {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-ghost[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

audio {
  width: 100%;
  margin-top: 12px;
}

.speed-group {
  display: inline-flex;
  gap: 4px;
}

.speed-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 0.82rem;
  cursor: pointer;
  font-family: inherit;
  color: var(--muted);
}

.speed-btn.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

/* 展開文稿 */
.detail {
  margin-top: 14px;
  border-top: 1px dashed var(--border);
  padding-top: 14px;
  display: none;
}

.detail.open {
  display: block;
}

.detail h4 {
  margin: 14px 0 6px;
  font-size: 0.9rem;
  color: var(--accent);
}

.detail p {
  margin: 0;
  white-space: pre-wrap;
  font-size: 0.96rem;
}

.toggle-detail {
  margin-top: 12px;
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-size: 0.9rem;
  font-family: inherit;
}

/* 工具列 */
.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.status-msg {
  font-size: 0.9rem;
  color: var(--muted);
  padding: 20px 0;
  text-align: center;
}

/* 首頁：即時導覽入口 + 頁尾 */
.live-entry {
  display: block;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
  font-weight: 600;
  font-size: 0.95rem;
}

.live-entry:active {
  transform: scale(0.99);
}

.site-footer {
  margin-top: 32px;
  text-align: center;
  font-size: 0.85rem;
}

.site-footer a {
  color: var(--muted);
}

/* Admin 模式 */
.admin-login-link {
  color: var(--muted);
  opacity: 0.7;
  text-decoration: none;
}

.admin-login-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 360px;
  margin: 0 auto;
}

.admin-login-form input[type="password"] {
  flex: 1 1 140px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
}

.admin-login-msg {
  flex-basis: 100%;
  color: var(--accent);
  font-size: 0.8rem;
}

.admin-badge {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  box-shadow: var(--shadow);
  z-index: 50;
}

.admin-badge a {
  color: #fde7dc;
  text-decoration: underline;
}

/* 即時模式頁 */
.live-search {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.live-search input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--card);
  color: var(--ink);
}

.live-search input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.live-search .btn {
  white-space: nowrap;
}

.live-working {
  color: var(--accent);
  font-weight: 600;
}

.live-error {
  color: #b91c1c;
  font-weight: 600;
}

.live-h4 {
  margin: 16px 0 6px;
  font-size: 0.9rem;
  color: var(--accent);
}

.live-script {
  margin: 0;
  white-space: pre-wrap;
  font-size: 0.96rem;
}

/* 費用統計頁 */
.stat-hero {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 18px;
  text-align: center;
  margin-bottom: 16px;
}

.stat-usd {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.1;
}

.stat-usd-label {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.stat-free {
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--muted);
}

/* 通關密語管理卡片（§B） */
.token-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 20px;
}

.token-current {
  font-size: 1rem;
  margin: 4px 0;
}

.token-code {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 12px;
  border-radius: 8px;
  letter-spacing: 2px;
}

.token-updated,
.token-hint,
.token-none {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 4px 0;
}

.token-link {
  word-break: break-all;
}

.token-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.token-msg {
  min-height: 1em;
  font-size: 0.85rem;
}

.stat-cards {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.stat-mini {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: center;
}

.stat-mini-num {
  font-size: 1.4rem;
  font-weight: 700;
}

.stat-mini-label {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.stat-h2 {
  font-size: 1rem;
  color: var(--accent);
  margin: 8px 0 10px;
}

.stat-table-wrap {
  overflow-x: auto;
  margin-bottom: 24px;
}

.stat-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.9rem;
}

.stat-table th,
.stat-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.stat-table thead th {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.stat-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.stat-table tr:last-child td {
  border-bottom: none;
}

.muted-cell {
  color: var(--muted);
  text-align: center;
}

.stat-updated {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

/* ---------------- §B 首頁行程卡刪除 / 產生中 ---------------- */
.trip-card-wrap {
  position: relative;
  margin-bottom: 14px;
}

.trip-card-wrap .trip-card {
  margin-bottom: 0;
}

.trip-del {
  position: absolute;
  top: 10px;
  right: 10px;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 12px;
  font-size: 1.05rem;
  cursor: pointer;
}

.trip-card-generating {
  opacity: 0.9;
  border-style: dashed;
}

/* ---------------- §B 即時快取列表 ---------------- */
.live-list {
  margin-top: 8px;
}

.live-list-title {
  font-size: 1rem;
  color: var(--accent);
  margin: 18px 0 10px;
}

.live-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.live-item-open {
  flex: 1 1 160px;
  min-width: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.98rem;
  color: var(--ink);
  text-align: left;
  padding: 4px 2px;
}

.live-item-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-textonly {
  color: var(--muted);
}

.live-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.live-item-btn {
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

.live-item-btn.live-del {
  background: var(--card);
  color: var(--ink);
  padding: 6px 10px;
}

/* ---------------- 加入行程彈窗 ---------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.modal-title {
  margin: 0 0 14px;
  font-size: 1.05rem;
}

.modal-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.modal-label select {
  display: block;
  width: 100%;
  margin-top: 5px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--card);
  color: var(--ink);
}

.modal-msg {
  min-height: 1.2em;
  font-size: 0.85rem;
  margin: 4px 0 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-actions .btn {
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
}

.modal-actions .btn-play {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

/* ---------------- §C 匯入行程頁 ---------------- */
.import-label {
  display: block;
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 14px;
}

.import-label input[type="text"],
.import-label input[type="date"],
.import-label textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--card);
  color: var(--ink);
}

.import-label input[type="file"] {
  display: block;
  margin-top: 6px;
  font-family: inherit;
}

.import-label textarea {
  resize: vertical;
  line-height: 1.6;
}

#import-parse {
  min-height: 44px;
}

.import-result-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-top: 16px;
}

.import-day {
  margin-bottom: 16px;
}

.import-day-head {
  font-size: 0.95rem;
  color: var(--accent);
  margin: 0 0 8px;
}

.import-poi {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 44px;
  padding: 6px 4px;
  cursor: pointer;
}

.import-poi input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  flex-shrink: 0;
}

.import-note {
  color: var(--muted);
  font-size: 0.85rem;
}

.import-estimate {
  margin: 14px 0;
  font-weight: 600;
  color: var(--accent);
}

/* ---------------- 觸控目標最小高度 ---------------- */
.btn,
.speed-btn,
.toggle-detail {
  min-height: 44px;
}

/* ---------------- iPhone 瀏海／安全區 ---------------- */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

header.site .wrap {
  padding-top: max(14px, env(safe-area-inset-top));
}

.wrap {
  padding-bottom: max(64px, env(safe-area-inset-bottom));
}

.admin-badge {
  bottom: max(12px, env(safe-area-inset-bottom));
  max-width: calc(100vw - 24px);
}

/* ---------------- 響應式：中大螢幕 ---------------- */
@media (min-width: 700px) {
  .wrap {
    max-width: 840px;
  }
  /* 首頁行程卡 2 欄 */
  #trip-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    align-items: start;
  }
  #trip-list .trip-card-wrap {
    margin-bottom: 0;
  }
  #trip-list .status-msg {
    grid-column: 1 / -1;
  }
  /* 景點卡 2 欄（日標題橫跨整列） */
  .day-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    align-items: start;
  }
  .day-head {
    grid-column: 1 / -1;
    margin-bottom: 0;
  }
  .poi-card {
    margin-bottom: 0;
  }
  /* live 快取列表 2 欄（標題橫跨） */
  .live-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    align-items: start;
  }
  .live-list-title {
    grid-column: 1 / -1;
    margin-bottom: 0;
  }
  .live-item {
    margin-bottom: 0;
  }
}

@media (min-width: 1100px) {
  .wrap {
    max-width: 960px;
  }
  #trip-list {
    grid-template-columns: repeat(3, 1fr);
  }
  .live-list {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --card: #21242b;
    --ink: #e8eaed;
    --muted: #9aa0aa;
    --accent: #f97316;
    --accent-soft: #3a2417;
    --border: #333842;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
  header.site {
    background: rgba(22, 24, 29, 0.92);
  }
  .speed-btn {
    background: var(--card);
  }
}
