/* style.css —— 正午时刻工具 */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #14171c;
  --text-dim: #5d6673;
  --line: #e2e5ea;
  --accent: #c2410c;
  --accent-soft: #fff2e8;
  --sun: #e8590c;
  --shadow: #2b3a55;
  --warn-bg: #fff8e1;
  --warn-line: #f0c36d;
  --danger-bg: #fdecec;
  --danger-line: #e08b8b;
  --info-bg: #eef4fd;
  --info-line: #9dbbe8;
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1e242c;
    --text: #e8ecf1;
    --text-dim: #98a2b0;
    --line: #2a323c;
    --accent: #ff8a4c;
    --accent-soft: #2a1d13;
    --sun: #ffa94d;
    --shadow: #8fa6c8;
    --warn-bg: #2a2410;
    --warn-line: #6b5a1f;
    --danger-bg: #2c1717;
    --danger-line: #6b3030;
    --info-bg: #14202e;
    --info-line: #2c4a6b;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0 16px 48px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC",
               "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

main { max-width: 1080px; margin: 0 auto; }

/* ───────────── header ───────────── */
header.site {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 0 18px;
}
header.site h1 {
  margin: 0;
  font-size: clamp(1.35rem, 4.2vw, 1.8rem);
  letter-spacing: -0.01em;
}
/* ───────────── 输入面板 ───────────── */
.panel.inputs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide { grid-column: span 2; }
.field.actions {
  grid-column: span 2;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.field label {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.field label .hint { font-weight: 400; opacity: 0.75; }

input[type="number"], input[type="date"], select {
  width: 100%;
  min-width: 0;      /* 关键：不写这句，原生日期控件会按固有宽度撑破栅格 */
  max-width: 100%;
  padding: 9px 10px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus-visible, select:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
select { background-image: none; }
/* 日期控件：外层画外观，内层只管取值。
   iOS WebKit bug 301648：date/time 输入带 padding 时，width:100% 会再叠加一次 padding，
   导致比容器宽出 2×padding；把横向 padding 还给外层即可绕开。 */
.control {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 0 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;            /* 兜底：任何残余超出都被裁掉，且内层无边框所以看不出来 */
  transition: border-color .15s, box-shadow .15s;
}
.control > input[type="date"] {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 9px 0;              /* 关键：横向 padding 必须为 0 */
  border: 0;
  border-radius: 0;
  background: transparent;
  font: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-align: left;
  outline: none;
}
.control:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.control > input[type="date"]:focus,
.control > input[type="date"]:focus-visible { outline: none; box-shadow: none; }

/* ───────────── 按钮 ───────────── */
.btn {
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: filter .15s, background .15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}
.btn.ghost:hover { background: var(--surface-2); }
.btn.icon { padding: 6px 10px; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.daynav { display: flex; gap: 6px; }

/* ───────────── 警告 ───────────── */
.warnings {
  display: none;
  margin-bottom: 14px;
  border-radius: var(--radius);
  overflow: hidden;
}
.warn-item {
  margin: 0;
  padding: 10px 14px;
  font-size: 0.88rem;
  border-left: 4px solid;
}
.warn-item.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.warn-item.danger { background: var(--danger-bg); border-color: var(--danger-line); }
.warn-item.info { background: var(--info-bg); border-color: var(--info-line); }

/* ───────────── 卡片网格 ───────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  min-width: 0;
}
.card h2 {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* 主卡 */
.card.primary {
  grid-column: span 2;
  background: linear-gradient(180deg, var(--accent-soft), var(--surface) 62%);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
}
.time-row { display: flex; align-items: baseline; gap: 10px; }
.clock {
  font-family: var(--mono);
  font-size: clamp(2.1rem, 7.6vw, 3.1rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
  color: var(--text);
}
.clock-tag {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.08em;
}
.sub-line {
  margin-top: 6px;
  color: var(--text-dim);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}
.sub-line .sep { margin: 0 6px; opacity: 0.5; }
.site-line {
  overflow-wrap: anywhere;
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  letter-spacing: 0.01em;
}
.countdown {
  margin-top: 12px;
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}
.countdown.soon { background: var(--accent); color: #fff; }
.countdown.past { color: var(--text-dim); }
.countdown.now { background: var(--accent); color: #fff; }
.fineprint {
  overflow-wrap: anywhere;
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* 键值表 */
dl.kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; }
dl.kv dt { color: var(--text-dim); font-size: 0.84rem; }
dl.kv dd {
  overflow-wrap: anywhere;
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
  font-weight: 600;
}
dl.kv dd small { font-weight: 400; color: var(--text-dim); font-size: 0.76rem; margin-left: 4px; }

/* 罗盘 */
.compass-card { display: flex; flex-direction: column; align-items: center; }
.compass-card h2 { align-self: flex-start; }
#compass { width: 100%; max-width: 250px; height: auto; display: block; }
.ring { fill: none; stroke: var(--line); stroke-width: 1.5; }
.ring.inner { stroke-dasharray: 3 5; opacity: 0.6; }
.tick { stroke: var(--line); stroke-width: 1.5; }
.tick.major { stroke: var(--text-dim); stroke-width: 2.5; }
.dir { fill: var(--text-dim); font-size: 13px; font-weight: 700; text-anchor: middle; }
.dir.n { fill: var(--accent); }
.needle-sun { stroke: var(--sun); stroke-width: 3; stroke-linecap: round; }
.sun-dot { fill: var(--sun); }
.needle-shadow { stroke: var(--shadow); stroke-width: 2.5; stroke-dasharray: 7 5; stroke-linecap: round; }
.hub { fill: var(--text-dim); }
.caption {
  overflow-wrap: anywhere;
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* 操作条 */
.actions-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}
.copy-hint { font-size: 0.82rem; color: var(--text-dim); }

/* 页脚 */
footer.site {
  max-width: 1080px;
  margin: 32px auto 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--text-dim);
}
footer.site p { margin: 6px 0; }
footer.site strong { color: var(--text); }
footer.site .muted { opacity: 0.75; }

/* ───────────── 移动端 ───────────── */
@media (max-width: 620px) {
  body {
    padding: 0 max(12px, env(safe-area-inset-right)) max(36px, env(safe-area-inset-bottom))
             max(12px, env(safe-area-inset-left));
    font-size: 14.5px;
  }
  header.site { padding: 20px 0 14px; }
  .card.primary { grid-column: span 1; }
  .field.wide, .field.actions, .field.full { grid-column: 1 / -1; }   /* 时区/日期/操作行占满整行 */
  .field.actions { justify-content: space-between; flex-wrap: wrap; }
  .panel.inputs { grid-template-columns: 1fr 1fr; gap: 10px 12px; padding: 14px; }
  .grid { grid-template-columns: 1fr; }
  .card { padding: 14px 15px 16px; }
  .card h2 { margin-bottom: 8px; }

  /* iOS Safari 聚焦输入框会自动放大页面：字号必须 ≥16px */
  input[type="number"], input[type="date"], select { font-size: 16px; padding: 9px 10px; }
  .control > input[type="date"] { font-size: 16px; padding: 9px 0; }

  /* 触控目标 ≥ 44px */
  .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .btn.icon { min-height: 38px; padding: 6px 12px; }
  .daynav { flex: 1 1 100%; justify-content: space-between; }
  .daynav .btn { flex: 1; }

  .clock { font-size: clamp(1.95rem, 9.5vw, 2.6rem); }
  .compass-card #compass { max-width: 220px; }
  .actions-bar .btn { flex: 1 1 auto; }
}

/* 极窄屏（320px 级）：压缩留白，保持两列以免滚动过长 */
@media (max-width: 359px) {
  body { padding-left: 10px; padding-right: 10px; }
  .panel.inputs { padding: 12px; gap: 8px 10px; }
  .card { padding: 12px 13px 14px; }
  .clock { font-size: 1.9rem; }
}

/* ───────────── 打印 ───────────── */
@media print {
  :root { --bg: #fff; --surface: #fff; --line: #bbb; --text: #000; --text-dim: #444; }
  body { padding: 0; }
  .panel.inputs, .actions-bar, .card.compass-card { display: none; }
  .card, .card.primary { break-inside: avoid; border: 1px solid #bbb; background: #fff; }
  .grid { grid-template-columns: 1fr 1fr; }
  footer.site { border-top: 1px solid #bbb; }
}
