/*!
 * styles.css —— 手机优先的深色相机界面
 */

:root {
  --bg: #0b0f14;
  --panel: #131a22;
  --panel-2: #0e141b;
  --line: rgba(255, 255, 255, 0.1);
  --text: #e9eff6;
  --muted: #8ea0b3;
  --blue: #3399cc;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  overflow: hidden;
}

button { font: inherit; cursor: pointer; }

/* ───────── 主框架 ───────── */
.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}

.topbar {
  flex: 0 0 auto;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .3px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 10px rgba(51, 153, 204, .9); }
.top-actions { display: flex; gap: 8px; align-items: center; }

/* ───────── 取景区 ───────── */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}

.frame {
  position: relative;
  /* 实际尺寸由 JS 按 1560:701 精确计算，这里只是 JS 执行前的占位（同比例） */
  width: 320px;
  height: 144px;
  overflow: hidden;
  background: #000;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .6);
}

#cam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
  /* 数码变焦：与成片的 1.5× 中心裁剪完全一致 */
  transform: scale(var(--zoom, 1.5));
  transform-origin: 50% 50%;
  will-change: transform;
  background: #000;
}

#wmOverlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* 相机未开启 / 出错时的卡片 */
.cam-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(120% 90% at 50% 30%, #16212c 0%, #05080b 70%);
  text-align: center;
}
.cam-state[hidden] { display: none; }
.cam-card { width: 100%; max-width: 340px; }
.cam-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.cam-msg { color: var(--muted); font-size: 13px; margin-bottom: 18px; word-break: break-word; }

/* ───────── 底部操作区 ───────── */
.hint {
  flex: 0 0 auto;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 12px 0;
  min-height: 22px;
}

.bottombar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 30px 14px;
  gap: 16px;
}

.round {
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .08);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  transition: transform .12s ease, background .12s ease;
}
.round svg { width: 24px; height: 24px; fill: currentColor; }
.round:active { transform: scale(.93); background: rgba(255, 255, 255, .16); }
.round:disabled { opacity: .4; }

.shutter {
  width: 78px;
  height: 78px;
  padding: 0;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .92);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .1s ease;
}
.shutter span {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: #fff;
  transition: transform .1s ease, background .15s ease;
}
.shutter:active span { transform: scale(.86); }
.shutter:disabled { opacity: .45; }
.shutter.busy span { background: var(--blue); }

/* ───────── 按钮 ───────── */
.primary {
  background: var(--blue);
  color: #fff;
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
}
.primary:active { background: #2b86b5; }

.ghost {
  background: rgba(255, 255, 255, .08);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 14px;
}
.ghost:active { background: rgba(255, 255, 255, .16); }
.ghost.sm { padding: 8px 11px; font-size: 13px; border-radius: 10px; }
.ghost.icon { min-width: 38px; padding: 8px 10px; font-size: 15px; line-height: 1; }
.ghost.big { padding: 14px 16px; font-size: 15px; font-weight: 600; }
.ghost.block, .primary.block { display: block; width: 100%; margin-top: 10px; }

/* ───────── 成片预览 ───────── */
.result {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: #05080b;
  display: flex;
  flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}
.result[hidden] { display: none; }
.result-top {
  flex: 0 0 auto;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
}
.result-meta { color: var(--muted); font-size: 13px; }
.result-stage { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 4px 10px; }
.result-stage img { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: 0 16px 44px rgba(0, 0, 0, .7); }
.result-actions { flex: 0 0 auto; display: flex; gap: 10px; padding: 12px 14px calc(12px + var(--safe-b)); }
.result-actions .primary.big { flex: 1 1 auto; }
.result-actions .ghost.big { flex: 0 0 auto; }
#btnSave { padding: 14px 26px; }

/* ───────── 设置面板 ───────── */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, .55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}
.scrim.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line);
  transform: translateY(102%);
  visibility: hidden;
  transition: transform .28s cubic-bezier(.22, .61, .36, 1), visibility .28s;
  padding-bottom: var(--safe-b);
}
.sheet.open { transform: none; visibility: visible; }

.sheet-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet-head b { font-size: 16px; }

.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px 26px; }

.field { padding: 13px 0; border-bottom: 1px solid var(--line); }
.field > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.field .tip, .about { color: var(--muted); font-size: 12px; line-height: 1.5; margin-top: 7px; }

.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1 1 auto; min-width: 0; }
.unit { color: var(--muted); font-size: 13px; }

input[type="text"], input[type="number"] {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 12px;
  font-size: 15px;
  -webkit-user-select: text;
  user-select: text;
}
input[type="text"]:focus, input[type="number"]:focus { outline: none; border-color: var(--blue); }
input[type="file"] { width: 100%; font-size: 13px; color: var(--muted); }

.check { display: flex; align-items: center; gap: 9px; margin-top: 11px; font-size: 13px; color: var(--text); }
.check input { width: 18px; height: 18px; accent-color: var(--blue); }
.field > label.check { color: var(--text); margin-bottom: 0; }

.seg { display: flex; gap: 5px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg button {
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 6px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seg button.on { background: var(--blue); color: #fff; }

.adv { border-bottom: 1px solid var(--line); }
.adv > summary { padding: 14px 0; font-size: 14px; color: var(--muted); list-style: none; cursor: pointer; }
.adv > summary::-webkit-details-marker { display: none; }
.adv > summary::after { content: "▾"; float: right; opacity: .7; }
.adv[open] > summary::after { content: "▴"; }
.adv .field:last-child { border-bottom: 0; }

.about { padding-top: 16px; border-top: 1px solid var(--line); margin-top: 6px; }

/* ───────── 提示条 ───────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(120px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 90;
  max-width: 86vw;
  padding: 11px 16px;
  border-radius: 999px;
  background: rgba(20, 28, 36, .96);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.toast[hidden] { display: none; }

/* ───────── 横屏：让取景区吃满屏幕，控件浮在画面上 ───────── */
@media (orientation: landscape) and (max-height: 560px) {
  .app { padding: 0; }
  .stage { position: absolute; inset: 0; }
  .frame { border-radius: 0; box-shadow: none; }
  .topbar {
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 20;
    height: auto;
    padding: calc(6px + var(--safe-t)) calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l));
    background: linear-gradient(rgba(0, 0, 0, .6), rgba(0, 0, 0, 0));
  }
  .hint {
    position: absolute;
    left: 0; right: 0;
    bottom: calc(92px + var(--safe-b));
    z-index: 20;
    color: rgba(255, 255, 255, .78);
    text-shadow: 0 1px 4px rgba(0, 0, 0, .9);
  }
  .bottombar {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    z-index: 20;
    padding: 8px calc(30px + var(--safe-r)) calc(10px + var(--safe-b)) calc(30px + var(--safe-l));
    background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, .55));
  }
  .shutter { width: 62px; height: 62px; border-width: 3px; }
  .shutter span { width: 48px; height: 48px; }
  .round { width: 48px; height: 48px; }
  .round svg { width: 20px; height: 20px; }
  .round span { display: none; }
}

@media (min-width: 720px) {
  .sheet { left: 50%; right: auto; width: 560px; transform: translate(-50%, 102%); border-radius: 20px 20px 0 0; }
  .sheet.open { transform: translate(-50%, 0); }
}
