:root {
  --desk: #0e2a1f;
  --sheet: #f6f4ea;
  --ink: #1b211a;
  --muted: #5c6857;
  --line: #cfd2c1;
  --accent: #d9a521;
  --accent-soft: rgba(217, 165, 33, 0.28);
  --focus: #8a5f00;
  --up: #b93a2b;
  --down: #1f6b4a;
  --warn: #7d4f10;
  --warn-bg: #f3e4c6;
  --mono: "SF Mono", "Menlo", "Consolas", monospace;
  --sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-color: var(--line) var(--sheet);
}

body {
  margin: 0;
  min-height: 100vh;
  padding: 48px 0;
  background: var(--desk);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--accent-soft);
  color: var(--ink);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.sheet {
  width: min(1120px, calc(100% - 64px));
  margin: 0 auto;
  background: var(--sheet);
  border-top: 6px solid var(--accent);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.28), 0 2px 0 rgba(0, 0, 0, 0.18);
}

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 40px 22px;
  border-bottom: 1px solid var(--line);
}

.brand h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: 1.1;
}

.date {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 16px;
}

.stamp {
  padding: 3px 8px;
  border: 1px solid var(--ink);
  color: var(--ink);
  font-size: 11px;
  letter-spacing: 0.08em;
  white-space: nowrap;
  transform: rotate(-1.2deg);
}

.stamp.cached {
  border-color: var(--warn);
  color: var(--warn);
}

.updated {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.refresh {
  height: 30px;
  padding: 0 14px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.refresh:hover:not(:disabled) {
  background: var(--ink);
  color: var(--sheet);
}

.refresh:active:not(:disabled) {
  transform: translateY(1px);
}

.refresh:disabled {
  opacity: 0.45;
  cursor: default;
}

.notice {
  padding: 10px 40px;
  border-bottom: 1px solid #dfc9a0;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 12px;
}

.notice.warn {
  border-bottom-color: #d8b98a;
  background: #eed7bd;
  color: #6b3a10;
}

.board {
  padding: 0 40px;
}

.board.loading {
  padding: 56px 40px;
  color: var(--muted);
  font-size: 13px;
}

.contract {
  padding: 28px 0 24px;
  border-bottom: 1px solid var(--line);
}

.contract:last-child {
  border-bottom: 0;
}

.contract-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px 12px;
}

.name-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.name {
  max-width: 100%;
  padding: 0;
  border: 0;
  border-bottom: 1px solid transparent;
  background: none;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.25;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.name:hover {
  border-bottom-color: var(--focus);
}

.name.name-readonly {
  cursor: default;
}

.name.name-readonly:hover {
  border-bottom-color: transparent;
}

.pencil {
  width: 14px;
  height: 14px;
  flex: none;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.name-wrap:hover .pencil,
.name:focus-visible + .pencil {
  opacity: 1;
}

.name-input {
  width: 16em;
  max-width: 100%;
  padding: 0 0 2px;
  border: 0;
  border-bottom: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.25;
  caret-color: var(--ink);
}

.name-input:focus {
  outline: none;
  border-bottom-color: var(--focus);
}

.name-input:disabled {
  opacity: 0.6;
}

.edit-hint {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.code {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.qtime {
  margin-left: auto;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  white-space: nowrap;
}

.contract-body {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 32px;
  align-items: start;
  margin-top: 18px;
}

.last {
  font-family: var(--mono);
  font-size: 60px;
  font-weight: 500;
  line-height: 0.95;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
}

.last.flash-up,
.last.flash-down {
  animation: flash 0.72s ease-out;
}

@keyframes flash {
  0% {
    box-shadow: inset 0 -0.28em 0 var(--accent-soft);
  }
  100% {
    box-shadow: inset 0 -0.28em 0 transparent;
  }
}

.change {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.change.up {
  color: var(--up);
}

.change.down {
  color: var(--down);
}

.change.flat {
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px 24px;
  margin: 0;
  padding-top: 4px;
}

.stat {
  min-width: 0;
}

.stat.wide {
  grid-column: span 2;
}

.stat dt {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.stat dd {
  margin: 3px 0 0;
  font-family: var(--mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stat .sub {
  margin-left: 6px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 11px;
}

.range {
  margin-top: 24px;
}

.range-head,
.range-legend {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.track {
  position: relative;
  height: 2px;
  margin: 12px 0 9px;
  background: var(--line);
}

.track .marker {
  position: absolute;
  top: -7px;
  width: 3px;
  height: 16px;
  background: var(--ink);
}

.track .marker::after {
  content: "";
  position: absolute;
  top: -3px;
  left: -2px;
  width: 7px;
  height: 3px;
  background: var(--accent);
}

.track .settle {
  position: absolute;
  top: -4px;
  width: 1px;
  height: 10px;
  background: var(--muted);
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 40px 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

#origin {
  font-family: var(--mono);
  white-space: nowrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  max-width: calc(100vw - 32px);
  padding: 9px 16px;
  border-radius: 2px;
  background: var(--ink);
  color: var(--sheet);
  font-size: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  background: #6d2b1e;
  color: #f8efe9;
}

@media (max-width: 860px) {
  body {
    padding: 16px 0;
  }

  .sheet {
    width: calc(100% - 32px);
    margin: 0 auto;
  }

  .masthead {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
    padding: 22px 22px 18px;
  }

  .meta {
    justify-content: flex-start;
  }

  .notice {
    padding: 10px 22px;
  }

  .board {
    padding: 0 22px;
  }

  .board.loading {
    padding: 44px 22px;
  }

  .contract-body {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .last {
    font-size: 48px;
  }

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

  .stat.wide {
    grid-column: span 2;
  }

  .footer {
    flex-direction: column;
    gap: 6px;
    padding: 14px 22px 18px;
  }
}

@media (max-width: 560px) {
  .brand h1 {
    font-size: 26px;
  }

  .name {
    font-size: 21px;
  }

  .name-input {
    font-size: 21px;
  }

  .last {
    font-size: 42px;
  }

  .meta {
    gap: 10px;
  }

  .stat dd {
    white-space: normal;
  }

  .stat .sub {
    display: block;
    margin-left: 0;
  }

  .qtime {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
