/**
 * 留痕 — 移动端 MVP（375px 基准，不破坏桌面布局）
 * 配合 theme.js 的 CSS 变量；share 页单独 class .share-page
 */

:root {
  --ui-toggle-btn: 34px;
  --ui-toggle-gap: 10px;
  --ui-toggle-edge: max(14px, env(safe-area-inset-right, 0));
  --ui-toggle-reserve: calc(var(--ui-toggle-edge) + var(--ui-toggle-btn) * 2 + var(--ui-toggle-gap) + 12px);
}

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

body {
  overflow-x: clip;
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

/* 语言 / 主题（右上角，间距用 calc 避免叠在一起） */
.locale-toggle,
.theme-toggle {
  position: fixed;
  z-index: 10001;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--border);
  cursor: pointer;
  line-height: 1;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-sizing: border-box;
  top: max(14px, env(safe-area-inset-top, 0));
}

.theme-toggle {
  right: var(--ui-toggle-edge);
  width: var(--ui-toggle-btn);
  height: var(--ui-toggle-btn);
  min-width: var(--ui-toggle-btn);
  min-height: var(--ui-toggle-btn);
  font-size: 15px;
}

.locale-toggle {
  right: calc(var(--ui-toggle-edge) + var(--ui-toggle-btn) + var(--ui-toggle-gap));
  width: var(--ui-toggle-btn);
  height: var(--ui-toggle-btn);
  min-width: var(--ui-toggle-btn);
  min-height: var(--ui-toggle-btn);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
}

/* 首页顶栏：为固定语言/主题钮预留右侧，避免与「免费开始」等叠在一起 */
body:has(> .locale-toggle) .nav .nav-inner {
  padding-right: max(24px, var(--ui-toggle-reserve));
}

.locale-toggle:hover,
.theme-toggle:hover {
  border-color: var(--muted);
}

@media (max-width: 640px) {
  :root {
    --ui-toggle-btn: 44px;
    --ui-toggle-edge: max(12px, env(safe-area-inset-right, 0));
  }

  /* —— 通用触控 —— */
  .btn,
  .btn-primary,
  .btn-ghost,
  .btn-outline,
  button.btn {
    min-height: 44px;
    font-size: 14px;
  }

  .field input,
  .field textarea,
  input[type="email"],
  input[type="text"] {
    font-size: 16px;
  }

  /* —— 首页 nav —— */
  .nav-inner {
    height: auto;
    min-height: 56px;
    padding: 10px max(16px, env(safe-area-inset-right, 0)) 10px 16px;
    padding-right: max(var(--ui-toggle-reserve), calc(16px + env(safe-area-inset-right, 0)));
    flex-wrap: wrap;
    gap: 8px 12px;
  }

  .brand {
    font-size: 18px;
    letter-spacing: 4px;
  }

  .nav-auth {
    margin-right: 0;
    flex: 1 1 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 100%;
  }

  .nav-auth a.login,
  .nav-auth a.register,
  .nav-auth a.enter {
    max-width: calc(100% - 8px);
  }

  .nav-auth a.login,
  .nav-auth a.register,
  .nav-auth a.enter {
    min-height: 44px;
    padding: 10px 16px;
    display: inline-flex;
    align-items: center;
  }

  .nav-auth .user-email {
    max-width: min(160px, 42vw);
    font-size: 14px;
  }

  .hero h1 {
    white-space: normal;
    letter-spacing: 3px;
    line-height: 1.35;
  }

  .hero-sub {
    font-size: 17px;
  }

  .hero-philosophy {
    font-size: 15px;
  }

  .btn-primary,
  .btn-ghost {
    min-height: 48px;
    padding: 12px 28px;
    font-size: 16px;
  }

  .trust-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 6px;
    line-height: 1.5;
    padding: 0 4px;
  }

  .trust-bar span {
    margin: 0 6px;
  }

  .section-head h2 {
    font-size: 24px;
    letter-spacing: 2px;
  }

  .flow {
    grid-template-columns: 1fr;
  }

  .feature h3 {
    padding-right: 0;
    margin-top: 8px;
  }

  .feature .status {
    top: 14px;
    right: 14px;
  }

  .brand-close {
    padding-left: 16px;
    padding-right: 16px;
  }

  /* —— 登录 auth —— */
  body.auth-page {
    align-items: flex-start;
    padding-top: max(56px, calc(12px + env(safe-area-inset-top, 0)));
    padding-bottom: max(24px, env(safe-area-inset-bottom, 0));
    padding-left: max(16px, env(safe-area-inset-left, 0));
    padding-right: max(16px, env(safe-area-inset-right, 0));
  }

  body.auth-page .card {
    width: 100%;
    max-width: 100%;
    padding: 28px 20px;
  }

  body.auth-page .btn {
    min-height: 48px;
  }

  /* —— 工作台 / 详情 —— */
  .container {
    padding: max(20px, env(safe-area-inset-top, 0)) 16px 32px;
    padding-bottom: max(32px, env(safe-area-inset-bottom, 0));
  }

  .locale-toggle,
  .theme-toggle {
    top: max(12px, env(safe-area-inset-top, 0));
  }

  .user-bar {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 10px;
    padding-right: var(--ui-toggle-reserve);
    font-size: 14px;
  }

  .user-bar a,
  .user-bar button:not(.plain) {
    min-height: 44px;
    padding: 10px 14px;
  }

  .drop-zone {
    padding: 40px 16px;
  }

  .drop-zone .text {
    font-size: 17px;
  }

  .drop-zone .hint {
    font-size: 13px;
    line-height: 1.5;
  }

  .cert-card {
    padding: 22px 16px;
  }

  .cert-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 10px 0;
  }

  .cert-row .label {
    width: auto;
    font-size: 12px;
  }

  .cert-row .value {
    font-size: 13px;
    width: 100%;
  }

  .cert-row .value.plain {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }

  .cert-actions {
    gap: 8px;
  }

  .cert-actions .btn {
    flex: 1 1 calc(50% - 4px);
    min-width: calc(50% - 4px);
    text-align: center;
  }

  .history-item {
    padding: 14px;
    font-size: 14px;
  }

  .verify-drop-zone {
    padding: 20px 12px;
    font-size: 14px;
  }

  .verify-result .result-row {
    flex-direction: column;
    gap: 2px;
  }

  .verify-result .result-row .rlabel {
    width: auto;
  }

  .file-verify-section {
    padding: 16px;
  }

  /* —— 分享页 share.html —— */
  body.share-page {
    padding-top: max(16px, env(safe-area-inset-top, 0));
    padding-bottom: max(32px, env(safe-area-inset-bottom, 0));
    padding-left: max(16px, env(safe-area-inset-left, 0));
    padding-right: max(16px, env(safe-area-inset-right, 0));
    overflow-x: clip;
    min-height: 100dvh;
  }

  body.share-page .save-btn {
    min-height: 48px;
    min-width: 44px;
    padding: 14px 28px;
    font-size: 16px;
  }

  body.share-page .detail-link {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  body.share-page .card-wrapper {
    max-width: min(375px, 100%);
  }
}
