:root {
  color-scheme: light;
  --bg: #f7f4ef;
  --surface: #fffaf4;
  --surface-strong: #ffffff;
  --ink: #241f21;
  --muted: #6f6762;
  --line: #e8ddd2;
  --rose: #c64f64;
  --rose-soft: #f7d9df;
  --teal: #247b73;
  --teal-soft: #d8efeb;
  --gold: #a46f15;
  --gold-soft: #f5e4bd;
  --blue: #3d6b9d;
  --blue-soft: #d9e7f5;
  --shadow: 0 18px 55px rgba(68, 48, 32, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at top left, rgba(198, 79, 100, 0.12), transparent 32rem),
    linear-gradient(180deg, #fbf7f1 0%, var(--bg) 46%, #f4efe8 100%);
  color: var(--ink);
  font-family:
    "Noto Sans TC",
    "Microsoft JhengHei",
    "PingFang TC",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.topbar h1,
.panel h2,
.cycle-summary h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 4.25rem;
  line-height: 0.95;
}

.eyebrow,
.section-label {
  margin: 0 0 6px;
  color: var(--rose);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions,
.month-actions,
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-panel {
  display: grid;
  grid-template-columns: minmax(170px, 0.38fr) minmax(0, 1fr);
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
}

.profile-current h2 {
  margin: 0;
  font-size: 1.55rem;
  overflow-wrap: anywhere;
}

.profile-controls {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(190px, 1.15fr) auto auto auto;
  gap: 10px;
  align-items: end;
}

.profile-controls button {
  white-space: nowrap;
}

.sync-panel {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.sync-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.sync-heading h2,
.sync-heading p {
  margin: 0;
}

.sync-heading p {
  max-width: 38ch;
  color: var(--muted);
  font-size: 0.88rem;
  text-align: right;
}

.sync-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 0.85fr) auto auto auto;
  gap: 10px;
  align-items: end;
}

.sync-controls button {
  white-space: nowrap;
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 244, 0.86);
  color: var(--ink);
  box-shadow: 0 8px 18px rgba(70, 49, 36, 0.08);
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

.icon-button:hover {
  transform: translateY(-1px);
  border-color: rgba(198, 79, 100, 0.45);
  background: #ffffff;
}

.icon-button span {
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.dashboard,
.workspace-grid,
.calendar-history-grid {
  display: grid;
  gap: 18px;
}

.dashboard {
  margin-bottom: 18px;
}

.cycle-hero {
  display: grid;
  grid-template-columns: minmax(220px, 0.85fr) minmax(0, 1.4fr);
  gap: 24px;
  align-items: stretch;
  min-height: 330px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, #fffaf4 0%, #ffffff 48%, #f4fbf9 100%);
  box-shadow: var(--shadow);
}

.cycle-visual {
  display: grid;
  min-height: 230px;
  place-items: center;
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(36, 123, 115, 0.08), transparent),
    repeating-linear-gradient(135deg, rgba(198, 79, 100, 0.08) 0 1px, transparent 1px 17px);
}

.cycle-ring {
  --progress: 0deg;
  display: grid;
  width: min(220px, 78vw);
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--surface-strong) 0 57%, transparent 58%),
    conic-gradient(var(--rose) var(--progress), var(--teal-soft) 0);
  box-shadow:
    inset 0 0 0 12px rgba(255, 255, 255, 0.88),
    0 18px 38px rgba(80, 42, 47, 0.18);
}

.cycle-ring span {
  display: grid;
  width: 108px;
  height: 108px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #ffffff;
  color: var(--rose);
  font-size: 2.2rem;
  font-weight: 850;
}

.cycle-summary {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
}

.cycle-summary h2 {
  font-size: 4.35rem;
  line-height: 1.02;
  max-width: 11ch;
}

.cycle-summary p:not(.section-label) {
  max-width: 64ch;
  margin: 16px 0 24px;
  color: var(--muted);
  font-size: 1.02rem;
}

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

.metric-row > div {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.76);
}

.metric-value,
.metric-label {
  display: block;
}

.metric-value {
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.metric-label {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
}

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

.insight-strip > div {
  min-width: 0;
  border: 1px solid rgba(36, 123, 115, 0.18);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: rgba(216, 239, 235, 0.42);
}

.insight-strip span,
.history-summary span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
}

.insight-strip strong,
.history-summary strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: 0.98rem;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.prediction-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.workspace-grid {
  grid-template-columns: minmax(0, 1.45fr) minmax(260px, 0.75fr);
  margin-bottom: 18px;
}

.calendar-history-grid {
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
}

.panel {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 244, 0.88);
  box-shadow: 0 12px 34px rgba(68, 48, 32, 0.08);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-heading.compact {
  align-items: center;
}

.panel h2 {
  font-size: 1.35rem;
}

.date-list {
  display: grid;
  gap: 12px;
  margin: 14px 0 0;
}

.date-list div {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 12px;
  align-items: baseline;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.date-list div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.date-list dt {
  color: var(--muted);
  font-size: 0.92rem;
}

.date-list dd {
  margin: 0;
  font-weight: 750;
}

.reaction-stack {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.reaction-stack > div {
  padding: 14px;
  border-radius: var(--radius);
  background: #ffffff;
  border: 1px solid var(--line);
}

.reaction-stack h3 {
  margin: 0 0 5px;
  font-size: 1rem;
}

.reaction-stack p {
  margin: 0;
  color: var(--muted);
}

.libido-chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.libido-chart-header strong {
  color: var(--rose);
  font-weight: 850;
  white-space: nowrap;
}

.libido-chart {
  display: block;
  width: 100%;
  min-height: 150px;
  margin-bottom: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #ffffff 0%, #fff8f9 100%);
}

.chart-grid {
  stroke: rgba(111, 103, 98, 0.18);
  stroke-width: 1;
}

.chart-axis {
  stroke: rgba(36, 31, 33, 0.32);
  stroke-width: 1.4;
}

.chart-label,
.chart-day-label,
.chart-empty {
  fill: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.chart-empty {
  fill: rgba(111, 103, 98, 0.78);
}

.chart-today-label {
  fill: var(--rose);
}

.libido-fertile-band {
  fill: rgba(36, 123, 115, 0.12);
}

.libido-pms-band {
  fill: rgba(164, 111, 21, 0.11);
}

.libido-area {
  fill: rgba(198, 79, 100, 0.14);
}

.libido-line {
  fill: none;
  stroke: var(--rose);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.libido-today-line {
  stroke: rgba(61, 107, 157, 0.76);
  stroke-dasharray: 4 4;
  stroke-width: 1.6;
}

.libido-point {
  fill: var(--blue);
  stroke: #ffffff;
  stroke-width: 2;
}

.libido-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
  margin: -1px 0 9px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.libido-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-line,
.legend-block {
  display: inline-block;
  width: 18px;
  height: 8px;
  border-radius: 999px;
}

.legend-line.libido {
  height: 3px;
  background: var(--rose);
}

.legend-line.today {
  height: 3px;
  background: repeating-linear-gradient(90deg, var(--blue) 0 5px, transparent 5px 9px);
}

.legend-block.fertile {
  background: rgba(36, 123, 115, 0.22);
}

.legend-block.pms {
  background: rgba(164, 111, 21, 0.22);
}

.entry-form,
.settings-form {
  display: grid;
  gap: 15px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label,
fieldset {
  min-width: 0;
}

label span,
legend {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  outline: 0;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

input,
select {
  height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 106px;
  resize: vertical;
  padding: 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(36, 123, 115, 0.62);
  box-shadow: 0 0 0 3px rgba(36, 123, 115, 0.12);
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.chip {
  position: relative;
}

.chip input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.chip span {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 11px;
  background: #ffffff;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
}

.chip input:checked + span {
  border-color: rgba(198, 79, 100, 0.5);
  background: var(--rose-soft);
  color: #7b2534;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 42px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 15px;
  font-weight: 800;
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled,
.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.primary-button {
  background: var(--rose);
  color: #ffffff;
}

.secondary-button {
  width: 100%;
  background: var(--teal);
  color: #ffffff;
}

.ghost-button {
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
}

.danger-button {
  border-color: rgba(198, 79, 100, 0.26);
  background: #fff;
  color: var(--rose);
}

.notice {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid rgba(164, 111, 21, 0.32);
  border-radius: var(--radius);
  background: var(--gold-soft);
}

.notice strong {
  display: block;
  margin-bottom: 5px;
}

.notice p {
  margin: 0;
  color: #6d4b13;
  font-size: 0.92rem;
}

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.82rem;
}

.calendar-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.calendar-note {
  margin: -5px 0 14px;
  color: var(--muted);
  font-size: 0.84rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-dot.actual {
  background: var(--rose);
}

.legend-dot.predicted {
  background: var(--rose-soft);
  border: 1px solid var(--rose);
}

.legend-dot.fertile {
  background: var(--teal-soft);
  border: 1px solid var(--teal);
}

.legend-dot.ovulation {
  background: var(--blue);
}

.legend-dot.pms {
  background: var(--gold-soft);
  border: 1px solid var(--gold);
}

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

.weekday,
.day-cell {
  min-width: 0;
}

.weekday {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
}

.day-cell {
  position: relative;
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  background: #ffffff;
}

.day-cell.outside {
  opacity: 0.45;
}

.day-number {
  display: inline-grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 50%;
  font-size: 0.86rem;
  font-weight: 800;
}

.day-cell.today .day-number {
  background: var(--ink);
  color: #ffffff;
}

.day-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 7px;
}

.tag {
  min-height: 18px;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 0.67rem;
  font-weight: 800;
  line-height: 1.25;
}

.tag.actual {
  background: var(--rose);
  color: #ffffff;
}

.tag.predicted {
  border: 1px solid rgba(198, 79, 100, 0.45);
  background: var(--rose-soft);
  color: #7b2534;
}

.tag.fertile {
  border: 1px solid rgba(36, 123, 115, 0.35);
  background: var(--teal-soft);
  color: #19554f;
}

.tag.ovulation {
  background: var(--blue);
  color: #ffffff;
}

.tag.pms {
  border: 1px solid rgba(164, 111, 21, 0.36);
  background: var(--gold-soft);
  color: #674608;
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: 560px;
  overflow: auto;
  padding-right: 3px;
}

.history-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.history-summary > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #ffffff;
}

.history-item {
  display: grid;
  gap: 8px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.history-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.history-item h3 {
  margin: 0;
  font-size: 1rem;
}

.history-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.mini-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.mini-tags span {
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--teal-soft);
  color: #19554f;
  font-size: 0.74rem;
  font-weight: 800;
}

.delete-entry {
  border: 0;
  background: transparent;
  color: var(--rose);
  font-size: 0.86rem;
  font-weight: 800;
}

.empty-state {
  padding: 22px;
  border: 1px dashed rgba(111, 103, 98, 0.42);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: min(360px, calc(100% - 40px));
  transform: translateY(18px);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--ink);
  color: #ffffff;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 940px) {
  .cycle-hero,
  .prediction-grid,
  .workspace-grid,
  .calendar-history-grid,
  .profile-panel {
    grid-template-columns: 1fr;
  }

  .profile-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sync-heading {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .sync-heading p {
    max-width: none;
    text-align: left;
  }

  .sync-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sync-controls label {
    grid-column: 1 / -1;
  }

  .cycle-summary h2 {
    font-size: 3.25rem;
    max-width: 100%;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 3rem;
  }

  .cycle-summary h2 {
    font-size: 2.35rem;
  }

  .cycle-hero,
  .panel {
    padding: 14px;
  }

  .profile-panel {
    gap: 10px;
    padding: 12px;
  }

  .profile-current {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
  }

  .profile-current .section-label {
    margin: 0;
  }

  .profile-current h2 {
    font-size: 1.15rem;
    text-align: right;
  }

  .profile-controls {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
  }

  .profile-controls label:nth-of-type(1),
  .profile-controls label:nth-of-type(2) {
    grid-column: span 3;
  }

  .profile-controls label span {
    margin-bottom: 4px;
    font-size: 0.78rem;
  }

  .profile-controls input,
  .profile-controls select {
    height: 40px;
    padding-inline: 10px;
  }

  .profile-controls #addProfile,
  .profile-controls #renameProfile,
  .profile-controls #deleteProfile {
    grid-column: span 2;
    min-height: 38px;
    padding-inline: 8px;
    font-size: 0.92rem;
  }

  .sync-panel {
    gap: 10px;
    padding: 12px;
  }

  .sync-heading {
    gap: 6px;
  }

  .sync-heading h2 {
    font-size: 1.15rem;
  }

  .sync-heading p {
    font-size: 0.8rem;
  }

  .sync-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .sync-controls input {
    height: 40px;
  }

  .sync-controls button {
    min-height: 38px;
    padding-inline: 8px;
    font-size: 0.9rem;
  }

  .metric-row,
  .field-grid,
  .insight-strip,
  .history-summary {
    grid-template-columns: 1fr;
  }

  .profile-controls button {
    width: 100%;
  }

  .date-list div {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .calendar {
    gap: 4px;
  }

  .day-cell {
    min-height: 58px;
    padding: 5px;
  }

  .tag {
    width: 100%;
    padding-inline: 4px;
    text-align: center;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-heading.compact {
    align-items: stretch;
  }
}
