/* =========================================================
   考公结构化面试全真模拟器 - 手机优先样式
   适配:竖屏、全面屏安全区、触摸交互、动态视口(100dvh)
   ========================================================= */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --primary: #1a73e8;
  --primary-dark: #1558b0;
  --danger: #d93025;
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #1f2430;
  --text-light: #6b7280;
  --border: #e5e8ef;
  --radius: 14px;
  /* 全面屏安全区 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  /* 禁止橡皮筋滚动与下拉刷新误触 */
  overscroll-behavior: none;
  /* 禁止双击缩放 / 长按选中 */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* 输入框允许选择与光标 */
input, textarea { -webkit-user-select: text; user-select: text; }

/* 页面容器:移动端全屏布局,PC 上居中加窄版 */
.page {
  display: none;
  position: fixed;
  inset: 0;
  max-width: 100%;
  margin: 0 auto;
  overflow: hidden;
  flex-direction: column;
  background: var(--bg);
}
.page.active { display: flex; }

@media (min-width: 520px) {
  body { background: #dfe3ea; }
  .page { max-width: 480px; box-shadow: 0 0 40px rgba(0,0,0,.15); }
}

.hidden { display: none !important; }

/* ---------- 通用头部 ---------- */
.app-header {
  text-align: center;
  padding: calc(32px + var(--safe-top)) 16px 20px;
  flex-shrink: 0;
}
.app-header h1 { font-size: 26px; font-weight: 800; letter-spacing: 2px; color: var(--primary); line-height: 1.3; }
.app-header .subtitle { margin-top: 8px; color: var(--text-light); font-size: 14px; }
.app-header.small { padding: calc(18px + var(--safe-top)) 16px 12px; }
.app-header.small h2 { font-size: 21px; color: var(--text); }

/* ---------- 大按钮(触摸目标 ≥ 52px) ---------- */
.big-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 56px; padding: 14px 16px;
  font-size: 18px; font-weight: 600; text-align: center;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--text); cursor: pointer;
  transition: transform .06s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.big-btn .btn-icon { font-size: 20px; line-height: 1; }
.big-btn:active { transform: scale(.97); background: #f0f2f7; }
.big-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.big-btn.primary:active { background: var(--primary-dark); }
.big-btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.big-btn:disabled { opacity: .5; pointer-events: none; }

.small-btn {
  min-height: 42px; padding: 10px 18px; font-size: 15px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  margin-top: 10px;
}
.small-btn.danger-btn { border-color: #f5c6c2; color: var(--danger); background: #fdf3f2; }
.small-btn:active { background: #f0f2f7; }
.link-btn { background: none; border: none; color: var(--primary); font-size: 15px; cursor: pointer; padding: 10px 0; text-decoration: none; display: inline-block; }


/* ---------- 首页(内容可滚动) ---------- */
#page-home { overflow-y: auto; }
.home-main { flex: 1; padding: 8px 20px 20px; display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.home-main .tip { text-align: center; color: var(--text-light); font-size: 13px; margin-top: 10px; }

/* 首页未设置 Key 的引导卡 */
.key-hint {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #fff7e6; border: 1px solid #ffe1a8; color: #8a5a00;
  border-radius: 12px; padding: 12px 14px; font-size: 14px; line-height: 1.4;
}
.key-hint-btn {
  flex-shrink: 0; min-height: 38px; padding: 0 14px; border-radius: 9px;
  border: 1px solid #e0a94a; background: #ffb54a; color: #fff;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.key-hint-btn:active { background: #e89f33; }
.app-footer { text-align: center; color: var(--text-light); font-size: 12px; padding: 12px 16px calc(12px + var(--safe-bottom)); }

/* ---------- 加载 ---------- */
.exam-stage { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.exam-stage.hidden { display: none; }
.loading-box {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px;
}
.loading-box p { color: var(--text-light); }
.spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 计时条(吸顶,答题时始终可见) ---------- */
.timer-bar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border-radius: 0 0 var(--radius) var(--radius);
  padding: 12px 16px calc(12px + var(--safe-top) * 0);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.timer-bar.answering { border-bottom-color: var(--danger); }
.timer-label { font-size: 14px; color: var(--text-light); }
.timer-num {
  font-size: 36px; font-weight: 800; font-variant-numeric: tabular-nums;
  color: var(--primary); letter-spacing: 1px; line-height: 1;
}
.timer-bar.answering .timer-num { color: var(--danger); }

/* ---------- 倒计时进度条 ---------- */
.progress-track {
  height: 5px; background: #e3e7ef; flex-shrink: 0;
}
.progress-fill {
  height: 100%; width: 100%;
  background: var(--primary); transition: width .3s linear;
}
.timer-bar.answering + .progress-track .progress-fill,
.progress-track.answering .progress-fill { background: var(--danger); }

/* ---------- 滚动内容区(答题/看题) ---------- */
.scroll-area {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 16px;
}

/* 答题提示 */
.answer-tip { font-size: 13px; color: var(--text-light); margin-bottom: 12px; }

/* ---------- 底部固定操作栏 ---------- */
.action-bar {
  flex-shrink: 0;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0,0,0,.04);
}

/* ---------- 题目列表 ---------- */
.question-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 4px; }
.question-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.question-card .q-tag {
  display: inline-block; font-size: 12px; font-weight: 600;
  color: var(--primary); background: #e8f0fe;
  border-radius: 6px; padding: 2px 8px; margin-bottom: 6px;
}
.question-card .q-text { font-size: 15px; }
.question-list.compact .question-card { padding: 12px 14px; }
.question-list.compact .q-text { font-size: 14px; }

/* ---------- 答题输入卡片(每题文本框) ---------- */
.rec-card .rec-transcript {
  width: 100%; min-height: 110px; margin-top: 10px; padding: 12px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 10px; background: #fafbfd;
  color: var(--text); font-family: inherit; line-height: 1.6; resize: none;
}

/* ---------- 结果页(可滚动) ---------- */
#page-result, #page-history-detail { overflow-y: auto; }
.result-main, .history-detail-main { padding: 4px 16px calc(20px + var(--safe-bottom)); }
.score-card {
  background: linear-gradient(135deg, #1a73e8, #4c8ff5);
  color: #fff; border-radius: var(--radius); text-align: center; padding: 24px 16px; margin-bottom: 16px;
}
.score-card.small-card { padding: 18px; }
.total-score { font-size: 64px; font-weight: 800; line-height: 1; }
.total-score small { font-size: 18px; margin-left: 4px; }
.score-label { margin-top: 4px; font-size: 14px; opacity: .9; }
.score-card.small-card .total-score { font-size: 48px; }

.dimension-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.dimension-item { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.dimension-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.dimension-name { font-size: 15px; font-weight: 600; }
.dimension-score { font-size: 16px; font-weight: 700; color: var(--primary); }
.dimension-comment { font-size: 14px; color: #4a5260; }

.result-section { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.result-section h3 { font-size: 16px; margin-bottom: 8px; color: var(--text); }
.plain-text { font-size: 14px; color: #4a5260; white-space: pre-wrap; word-break: break-word; }

.result-actions { padding-top: 6px; padding-bottom: var(--safe-bottom); }

/* ---------- 历史列表 ---------- */
#page-history { overflow-y: auto; }
.history-main { padding: 4px 16px calc(20px + var(--safe-bottom)); }
.history-item {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px; cursor: pointer;
}
.history-item:active { background: #f0f2f7; }
.history-item-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.history-date { font-size: 13px; color: var(--text-light); }
.history-score { font-size: 20px; font-weight: 800; color: var(--primary); }
.history-types { font-size: 13px; color: #4a5260; }
.empty-tip { text-align: center; color: var(--text-light); padding: 60px 0; }

/* ---------- 设置页(可滚动) ---------- */
#page-settings { overflow-y: auto; }
.settings-main { padding: 4px 16px calc(20px + var(--safe-bottom)); }
.settings-section { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.settings-section h3 { font-size: 16px; margin-bottom: 10px; }
.settings-section input[type="password"],
.settings-section input[type="number"],
.settings-section select {
  width: 100%; padding: 12px; font-size: 16px; border: 1px solid var(--border);
  border-radius: 10px; background: #fafbfd; color: var(--text); margin-bottom: 8px;
  -webkit-appearance: none; appearance: none;
}
.settings-section select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-light) 50%),
    linear-gradient(135deg, var(--text-light) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
  padding-right: 34px;
}
.settings-hint { font-size: 12px; color: var(--text-light); margin: 4px 0 8px; }
.diag-result {
  margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  font-size: 13px; line-height: 1.5; word-break: break-word;
  border: 1px solid var(--border); background: #fafbfd; color: var(--text);
}
.diag-result.ok { border-color: #b7e0c1; background: #f0faf3; color: #1d7a3f; }
.diag-result.fail { border-color: #f5c6c2; background: #fdf3f2; color: var(--danger); }
.diag-result.loading { color: var(--text-light); }
.diag-result .diag-note { display: block; margin-top: 4px; color: var(--text-light); font-size: 12px; }
.custom-rule { margin-top: 8px; border-top: 1px dashed var(--border); padding-top: 10px; }
.custom-rule label { display: block; font-size: 14px; color: var(--text-light); }
.settings-actions { padding-top: 6px; padding-bottom: var(--safe-bottom); }

/* ---------- Toast(底部居中,避开安全区) ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(31, 36, 48, .92); color: #fff; font-size: 14px;
  padding: 12px 22px; border-radius: 24px; z-index: 999; max-width: 86%;
  text-align: center; box-shadow: 0 4px 14px rgba(0,0,0,.2);
}

/* ---------- 时间提醒覆盖层 ---------- */
.time-warning {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 998;
  display: flex; align-items: center; justify-content: center;
}
.time-warning-box {
  background: var(--card); border-radius: var(--radius); padding: 28px 36px;
  text-align: center; max-width: 80%;
}
.time-warning-num { font-size: 48px; }
#time-warning-text { font-size: 18px; font-weight: 700; margin: 8px 0 14px; }

/* ---------- 滚动条(触屏基本隐藏) ---------- */
::-webkit-scrollbar { width: 0; height: 0; }

/* =========================================================
   多设备响应式适配
   手机(<640px): 全屏单列(默认)
   小平板/折叠屏(640-1023px): 窄版居中
   平板横屏/桌面(≥1024px): 宽版居中,内容双列/网格,可用键盘鼠标
   ========================================================= */

@media (min-width: 640px) {
  .page { max-width: 560px; box-shadow: 0 0 40px rgba(0,0,0,.15); }
  body { background: #dfe3ea; }
  .timer-num { font-size: 40px; }
  .total-score { font-size: 72px; }
  .big-btn { font-size: 19px; min-height: 54px; }
}

@media (min-width: 1024px) {
  /* 桌面:750px 窄版居中(v2.0 规范),保留移动端交互手感 */
  .page { max-width: 750px; border-radius: 18px; }
  .app-header { padding-top: calc(36px + var(--safe-top)); }
  .app-header h1 { font-size: 32px; }

  /* 首页按钮:三列横排 */
  .home-main { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: center; gap: 16px; }
  .home-main .big-btn { flex: 1 1 200px; max-width: 260px; margin: 0; }
  .home-main .tip { flex-basis: 100%; }

  /* 题目/维度/结果:双列网格,充分利用宽度 */
  .question-list { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .dimension-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

  /* 历史记录:双列 */
  .history-item { margin-bottom: 12px; }

  /* 设置区:两栏布局 */
  .settings-main { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
  .settings-actions { grid-column: 1 / -1; }

  /* 答题区:题目与转写分栏 */
  .scroll-area { padding: 18px 24px; }

  /* 桌面端允许文本选择与复制(便于复制参考答案) */
  body { -webkit-user-select: text; user-select: text; }

  /* 桌面端鼠标悬停反馈(移动端无 hover) */
  .big-btn:hover { filter: brightness(.97); }
  .big-btn.primary:hover { filter: brightness(1.08); }
  .history-item:hover { background: #f7f9fc; }
}

@media (min-width: 1440px) {
  .page { max-width: 750px; }
  .question-list { grid-template-columns: repeat(3, 1fr); }
  .dimension-list { grid-template-columns: repeat(3, 1fr); }
  .history-item { margin-bottom: 12px; }
}
