:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --ink: #20231f;
  --muted: #687065;
  --line: #d9ddd2;
  --panel: #ffffff;
  --accent: #176b5b;
  --accent-2: #e3a72f;
  --accent-soft: #dceee9;
  --danger: #b94738;
  --shadow: 0 18px 50px rgba(36, 48, 38, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system,
    sans-serif;
  background:
    linear-gradient(120deg, rgba(23, 107, 91, 0.08), transparent 36%),
    var(--bg);
  color: var(--ink);
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

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

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 4.5rem);
  line-height: 1;
}

h2 {
  font-size: 1.1rem;
}

.date-picker,
.segmented,
.record-meta,
.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-picker {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  box-shadow: var(--shadow);
  flex-wrap: nowrap;
}

input,
select,
.unit-display {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

.unit-display {
  display: flex;
  align-items: center;
  background: #f4f5f1;
  font-weight: 900;
}

.date-picker input {
  width: 150px;
  min-width: 150px;
  border: 0;
  padding: 0 4px;
}

.icon-button,
.ghost-button,
.segmented button,
.record-meta button,
.secondary-button,
.primary-button {
  border: 0;
  cursor: pointer;
}

.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.5rem;
  line-height: 1;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.3fr repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.target-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.sync-status {
  margin: -6px 0 14px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.dev-status {
  margin: -8px 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: #f8faf6;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.dev-status[data-type="success"] {
  border-left-color: var(--accent);
  color: var(--accent);
}

.dev-status[data-type="error"] {
  border-left-color: var(--danger);
  color: var(--danger);
}

.target-strip span,
.target-strip strong {
  display: block;
}

.target-strip span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.target-strip strong {
  margin-top: 3px;
  font-size: 1.05rem;
}

.action-buttons {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.metric,
.entry-panel,
.records-panel {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  min-height: 122px;
  padding: 18px;
}

.metric span {
  color: var(--muted);
  font-size: 0.92rem;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 2rem;
}

.metric.primary {
  background: #173f37;
  color: #fff;
}

.metric.primary span {
  color: #cfe2db;
}

.progress {
  display: flex;
  height: 9px;
  margin-top: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent-2);
  transition: width 180ms ease;
}

.progress span + span {
  background: #f3c14c;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}

.entry-panel,
.records-panel {
  padding: 18px;
}

.entry-panel.settings-mode > label,
.entry-panel.settings-mode > .field-row,
.entry-panel.settings-mode > .primary-button,
.entry-panel.settings-mode > #resetDay,
.entry-panel.settings-mode > .form-status,
.entry-panel.sync-mode > label,
.entry-panel.sync-mode > .field-row,
.entry-panel.sync-mode > .primary-button,
.entry-panel.sync-mode > #resetDay,
.entry-panel.sync-mode > .form-status,
.entry-panel.sync-mode > .settings-divider,
.entry-panel.sync-mode > .custom-divider {
  display: none;
}

.entry-panel.settings-mode > .settings-divider,
.entry-panel.settings-mode > .custom-divider {
  display: none;
}

.records-panel {
  grid-column: 1 / -1;
}

.entry-panel {
  display: grid;
  gap: 16px;
}

.panel-hidden,
.entry-panel.panel-hidden,
.goal-editor.panel-hidden,
.modal-backdrop.panel-hidden,
.sync-auth.panel-hidden,
.sync-progress.panel-hidden,
.sync-ready.panel-hidden,
button.panel-hidden {
  display: none !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(20, 27, 23, 0.46);
}

.entry-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 30;
  width: min(520px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  transform: translate(-50%, -50%);
}

.icon-close {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 8px;
  background: #f4f5f1;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.4rem;
  font-weight: 900;
  line-height: 1;
}

.panel-heading,
.view-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.field-row > label {
  flex: 1;
}

.primary-button {
  min-height: 46px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.secondary-button {
  min-height: 42px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.form-status {
  min-height: 20px;
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.form-status[data-type="success"] {
  color: var(--accent);
}

.form-status[data-type="error"] {
  color: var(--danger);
}

.sync-auth,
.sync-ready,
.sync-progress {
  display: grid;
  gap: 14px;
}

.sync-ready {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f5f1;
}

.sync-ready strong,
.sync-ready span,
.sync-progress strong {
  display: block;
}

.sync-ready span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

#retrySync.panel-hidden,
#diagnoseSync.panel-hidden {
  display: none !important;
}

.sync-progress {
  place-items: center;
  padding: 26px 10px;
  text-align: center;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 5px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.ghost-button {
  border-radius: 8px;
  background: #f4f5f1;
  color: var(--danger);
  padding: 8px 10px;
  font-size: 0.86rem;
  font-weight: 800;
}

.divider {
  height: 1px;
  background: var(--line);
}

.settings-divider {
  display: none;
}

.goal-editor {
  display: grid;
  gap: 14px;
}

.entry-panel.settings-mode #settingsPanel h2 {
  display: none;
}

.segmented {
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f5f1;
}

.segmented button {
  min-width: 42px;
  height: 34px;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segmented button.active {
  background: var(--accent);
  color: #fff;
}

.view-title {
  margin: 18px 0 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.view-title span {
  color: var(--muted);
  font-weight: 700;
}

.content-area {
  min-height: 360px;
}

.section-title {
  margin: 20px 0 2px;
  color: var(--muted);
  font-size: 0.92rem;
}

.basic-list {
  display: grid;
  gap: 12px;
}

.basic-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.basic-card.achieved,
.calendar-cell.achieved,
.bar-row.achieved {
  border: 3px solid var(--accent-2);
  box-shadow: 0 0 0 4px rgba(227, 167, 47, 0.14);
}

.basic-heading,
.basic-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.basic-heading strong,
.basic-heading span {
  display: block;
}

.basic-heading span,
.basic-meta {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.basic-heading em {
  color: var(--accent);
  font-style: normal;
  font-weight: 900;
  text-align: right;
  white-space: nowrap;
}

.step-meter {
  position: relative;
  display: flex;
  height: 18px;
  border: 1px solid #d8ded6;
  overflow: hidden;
  border-radius: 999px;
  background: #edf0e8;
}

.step-meter::after {
  position: absolute;
  top: -2px;
  bottom: -2px;
  left: calc(100% - 2px);
  width: 2px;
  background: rgba(32, 35, 31, 0.42);
  content: "";
}

.step-fill,
.step-over {
  display: block;
  height: 100%;
}

.step-fill {
  background: var(--accent);
}

.step-over {
  background: var(--accent-2);
}

.tally-mark {
  display: flex;
  min-height: 54px;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  border-radius: 8px;
  background: #f4f5f1;
  color: var(--ink);
  padding: 8px 10px;
}

.summary-tally {
  min-height: 46px;
}

.summary-tally .zheng {
  width: 34px;
  height: 34px;
  margin-right: 3px;
  vertical-align: middle;
}

.zheng {
  display: inline-block;
  width: 42px;
  height: 46px;
}

.zheng path {
  fill: none;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.zheng path.goal {
  stroke: var(--accent);
}

.zheng path.over {
  stroke: var(--accent-2);
}

.tiny-tally {
  display: flex;
  min-height: 30px;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.tiny-tally .zheng {
  width: 30px;
  height: 30px;
}

.tiny-tally .zheng path {
  stroke-width: 5;
}

.goal-list {
  display: grid;
  gap: 10px;
}

.goal-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) 1.4fr 48px;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.goal-row strong,
.goal-row span {
  display: block;
}

.goal-row span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.goal-row em {
  color: var(--accent);
  font-style: normal;
  font-weight: 900;
  text-align: right;
}

.mini-progress {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf0e8;
}

.mini-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent-2);
}

.record {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.record strong,
.record span {
  display: block;
}

.record [data-note] {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.88rem;
}

.record-meta span {
  white-space: nowrap;
  color: var(--muted);
  font-weight: 800;
}

.record-meta input {
  width: 92px;
  min-height: 34px;
  padding: 0 8px;
  text-align: right;
  font-weight: 900;
}

.record-meta button {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #f7e4df;
  color: var(--danger);
  font-size: 1.1rem;
  font-weight: 900;
}

.empty {
  display: grid;
  min-height: 300px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.bars {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: 84px 1fr 72px minmax(42px, auto);
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
}

.bar-track {
  display: flex;
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf0e8;
}

.bar-track span {
  display: block;
  height: 100%;
}

.bar-track span:first-child {
  border-radius: 999px 0 0 999px;
  background: var(--accent);
}

.bar-track span:last-child {
  border-radius: 0 999px 999px 0;
  background: var(--accent-2);
}

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

.month-layout {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) 112px;
  gap: 10px;
  align-items: stretch;
}

.step-ledger {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ledger-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1;
}

.step-ledger.plus .ledger-icon {
  background: var(--accent);
}

.step-ledger.minus .ledger-icon {
  background: var(--danger);
}

.step-ledger strong {
  font-size: 1.5rem;
}

.ledger-tally {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.ledger-tally .zheng {
  width: 32px;
  height: 32px;
}

.step-ledger.minus .zheng path.goal {
  stroke: var(--danger);
}

.calendar-cell {
  min-height: 126px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.calendar-cell.weekend {
  background: #dff0f8;
}

.calendar-cell.muted {
  background: #f5f5f1;
  color: #9aa095;
}

.calendar-cell.weekend.muted {
  background: #d7e8ef;
}

.calendar-cell strong {
  display: block;
  margin-bottom: 8px;
}

.calendar-cell span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.calendar-step-meter {
  display: flex;
  height: 9px;
  margin-top: 8px;
  border: 1px solid #d8ded6;
  overflow: hidden;
  border-radius: 999px;
  background: #edf0e8;
}

.calendar-step-meter i {
  display: block;
  height: 100%;
}

.calendar-step-meter .step-fill {
  background: var(--accent);
}

.calendar-step-meter .step-over {
  background: var(--accent-2);
}

@media (max-width: 860px) {
  .topbar,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .date-picker {
    width: 100%;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 42px;
    justify-content: space-between;
  }

  .date-picker input {
    width: 100%;
    min-width: 0;
    text-align: center;
  }

  .summary-grid,
  .workspace {
    grid-template-columns: 1fr;
  }

  .target-strip,
  .action-buttons {
    align-items: stretch;
    flex-direction: column;
  }

  .metric {
    min-height: 104px;
  }

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

  .calendar {
    gap: 5px;
  }

  .month-layout {
    grid-template-columns: 1fr;
  }

  .step-ledger {
    min-height: auto;
    align-items: flex-start;
  }

  .ledger-tally {
    justify-content: flex-start;
  }

  .calendar-cell {
    min-height: 108px;
    padding: 7px;
  }

  .tiny-tally .zheng {
    width: 24px;
    height: 24px;
  }

  .bar-row {
    grid-template-columns: 58px 1fr 58px;
  }

  .bar-row .tiny-tally {
    grid-column: 2 / -1;
  }

  .goal-row {
    grid-template-columns: 1fr;
  }

  .goal-row em {
    text-align: left;
  }

  .basic-heading,
  .basic-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .basic-heading em {
    text-align: left;
  }
}

@media (max-width: 560px) {
  .app {
    width: min(100% - 20px, 1180px);
    padding: 16px 0;
  }

  h1 {
    font-size: 2.5rem;
  }

  .date-picker {
    grid-template-columns: 38px minmax(180px, 1fr) 38px;
    overflow-x: auto;
  }

  .date-picker input {
    min-width: 180px;
    padding: 0 10px;
  }

  .summary-grid {
    gap: 10px;
  }

  .target-strip,
  .metric,
  .records-panel,
  .entry-panel {
    padding: 14px;
  }

  .sync-status,
  .dev-status {
    font-size: 0.8rem;
    line-height: 1.45;
  }

  .calendar {
    grid-template-columns: repeat(7, minmax(42px, 1fr));
    overflow-x: auto;
  }

  .calendar-cell {
    min-width: 42px;
    min-height: 94px;
    padding: 6px;
  }
}
