/* SafeBite China — 改版样式
   设计原则：
   1) 降噪：不做全页网格，描边只给可点元素，面板靠间距和底色分层。
   2) 红色只表示「危险 / 我过敏的东西」，品牌和操作色用墨绿。
   3) 中文是主角：展示模式下要占满屏。
   4) 手机优先：单列、按钮 ≥48px、安全区留白。
*/

:root {
  color-scheme: light;

  --bg: #fbf8f3;
  --surface: #ffffff;
  --ink: #1c1917;
  --muted: #6b6259;
  --line: #ece5db;
  --line-strong: #dcd3c7;

  --jade: #0f6b5f;
  --jade-dark: #0a4f46;
  --jade-soft: #e7f2ef;

  --danger: #b42318;
  --danger-soft: #fdf2f0;

  --amber: #b45309;
  --amber-soft: #fdf6ec;

  --radius: 16px;
  --radius-lg: 22px;

  --font-ui: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Noto Sans SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  --font-brand: Georgia, "Iowan Old Style", "Times New Roman", serif;

  font-family: var(--font-ui);
  -webkit-text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

/* 作者样式里的 display 会盖掉浏览器对 [hidden] 的默认隐藏，必须显式处理 */
[hidden] {
  display: none !important;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button:disabled:hover {
  border-color: var(--line-strong);
  background: inherit;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
  line-height: 1.5;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.app {
  width: min(640px, 100%);
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
}

/* ---------- 顶栏 ---------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-text {
  min-width: 0;
}

/* 副标题：桌面端显示，手机端收起（避免页头变高） */
.brand-tagline {
  display: none;
  margin-top: 1px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 620px) {
  .brand-tagline {
    display: block;
  }
}

.mark {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 50% 50% 50% 4px;
  background: var(--jade);
  position: relative;
}

.mark::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: var(--bg);
}

h1 {
  font-family: var(--font-brand);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

h1 span {
  color: var(--muted);
  font-weight: 400;
}

.bar-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.offline-badge {
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.lang-field select {
  min-height: 44px;
  max-width: 44vw;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
}

/* 窄屏：品牌独占一行，语言选择器单独一整行，做大做好点 */
@media (max-width: 480px) {
  .bar {
    flex-wrap: wrap;
    gap: 10px;
  }

  .brand {
    flex: 1 1 100%;
  }

  .bar-tools {
    flex: 1 1 100%;
  }

  .lang-field {
    flex: 1 1 auto;
  }

  .lang-field select {
    width: 100%;
    max-width: none;
    min-height: 50px;
    padding: 0 14px;
    font-size: 15.5px;
  }
}

/* ---------- 通用控件 ---------- */

button {
  font: inherit;
  cursor: pointer;
}

.primary,
.ghost,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 700;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.primary {
  background: var(--jade);
  color: #fff;
}

.primary:hover {
  background: var(--jade-dark);
}

.primary:active {
  transform: translateY(1px);
}

.ghost {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink);
}

.ghost:hover {
  border-color: var(--muted);
}

.ghost.small {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 9px;
  font-size: 13px;
}

.icon-button {
  width: 44px;
  min-height: 44px;
  padding: 0;
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink);
}

.large {
  min-height: 54px;
  padding: 0 22px;
  font-size: 16px;
}

/* 语音合成/播放中：按钮变淡 + 不可重复点 */
.is-busy {
  opacity: 0.6;
  pointer-events: none;
}

svg {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:focus-visible {
  outline: 3px solid var(--jade);
  outline-offset: 2px;
}

/* ---------- 第一步：过敏原 ---------- */

.setup {
  padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.04);
}

.setup + .setup {
  margin-top: 12px;
}

.setup-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.step {
  margin-bottom: 2px;
  color: var(--jade);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.setup h2 {
  font-size: 17px;
  font-weight: 700;
}

.chip-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.chip-grid.is-collapsed .chip:not([aria-pressed="true"]) {
  display: none;
}

.chip {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  /* 右侧留出图标的位置，文字不会压在图上面 */
  padding: 9px 44px 9px 11px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  text-align: start;
}

/* 图标：半透明水印，压在右侧，不吃点击 */
.chip-icon {
  position: absolute;
  top: 50%;
  right: 4px;
  width: 36px;
  height: 36px;
  transform: translateY(-50%);
  opacity: 0.32;
  pointer-events: none;
  user-select: none;
}

/* 宽屏给图标多一点空间 */
@media (min-width: 480px) {
  .chip {
    padding-right: 52px;
  }

  .chip-icon {
    right: 6px;
    width: 42px;
    height: 42px;
  }
}

.chip[aria-pressed="true"] .chip-icon {
  opacity: 0.5;
}

.chip:hover {
  border-color: var(--muted);
}

.chip[aria-pressed="true"] {
  border-color: var(--danger);
  background: var(--danger-soft);
  box-shadow: inset 3px 0 0 var(--danger);
}

/* 忌口用琥珀色：和「过敏（红）」在视觉上分开，别混成一种严重程度 */
.chip[data-kind="diet"][aria-pressed="true"] {
  border-color: var(--amber);
  background: var(--amber-soft);
  box-shadow: inset 3px 0 0 var(--amber);
}

.chip[data-kind="diet"][aria-pressed="true"] span {
  color: var(--amber);
}

.chip strong {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
}

.chip span {
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.3;
}

.chip[aria-pressed="true"] span {
  color: var(--danger);
}

.hint {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.hint.danger {
  color: var(--danger);
  font-weight: 700;
}

/* ---------- 场景切换 ---------- */

.scene-tabs {
  display: flex;
  gap: 8px;
  margin: 22px -16px 18px;
  padding: 0 16px 2px;
  overflow-x: auto;
  scrollbar-width: none;
  /* 右边缘渐隐，提示还能横向滑 */
  mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 28px), transparent 100%);
  -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 28px), transparent 100%);
}

.step-standalone {
  margin-top: 24px;
  margin-bottom: 10px;
}

.scene-tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 700;
  white-space: nowrap;
}

.tab[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

/* ---------- 主卡片 ---------- */

.card {
  padding: 24px 20px 20px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(28, 25, 23, 0.08);
}

.card[aria-disabled="true"] {
  box-shadow: none;
  border: 1px dashed var(--line-strong);
}

.card-en {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

/* 一张卡说两件事：上面过敏（红），下面忌口（琥珀）。
   不是过敏的，就别给它过敏的视觉权重。 */
.card-block + .card-block {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px dashed var(--line-strong);
}

.card-block[data-kind="diet"] {
  border-left: 3px solid var(--amber);
  padding-left: 14px;
}

.card-block[data-kind="diet"] .card-en,
.card-block[data-kind="diet"] .card-py {
  color: var(--amber);
}

/* 忌口的正文比过敏小一档，但仍在臂展距离可读 */
.card-block[data-kind="diet"] .card-zh {
  font-size: clamp(24px, 7vw, 32px);
}

.card-zh {
  margin-top: 10px;
  font-size: clamp(30px, 8.5vw, 40px);
  font-weight: 700;
  line-height: 1.22;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
  /* 折行时均分，避免「敏。」这种孤字 */
  text-wrap: balance;
}

.card-py {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.card-actions .primary {
  flex: 1 1 180px;
}

/* ---------- 短语列表 ---------- */

.list {
  margin-top: 26px;
}

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

.list-head h3 {
  font-size: 15px;
  font-weight: 700;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.05);
}

.row.saved {
  box-shadow: inset 0 0 0 1.5px var(--jade);
}

.row-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.row-en {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.4;
}

.row-zh {
  margin-top: 6px;
  font-size: 23px;
  font-weight: 700;
  line-height: 1.28;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.row-py {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.row-actions .more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.row-actions .more:hover {
  border-color: var(--muted);
}

/* 列表里「Show」是主操作，不能被 .more 的底色盖掉 */
.row-actions .more.primary {
  background: var(--jade);
  border-color: var(--jade);
  color: #fff;
  font-weight: 700;
}

.row-actions .more.primary:hover {
  background: var(--jade-dark);
  border-color: var(--jade-dark);
}

.row-actions .more.is-saved {
  border-color: var(--jade);
  color: var(--jade);
  background: var(--jade-soft);
}

.empty {
  padding: 22px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

/* ---------- 展示模式 ---------- */

.display {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  background: #ffffff;
  overflow-y: auto;
}

.display[hidden] {
  display: none;
}

.display-inner {
  width: min(680px, 100%);
  text-align: center;
}

.display-en {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.4;
}

/* 展示模式也要把两件事一起举给店员看 */
.display-block + .display-block {
  margin-top: 28px;
  padding-top: 28px;
  border-top: 2px dashed var(--line-strong);
}

.display-block[data-kind="diet"] .display-py {
  color: var(--amber);
}

/* 忌口句在展示模式下不超过主句的三分之二，避免抢走过敏提示的注意力 */
.display-block[data-kind="diet"] .display-zh {
  max-width: 100%;
}

.display-zh {
  margin: 14px 0 0;
  font-size: clamp(40px, 12vw, 92px);
  font-weight: 700;
  line-height: 1.16;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.display-py {
  margin-top: 16px;
  color: var(--muted);
  font-size: clamp(14px, 3.4vw, 20px);
  font-weight: 600;
}

.display-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 32px;
}

/* ---------- 首次进入：介绍 + 选语言 ---------- */

.welcome {
  position: fixed;
  inset: 0;
  z-index: 300;
  overflow-y: auto;
  background: var(--bg);
  padding: max(28px, env(safe-area-inset-top)) 24px max(28px, env(safe-area-inset-bottom));
}

.welcome-inner {
  width: min(520px, 100%);
  margin: 0 auto;
}

.welcome-inner:focus {
  outline: none;
}

.welcome-mark {
  display: block;
  width: 40px;
  height: 40px;
  margin-bottom: 14px;
}

.welcome-brand {
  font-family: var(--font-brand);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.welcome-lead {
  margin-top: 12px;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.5;
  text-wrap: balance;
}

/* 副标题：一句话说明这是什么工具 */
.welcome-tagline {
  margin-top: 8px;
  color: var(--jade);
  font-size: 15px;
  font-weight: 650;
  line-height: 1.45;
  text-wrap: balance;
}

.welcome-steps {
  display: grid;
  gap: 8px;
  margin: 20px 0 26px;
  padding-inline-start: 22px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
}

.welcome-steps li::marker {
  color: var(--jade);
  font-weight: 700;
}

.lang-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0 24px;
}

.lang-btn {
  min-height: 48px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}

.lang-btn[aria-pressed="true"] {
  border-color: var(--jade);
  background: var(--jade-soft);
  color: var(--jade-dark);
  box-shadow: inset 0 0 0 1px var(--jade);
}

.welcome-start {
  width: 100%;
}

.linklike {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- 紧急电话（跟随页面滚动，不悬浮） ---------- */

.hotlines {
  margin-top: 26px;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
}

.hotlines h3 {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hotline-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

@media (min-width: 460px) {
  .hotline-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.hotline-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 58px;
  padding: 8px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 650;
  line-height: 1.2;
  text-align: center;
}

.hotline-item strong {
  color: var(--danger);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.hotline-item:hover {
  border-color: var(--danger);
  background: var(--danger-soft);
}

/* ---------- 提示 ---------- */

/* 图标署名：CC-BY 4.0 要求保留出处 */
.foot {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--muted);
  font-size: 11.5px;
}

.foot a {
  color: inherit;
  text-decoration: underline;
}

.toast {
  position: fixed;  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 200;
  max-width: min(90vw, 420px);
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

/* ---------- RTL ---------- */

[dir="rtl"] .chip,
[dir="rtl"] .row-en,
[dir="rtl"] .row-zh,
[dir="rtl"] .row-py,
[dir="rtl"] .card-en,
[dir="rtl"] .display-en {
  text-align: start;
}

[dir="rtl"] .chip[aria-pressed="true"] {
  box-shadow: inset -3px 0 0 var(--danger);
}

/* ---------- 大屏 ---------- */

@media (max-width: 420px) {
  /* 窄屏：主次操作各占一整行，别挤成半宽 */
  .card-actions > .primary,
  .card-actions > .ghost {
    flex: 1 1 100%;
  }
}

@media (min-width: 720px) {
  .app {
    padding-top: 28px;
  }

  .card {
    padding: 32px 28px 26px;
  }

  h1 {
    font-size: 24px;
  }
}

/* ---------- 减弱动效 ---------- */

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
