:root {
  color-scheme: light;
  --mist: #eaf3ef;
  --paper: #fbfaf6;
  --ink: #17201d;
  --muted: #64716c;
  --teal: #197c74;
  --teal-soft: #d7eee9;
  --amber: #d68b16;
  --amber-soft: #fff0cf;
  --coral: #d95f4f;
  --coral-soft: #ffe2dc;
  --line: rgba(25, 124, 116, 0.28);
  --shadow: 0 24px 70px rgba(34, 56, 51, 0.14);
  --radius: 8px;
  font-family:
    -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(140deg, rgba(251, 250, 246, 0.88), rgba(234, 243, 239, 0.92)),
    repeating-linear-gradient(
      90deg,
      rgba(25, 124, 116, 0.05) 0,
      rgba(25, 124, 116, 0.05) 1px,
      transparent 1px,
      transparent 38px
    );
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 0 max(28px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(280px, 0.84fr) minmax(360px, 1.16fr);
  align-items: center;
  gap: 28px;
}

.control-panel,
.ruler-panel {
  position: relative;
  border: 1px solid rgba(23, 32, 29, 0.08);
  border-radius: var(--radius);
  background: rgba(251, 250, 246, 0.84);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.control-panel {
  padding: clamp(26px, 5vw, 48px);
}

.ruler-panel {
  padding: clamp(22px, 4vw, 38px);
  overflow: hidden;
}

.ruler-panel::before {
  position: absolute;
  inset: 24px auto 24px 31px;
  width: 2px;
  border-radius: 99px;
  background: linear-gradient(var(--line), rgba(214, 139, 22, 0.6), rgba(217, 95, 79, 0.26));
  content: "";
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--teal);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 9.5em;
  margin-bottom: 18px;
  font-family: "Songti SC", "STSong", "Noto Serif SC", serif;
  font-size: clamp(2.35rem, 6.4vw, 4.85rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0;
}

.intro {
  max-width: 32em;
  margin-bottom: 28px;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.75;
}

.time-form {
  margin: 0;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}

.time-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: end;
  gap: 10px;
}

.time-fields label {
  min-width: 0;
}

.time-fields span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.time-fields input {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(25, 124, 116, 0.22);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: clamp(2.2rem, 9vw, 4.4rem);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  line-height: 1;
  padding: 14px 10px 16px;
  text-align: center;
  appearance: textfield;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.8);
}

.time-fields input::-webkit-outer-spin-button,
.time-fields input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.time-fields input:focus {
  border-color: var(--teal);
  outline: 3px solid rgba(25, 124, 116, 0.18);
}

.time-separator {
  align-self: center;
  margin-top: 24px;
  color: var(--teal);
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: clamp(2rem, 8vw, 4rem);
  font-weight: 900;
}

.form-error {
  min-height: 1.4em;
  margin: 12px 0 0;
  color: var(--coral);
  font-size: 0.94rem;
  font-weight: 700;
}

.summary-strip {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 20px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--teal-soft);
  color: #29544f;
}

.summary-strip strong {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

.ruler-heading {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-left: 22px;
  margin-bottom: 24px;
}

.ruler-heading h2,
.advice-panel h2 {
  margin-bottom: 0;
  font-family: "Songti SC", "STSong", "Noto Serif SC", serif;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  letter-spacing: 0;
}

.ruler-heading > p {
  align-self: end;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.sleep-ruler {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 10px;
  margin: 0 0 28px;
  padding: 0;
  list-style: none;
}

.cycle-card {
  --node-color: var(--teal);
  position: relative;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 14px;
  min-height: 82px;
  padding: 14px 14px 14px 0;
}

.cycle-card::before {
  position: absolute;
  top: 34px;
  left: 23px;
  width: 18px;
  height: 18px;
  border: 4px solid var(--paper);
  border-radius: 50%;
  background: var(--node-color);
  box-shadow: 0 0 0 1px rgba(23, 32, 29, 0.08);
  content: "";
  z-index: 2;
}

.cycle-card.preferred {
  --node-color: var(--amber);
}

.cycle-card.preferred::before {
  box-shadow:
    0 0 0 1px rgba(23, 32, 29, 0.1),
    0 0 0 10px rgba(214, 139, 22, 0.14),
    0 12px 28px rgba(214, 139, 22, 0.28);
}

.cycle-card.caution {
  --node-color: var(--coral);
  opacity: 0.84;
}

.cycle-index {
  position: absolute;
  top: 9px;
  left: 32px;
  transform: translateX(-50%);
  z-index: 2;
  background: var(--paper);
  padding: 2px 6px;
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(25, 124, 116, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--teal);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
}

.cycle-card.preferred .cycle-index {
  color: #a26100;
  box-shadow: 0 0 0 1px rgba(214, 139, 22, 0.25);
}

.cycle-card.caution .cycle-index {
  color: #a73425;
  box-shadow: 0 0 0 1px rgba(217, 95, 79, 0.2);
}

.cycle-body {
  grid-column: 2;
  min-width: 0;
  border: 1px solid rgba(23, 32, 29, 0.08);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  padding: 13px 14px;
}

.cycle-card.preferred .cycle-body {
  border-color: rgba(214, 139, 22, 0.3);
  background: var(--amber-soft);
}

.cycle-card.caution .cycle-body {
  border-color: rgba(217, 95, 79, 0.26);
  background: var(--coral-soft);
}

.cycle-topline {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}

.cycle-time {
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: clamp(2rem, 6vw, 3.35rem);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  line-height: 0.95;
}

.cycle-meta {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  white-space: nowrap;
}

.cycle-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 10px 0 4px;
  font-size: 1.02rem;
  font-weight: 800;
}

.badge {
  border-radius: 999px;
  background: var(--teal-soft);
  color: #1e6861;
  padding: 3px 8px;
  font-size: 0.78rem;
  font-weight: 900;
}

.preferred .badge {
  background: #ffffff;
  color: #a26100;
}

.caution .badge {
  background: #ffffff;
  color: #a73425;
}

.cycle-detail {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.advice-panel {
  position: relative;
  z-index: 1;
  margin-left: 22px;
}

.advice-panel h2 {
  margin-bottom: 14px;
}

.advice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.advice-grid article {
  min-width: 0;
  border: 1px solid rgba(23, 32, 29, 0.08);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.66);
  padding: 13px;
}

.advice-grid span {
  color: var(--teal);
  font-size: 0.9rem;
  font-weight: 900;
}

.advice-grid p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.55;
}

.advice-featured {
  background: var(--amber-soft) !important;
}

.advice-featured span {
  color: #a26100;
}

.advice-caution {
  background: var(--coral-soft) !important;
}

.advice-caution span {
  color: #a73425;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 24px, 560px);
    min-height: auto;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 14px;
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .control-panel,
  .ruler-panel {
    box-shadow: 0 18px 44px rgba(34, 56, 51, 0.12);
  }

  .control-panel {
    padding: 22px;
  }

  .ruler-panel {
    padding: 20px 14px 22px;
  }

  .ruler-panel::before {
    inset: 20px auto 22px 22px;
  }

  h1 {
    max-width: 10em;
  }

  .intro {
    margin-bottom: 20px;
    font-size: 0.96rem;
  }

  .ruler-heading,
  .advice-panel {
    margin-left: 26px;
  }

  .ruler-heading {
    display: block;
    margin-bottom: 14px;
  }

  .ruler-heading > p {
    margin-top: 6px;
  }

  .cycle-card {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 10px;
    min-height: 76px;
  }

  .cycle-card::before {
    left: 14px;
  }

  .cycle-index {
    width: auto;
    left: 23px;
    top: 6px;
  }

  .cycle-body {
    padding: 12px;
  }

  .advice-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 390px) {
  .app-shell {
    width: min(100% - 16px, 560px);
  }

  .control-panel {
    padding: 18px;
  }

  .time-fields {
    gap: 7px;
  }

  .cycle-topline {
    display: block;
  }

  .cycle-meta {
    display: block;
    margin-top: 4px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .cycle-card {
    animation: rise-in 520ms ease both;
    animation-delay: calc(var(--cycle-order) * 45ms);
  }

  @keyframes rise-in {
    from {
      opacity: 0;
      transform: translateY(10px);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}
