:root {
  color: #17201d;
  background: #eef1ef;
  font-family: "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  font-synthesis: none;
  --ink: #17201d;
  --muted: #66706c;
  --line: #d7ddda;
  --surface: #ffffff;
  --soft: #f4f6f5;
  --green: #176b4d;
  --green-hover: #105a40;
  --amber: #d99614;
  --danger: #b44137;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: #eef1ef;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(23, 107, 77, 0.25);
  outline-offset: 2px;
}

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

.app-header,
.section-heading,
.question-main,
.primary-actions,
.dialog-heading,
.dialog-actions {
  display: flex;
  align-items: center;
}

.app-header {
  justify-content: space-between;
  margin-bottom: 24px;
}

.eyebrow,
.section-kicker,
.result-copy p {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.2;
}

h2 {
  margin: 0;
  font-size: 20px;
}

h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.quiet-button,
.secondary-button,
.text-button,
.close-button {
  border: 0;
  color: var(--ink);
  background: transparent;
}

.quiet-button,
.secondary-button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font-weight: 700;
}

.quiet-button:hover,
.secondary-button:hover {
  border-color: #aab4af;
  background: var(--soft);
}

.result-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 142px;
  padding: 28px 32px;
  border-left: 5px solid var(--amber);
  background: #202a26;
  color: #fff;
}

.result-copy {
  min-width: 0;
}

.result-copy p {
  color: #aeb9b4;
}

#numberPreview {
  display: block;
  overflow-wrap: anywhere;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: clamp(22px, 4.5vw, 38px);
  font-weight: 700;
  line-height: 1.25;
}

.copy-button,
.primary-button {
  flex: 0 0 auto;
  min-height: 46px;
  border: 0;
  border-radius: 6px;
  font-weight: 700;
}

.copy-button {
  padding: 0 18px;
  background: #f5f7f6;
  color: var(--ink);
}

.copy-button:hover {
  background: #fff;
}

.counter-section,
.history-section {
  padding: 30px 32px;
  background: var(--surface);
}

.counter-section {
  border-bottom: 1px solid var(--line);
}

.section-heading {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.section-heading.compact {
  margin-bottom: 16px;
}

.status-text {
  color: var(--green);
  font-size: 13px;
}

.question-list {
  border-top: 1px solid var(--line);
}

.question-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 14px;
  padding: 19px 0;
  border-bottom: 1px solid var(--line);
}

.question-index {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-top: 5px;
  border-radius: 50%;
  background: #e6f1ec;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
}

.question-main {
  justify-content: space-between;
  gap: 20px;
  min-width: 0;
}

.question-main-year {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) 100px auto;
}

.previous-main {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) minmax(220px, 1.2fr) auto;
}

.previous-field {
  min-width: 0;
}

.previous-field input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  font-family: Consolas, monospace;
  font-size: 13px;
}

.apply-previous-button {
  white-space: nowrap;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.question-labels p {
  margin: 6px 0 0;
  color: var(--muted);
  font-family: Consolas, monospace;
  font-size: 13px;
}

.question-labels strong {
  color: var(--green);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(60px, 1fr));
  flex: 0 0 auto;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}

.segmented button {
  min-height: 34px;
  padding: 0 11px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button.active {
  background: var(--surface);
  color: var(--green);
  box-shadow: 0 1px 3px rgba(21, 32, 27, 0.14);
  font-weight: 700;
}

.year-field,
.dialog-fields label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.year-field input,
.dialog-fields input {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
}

.primary-actions {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.primary-button {
  padding: 0 22px;
  background: var(--green);
  color: #fff;
}

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

.secondary-button:disabled,
.text-button:disabled {
  cursor: default;
  opacity: 0.45;
}

.text-button {
  padding: 8px;
  color: var(--muted);
  font-size: 13px;
}

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

.empty-state {
  padding: 26px 0 8px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

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

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

.history-number {
  overflow-wrap: anywhere;
  font-family: Consolas, monospace;
  font-size: 15px;
  font-weight: 700;
}

.history-time {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.history-copy {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
}

.history-copy:hover {
  background: var(--soft);
}

dialog {
  width: min(520px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(17, 28, 23, 0.28);
}

dialog::backdrop {
  background: rgba(17, 28, 23, 0.55);
}

#adjustForm {
  padding: 26px;
}

.dialog-heading {
  justify-content: space-between;
  margin-bottom: 22px;
}

.close-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  color: var(--muted);
  font-size: 27px;
  line-height: 1;
}

.close-button:hover {
  background: var(--soft);
  color: var(--ink);
}

.dialog-fields {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.dialog-actions {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  max-width: calc(100% - 40px);
  padding: 11px 15px;
  border-radius: 6px;
  background: #17201d;
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 620px);
    padding: 20px 0 36px;
  }

  .result-band {
    align-items: stretch;
    flex-direction: column;
    padding: 24px;
  }

  .copy-button {
    width: 100%;
  }

  .counter-section,
  .history-section {
    padding: 24px 20px;
  }

  .question-main,
  .question-main-year,
  .previous-main {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .segmented {
    width: 100%;
  }

  .year-field {
    width: 120px;
  }

  .previous-field {
    width: 100%;
  }

  .primary-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .history-item {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .history-time {
    grid-column: 1;
    grid-row: 2;
  }

  .history-copy {
    grid-column: 2;
    grid-row: 1 / 3;
  }

  .dialog-fields {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .app-header {
    align-items: flex-end;
  }

  h1 {
    font-size: 25px;
  }

  .quiet-button {
    min-height: 38px;
    padding: 0 12px;
    font-size: 13px;
  }

  .question-row {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 10px;
  }

  .segmented {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .segmented button {
    padding: 0 5px;
  }
}
