:root {
  --radius: 16px;
  --radius-sm: 12px;
  --gap: 14px;
  --tap: 52px;
  --font: -apple-system, "Segoe UI", Roboto, "Noto Sans TC", "PingFang TC",
          "Microsoft JhengHei", system-ui, sans-serif;
}

/* 深色（預設） */
html[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #232730;
  --border: #2d323c;
  --text: #e8eaed;
  --muted: #9aa0aa;
  --accent: #3b82f6;
  --accent-text: #ffffff;
}

/* 淺色 */
html[data-theme="light"] {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dce0e6;
  --text: #1a1d24;
  --muted: #5c6470;
  --accent: #2563eb;
  --accent-text: #ffffff;
}

/* 漲跌配色慣例：台股(紅漲綠跌) */
html[data-convention="tw"] {
  --up: #ff5a5f;     /* 溢價 */
  --down: #16c784;   /* 折價 */
}
/* 國際(綠漲紅跌) */
html[data-convention="intl"] {
  --up: #16c784;     /* 溢價 */
  --down: #ff5a5f;   /* 折價 */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 12px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 20px)
    calc(env(safe-area-inset-left) + 16px);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-height: 100dvh;
}

/* 頂列 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.topbar__title {
  font-size: 19px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.2px;
}
.topbar__actions { display: flex; gap: 8px; }
.icon-btn {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

/* 結果區 */
.result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  text-align: center;
}
.result__label {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 1px;
}
.result__hero {
  margin: 6px 0 10px;
  font-size: clamp(44px, 16vw, 64px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.badge {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  background: var(--surface-2);
}
.result__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 18px 0 0;
}
.result__item {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.result__item dt {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.result__item dd {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* 狀態語意色 */
.is-premium { color: var(--up); }
.is-discount { color: var(--down); }
.is-flat { color: var(--muted); }
.badge.is-premium { background: color-mix(in srgb, var(--up) 18%, transparent); color: var(--up); }
.badge.is-discount { background: color-mix(in srgb, var(--down) 18%, transparent); color: var(--down); }

/* 輸入卡 */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.quick {
  display: flex;
  align-items: center;
  gap: 12px;
}
.quick__btn {
  flex: 1;
  min-height: 44px;
  border: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--accent);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.quick__btn:active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.quick__hint { font-size: 13px; color: var(--muted); white-space: nowrap; }

.fetch { display: flex; flex-direction: column; gap: 6px; }
.fetch__btn {
  min-height: 48px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.fetch__btn:active { filter: brightness(0.92); }
.fetch__btn:disabled { opacity: 0.6; cursor: default; }
.fetch__status { font-size: 12.5px; color: var(--muted); text-align: center; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.field__unit { font-size: 12px; font-weight: 500; color: var(--muted); }
.field input {
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 18px;            /* ≥16px 避免 iOS focus 自動放大 */
  font-variant-numeric: tabular-nums;
  width: 100%;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.field input::placeholder { color: var(--muted); opacity: 0.7; }

/* 動作列 */
.actions { display: flex; gap: 12px; }
.btn {
  min-height: var(--tap);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn--primary { flex: 2; background: var(--accent); color: var(--accent-text); }
.btn--primary:active { filter: brightness(0.92); }
.btn--ghost { flex: 1; background: var(--surface); color: var(--text); border-color: var(--border); }
.btn--ghost:active { background: var(--surface-2); }

.foot {
  margin-top: auto;
  text-align: center;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.6;
}
.foot p { margin: 0; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
