@font-face {
  font-family: "Martian Mono";
  src: url(fonts/martian-mono-latin.woff2) format("woff2");
  font-weight: 100 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F, U+2190-2193, U+2212;
}

:root {
  --bg: #0d0e0b;
  --bg-2: #14160f;
  --surface: #191b15;
  --surface-2: #22251d;
  --ink: #eeede4;
  --muted: #9a998d;
  --faint: #5f5e55;
  --line: rgba(238, 237, 228, 0.11);
  --line-2: rgba(238, 237, 228, 0.22);

  --find: #ff6b2c;
  --place: #3ddc97;
  --move: #ffd23f;
  --ask: #b9c8ff;
  --accent: var(--find);

  --radius: 14px;
  --cn: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  --mono: "Martian Mono", ui-monospace, "SFMono-Regular", "Menlo", "Consolas", var(--cn);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(255, 107, 44, 0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(61, 220, 151, 0.06), transparent 60%),
    linear-gradient(var(--bg), var(--bg));
  color: var(--ink);
  font: 15px/1.6 var(--cn);
  padding: env(safe-area-inset-top, 0) max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom, 0) max(16px, env(safe-area-inset-left));
  -webkit-tap-highlight-color: transparent;
}
body[data-task="find"] { --accent: var(--find); }
body[data-task="place"] { --accent: var(--place); }
body[data-task="move"] { --accent: var(--move); }
body[data-task="ask"] { --accent: var(--ask); }

.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .06;
  background-image:
    linear-gradient(var(--line-2) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-2) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(ellipse at 50% 20%, #000 20%, transparent 75%);
}

.mono { font-family: var(--mono); letter-spacing: 0; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── 顶栏 ─────────────────────────── */
.top {
  position: relative; z-index: 1;
  max-width: 1180px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 0 14px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 38px; height: 38px; color: var(--ink); flex: none; }
.brand h1 { margin: 0; font-size: 21px; line-height: 1.1; font-weight: 800; letter-spacing: .06em; }
.brand-sub { margin: 3px 0 0; font-size: 10px; color: var(--muted); letter-spacing: .12em; }

.status {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--muted);
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: rgba(20, 22, 15, .6);
  white-space: nowrap;
}
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.status[data-state="ready"] .dot { background: var(--place); box-shadow: 0 0 0 3px rgba(61, 220, 151, .18); }
.status[data-state="sleep"] .dot { background: var(--move); }
.status[data-state="busy"] .dot { background: var(--find); animation: blink 1s infinite; }
.status[data-state="down"] .dot { background: #ff4d4d; }
@keyframes blink { 50% { opacity: .35; } }

/* ── 布局 ─────────────────────────── */
.layout {
  position: relative; z-index: 1;
  max-width: 1180px; margin: 0 auto;
  display: grid; gap: 18px;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 920px) {
  .layout { grid-template-columns: minmax(0, 1.45fr) minmax(340px, 1fr); gap: 28px; align-items: start; }
  .panel { position: sticky; top: 18px; }
}

/* ── 取景框 ───────────────────────── */
.frame {
  position: relative;
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line);
  min-height: 300px;
  display: grid; place-items: center;
  padding: 14px;
  transition: border-color .3s;
}
.frame.has-image { min-height: 0; padding: 10px; }
@media (max-width: 600px) {
  .frame.has-image { padding: 6px; border-radius: 12px; }
  .frame.has-image .corner { width: 14px; height: 14px; }
  .frame.has-image .corner.tl, .frame.has-image .corner.tr { top: 2px; }
  .frame.has-image .corner.bl, .frame.has-image .corner.br { bottom: 2px; }
  .frame.has-image .corner.tl, .frame.has-image .corner.bl { left: 2px; }
  .frame.has-image .corner.tr, .frame.has-image .corner.br { right: 2px; }
}
.frame.drag { border-color: var(--accent); }
.frame.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.corner { position: absolute; width: 18px; height: 18px; border: 2px solid var(--accent); transition: border-color .3s; pointer-events: none; }
.corner.tl { top: 8px; left: 8px; border-right: 0; border-bottom: 0; border-top-left-radius: 6px; }
.corner.tr { top: 8px; right: 8px; border-left: 0; border-bottom: 0; border-top-right-radius: 6px; }
.corner.bl { bottom: 8px; left: 8px; border-right: 0; border-top: 0; border-bottom-left-radius: 6px; }
.corner.br { bottom: 8px; right: 8px; border-left: 0; border-top: 0; border-bottom-right-radius: 6px; }

.empty { text-align: center; padding: 36px 8px; }
.empty-lead { margin: 0 0 24px; font-size: 19px; line-height: 1.55; font-weight: 600; letter-spacing: .02em; }
.empty-hint { margin: 16px 0 0; font-size: 11px; color: var(--muted); }
.pick { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

@media (pointer: coarse) { .mouse-only { display: none !important; } }
@media (pointer: fine), (pointer: none) { .touch-only { display: none !important; } }

.shot {
  position: relative;
  width: min(100%, calc(72dvh * var(--ar, 1.5)));
  aspect-ratio: var(--ar, 1.5);
  border-radius: 8px; overflow: hidden;
  background: #000;
}
.shot img { display: block; width: 100%; height: 100%; object-fit: fill; user-select: none; -webkit-user-drag: none; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
/* 挂在 .frame 上，不随图片尺寸缩；没图时隐藏 */
.shot-tools { position: absolute; top: 18px; right: 18px; z-index: 2; display: flex; gap: 8px; }
.frame:not(.has-image) .shot-tools, .frame:not(.has-image) .readout { display: none; }
@media (max-width: 600px) { .shot-tools { top: 12px; right: 12px; } .readout { left: 12px !important; bottom: 12px !important; } }
.readout {
  position: absolute; left: 18px; bottom: 18px; z-index: 2;
  font-size: 10px; color: rgba(255, 255, 255, .85);
  background: rgba(0, 0, 0, .5); padding: 3px 7px; border-radius: 4px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}

/* 扫描动画 */
.scan { position: absolute; inset: 0; pointer-events: none; background: rgba(0, 0, 0, .18); }
.scan span {
  position: absolute; left: 0; right: 0; height: 26%;
  background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--accent) 35%, transparent) 85%, var(--accent));
  border-bottom: 1px solid var(--accent);
  animation: sweep 1.8s cubic-bezier(.45, .05, .55, .95) infinite;
}
@keyframes sweep { from { top: -26%; } to { top: 100%; } }

/* ── 示例 ─────────────────────────── */
.samples { margin-top: 14px; }
.samples-title { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.samples-row { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; scrollbar-width: thin; }
.sample {
  flex: none; scroll-snap-align: start;
  width: 118px; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  background: var(--surface); text-align: left; transition: transform .2s, border-color .2s;
}
.sample:hover { transform: translateY(-2px); border-color: var(--line-2); }
.sample[aria-pressed="true"] { border-color: var(--accent); }
.sample img { display: block; width: 100%; height: 76px; object-fit: cover; }
.sample span { display: block; padding: 5px 8px; font-size: 12px; }

/* ── 按钮 ─────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: 999px; border: 1px solid var(--line-2);
  background: transparent; font-weight: 600; white-space: nowrap;
  transition: transform .15s, background .2s, border-color .2s;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 20px; height: 20px; }
.btn-lg { min-height: 52px; padding: 0 26px; font-size: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #140a04; }
.btn-ghost:hover { background: var(--surface-2); }
.chip-btn {
  display: inline-flex; align-items: center; gap: 5px;
  height: 32px; padding: 0 11px; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .22);
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 13px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.chip-btn svg { width: 15px; height: 15px; }

/* ── 操作区 ───────────────────────── */
.panel {
  background: linear-gradient(180deg, rgba(25, 27, 21, .85), rgba(20, 22, 15, .85));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px;
}
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--bg); border-radius: 12px; padding: 4px; }
.tab {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; border: 0; border-radius: 9px; background: transparent;
  color: var(--muted); font-size: 14px; font-weight: 600; white-space: nowrap;
  transition: background .2s, color .2s;
}
.tab i { width: 8px; height: 8px; border-radius: 50%; flex: none; opacity: .75; }
.tab[data-task="find"] i { background: var(--find); }
.tab[data-task="place"] i { background: var(--place); }
.tab[data-task="move"] i { background: var(--move); }
.tab[data-task="ask"] i { background: var(--ask); }
.tab[aria-selected="true"] { background: var(--surface-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-2); }
.tab[aria-selected="true"] i { opacity: 1; }
@media (max-width: 360px) { .tab { font-size: 13px; gap: 4px; } .tab i { width: 6px; height: 6px; } }

.task-desc { margin: 12px 2px 10px; font-size: 13px; color: var(--muted); min-height: 1.6em; }

.ask { display: flex; gap: 8px; }
.ask input {
  flex: 1; min-width: 0; height: 50px; padding: 0 14px;
  border-radius: 12px; border: 1px solid var(--line-2); background: var(--bg);
  font-size: 16px; /* ≥16px 防止 iOS 聚焦放大 */
  transition: border-color .2s;
}
.ask input:focus { outline: none; border-color: var(--accent); }
.ask input::placeholder { color: var(--faint); }
.send {
  flex: none; width: 50px; height: 50px; border-radius: 12px; border: 0;
  background: var(--accent); color: #140a04; display: grid; place-items: center;
  transition: transform .15s, opacity .2s, background .3s;
}
.send svg { width: 24px; height: 24px; }
.send:active { transform: scale(.94); }
.send:disabled { opacity: .45; cursor: not-allowed; }
.send.stop { background: var(--surface-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-2); }

.hints { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.hint {
  height: 34px; padding: 0 13px; border-radius: 999px;
  border: 1px dashed var(--line-2); background: transparent; color: var(--ink); font-size: 14px;
  transition: border-color .2s, background .2s;
}
.hint:hover { border-color: var(--accent); background: var(--surface-2); }

/* ── 结果 ─────────────────────────── */
.result:empty { display: none; }
.result { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
.res-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.res-title { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.45; }
.res-title em { font-style: normal; color: var(--accent); }
.res-meta { font-size: 10px; color: var(--muted); white-space: nowrap; }
.res-body { margin: 8px 0 0; font-size: 15px; line-height: 1.75; }
.res-tip { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.res-wait { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.res-wait .mono { color: var(--ink); font-size: 12px; }
.res-error { color: #ffb4a0; }
details.raw { margin-top: 12px; }
details.raw summary { font-size: 12px; color: var(--muted); cursor: pointer; list-style: none; }
details.raw summary::before { content: "▸ "; }
details.raw[open] summary::before { content: "▾ "; }
details.raw pre {
  margin: 8px 0 0; padding: 10px; border-radius: 8px; background: var(--bg);
  font: 11px/1.6 var(--mono); color: #c9c8bd; white-space: pre-wrap; word-break: break-all; max-height: 220px; overflow: auto;
}

.history { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.history-title { margin: 0 0 8px; font-size: 12px; color: var(--muted); }
.history-row { display: flex; flex-wrap: wrap; gap: 6px; }
.hist {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); font-size: 13px; max-width: 100%;
}
.hist i { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.hist span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist[aria-current="true"] { border-color: var(--line-2); background: var(--surface-2); }

/* ── 叠加层元素 ───────────────────── */
.mk { transform-box: fill-box; transform-origin: center; animation: pop .45s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes pop { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }
/* 线宽、字号由脚本按图片尺寸写在属性上，这里不能再设，否则 CSS 会盖掉属性 */
.mk-ring { fill: none; }
.mk-core { stroke: #000; }
.mk-tick { stroke-linecap: round; }
.mk-pulse { fill: none; transform-box: fill-box; transform-origin: center; animation: pulse 1.8s ease-out infinite; }
@keyframes pulse { from { transform: scale(.6); opacity: .9; } to { transform: scale(2.2); opacity: 0; } }
.mk-label rect:first-child { fill: rgba(0, 0, 0, .72); }
.mk-label text { fill: #fff; font-family: var(--cn); font-weight: 600; dominant-baseline: middle; }
.overlay text { font-family: var(--cn); }
.path-line { fill: none; stroke-linecap: round; stroke-linejoin: round; animation: draw 1.1s ease-out both; }
.path-shadow { fill: none; stroke: rgba(0, 0, 0, .55); stroke-linecap: round; stroke-linejoin: round; }
@keyframes draw { from { stroke-dashoffset: var(--len); } to { stroke-dashoffset: 0; } }

/* ── 摄像头弹层 ───────────────────── */
.cam { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .9); display: grid; place-items: center; padding: 16px; }
.cam-box { width: min(920px, 100%); }
.cam video { display: block; width: 100%; max-height: 72dvh; border-radius: 12px; background: #000; object-fit: contain; }
.cam-msg { color: #ffb4a0; text-align: center; margin: 16px 0; }
.cam-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; margin-top: 16px; }
.cam-bar > :first-child { justify-self: start; }
.cam-bar > :last-child { justify-self: end; }
.shutter { width: 70px; height: 70px; border-radius: 50%; border: 4px solid #fff; background: transparent; padding: 5px; }
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; transition: transform .1s; }
.shutter:active span { transform: scale(.88); }

/* ── 提示条 ───────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0)); transform: translateX(-50%);
  z-index: 30; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  animation: toast-in .25s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ── 页脚 ─────────────────────────── */
.foot { position: relative; z-index: 1; max-width: 1180px; margin: 26px auto 0; padding: 18px 0 30px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.7; }
.foot p { margin: 0 0 6px; }
.foot b { color: var(--ink); font-weight: 600; }

/* ── 进场 ─────────────────────────── */
.top, .stage-col, .panel { animation: rise .6s cubic-bezier(.2, .8, .2, 1) both; }
.stage-col { animation-delay: .06s; }
.panel { animation-delay: .14s; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition: none !important; }
  .scan span { top: 40%; }
}
