/* 悔笺 · 台历仪 — tokens from design plan */
:root {
  --paper: #f2ede4;
  --ink: #1a1f26;
  --maple: #c45c3a;
  --rule: #c9c0b2;
  --steel: #4a5568;
  --moss: #3d6b5a;
  --paper-deep: #ebe4d8;
  --stamp-ink: #8b3a2a;
  --shadow: rgba(26, 31, 38, 0.08);

  --font-display: "STKaiti", "KaiTi", "Kaiti SC", "楷体", Georgia, serif;
  --font-body: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  --font-data: "Cascadia Code", "SF Mono", Consolas, "Courier New", monospace;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --max-w: 920px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  background-color: var(--paper);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(196, 92, 58, 0.06), transparent 55%),
    linear-gradient(180deg, var(--paper) 0%, var(--paper-deep) 100%);
}

.desk {
  width: min(100% - 2rem, var(--max-w));
  margin: 0 auto;
  padding: var(--space-6) 0 var(--space-7);
}

/* —— Hero —— */
.hero {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-5);
}

.hero-copy {
  flex: 1 1 260px;
  min-width: 0;
}

.eyebrow {
  margin: 0 0 var(--space-2);
  font-family: var(--font-data);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: var(--steel);
  text-transform: uppercase;
}

.name {
  margin: 0 0 var(--space-3);
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 6vw, 3.6rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: 0.08em;
  color: var(--ink);
}

.signature {
  margin: 0;
  max-width: 22em;
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 2.4vw, 1.25rem);
  line-height: 1.5;
  color: var(--moss);
}

.sig-em {
  color: var(--moss);
  border-bottom: 2px solid rgba(61, 107, 90, 0.35);
  padding-bottom: 1px;
}

/* —— Clock —— */
.clock-block {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.clock-toggle {
  appearance: none;
  border: 0;
  background: transparent;
  padding: var(--space-2);
  cursor: pointer;
  border-radius: 8px;
  transition: transform 0.15s ease;
}

.clock-toggle:hover {
  transform: scale(1.02);
}

.clock-toggle:focus-visible {
  outline: 2px solid var(--maple);
  outline-offset: 4px;
}

.clock-stage {
  position: relative;
  width: 148px;
  height: 148px;
}

/* 互斥叠放：任一时刻只显示一种时钟（visibility 即时切换，避免淡出拖尾叠影） */
.clock-view {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(0.94);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease;
}

.clock-view.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(1);
  transition:
    opacity 0.26s ease,
    transform 0.26s ease;
}

.clock-view.is-leaving {
  opacity: 0;
  visibility: visible;
  pointer-events: none;
  transform: scale(1.04);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.clock-analog svg {
  display: block;
  width: 140px;
  height: 140px;
}

.clock-bezel {
  fill: var(--ink);
  stroke: var(--steel);
  stroke-width: 3;
}

.clock-dial {
  fill: var(--paper);
}

.clock-marks .mark {
  stroke-linecap: round;
}

.clock-marks .major {
  stroke: var(--ink);
  stroke-width: 3;
}

.clock-marks .minor {
  stroke: var(--steel);
  stroke-width: 2;
}

/* 指针：绕 viewBox 中心 80,80 旋转，CSS transform 独占，避免与 SVG transform 打架 */
.hand {
  transform-box: view-box;
  transform-origin: 80px 80px;
  will-change: transform;
}

.hand line {
  stroke-linecap: round;
}

.hand.hour line {
  stroke: var(--ink);
  stroke-width: 4.5;
}

.hand.minute line {
  stroke: var(--ink);
  stroke-width: 3;
}

.hand.second line {
  stroke: var(--maple);
  stroke-width: 1.6;
}

.clock-hub {
  fill: var(--maple);
}

/* 数字钟：无框无底，只显示文字 */
.clock-digital {
  background: transparent;
  border: 0;
  box-shadow: none;
}

.digital-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  font-family: var(--font-data);
}

.digital-time {
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  line-height: 1.1;
}

.digital-date {
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  color: var(--steel);
}

.clock-hint {
  margin: 0;
  font-family: var(--font-data);
  font-size: 0.7rem;
  color: var(--steel);
}

/* —— Rule —— */
.almanac-rule {
  height: 0;
  border: 0;
  border-top: 1px solid var(--rule);
  margin: var(--space-2) 0 var(--space-6);
  position: relative;
}

.almanac-rule::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 4px;
  border-top: 1px dashed rgba(201, 192, 178, 0.7);
}

/* —— Sections —— */
.section {
  margin-bottom: var(--space-6);
  padding: var(--space-5);
  background: rgba(255, 253, 248, 0.72);
  border: 1px solid var(--rule);
  box-shadow: 0 1px 0 var(--shadow), 0 10px 24px -18px var(--shadow);
}

.section:nth-child(even) .section-head .stamp {
  transform: rotate(-0.6deg);
}

.section:nth-child(odd) .section-head .stamp {
  transform: rotate(0.5deg);
}

.section-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.stamp {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  background: var(--stamp-ink);
  color: var(--paper);
  font-family: var(--font-data);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  border: 1px solid rgba(26, 31, 38, 0.25);
  box-shadow: inset 0 0 0 1px rgba(242, 237, 228, 0.15);
  flex-shrink: 0;
}

.section-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink);
}

.section-desc {
  margin: 0 0 var(--space-4);
  color: var(--steel);
  font-size: 0.95rem;
}

.section-desc .note {
  display: inline-block;
  margin-top: 0.25rem;
  font-size: 0.85rem;
  color: var(--maple);
}

.info-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.info-row .section-desc {
  margin: 0;
  flex: 1 1 200px;
}

/* —— Buttons —— */
.btn-stamp {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.65rem 1.25rem;
  background: var(--maple);
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid rgba(26, 31, 38, 0.2);
  box-shadow: 2px 2px 0 rgba(26, 31, 38, 0.12);
  transition: transform 0.12s ease, background-color 0.12s ease, box-shadow 0.12s ease;
}

.btn-stamp:hover {
  background: #a84a2e;
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 rgba(26, 31, 38, 0.14);
}

.btn-stamp:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.btn-stamp:active {
  transform: translate(0, 0);
  box-shadow: 1px 1px 0 rgba(26, 31, 38, 0.1);
}

.btn-small {
  min-height: 40px;
  padding: 0.45rem 0.9rem;
  font-size: 0.88rem;
}

.btn-ghost {
  min-height: 40px;
  padding: 0.45rem 0.85rem;
  background: transparent;
  color: var(--steel);
  font-family: var(--font-body);
  font-size: 0.85rem;
  border: 1px solid var(--rule);
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}

.btn-ghost:hover {
  color: var(--maple);
  border-color: var(--maple);
}

.btn-ghost:focus-visible {
  outline: 2px solid var(--maple);
  outline-offset: 2px;
}

/* —— Module grid (02) —— */
.module-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-3);
}

.module-link {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.25rem;
  min-height: 88px;
  padding: var(--space-3);
  text-decoration: none;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  transition: border-color 0.12s ease, background-color 0.12s ease, transform 0.12s ease;
}

.module-link:hover {
  border-color: var(--maple);
  background: #fffaf3;
  transform: translateY(-2px);
}

.module-link:focus-visible {
  outline: 2px solid var(--maple);
  outline-offset: 2px;
}

.module-name {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.module-meta {
  font-family: var(--font-data);
  font-size: 0.72rem;
  color: var(--steel);
  letter-spacing: 0.04em;
}

/* —— Music (03) —— */
.chart-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.chart-tab {
  min-height: 40px;
  padding: 0.4rem 0.9rem;
  background: transparent;
  color: var(--steel);
  font-family: var(--font-body);
  font-size: 0.88rem;
  border: 1px solid var(--rule);
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.chart-tab:hover {
  border-color: var(--maple);
  color: var(--maple);
}

.chart-tab.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.chart-tab:focus-visible {
  outline: 2px solid var(--maple);
  outline-offset: 2px;
}

.playlist-form {
  margin-bottom: var(--space-4);
}

.playlist-form label {
  display: block;
  margin-bottom: var(--space-2);
  font-family: var(--font-data);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  color: var(--steel);
}

.playlist-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

#playlist-input {
  flex: 1 1 160px;
  min-height: 40px;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-data);
  font-size: 0.95rem;
}

#playlist-input:focus {
  outline: 2px solid var(--maple);
  outline-offset: 1px;
  border-color: var(--maple);
}

.playlist-hint {
  margin: var(--space-2) 0 0;
  font-size: 0.82rem;
  color: var(--steel);
}

.playlist-hint.is-ok {
  color: var(--moss);
}

.playlist-hint.is-err {
  color: var(--maple);
}

.player-frame {
  border: 1px solid var(--rule);
  background: var(--ink);
  overflow: hidden;
}

.player-frame iframe {
  display: block;
  width: 100%;
  height: 430px;
  border: 0;
  background: var(--ink);
}

/* —— Setup (04) —— */
.setup-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: var(--space-2);
}

.setup-stamp {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0.55rem 0.65rem;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  font-family: var(--font-data);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.setup-stamp:nth-child(3n + 1) {
  border-top: 3px solid var(--maple);
}

.setup-stamp:nth-child(3n + 2) {
  border-top: 3px solid var(--steel);
}

.setup-stamp:nth-child(3n) {
  border-top: 3px solid var(--moss);
}

.setup-stamp:hover {
  background: #fffaf3;
  border-color: var(--maple);
  color: var(--stamp-ink);
}

.setup-stamp:focus-visible {
  outline: 2px solid var(--maple);
  outline-offset: 2px;
}

/* —— Footer —— */
.footer {
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--rule);
  text-align: center;
}

.footer p {
  margin: 0;
  font-family: var(--font-data);
  font-size: 0.75rem;
  color: var(--steel);
  letter-spacing: 0.04em;
}

/* —— Reduced motion —— */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .clock-toggle,
  .btn-stamp,
  .module-link,
  .chart-tab,
  .setup-stamp,
  .btn-ghost,
  .clock-view,
  .clock-view.is-active,
  .clock-view.is-leaving {
    transition: none;
  }

  .clock-toggle:hover,
  .btn-stamp:hover,
  .module-link:hover {
    transform: none;
  }

  .clock-view.is-leaving {
    visibility: hidden;
  }
}

/* —— Narrow —— */
@media (max-width: 560px) {
  .desk {
    width: min(100% - 1.25rem, var(--max-w));
    padding-top: var(--space-5);
  }

  .section {
    padding: var(--space-4);
  }

  .hero {
    flex-direction: column;
    align-items: stretch;
  }

  .clock-block {
    align-items: flex-start;
  }

  .info-row {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-stamp {
    width: 100%;
  }

  .player-frame iframe {
    height: 360px;
  }
}
