/* 数签子 · 网页版样式
 *
 * 设计 token 全部照搬安卓工程：
 *   res/values/themes.xml        colorPrimary #2C2C2A, colorAccent #D85A30
 *   res/drawable/bg_primary      填充 #2C2C2A，圆角 14dp
 *   res/drawable/bg_outline      白底 + 1dp 描边 #D3D1C7，圆角 14dp
 *   res/drawable/bg_mode_on/off  圆角 10dp
 * 尺寸直接用 dp/sp 数值，1dp = 1 CSS px。
 */

:root {
  --ink: #1A1A1A;      /* 主文字（大数字、标题） */
  --ink-btn: #2C2C2A;  /* 按钮底色、按钮文字 */
  --gray: #6B6B6B;     /* 副文字 */
  --gray-status: #888780;
  --gray-tip: #B4B2A9;
  --line: #D3D1C7;
  --accent: #D85A30;
  --bg: #FFFFFF;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* 长按画布会弹「存储图片」菜单，干扰点选操作 */
#canvas,
.home,
.result {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue",
               "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.view[hidden] { display: none; }

/* ==================== 首屏 ==================== */

.home {
  /* 顶部/底部避开刘海和横条，横屏时左右也要避让 */
  padding:
    calc(8px + env(safe-area-inset-top)) calc(24px + env(safe-area-inset-right))
    calc(28px + env(safe-area-inset-bottom)) calc(24px + env(safe-area-inset-left));
}

.homeTop {
  margin-top: 56px;
}

.homeTop h1 {
  margin: 0;
  font-size: 23px;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--ink);
}

.homeSub {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--gray);
  white-space: pre-line;
}

.homeSpacer {
  flex: 1;
  min-height: 24px;
}

.homeTip {
  margin: 22px 0 0;
  font-size: 11px;
  line-height: 1.55;
  text-align: center;
  color: var(--gray-status);
}

/* ==================== 按钮 ==================== */

.btnPrimary,
.btnOutline {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .15s;
}

.btnPrimary:active,
.btnOutline:active { opacity: .72; }

/* 模型还没加载完时不允许点，否则点了会抛错 */
.btnPrimary.isDisabled,
.btnOutline.isDisabled {
  opacity: .38;
  pointer-events: none;
}

.btnPrimary {
  background: var(--ink-btn);
  color: #FFFFFF;
  border-radius: 14px;
}

.btnOutline {
  background: #FFFFFF;
  color: var(--ink-btn);
  border: 1px solid var(--line);
  border-radius: 14px;
}

/* 首屏两个按钮 */
.btnTall {
  height: 74px;
  font-size: 17px;
}

.btnMed {
  height: 52px;
  font-size: 14px;
  margin-top: 12px;
}

/* 结果页底部按钮行 */
.actions {
  display: flex;
  gap: 12px;
  margin-top: 10px;
  flex: none;
}

.actions button {
  flex: 1;
  height: 44px;
  font-size: 14px;
}

/* ==================== 结果页 ==================== */

.result {
  position: relative;
  padding:
    calc(12px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right))
    calc(18px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left));
}

/* 结果页左上角回首页。安卓有系统返回键，网页没有，必须自己给一个 */
.backBtn {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  left: calc(8px + env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 2px;
  height: 34px;
  padding: 0 10px 0 6px;
  background: none;
  border: none;
  color: var(--gray);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  z-index: 2;
}

.backBtn:active { opacity: .6; }

.backBtn .chev {
  font-size: 20px;
  line-height: 1;
  margin-top: -2px;
}

.countRow {
  display: flex;
  align-items: baseline;
  justify-content: center;
  margin-top: 12px;
  flex: none;
}

.countRow .num {
  font-size: 50px;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.countRow .unit {
  font-size: 15px;
  color: var(--gray);
  margin-left: 4px;
}

.status {
  margin: 2px 0 0;
  font-size: 12px;
  text-align: center;
  color: var(--gray-status);
  min-height: 17px;
  flex: none;
}

/* 图片区：对应 layout_weight="1"，占满剩余高度 */
.canvasCard {
  flex: 1;
  min-height: 0;
  margin-top: 10px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#canvas {
  display: block;
  flex: none;
  touch-action: none;
}

.tip {
  margin: 8px 0 0;
  font-size: 11px;
  text-align: center;
  color: var(--gray-tip);
  flex: none;
}

.meta {
  margin: 10px 0 0;
  font-size: 11px;
  text-align: center;
  color: var(--gray-status);
  font-variant-numeric: tabular-nums;
  min-height: 16px;
  flex: none;
}

/* ==================== 编辑工具条 ==================== */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  flex: none;
}

.toolbar[hidden] { display: none; }

/* SwitchCompat 风格开关 */
.switchWrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-btn);
  cursor: pointer;
  user-select: none;
}

.switchWrap input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.swTrack {
  width: 38px;
  height: 22px;
  border-radius: 11px;
  background: var(--line);
  position: relative;
  transition: background .18s;
  flex: none;
}

.swTrack::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .22);
  transition: transform .18s;
}

.switchWrap input:checked + .swTrack {
  background: var(--accent);
}

.switchWrap input:checked + .swTrack::after {
  transform: translateX(16px);
}

.swText {
  margin-left: 2px;
}

.miniBtn {
  height: 34px;
  padding: 0 14px;
  background: #FFFFFF;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink-btn);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.miniBtn:active { opacity: .7; }

.miniBtn:disabled {
  opacity: .38;
  cursor: not-allowed;
}

/* 加 / 删 模式 */
.modeGroup {
  display: flex;
  gap: 12px;
  height: 38px;
  margin-top: 8px;
  flex: none;
}

.modeGroup[hidden] { display: none; }

.modeBtn {
  flex: 1;
  height: 100%;
  background: #FFFFFF;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink-btn);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}

.modeBtn.on {
  background: var(--ink-btn);
  border-color: var(--ink-btn);
  color: #FFFFFF;
}

/* ==================== 识别中遮罩 ==================== */

.busy {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.82);
  font-size: 13px;
  color: var(--gray);
}

.busy[hidden] { display: none; }

.spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid #E6E4DC;
  border-top-color: var(--ink-btn);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.warn { color: #B45309; }
