:root {
  color-scheme: light;
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-muted: #eef1ed;
  --ink: #18201c;
  --muted: #647069;
  --line: #d7ddd8;
  --line-strong: #bbc5bd;
  --accent: #157347;
  --accent-dark: #0d5634;
  --accent-soft: #e3f3e9;
  --signal: #2667a8;
  --signal-soft: #e9f1f9;
  --danger: #b32d27;
  --danger-soft: #faecea;
  --warning: #8a5a00;
  --shadow: 0 18px 50px rgba(27, 43, 34, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, #edf2ee 0, var(--bg) 260px, var(--bg) 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding-bottom: 64px;
}

.topbar {
  display: flex;
  min-height: 70px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(24, 32, 28, 0.12);
}

.brand {
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
  text-decoration: none;
}

.session-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-label {
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-view {
  display: grid;
  min-height: calc(100vh - 140px);
  grid-template-columns: minmax(0, 1fr) minmax(340px, 440px);
  align-items: center;
  gap: 9vw;
  padding: 60px 5vw;
}

.auth-intro h1,
.dashboard-heading h1 {
  margin: 4px 0 14px;
  font-size: 5.2rem;
  font-weight: 760;
  line-height: 0.96;
  letter-spacing: 0;
}

.auth-intro p:last-child {
  max-width: 480px;
  margin: 0;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.7;
}

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

.auth-panel {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-tabs {
  margin-bottom: 26px;
}

.stack-form {
  display: grid;
  gap: 17px;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

label > span {
  color: #3f4b44;
  font-size: 0.82rem;
  font-weight: 680;
}

input,
select {
  width: 100%;
  height: 44px;
  min-width: 0;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  outline: 0;
  background: var(--surface);
  color: var(--ink);
  letter-spacing: 0;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(21, 115, 71, 0.13);
}

input[readonly] {
  border-color: var(--line);
  background: var(--surface-muted);
  color: var(--muted);
}

.two-column-form,
.entry-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-weight: 720;
  letter-spacing: 0;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

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

.button-primary:hover {
  background: var(--accent-dark);
}

.button-secondary {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.button-secondary:hover,
.button-quiet:hover {
  background: var(--surface-muted);
}

.button-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.button-danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.button-danger:hover {
  background: #91231e;
}

.button-small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.82rem;
}

.button-block {
  width: 100%;
}

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

.form-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.form-status.is-error {
  color: var(--danger);
}

.form-status.is-success {
  color: var(--accent);
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
}

.segment {
  min-height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 720;
  white-space: nowrap;
}

.segment.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(24, 32, 28, 0.1);
}

.segmented.compact .segment {
  min-width: 58px;
  min-height: 32px;
  padding: 0 12px;
}

.dashboard-view {
  padding-top: 40px;
}

.dashboard-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: 36px;
}

.dashboard-heading h1 {
  margin: 2px 0 0;
  font-size: 4.4rem;
}

.main-tabs {
  display: flex;
  gap: 4px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--line-strong);
}

.main-tab {
  min-height: 42px;
  padding: 0 17px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 720;
  white-space: nowrap;
}

.main-tab.is-active {
  border-bottom-color: var(--accent);
  color: var(--ink);
}

.page-view {
  animation: page-in 170ms ease-out;
}

@keyframes page-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-toolbar,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-toolbar {
  margin-bottom: 20px;
}

.page-toolbar h2,
.panel-head h3,
.modal-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.page-toolbar h2 {
  font-size: 1.55rem;
}

.panel-head h3 {
  font-size: 1rem;
}

.muted,
.subtle {
  color: var(--muted);
}

.muted {
  margin: 5px 0 0;
  font-size: 0.88rem;
}

.subtle {
  font-size: 0.78rem;
  font-weight: 500;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.metric-item {
  min-width: 0;
  padding: 20px 22px;
  border-right: 1px solid var(--line);
}

.metric-item:last-child {
  border-right: 0;
}

.metric-item span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.78rem;
}

.metric-item strong {
  display: block;
  overflow: hidden;
  font-size: 1.65rem;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-value-row {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 10px;
}

.metric-value-row small {
  flex: 0 0 auto;
  color: var(--signal);
  font-size: 0.82rem;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.metric-item strong.is-good {
  color: var(--accent);
}

.metric-item strong.is-bad {
  color: var(--danger);
}

.records-workspace {
  display: grid;
  grid-template-columns: minmax(310px, 0.82fr) minmax(420px, 1.18fr);
  gap: 16px;
  margin-top: 16px;
}

.entry-panel,
.chart-panel,
.history-section,
.account-section,
.unranked-section {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.entry-panel {
  display: grid;
  align-content: start;
  gap: 16px;
  padding: 20px;
}

.optional-details {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.optional-details summary {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #3f4b44;
  font-size: 0.84rem;
  font-weight: 700;
  list-style-position: inside;
  user-select: none;
}

.optional-details summary::marker {
  color: var(--muted);
}

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

.measurement-grid input {
  height: 40px;
}

.chart-panel {
  min-width: 0;
  padding: 20px;
}

.trend-chart {
  display: block;
  width: 100%;
  height: auto;
  min-height: 250px;
  margin-top: 8px;
  overflow: visible;
}

.chart-grid {
  stroke: #e4e8e5;
  stroke-width: 1;
}

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

.chart-area {
  fill: var(--signal-soft);
  opacity: 0.7;
}

.chart-dot {
  fill: var(--surface);
  stroke: var(--signal);
  stroke-width: 2;
}

.chart-label,
.chart-empty {
  fill: var(--muted);
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0;
}

.chart-empty {
  font-size: 15px;
  text-anchor: middle;
}

.history-section {
  margin-top: 16px;
  overflow: hidden;
}

.history-section > .panel-head,
.unranked-section > .panel-head,
.account-section > .panel-head {
  min-height: 56px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
}

.history-list:empty::after,
.leaderboard-list:empty::after {
  display: block;
  padding: 42px 20px;
  color: var(--muted);
  text-align: center;
  content: "暂无记录";
}

.record-row {
  display: grid;
  min-height: 68px;
  grid-template-columns: 120px minmax(110px, 0.55fr) minmax(180px, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 11px 20px;
  border-bottom: 1px solid var(--line);
}

.record-row:last-child {
  border-bottom: 0;
}

.record-date,
.record-weight,
.rank-number,
.rank-result {
  font-variant-numeric: tabular-nums;
}

.record-date {
  color: #3f4b44;
  font-size: 0.86rem;
}

.record-weight {
  font-size: 1.05rem;
  font-weight: 760;
}

.record-note {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.86rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-actions {
  display: flex;
  gap: 4px;
}

.text-button {
  min-height: 32px;
  padding: 0 9px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--signal);
  font-size: 0.8rem;
  font-weight: 700;
}

.text-button:hover {
  background: var(--signal-soft);
}

.text-button.danger-text {
  color: var(--danger);
}

.read-only-badge {
  padding: 4px 7px;
  border-radius: 4px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.leaderboard-toolbar {
  margin-bottom: 12px;
}

.leaderboard-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  padding: 16px 0 22px;
  border-bottom: 1px solid var(--line);
}

.custom-range {
  display: flex;
  align-items: end;
  gap: 8px;
}

.custom-range label {
  width: 148px;
}

.custom-range input {
  height: 42px;
}

.ranking-metric {
  margin-left: auto;
}

#leaderboardStatus {
  margin: 14px 0 0;
}

.leaderboard-list {
  overflow: hidden;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.leaderboard-row {
  display: grid;
  min-height: 78px;
  grid-template-columns: 64px minmax(150px, 1fr) minmax(150px, 0.8fr) minmax(130px, 0.5fr);
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
}

.leaderboard-row:last-child {
  border-bottom: 0;
}

.leaderboard-row.is-me {
  background: var(--accent-soft);
  box-shadow: inset 4px 0 var(--accent);
}

.rank-number {
  color: var(--muted);
  font-size: 1.15rem;
  font-weight: 800;
}

.rank-person {
  min-width: 0;
}

.rank-person strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-person span,
.rank-dates,
.rank-secondary {
  color: var(--muted);
  font-size: 0.78rem;
}

.rank-result {
  color: var(--accent);
  font-size: 1.25rem;
  font-weight: 800;
  text-align: right;
}

.rank-result.is-gain {
  color: var(--danger);
}

.rank-secondary {
  display: block;
  margin-top: 3px;
  text-align: right;
}

.unranked-section {
  margin-top: 16px;
}

.unranked-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.unranked-item {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  color: #3f4b44;
  font-size: 0.86rem;
}

.unranked-item:nth-child(odd) {
  border-right: 1px solid var(--line);
}

.unranked-item span:last-child {
  color: var(--muted);
  font-size: 0.76rem;
  text-align: right;
}

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

.account-section .stack-form {
  padding: 20px;
}

.height-field {
  display: grid;
  gap: 7px;
}

.field-label {
  color: #3f4b44;
  font-size: 0.82rem;
  font-weight: 680;
}

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

.data-section {
  grid-column: 1 / -1;
}

.data-actions {
  display: flex;
  min-height: 86px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.data-actions div {
  display: grid;
  gap: 5px;
}

.data-actions span {
  color: var(--muted);
  font-size: 0.8rem;
}

.danger-row {
  border-bottom: 0;
  background: #fffafa;
}

.data-section > .form-status {
  padding: 0 20px;
}

.modal {
  width: min(720px, calc(100% - 28px));
  max-height: min(760px, calc(100vh - 30px));
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 28px 90px rgba(15, 30, 22, 0.25);
}

.modal::backdrop {
  background: rgba(18, 29, 23, 0.48);
}

.modal-shell {
  display: grid;
  gap: 16px;
  padding: 24px;
}

.modal-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
}

.modal-head h2 {
  margin-top: 4px;
  font-size: 1.35rem;
}

.icon-button {
  display: inline-flex;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 1.45rem;
  line-height: 1;
}

.batch-rows {
  display: grid;
  gap: 8px;
}

.batch-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(110px, 0.75fr) 74px minmax(110px, 1fr) 34px;
  align-items: end;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.batch-row input,
.batch-row select {
  height: 40px;
}

.remove-batch-button {
  width: 34px;
  height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: 1.25rem;
}

.modal-actions {
  justify-content: flex-end;
  padding-top: 4px;
}

.delete-shell {
  width: 100%;
}

.delete-warning {
  padding: 13px 14px;
  border-left: 4px solid var(--danger);
  background: var(--danger-soft);
  color: #72201c;
  font-size: 0.86rem;
  line-height: 1.55;
}

.danger-text {
  color: var(--danger) !important;
}

.confirm-check {
  display: flex;
  align-items: start;
  gap: 10px;
  padding: 12px;
  border: 1px solid #e8bbb7;
  border-radius: 5px;
  background: #fffafa;
}

.confirm-check input {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  margin: 1px 0 0;
}

.confirm-check span {
  font-size: 0.84rem;
  line-height: 1.45;
}

@media (max-width: 900px) {
  .auth-view {
    grid-template-columns: 1fr;
    gap: 34px;
    padding: 48px 4vw;
  }

  .auth-intro h1 {
    font-size: 3.8rem;
  }

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

  .ranking-metric {
    margin-left: 0;
  }

  .leaderboard-row {
    grid-template-columns: 52px minmax(130px, 1fr) minmax(120px, 0.7fr);
  }

  .rank-dates {
    display: none;
  }

  .batch-row {
    grid-template-columns: 1fr 1fr 68px 34px;
  }

  .batch-note-label {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .remove-batch-button {
    grid-column: 4;
    grid-row: 1;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 24px, 1180px);
    padding-bottom: 36px;
  }

  .topbar {
    min-height: 58px;
  }

  .auth-view {
    min-height: calc(100vh - 82px);
    padding: 34px 0;
  }

  .auth-intro h1 {
    font-size: 3.1rem;
  }

  .auth-panel {
    padding: 20px;
  }

  .two-column-form,
  .entry-fields,
  .account-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-view {
    padding-top: 26px;
  }

  .dashboard-heading {
    display: block;
    margin-bottom: 28px;
  }

  .dashboard-heading h1 {
    font-size: 3rem;
  }

  .main-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 22px;
  }

  .main-tab {
    padding: 0 6px;
    font-size: 0.84rem;
  }

  .page-toolbar {
    align-items: end;
  }

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

  .metric-item {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 15px 17px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .metric-item:last-child {
    border-bottom: 0;
  }

  .metric-item span {
    margin: 0;
  }

  .metric-item strong {
    font-size: 1.3rem;
  }

  .metric-value-row {
    justify-content: flex-end;
  }

  .entry-panel,
  .chart-panel {
    padding: 16px;
  }

  .entry-panel .panel-head {
    align-items: start;
  }

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

  .trend-chart {
    min-height: 200px;
  }

  .history-section > .panel-head {
    padding: 0 14px;
  }

  .record-row {
    grid-template-columns: 88px 1fr auto;
    gap: 9px;
    padding: 11px 14px;
  }

  .record-note {
    display: none;
  }

  .leaderboard-controls {
    align-items: stretch;
  }

  .segmented.scrollable {
    width: 100%;
    overflow-x: auto;
  }

  .segmented.scrollable .segment {
    padding: 0 12px;
  }

  .custom-range {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr 1fr;
  }

  .custom-range label {
    width: auto;
  }

  .custom-range .button {
    grid-column: 1 / -1;
  }

  .ranking-metric {
    width: 100%;
  }

  .leaderboard-row {
    min-height: 70px;
    grid-template-columns: 38px minmax(100px, 1fr) minmax(100px, auto);
    gap: 8px;
    padding: 10px 13px;
  }

  .rank-result {
    font-size: 1.05rem;
  }

  .unranked-list {
    grid-template-columns: 1fr;
  }

  .unranked-item:nth-child(odd) {
    border-right: 0;
  }

  .data-section {
    grid-column: auto;
  }

  .data-actions {
    align-items: start;
    flex-direction: column;
  }

  .data-actions .button {
    width: 100%;
  }

  .modal-shell {
    padding: 18px;
  }

  .batch-row {
    grid-template-columns: 1fr 76px 34px;
  }

  .batch-date-label,
  .batch-weight-label,
  .batch-note-label {
    grid-column: 1 / -1;
  }

  .batch-unit-label {
    grid-column: 1 / 3;
  }

  .remove-batch-button {
    grid-column: 3;
    grid-row: 3;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
