:root {
  --orange: #ff6819;
  --orange-dark: #c84a08;
  --ink: #201713;
  --muted: #756c66;
  --line: #eadfd8;
  --soft: #fff2ea;
  --panel: #ffffff;
  --green: #168454;
  --yellow: #a96b00;
  --red: #c73a2c;
  --purple: #7137a8;
  --shadow: 0 12px 34px rgba(80, 40, 12, 0.1);
  font-family: "Microsoft YaHei", "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: #fff8f3;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  font-weight: 800;
}

button:active {
  transform: translateY(1px);
}

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

input:disabled,
select:disabled {
  background: #f6f0ec;
  color: #8a817c;
  opacity: 1;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--orange);
  color: #1f1009;
  box-shadow: 0 4px 16px rgba(120, 48, 8, 0.18);
}

.topbar h1 {
  margin: 3px 0 0;
  font-size: 26px;
  line-height: 1.1;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.section-eyebrow {
  color: var(--orange-dark);
}

.sync-state,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--orange-dark);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px;
}

.panel,
.hero-panel {
  margin: 12px 0;
}

.panel {
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.hero-panel {
  display: grid;
  gap: 10px;
}

.current-card {
  padding: 16px;
  border: 2px solid var(--orange);
  border-radius: 12px;
  background: linear-gradient(180deg, #fff 0%, #fff4ed 100%);
  box-shadow: var(--shadow);
}

.dashboard-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.dashboard-head h2 {
  margin: 3px 0 0;
  font-size: 28px;
  line-height: 1.15;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.support-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.metric {
  min-width: 0;
  border-left: 4px solid var(--orange);
  padding: 8px 0 8px 10px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.25;
}

.metric-large {
  min-height: 86px;
  border: 1px solid var(--line);
  border-left: 6px solid var(--orange);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}

.metric-large strong {
  font-size: clamp(23px, 4vw, 36px);
}

.action-prompt {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #201713;
  color: #fff;
  font-weight: 900;
  line-height: 1.45;
}

.status-chip,
.difficulty-pill,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.status-chip.finish,
.difficulty-pill.diff-neutral {
  background: var(--soft);
  color: var(--orange-dark);
}

.diff-e {
  --diff-color: var(--green);
  --diff-bg: #eaf7ef;
}

.diff-m {
  --diff-color: var(--yellow);
  --diff-bg: #fff6df;
}

.diff-h {
  --diff-color: var(--red);
  --diff-bg: #ffecea;
}

.diff-vh {
  --diff-color: var(--purple);
  --diff-bg: #f3eaff;
}

.difficulty-pill.diff-e,
.difficulty-pill.diff-m,
.difficulty-pill.diff-h,
.difficulty-pill.diff-vh,
.status-chip.diff-e,
.status-chip.diff-m,
.status-chip.diff-h,
.status-chip.diff-vh {
  background: var(--diff-bg);
  color: var(--diff-color);
}

.actions,
.auth-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.auth-toggle {
  width: 100%;
  justify-content: space-between;
  background: #fff;
}

.auth-form {
  margin-top: 12px;
}

.auth-row input {
  flex: 1 1 190px;
}

#unlockBtn,
.segmented button.active {
  border-color: var(--orange);
  background: var(--orange);
  color: #fff;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.section-title h2 {
  margin: 2px 0 0;
  font-size: 20px;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

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

.field span,
.runner-field span,
.leg-field span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field {
  display: block;
  margin-bottom: 12px;
}

.runner-filter {
  display: grid;
  grid-template-columns: repeat(7, minmax(128px, 1fr));
  gap: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.runner-summary {
  min-height: 92px;
  display: grid;
  align-content: center;
  gap: 4px;
  text-align: left;
  border-radius: 10px;
  padding: 10px;
  color: var(--ink);
}

.runner-summary span,
.runner-summary strong,
.runner-summary em {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.runner-summary span {
  font-size: 15px;
}

.runner-summary strong {
  color: var(--orange-dark);
  font-size: 18px;
}

.runner-summary em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.runner-summary.active {
  border-color: var(--orange);
  background: var(--orange);
  color: #fff;
}

.runner-summary.active strong,
.runner-summary.active em {
  color: #fff;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  background: #fff;
}

.segmented button {
  border: 0;
  border-radius: 0;
  min-height: 36px;
}

.offline-note {
  margin-bottom: 10px;
  border: 1px solid #f4c8a9;
  border-left: 4px solid var(--orange);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff7ef;
  color: var(--orange-dark);
  font-weight: 800;
}

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

.empty-filter {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 22px;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
  background: #fffaf6;
}

.leg-card {
  border: 1px solid var(--line);
  border-left: 6px solid var(--diff-color, var(--line));
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}

.leg-card.current {
  border-color: var(--orange);
  border-left-color: var(--orange);
  box-shadow: 0 0 0 2px rgba(255, 104, 25, 0.16);
}

.leg-card.done {
  opacity: 0.68;
  background: #f7fbf8;
}

.leg-card.done .leg-head {
  background: #f3fbf7;
}

.leg-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  background: var(--diff-bg, #fff9f5);
}

.leg-head h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.strength-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.strength-row strong,
.strength-row span {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  padding: 3px 9px;
  background: rgba(255, 255, 255, 0.72);
}

.strength-row strong {
  color: var(--ink);
}

.leg-body {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
}

.read-value {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf7f4;
  font-weight: 800;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  min-width: 980px;
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  position: sticky;
  top: 69px;
  z-index: 3;
  background: #fff0e7;
  color: var(--orange-dark);
  font-size: 12px;
}

.revision-list {
  display: grid;
  gap: 8px;
}

.revision-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(420px, calc(100vw - 24px));
  border-radius: 999px;
  padding: 10px 14px;
  background: #201713;
  color: #fff;
  font-weight: 800;
  box-shadow: var(--shadow);
  z-index: 40;
}

.editor-only {
  display: none;
}

body.editing .editor-only {
  display: block;
}

body.editing #modeBadge {
  background: #eaf7ef;
  color: var(--green);
}

body.offline .sync-state {
  background: #ffe9e6;
  color: var(--red);
}

@media (max-width: 860px) {
  .dashboard-grid,
  .support-grid,
  .runner-grid,
  .leg-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar h1 {
    font-size: 23px;
  }
}

@media (max-width: 560px) {
  main {
    padding: 8px;
  }

  .topbar {
    padding-left: 12px;
    padding-right: 12px;
  }

  .panel,
  .current-card {
    margin: 8px 0;
    padding: 11px;
    border-radius: 8px;
  }

  .dashboard-grid,
  .support-grid,
  .runner-grid,
  .leg-body {
    grid-template-columns: 1fr;
  }

  .metric-large {
    min-height: 74px;
  }

  .actions button,
  .auth-row button {
    flex: 1 1 100%;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }

  .leg-head {
    grid-template-columns: 1fr;
  }
}
