/* TNH 香港英文地址识别助手 —— 视觉系统 V4「标牌 / Instrument」

   目标：降低通用 AI 生成感（奶油底色、圆角药丸、装饰卡片），改成仪表化的工业标牌语言；
   同时保证强日光下的可读性：全部为不透明色，正文对比度 ≥ 7:1，次要文字 ≥ 4.5:1，
   交互描边 ≥ 3:1；金色只用于图形标记，不用于文字。 */

:root {
  /* 画布与纸张 */
  --bg-primary: #ffffff;
  --bg-secondary: #f2f5f8;
  --paper: #ffffff;
  --canvas: #e5e9ef;

  /* 文字（括号内为白底对比度） */
  --text-primary: #0a1220;    /* 18.7:1 */
  --text-secondary: #3d4552;  /* 9.7:1 */
  --text-muted: #4f5866;      /* 7.2:1 */

  /* 线条与描边 */
  --border: #d8dee6;
  --border-dark: #808b99;     /* 3.5:1，可作交互描边 */

  /* 语义色 */
  --signal: #0b3b60;          /* 主行动，白字 11.6:1 */
  --signal-soft: #eaf1f7;
  --success: #14653c;         /* 白字 7.1:1 */
  --success-light: #e8f4ec;
  --success-line: #b7d6c4;
  --warning: #a8620a;
  --warning-light: #fff8ec;
  --warning-line: #efd8b4;
  --warning-ink: #4a3200;     /* 11.2:1 */
  --danger: #93261f;
  --tnh-gold: #c9a227;        /* 仅图形标记，不作文字色 */

  --page-pad: clamp(16px, 4.8vw, 24px);
  --title-size: clamp(22px, 6vw, 27px);
  --building-size: clamp(28px, 8.2vw, 34px);

  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;

  --shadow: 0 2px 8px rgba(11, 59, 96, 0.07);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  background: var(--canvas);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--canvas);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

button,
input { font: inherit; }

button,
label { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
label:focus-within,
summary:focus-visible {
  outline: 3px solid var(--signal);
  outline-offset: 3px;
}

.shell {
  width: min(100%, 430px);
  min-height: 100vh;
  margin: 0 auto;
  overflow-x: hidden;
  background: var(--bg-primary);
}

/* 顶栏：白纸 + 一条发丝线，右下角保留一小段信号色标尺。 */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: max(8px, env(safe-area-inset-top)) var(--page-pad) 8px;
  border-bottom: 1px solid var(--border);
  background: var(--paper);
}

.topbar::after {
  content: "";
  position: absolute;
  right: var(--page-pad);
  bottom: 0;
  width: 56px;
  height: 2px;
  background: var(--signal);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
}

.brand img {
  width: 44px;
  height: 30px;
  flex: 0 0 auto;
  object-fit: contain;
}

.brand-copy {
  display: grid;
  min-width: 0;
  line-height: 1.2;
}

.brand-copy strong {
  overflow: hidden;
  font-size: 15px;
  font-weight: 720;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy small {
  margin-top: 3px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

/* 语言切换：方角分段控件，右侧固定，不参与标题省略 */
.lang-switch {
  display: inline-flex;
  flex: 0 0 auto;
  margin-left: auto;
  overflow: hidden;
  border: 1px solid var(--border-dark);
  border-radius: var(--r-xs);
}

.lang-switch button {
  min-width: 42px;
  min-height: 34px;
  padding: 0 8px;
  border: 0;
  background: var(--paper);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.lang-switch button + button { border-left: 1px solid var(--border-dark); }
.lang-switch button[aria-pressed="true"] { background: var(--signal); color: #ffffff; }

.screen {
  display: none;
  min-height: calc(100vh - 64px);
  padding: 24px var(--page-pad) max(32px, env(safe-area-inset-bottom));
}

.screen.active {
  display: block;
  animation: view-in 220ms ease both;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

h1,
h2 {
  margin: 0;
  color: var(--text-primary);
  font-weight: 760;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

h1 { font-size: var(--title-size); }

h2 {
  font-size: clamp(26px, 7.2vw, 30px);
  text-wrap: balance;
}

/* 首页 */
.home-copy { padding: 0 0 16px; }

.home-copy h1 {
  max-width: 100%;
  margin-top: 2px;
  letter-spacing: -0.035em;
  line-height: 1.22;
  overflow-wrap: normal;
}

/* 两段各自成行且不换行：iOS 16 等不支持 text-wrap: balance 的机型也不会出现单字孤行。 */
.home-copy h1 span {
  display: block;
  white-space: nowrap;
}

.home-copy p {
  margin: 10px 0 0;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.55;
}

.home-subtitle span {
  display: block;
  white-space: nowrap;
}

@media (max-width: 359px) {
  :root { --title-size: 21px; }
  .home-copy p { font-size: 15px; }
}

.test-label,
.processing-mode {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 26px;
  padding: 3px 9px;
  border: 1px solid var(--signal);
  border-radius: var(--r-xs);
  background: var(--signal-soft);
  color: var(--signal);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* 测试用元素默认不出现在界面上（连 JS 没跑之前也不闪），只有主持人模式 ?facilitator=1 才显示。 */
.test-label,
.demo-cta,
.facilitator-panel,
.coverage { display: none; }

html.test-mode .test-label { display: inline-flex; }
html.test-mode .demo-cta { display: flex; }
html.test-mode .facilitator-panel { display: block; }
html.test-mode .coverage { display: grid; }

.test-label::before,
.processing-mode::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  background: var(--tnh-gold);
}

/* 提示块：白纸 + 左侧语义条；大面积留白可提高强光下的对比度 */
.privacy,
.safety-note {
  display: grid;
  gap: 4px;
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
  border-radius: var(--r-xs);
  background: var(--paper);
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
  text-wrap: pretty;
}

.privacy strong,
.safety-note strong {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-primary);
}

.privacy strong::before,
.safety-note strong::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  background: var(--warning);
}

.safety-note { text-wrap: balance; }

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

.camera-cta,
.gallery-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border-radius: var(--r-md);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 150ms ease, background-color 150ms ease, border-color 150ms ease;
  white-space: nowrap;
}

/* 主行动：深信号蓝 + 内嵌亮边 + 取景角标 */
.camera-cta {
  position: relative;
  min-height: 56px;
  gap: 10px;
  border: 1px solid var(--signal);
  background: var(--signal);
  color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.camera-cta::before,
.camera-cta::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  border: 2px solid rgba(255, 255, 255, 0.6);
  pointer-events: none;
}

.camera-cta::before { top: 6px; left: 6px; border-right: 0; border-bottom: 0; }
.camera-cta::after { right: 6px; bottom: 6px; border-left: 0; border-top: 0; }

.camera-cta:active,
.gallery-cta:active,
.demo-cta:active,
.primary-action:active,
.secondary-action:active { transform: scale(0.985); }

.camera-icon {
  position: relative;
  width: 23px;
  height: 18px;
  margin-top: 2px;
  border: 2px solid currentColor;
  border-radius: 4px;
}

.camera-icon::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 5px;
  width: 9px;
  height: 4px;
  border: 2px solid currentColor;
  border-bottom: 0;
  border-radius: 3px 3px 0 0;
}

.camera-icon span {
  position: absolute;
  top: 4px;
  left: 7px;
  width: 6px;
  height: 6px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.gallery-cta {
  min-height: 50px;
  margin-top: 10px;
  border: 1px solid var(--border-dark);
  background: var(--paper);
  color: var(--text-primary);
}

/* 演示入口：列表行，不再用下划线链接 */
.demo-cta {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  margin-top: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: transform 150ms ease, background-color 150ms ease;
}

.demo-cta .row-copy {
  display: grid;
  min-width: 0;
  gap: 1px;
}

.demo-cta strong {
  font-size: 16px;
  font-weight: 700;
}

.demo-cta small {
  color: var(--text-secondary);
  font-size: 14px;
  text-wrap: pretty;
}

.demo-cta .row-chevron {
  margin-left: auto;
  flex: 0 0 auto;
  color: var(--signal);
  font-family: var(--mono);
  font-size: 17px;
  line-height: 1;
}

/* 页脚规格条：上下发丝线，不用灰色卡片 */
.coverage {
  display: grid;
  gap: 4px;
  margin-top: 18px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: transparent;
  font-size: 14px;
}

.coverage strong {
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}

.coverage span { color: var(--text-secondary); }

.facilitator-panel {
  margin-top: 16px;
  padding: 14px;
  border: 1px dashed var(--signal);
  border-radius: var(--r-sm);
  background: var(--signal-soft);
}

.facilitator-panel p {
  margin: 4px 0 10px;
  color: var(--text-secondary);
  font-size: 14px;
}

.facilitator-panel div { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.facilitator-panel button {
  min-height: 48px;
  border: 1px solid var(--border-dark);
  border-radius: var(--r-sm);
  background: var(--paper);
  color: var(--text-primary);
  font-weight: 700;
  cursor: pointer;
}

/* 相机 */
.camera-screen { padding-top: 12px; }

.camera-copy { margin-bottom: 10px; }

.camera-copy h2 { font-size: clamp(22px, 5.8vw, 26px); }

.camera-copy p {
  margin: 6px 0 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.camera-frame {
  position: relative;
  min-height: clamp(300px, 52svh, 440px);
  overflow: hidden;
  border-radius: var(--r-lg);
  background: #05090f;
  box-shadow: var(--shadow);
}

.camera-frame video {
  display: block;
  width: 100%;
  height: clamp(300px, 52svh, 440px);
  object-fit: contain;
}

/* 取景范围就是整个画面，避免小框和外框让人误判该拍哪里。 */
.camera-guide {
  display: none;
}

#camera-status {
  position: absolute;
  right: 16px;
  bottom: 82px;
  left: 16px;
  margin: 0;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  background: rgba(10, 18, 32, 0.82);
  color: #ffffff;
  font-size: 14px;
  text-align: center;
}

.camera-controls {
  position: absolute;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 2;
}

.shutter-action {
  min-width: 144px;
  min-height: 58px;
  border: 0;
  border-radius: 999px;
  background: #ffffff;
  color: var(--text-primary);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.28);
  font-size: 17px;
  font-weight: 760;
}

.shutter-action span[aria-hidden="true"] { color: var(--danger); font-size: 23px; line-height: 0; vertical-align: -1px; }
.shutter-action span:not([aria-hidden]) { margin-left: 7px; }
.shutter-action:disabled { opacity: 0.58; }

.camera-fallback {
  display: grid;
  min-height: 48px;
  place-items: center;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 999px;
  background: rgba(10, 18, 32, 0.78);
  color: #ffffff;
  font-size: 14px;
  font-weight: 680;
  cursor: pointer;
}

#camera-cancel { display: block; margin: 10px auto 0; }

/* 识别中 */
#processing { text-align: center; }

.preview-wrap {
  position: relative;
  width: min(100%, 320px);
  height: min(42svh, 260px);
  margin: 6px auto 22px;
  overflow: hidden;
  border: 1px solid var(--border-dark);
  border-radius: var(--r-xs);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.preview-wrap img { width: 100%; height: 100%; object-fit: contain; }
.scan-line { display: none; }

#processing > p {
  margin: 10px 0 18px;
  color: var(--text-secondary);
  font-size: 15px;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe4ea;
}

.progress-track span {
  display: block;
  width: 4%;
  height: 100%;
  border-radius: inherit;
  background: var(--success);
  transition: width 200ms ease;
}

.steps {
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
}

.steps li {
  position: relative;
  min-height: 48px;
  padding: 12px 8px 12px 36px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 15px;
}

.steps li::before {
  content: "";
  position: absolute;
  top: 18px;
  left: 10px;
  width: 10px;
  height: 10px;
  border: 2px solid var(--border-dark);
  border-radius: 50%;
  background: var(--bg-primary);
}

.steps li.current { color: var(--text-primary); font-weight: 700; }
.steps li.current::before { border-color: var(--success); background: var(--success); animation: pulse 1.1s ease-in-out infinite; }
.steps li.done { color: var(--success); }
.steps li.done::before { border-color: var(--success); background: var(--success); box-shadow: inset 0 0 0 2px var(--bg-primary); }

@keyframes pulse { 50% { opacity: 0.4; } }

.processing-safety {
  margin: 14px 0 0 !important;
  color: var(--text-secondary) !important;
  font-size: 14px !important;
}

/* 结果与异常状态 */
.result-state,
.warning-state {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  margin: 0 0 14px;
  padding: 4px 9px;
  border-radius: var(--r-xs);
  font-size: 14px;
  font-weight: 750;
  white-space: nowrap;
}

.result-state { background: var(--success-light); color: var(--success); }
.result-state::before { content: "✓"; margin-right: 5px; }
.warning-state { background: var(--warning-light); color: var(--warning-ink); }
.warning-state::before { content: "◇"; margin-right: 5px; }

#result-name {
  font-size: var(--building-size);
  line-height: 1.15;
  letter-spacing: -0.02em;
  overflow-wrap: break-word;
  text-wrap: balance;
  white-space: normal;
}

/* 楼名区：与「打开导航」的绿色填充呼应——同一个绿，这里是细左条 + 浅绿描边，
   名字本身仍用墨色，保证强光下的对比度。 */
.result-panel {
  margin: 2px 0 14px;
  padding: 14px 16px;
  border: 1px solid var(--success-line);
  border-left: 4px solid var(--success);
  border-radius: var(--r-xs);
  background: var(--paper);
}

.result-panel #result-name { margin: 0; }
.result-panel .english-name { margin: 6px 0 0; }
.result-panel .street-address { margin: 10px 0 0; }

/* 这两个标题是为了读屏播报而程序化聚焦的，不在 Tab 顺序里，
   所以不显示焦点圈（原来那个"蓝框"就是这个圈）。 */
#result-name:focus,
#result-name:focus-visible,
#not-found-title:focus,
#not-found-title:focus-visible {
  outline: none;
}

.demo-banner {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--warning-line);
  border-left: 3px solid var(--warning);
  border-radius: var(--r-xs);
  background: var(--warning-light);
  color: var(--warning-ink);
  font-size: 14px;
  font-weight: 680;
  line-height: 1.45;
  text-wrap: balance;
}

.english-name {
  margin: 6px 0 12px;
  color: var(--text-secondary);
  font-size: 16px;
  overflow-wrap: break-word;
  text-wrap: balance;
}

.street-address {
  margin: 0 0 6px;
  color: var(--text-primary);
  font-size: 17px;
  font-weight: 680;
  overflow-wrap: break-word;
  text-wrap: balance;
}

.match-note,
.result-source {
  margin: 0 0 8px;
  color: var(--text-secondary);
  font-size: 14px;
}

.result-source { margin-bottom: 18px; }

.extracted {
  display: grid;
  gap: 3px;
  margin: 16px 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--tnh-gold);
  border-radius: var(--r-xs);
  background: var(--bg-secondary);
  font-size: 15px;
}

.extracted small { color: var(--text-secondary); font-size: 14px; }

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.next-scan-action {
  min-height: 54px;
  grid-column: 1 / -1;
  border: 2px solid var(--signal);
  border-radius: var(--r-md);
  background: var(--paper);
  color: var(--signal);
  font-size: 17px;
  font-weight: 760;
  cursor: pointer;
}

.primary-action,
.secondary-action {
  min-height: 48px;
  border-radius: var(--r-md);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 150ms ease, background-color 150ms ease, border-color 150ms ease;
  white-space: nowrap;
}

.primary-action {
  min-height: 52px;
  grid-column: 1 / -1;
  border: 1px solid var(--success);
  background: var(--success);
  color: #ffffff;
}

.secondary-action {
  border: 1px solid var(--border-dark);
  background: var(--paper);
  color: var(--text-primary);
}

.boundary {
  margin: 10px 0 18px;
  color: var(--text-secondary);
  font-size: 14px;
}

.details {
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--paper);
}

.details summary {
  min-height: 48px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 680;
  cursor: pointer;
}

.details dl { margin: 0; padding: 0 14px 14px; }
.details dt { margin-top: 10px; color: var(--text-secondary); font-size: 14px; }
.details dd { margin: 2px 0 0; font-size: 15px; overflow-wrap: break-word; }
.details pre {
  max-height: 160px;
  margin: 4px 0 0;
  overflow: auto;
  color: var(--text-primary);
  font: 14px/1.45 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
}

.text-button,
.danger-link {
  width: 100%;
  min-height: 48px;
  padding: 10px;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 620;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.danger-link { color: var(--danger); }

#not-found > p,
#error > p {
  margin: 10px 0 16px;
  color: var(--text-secondary);
  font-size: 17px;
  text-wrap: balance;
}

.safety-note { margin-top: 0; }

.stack-actions {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.stack-actions .primary-action {
  grid-column: auto;
  border-color: var(--signal);
  background: var(--signal);
}

.label-action { display: grid; place-items: center; }

.toast {
  position: fixed;
  z-index: 20;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  width: min(calc(100% - 36px), 390px);
  padding: 12px 15px;
  transform: translate(-50%, 18px);
  border-radius: var(--r-sm);
  background: var(--text-primary);
  color: #ffffff;
  text-align: center;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: 200ms ease;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 370px) {
  .brand { gap: 7px; }
  .brand img { width: 38px; height: 27px; }
  .brand-copy strong { max-width: 188px; font-size: 14px; }
  .brand-copy small { font-size: 12px; }
}

@media (min-width: 600px) {
  body { padding: 24px 0; }
  .shell {
    min-height: 844px;
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: 0 18px 50px rgba(11, 59, 96, 0.12);
  }
  .screen { min-height: 780px; }
}

@media (pointer: fine) {
  .camera-cta:hover { background: #0e4a77; border-color: #0e4a77; }
  .gallery-cta:hover,
  .secondary-action:hover,
  .demo-cta:hover { border-color: var(--signal); }
  .demo-cta:hover { background: #eaeff5; }
  .primary-action:hover { background: #10522f; border-color: #10522f; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
