:root {
  --bg: #ffffff;
  --panel: #fff;
  --panel-alt: #f7f8fa;
  --border: #e5e8ef;
  --accent: #c0392b;
  --title: #1a2332;
  --text: #2c3a4f;
  --muted: #6b778c;
  --btn-from: #5b8def;
  --btn-to: #2f6fed;
  --gold: #2f6fed;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  min-height: 100dvh;
  height: auto;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.stars {
  position: fixed;
  inset: 0;
  background: #ffffff;
  z-index: -1;
  pointer-events: none;
}

.top-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
  flex: 0 0 auto;
}

.link-back {
  color: var(--gold);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  height: 2rem;
  padding: 0 0.65rem 0 0.4rem;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  border-radius: 999px;
  border: 1px solid rgba(47, 111, 237, 0.28);
  background: #fff;
  white-space: nowrap;
}
.link-back-arrow { font-size: 1.05rem; }

.readout {
  position: relative;
  min-width: 0;
  text-align: center;
  display: inline-flex;
  justify-content: center;
  align-items: baseline;
  gap: 0.4rem;
  margin: 0 auto;
  padding: 0.28rem 0.85rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(47, 111, 237, 0.2);
  max-width: 100%;
}
.readout strong {
  color: var(--title);
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.readout .deg {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.1rem 0.2rem 0.1rem 0.35rem;
  border-left: 1px solid rgba(192, 57, 43, 0.22);
  border-radius: 6px;
  cursor: pointer;
}
.readout .deg:active { background: rgba(192, 57, 43, 0.08); }

.deg-pop {
  position: absolute;
  left: 50%;
  top: calc(100% + 0.45rem);
  transform: translateX(-50%);
  z-index: 20;
  width: min(16rem, 78vw);
  padding: 0.7rem 0.75rem;
  border-radius: 12px;
  background: #fff;
  border: 1px solid rgba(47, 111, 237, 0.28);
  box-shadow: 0 8px 24px rgba(26, 35, 50, 0.1);
  text-align: left;
}
.deg-pop.hidden { display: none; }
.deg-pop-label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}
.deg-pop-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.deg-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 2rem;
  border: 1px solid rgba(47, 111, 237, 0.32);
  border-radius: 8px;
  padding: 0 0.55rem;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}
.deg-unit { color: var(--muted); font-size: 0.9rem; }
.deg-ok { flex: 0 0 auto; }

.top-actions { display: flex; gap: 0.35rem; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin: 0.55rem 0.75rem 0;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 2px 10px rgba(26, 35, 50, 0.05);
  flex: 0 0 auto;
}
.toolbar-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.45rem;
  flex: 0 0 auto;
  min-width: 0;
}
.toolbar-opts {
  min-width: 0;
  flex: 1 1 auto;
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
}
.sensor-status {
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
body.is-live .sensor-status { color: #2e7d32; font-weight: 600; }
body.is-locked .sensor-status { color: var(--accent); font-weight: 600; }
.pan-name {
  display: inline-block;
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.tool-check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 2.15rem;
  padding: 0 0.85rem;
  border-radius: 999px;
  border: 1px solid rgba(47, 111, 237, 0.3);
  background: #fff;
  font-size: 0.86rem;
  font-weight: 650;
  color: var(--title);
  cursor: pointer;
  user-select: none;
}
.tool-check input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
}
body.is-locked .tool-check {
  border-color: rgba(192, 57, 43, 0.5);
  background: rgba(192, 57, 43, 0.07);
  color: var(--accent);
}
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--title);
  border-radius: 999px;
  height: 2.15rem;
  padding: 0 0.95rem;
  font-size: 0.86rem;
  font-weight: 650;
  cursor: pointer;
}
.btn.primary {
  border: 0;
  color: #fff;
  background: linear-gradient(180deg, var(--btn-from), var(--btn-to));
}
.btn.btn-compass {
  min-width: 4.6rem;
  height: 2.25rem;
  padding: 0 1.15rem;
  font-size: 0.92rem;
}
.btn.ghost {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}
.btn.ghost:hover {
  border-color: rgba(47, 111, 237, 0.4);
  color: var(--btn-to);
}
.btn.chip {
  height: 1.85rem;
  padding: 0 0.7rem;
  font-size: 0.78rem;
}
.btn.chip.deg-ok,
.btn.primary:active {
  filter: brightness(0.96);
}
.btn.btn-block {
  width: 100%;
  margin-top: 0.15rem;
}

/* 手机：罗盘不占满屏，下方理气汇总默认露出一截 */
.page-main {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  height: 48vh;
  min-height: 240px;
  max-height: 420px;
  background: #f7f8fa;
}

.compass-pane {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.25rem 0.35rem 0.35rem;
  overflow: hidden;
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 12px;
  background:
    #ffffff;
  border: 1px solid rgba(47, 111, 237, 0.16);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
  overflow: hidden;
  touch-action: none;
}
.load-panel {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 8;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.85) 0%, rgba(247, 248, 250, 0.92) 58%, rgba(232, 236, 244, 0.95) 100%);
  pointer-events: none;
}
.stage.is-loading .load-panel {
  display: flex;
}
.stage.is-loading .luopan-widget {
  opacity: 0;
  pointer-events: none;
}
.load-panel-card {
  width: min(280px, 86vw);
  padding: 1.15rem 1.2rem 1rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(47, 111, 237, 0.2);
  box-shadow:
    0 12px 30px rgba(26, 35, 50, 0.1),
    0 1px 0 rgba(255, 255, 255, 0.85) inset;
  text-align: center;
}
.load-panel-title {
  margin: 0 0 0.85rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.load-panel-track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(47, 111, 237, 0.12) 0%, rgba(47, 111, 237, 0.06) 100%);
  box-shadow: inset 0 1px 2px rgba(26, 35, 50, 0.06);
}
.load-panel-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--load-pct, 8%);
  border-radius: inherit;
  background: linear-gradient(90deg, #7aa4f5 0%, #2f6fed 45%, #5b8def 100%);
  box-shadow: 0 0 12px rgba(47, 111, 237, 0.28);
  transition: width 0.14s ease-out;
  overflow: hidden;
}
.load-panel-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    110deg,
    transparent 0%,
    transparent 40%,
    rgba(255, 255, 255, 0.55) 50%,
    transparent 60%,
    transparent 100%
  );
  background-size: 220% 100%;
  animation: load-shine 1.15s linear infinite;
}
.load-panel-meta {
  margin: 0.65rem 0 0;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: #6b778c;
}
@keyframes load-shine {
  from { background-position: 120% 0; }
  to { background-position: -120% 0; }
}

.luopan-widget {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 640px;
  height: 640px;
  margin-left: -320px;
  margin-top: -320px;
  z-index: 2;
  transform-origin: 50% 50%;
  touch-action: none;
}

.luopan-frame {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: grab;
}
.luopan-frame:active { cursor: grabbing; }

.luopan-rotator {
  position: absolute;
  left: 1%;
  top: 1%;
  width: 98%;
  height: 98%;
  transform-origin: 50% 50%;
  z-index: 1;
}

.luopan-media {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transform-origin: 50% 50%;
  width: auto;
  height: auto;
  /* 不改原图：圆形裁剪，去掉罗盘外白底四角 */
  border-radius: 50%;
  overflow: hidden;
  -webkit-clip-path: circle(50% at 50% 50%);
  clip-path: circle(50% at 50% 50%);
}

.luopan-src {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.luopan-face {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

/* 放大超过原图像素时用近邻采样，观感接近系统画图放大 */
.luopan-face.is-pixelated {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* 天心十道：红十字准线；尺寸由 JS 与盘面同步缩放，不随内盘旋转 */
.tianxin-cross {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  transform-origin: 50% 50%;
  z-index: 3;
  pointer-events: none;
}
.tianxin-h,
.tianxin-v {
  position: absolute;
  left: 50%;
  top: 50%;
  background: #d32f2f;
  box-shadow: 0 0 0 0.5px rgba(255, 255, 255, 0.35);
}
.tianxin-h {
  width: 100%;
  height: max(1.5px, 0.22%);
  transform: translate(-50%, -50%);
}
.tianxin-v {
  width: max(1.5px, 0.22%);
  height: 100%;
  transform: translate(-50%, -50%);
}
.tianxin-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: max(6px, 1.1%);
  height: max(6px, 1.1%);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #d32f2f;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.55);
}

.rotate-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  transform-origin: 50% 50%;
  border-radius: 50%;
  z-index: 2;
  pointer-events: none;
  box-shadow: inset 0 0 0 max(1.5px, 0.28%) rgba(192, 57, 43, 0.18);
}
body.is-live .rotate-ring {
  box-shadow: inset 0 0 0 max(1.5px, 0.28%) rgba(46, 125, 50, 0.28);
}
body.is-locked .rotate-ring {
  box-shadow: inset 0 0 0 max(1.5px, 0.28%) rgba(192, 57, 43, 0.35);
}

.help-mask {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(26, 35, 50, 0.32);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.help-mask.hidden { display: none; }

.help-card {
  width: min(22rem, 100%);
  max-height: min(80vh, 34rem);
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  padding: 1rem 1.05rem 0.95rem;
  border: 1px solid rgba(47, 111, 237, 0.22);
  box-shadow: 0 12px 36px rgba(26, 35, 50, 0.12);
}
.help-card h2 {
  font-size: 1.05rem;
  margin-bottom: 0.65rem;
  color: var(--title);
}
.help-card ul {
  padding-left: 1.1rem;
  margin-bottom: 0.9rem;
  color: var(--text);
  font-size: 0.86rem;
  line-height: 1.55;
}
.help-card li { margin: 0.25rem 0; }

.compass-card {
  width: min(28rem, 100%);
  padding: 1.15rem 1.1rem 1rem;
}
.compass-pick-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-bottom: 0.95rem;
}
.compass-pick {
  display: flex;
  align-items: center;
  gap: 0.95rem;
  width: 100%;
  text-align: left;
  padding: 0.75rem 0.85rem;
  border-radius: 16px;
  border: 1px solid rgba(47, 111, 237, 0.22);
  background: #ffffff;
  cursor: pointer;
  min-height: 5.4rem;
}
.compass-pick img {
  width: 4.6rem;
  height: 4.6rem;
  object-fit: cover;
  border-radius: 50%;
  background: #f7f8fa;
  border: 1px solid rgba(47, 111, 237, 0.14);
  flex: 0 0 auto;
  -webkit-clip-path: circle(50% at 50% 50%);
  clip-path: circle(50% at 50% 50%);
}
.compass-pick span {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--title);
  letter-spacing: 0.02em;
  line-height: 1.35;
}
.compass-pick.is-active {
  border-color: rgba(192, 57, 43, 0.55);
  background: rgba(192, 57, 43, 0.06);
  box-shadow: inset 0 0 0 1px rgba(192, 57, 43, 0.18);
}
.compass-pick-soon {
  cursor: default;
  pointer-events: none;
  border-style: dashed;
  border-color: rgba(26, 35, 50, 0.14);
  background: linear-gradient(180deg, #f7f8fa 0%, #eef2f8 100%);
  opacity: 0.92;
}
.compass-pick-soon-thumb {
  position: relative;
  width: 4.6rem;
  height: 4.6rem;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px dashed rgba(160, 130, 80, 0.45);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.55) 0 28%, transparent 29%),
    conic-gradient(from 0deg, rgba(47, 111, 237, 0.16), rgba(47, 111, 237, 0.04), rgba(47, 111, 237, 0.16));
  box-shadow: inset 0 0 0 6px rgba(255, 255, 255, 0.35);
}
.compass-pick-soon-thumb::before,
.compass-pick-soon-thumb::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: rgba(150, 120, 70, 0.35);
  transform: translate(-50%, -50%);
}
.compass-pick-soon-thumb::before {
  width: 1px;
  height: 58%;
}
.compass-pick-soon-thumb::after {
  width: 58%;
  height: 1px;
}
.compass-pick-soon-text {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  min-width: 0;
}
.compass-pick-soon-text strong {
  font-size: 1.05rem;
  font-weight: 700;
  color: rgba(44, 58, 79, 0.75);
  letter-spacing: 0.02em;
  line-height: 1.35;
}
.compass-pick-soon-text em {
  font-style: normal;
  font-size: 0.88rem;
  font-weight: 600;
  color: rgba(107, 119, 140, 0.85);
  letter-spacing: 0.06em;
}

@media (max-width: 420px) {
  .readout strong { font-size: 0.92rem; }
  .toolbar {
    gap: 0.4rem;
    margin: 0.45rem 0.55rem 0;
    padding: 0.45rem 0.5rem;
  }
  .toolbar-actions {
    flex-wrap: nowrap;
    gap: 0.28rem;
  }
  .btn {
    height: 1.95rem;
    padding: 0 0.55rem;
    font-size: 0.78rem;
  }
  .btn.btn-compass {
    min-width: 0;
    height: 1.95rem;
    padding: 0 0.7rem;
    font-size: 0.8rem;
  }
  .tool-check {
    height: 1.95rem;
    padding: 0 0.55rem;
    font-size: 0.78rem;
    gap: 0.25rem;
  }
  .tool-check input {
    width: 0.9rem;
    height: 0.9rem;
  }
  .pan-name {
    max-width: 36vw;
    font-size: 0.72rem;
  }
  .sensor-status { font-size: 0.66rem; }
  .compass-pick {
    min-height: 4.8rem;
    padding: 0.65rem 0.7rem;
  }
  .compass-pick img,
  .compass-pick-soon-thumb {
    width: 4rem;
    height: 4rem;
  }
  .compass-pick span,
  .compass-pick-soon-text strong { font-size: 0.98rem; }
  .compass-pick-soon-text em { font-size: 0.82rem; }
}

@media (min-width: 900px) {
  .page-main {
    height: calc(100dvh - 7.5rem);
    min-height: 420px;
    max-height: 780px;
  }
  .stage {
    width: 100%;
  }
}

/* 演海模块需授权时的提示卡片（替代被嵌进来的授权页） */
.yanhai-auth-notice {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 12px 0;
  padding: 15px 18px;
  border: 1px solid rgba(201, 148, 74, 0.32);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(255, 253, 248, 0.98), rgba(253, 246, 232, 0.94));
  box-shadow: 0 4px 16px rgba(184, 134, 11, 0.1);
}
.yanhai-auth-icon {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  background: linear-gradient(145deg, #f7dcae, #e0b878);
  box-shadow: 0 3px 10px rgba(184, 134, 11, 0.22);
}
.yanhai-auth-text {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.yanhai-auth-text strong {
  font-size: 14px;
  font-weight: 700;
  color: #5a4626;
  line-height: 1.35;
}
.yanhai-auth-text span {
  font-size: 12.5px;
  color: #8a7a5e;
  line-height: 1.5;
}
.yanhai-auth-link {
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 8px 17px;
  border-radius: 999px;
  background: linear-gradient(180deg, #d9a952, #c08a34);
  color: #fff !important;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(192, 138, 52, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.yanhai-auth-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(192, 138, 52, 0.4);
}
@media (max-width: 560px) {
  .yanhai-auth-notice { flex-wrap: wrap; gap: 10px; }
  .yanhai-auth-link { width: 100%; text-align: center; }
}
