/* 宠物箱控制台 · 全设备响应式样式
   手机（<680px）单列 → 平板（≥680px）双列 → 桌面（≥1080px）主辅双栏 */

:root {
  --primary: #0f5c6b;
  --accent: #1b8a9c;
  --bg: #f4f7f8;
  --card: #ffffff;
  --text: #1f2329;
  --muted: #8a9199;
  --line: #e3eaec;
  --ok: #2ba471;
  --danger: #d93026;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(16, 42, 50, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 内联 SVG 图标：零外部依赖，跟随文字颜色 */
.ico {
  width: 1.05em; height: 1.05em; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -.16em; margin-right: 6px;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
}

/* ---------- 顶栏 ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
h1 { font-size: clamp(19px, 4.6vw, 23px); margin: 0 0 4px; letter-spacing: .2px; }
.sub { margin: 0; font-size: 12px; color: var(--muted); }
.dot { flex: none; position: relative; width: 12px; height: 12px; border-radius: 50%; background: #c9d2d6; transition: background .2s, box-shadow .2s; }
.dot.online { background: var(--ok); box-shadow: 0 0 0 4px rgba(43, 164, 113, .15); }
.dot.online::after { content: ""; position: absolute; inset: -5px; border: 1px solid var(--ok); border-radius: 50%; animation: dotPulse 2s ease-out infinite; }
@keyframes dotPulse { 0% { transform: scale(.7); opacity: .8; } 100% { transform: scale(1.6); opacity: 0; } }

/* ---------- 温度主卡 ---------- */
.hero {
  background: linear-gradient(160deg, #0f5c6b, #146b7a);
  color: #fff; border-radius: 20px; padding: clamp(18px, 4.5vw, 26px);
  margin-bottom: 14px; box-shadow: 0 6px 18px rgba(15, 92, 107, .16);
}
.hero-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.label { font-size: 13px; color: #c3dbe0; }
.badge { font-size: 12px; background: rgba(255, 255, 255, .16); padding: 5px 12px; border-radius: 20px; white-space: nowrap; transition: background .25s, color .25s; }
.badge[data-state="heating"] { background: rgba(255, 183, 120, .26); color: #ffe0bd; }
.badge[data-state="cooling"] { background: rgba(120, 200, 240, .24); color: #cfeeff; }
.badge[data-state="fault"] { background: rgba(255, 110, 100, .3); color: #ffd5cf; }
.badge[data-state="balanced"] { background: rgba(72, 199, 142, .26); color: #c8f3dc; }
.temp { font-size: clamp(50px, 13vw, 68px); font-weight: 700; line-height: 1.1; margin: 8px 0 10px; font-variant-numeric: tabular-nums; }
.temp small { font-size: 18px; font-weight: 400; margin-left: 4px; color: #cfe6ea; }
.hero-foot { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: #bfd6da; }
.hero-foot b { color: #fff; font-weight: 600; }
.fault { color: #ffd2c9; }

/* ---------- 状态格子 ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.cell { background: var(--card); border-radius: 14px; padding: 13px 14px; box-shadow: var(--shadow); min-width: 0; }
.cell span { font-size: 12px; color: var(--muted); }
.cell strong { display: block; margin-top: 6px; font-size: clamp(17px, 4.5vw, 21px); font-variant-numeric: tabular-nums; }

/* ---------- 通用卡片 ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
h2 { font-size: 15px; margin: 0; }
.tip { font-size: 11px; color: var(--muted); text-align: right; }

/* ---------- 目标温度 ---------- */
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #f4f8f9; border-radius: 12px; padding: 8px; }
.stepper span { font-size: 20px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stepper button {
  flex: none; width: 46px; height: 46px; border: 0; border-radius: 10px; background: #fff;
  color: var(--primary); font-size: 24px; line-height: 1; box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
}
.stepper button:active { transform: scale(.96); }

/* ---------- 开关 / 滑杆 ---------- */
.switch { flex: none; width: 52px; height: 32px; border-radius: 18px; border: 0; background: #cbd5d9; position: relative; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .18); }
.switch.on { background: var(--accent); }
.switch.on::after { left: 23px; }

input[type="range"] { width: 100%; height: 32px; accent-color: var(--accent); }

/* ---------- 定时 ---------- */
.timers { display: flex; flex-direction: column; gap: 10px; }
.timer-row { display: grid; grid-template-columns: minmax(40px, 1fr) auto minmax(58px, 68px) minmax(58px, 68px); align-items: center; gap: 8px; font-size: 14px; }
.timer-row em { font-style: normal; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; }
.timer-row button { min-height: 40px; padding: 8px 0; border: 0; border-radius: 9px; background: #f1f5f6; color: #4a5157; font-size: 13px; }
.timer-row button:active { background: #e3ecee; }

/* ---------- 保存 / 日志 / 页脚 ---------- */
.save { width: 100%; min-height: 50px; padding: 14px; border: 0; border-radius: 14px; background: var(--primary); color: #fff; font-size: 15px; font-weight: 600; margin: 4px 0 16px; }
.save:active { opacity: .88; }
.log { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.log ul { list-style: none; margin: 10px 0 0; padding: 0; max-height: 200px; overflow-y: auto; }
.log li { font-size: 12px; color: #4a5157; padding: 6px 0; border-bottom: 1px solid #f1f4f5; display: flex; gap: 8px; }
.log li:last-child { border-bottom: 0; }
.log li time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.foot { text-align: center; font-size: 11px; color: var(--muted); line-height: 1.7; margin-top: 20px; }

/* ---------- 轻提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: rgba(31, 35, 41, .92); color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 10; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 稍宽的手机：状态格子改 3 列 ---------- */
@media (min-width: 380px) and (max-width: 679px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cell { padding: 12px 10px; }
}

/* ---------- 平板：双列卡片 ---------- */
@media (min-width: 680px) {
  .app {
    max-width: 900px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    align-items: start;
    padding-inline: 24px;
  }
  .app > * { margin-bottom: 0; }
  .topbar, .hero, .grid, .save, .log, .foot { grid-column: 1 / -1; }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "head foot" "temp foot";
    align-items: center;
  }
  .hero-head { grid-area: head; }
  .temp { grid-area: temp; }
  .hero-foot { grid-area: foot; flex-direction: column; align-items: flex-end; gap: 8px; }
  .log ul { max-height: 260px; }
}

/* ---------- 桌面 / 大屏：左侧主控 + 右侧辅助 ---------- */
@media (min-width: 1080px) {
  .app {
    max-width: 1280px;
    grid-template-columns: minmax(0, 1.15fr) minmax(340px, .85fr);
    grid-template-areas:
      "head   head"
      "hero   hero"
      "stats  stats"
      "target timer"
      "light  timer"
      "ion    log"
      "save   log"
      "foot   foot";
    gap: 16px;
    padding-top: 28px;
  }
  .topbar { grid-area: head; }
  .hero { grid-area: hero; }
  .grid { grid-area: stats; grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .card-target { grid-area: target; }
  .card-light { grid-area: light; }
  .card-ion { grid-area: ion; }
  .card-timer { grid-area: timer; }
  .save { grid-area: save; align-self: start; }
  .log { grid-area: log; }
  .foot { grid-area: foot; }
  .card-timer, .log { align-self: start; }
  .log ul { max-height: 340px; }
  .hero { padding: 28px 32px; }
  .temp { font-size: 68px; }
}

/* ---------- 手机横屏等矮屏：压缩纵向占用 ---------- */
@media (max-height: 480px) and (orientation: landscape) and (max-width: 1079px) {
  .app { padding-top: 10px; }
  .hero { padding: 14px 16px; }
  .temp { font-size: 38px; margin: 2px 0 4px; }
  .log ul { max-height: 110px; }
}

/* ---------- 跟随系统深色模式 ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10181b;
    --card: #182328;
    --text: #e8eef0;
    --muted: #93a3aa;
    --line: #26353a;
    --ok: #48c78e;
    --shadow: 0 1px 3px rgba(0, 0, 0, .25);
  }
  .hero { background: linear-gradient(160deg, #124450, #175a68); }
  .stepper { background: #202e33; }
  .stepper button { background: #26363c; color: #9fe3ef; }
  .switch { background: #3a4b51; }
  .timer-row button { background: #223136; color: #cbd8dc; }
  .timer-row button:active { background: #2b3d43; }
  .log li { color: #c3d0d4; border-bottom-color: #223136; }
  .toast { background: rgba(232, 238, 240, .94); color: #10181b; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
