:root {
  color-scheme: light;
  color: #392b22;
  background: #f5ede1;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
  --ink: #392b22;
  --muted: #66564a;
  --page: #fcf7ec;
  --rule: #dfcfba;
  --accent: #784831;
  --gain: #8b4333;
  --loss: #51634a;
  --journal: "Kaiti SC", KaiTi, STKaiti, "Songti SC", SimSun, serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(ellipse at 20% 0, #fdf8ee, transparent 38rem),
    linear-gradient(105deg, #f3eadc, #f8f1e7);
  line-height: 1.6;
}

h1, h2, h3, h4, p, dl, dd { margin: 0; }
button, input { font: inherit; }

a { color: var(--accent); text-underline-offset: .18em; }

button:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid #8d573c;
  outline-offset: 3px;
}

.layout {
  width: min(100% - 3rem, 65rem);
  margin-inline: auto;
}

.site-header, .dialog-title {
  display: flex;
  align-items: center;
  gap: .65rem;
}

.site-header {
  padding-block: 1.25rem 1rem;
}

.brand-seal {
  display: inline-grid;
  flex-shrink: 0;
  width: 2.12rem;
  height: 2.02rem;
  place-items: center;
  border: 1px solid #9a5c3b;
  border-radius: 4px 6px 5px 3px;
  background: #a05e40;
  color: #fff6e3;
  font-family: var(--journal);
  font-size: 1.28rem;
  line-height: 1;
  transform: rotate(-6deg);
}

.site-header h1 {
  color: #483327;
  font-family: var(--journal);
  font-size: clamp(1.35rem, 4vw, 1.6rem);
  line-height: 1.3;
}

.identity-badge {
  display: inline-block;
  flex-shrink: 0;
  padding: .14rem .62rem;
  border: 1px solid #d9bd94;
  border-radius: 3px 6px 4px 5px;
  background: #f5e7cf;
  color: #69482d;
  font-size: .86rem;
  white-space: nowrap;
}

.site-header .identity-badge { margin-inline-start: auto; }

.quote {
  position: relative;
  isolation: isolate;
  min-height: 20rem;
  overflow: hidden;
  border: 1px solid #e3d1b9;
  border-radius: 5px 13px 8px 5px;
  background: radial-gradient(ellipse at 77% 47%, #f8ecd5, transparent 59%),
    linear-gradient(105deg, #fffbf1, #faefdf);
  box-shadow: 0 .45rem 1.6rem rgb(87 58 32 / .07);
}

.quote-art {
  position: absolute;
  top: 8%;
  right: 1.8%;
  z-index: -1;
  width: 49%;
  height: 84%;
  object-fit: contain;
  pointer-events: none;
}

.quote-content {
  position: relative;
  width: 56%;
  padding: clamp(1.4rem, 4.3vw, 3rem);
}

.quote-source { color: var(--muted); font-size: .9rem; }

.quote h2 {
  margin-block: .28rem .6rem;
  font-family: var(--journal);
  font-size: clamp(2.3rem, 5.25vw, 4rem);
  font-weight: 600;
  line-height: 1.24;
}

.quote-value {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .08rem .5rem;
  margin-bottom: .8rem;
}

.quote-number {
  color: #74492d;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(2.05rem, 4vw, 3rem);
  font-weight: 600;
  line-height: 1.1;
}

.quote-unit, .quote-status, .estimate-note {
  color: var(--muted);
  font-size: .92rem;
}

.quote-status { margin-block: .12rem .55rem; }
.quote-status[data-state="live"] { display: none; }
.quote-status[data-state="stale"], .quote-status[data-state="error"] { color: var(--accent); }

.market-note {
  width: fit-content;
  max-width: 100%;
  margin-block: .26rem .5rem;
  padding: .06rem .38rem .09rem .48rem;
  border-left: 2px solid #bd9564;
  border-radius: 0 4px 4px 0;
  background: #f5e8d3;
  color: #674427;
  font-size: .9rem;
  overflow-wrap: anywhere;
}

.market-note[data-trend="down"] {
  border-left-color: #9a9e80;
  background: #eee9da;
  color: #4f5b43;
}

.purchase-motion { margin-bottom: .12rem; }

.quote-details {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  column-gap: .85rem;
  row-gap: .3rem;
}

.quote-reference { color: var(--muted); font-size: .86rem; }
.quote-reference summary { min-height: 2.3rem; padding-block: .3rem; }
.quote-reference p + p { margin-top: .18rem; }

summary {
  color: var(--accent);
  cursor: pointer;
  list-style: none;
  width: fit-content;
  max-width: 100%;
}

summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; margin-left: .38em; }
details[open] > summary::after { content: "−"; }
summary:hover { text-decoration: underline; text-underline-offset: .18em; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  margin-top: clamp(1.15rem, 4vw, 2.1rem);
  border-block: 1px solid var(--rule);
  background: rgb(255 251 241 / .63);
}

.card {
  min-width: 0;
  padding: clamp(1.2rem, 3.9vw, 2.15rem);
}

.card h2 {
  font-family: var(--journal);
  font-size: clamp(1.45rem, 3vw, 1.95rem);
  font-weight: 650;
  line-height: 1.35;
}

.position { border-right: 1px solid var(--rule); }

.profile-heading, .dialog-header, .selected-purpose, .dialog-actions, .purchase-top, .purchase-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem .7rem;
}

.profile-heading, .dialog-header, .purchase-top { justify-content: space-between; }
.profile-overview { margin-block: .84rem 1.1rem; color: var(--muted); }
.profile-overview strong { color: var(--ink); font-weight: 650; }

.primary-button, .secondary-button, .roast-button, .roast-pause {
  min-height: 2.3rem;
  padding: .3rem .75rem;
  border: 1px solid #d5c0a7;
  border-radius: 4px 7px 5px 4px;
  background: transparent;
  color: var(--accent);
  font-size: .89rem;
  font-weight: 630;
  line-height: 1.45;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .16s ease;
}

.primary-button {
  min-height: 2.75rem;
  padding-inline: .95rem;
  border-color: #75452e;
  background: #75452e;
  color: #fff8ed;
}

.primary-button:hover:not(:disabled) { border-color: #613722; background: #613722; }
.primary-button:disabled { border-color: #e1d5c7; background: #e6dccd; color: #6b5b4d; cursor: default; }
.secondary-button:hover:not(:disabled), .roast-button:hover, .roast-pause:hover { background: #f1e5d4; }
.secondary-button:disabled { opacity: .74; cursor: wait; }

#refresh-quote { min-width: 5.35rem; }

.estimate-total {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .16rem .5rem;
  margin-top: .35rem;
  color: var(--muted);
  font-size: .95rem;
}

.estimate-total strong {
  color: var(--ink);
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(1.6rem, 3.7vw, 2.2rem);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.estimate[data-direction="gain"] .estimate-total strong, #gross-gain { color: var(--gain); }
.estimate[data-direction="loss"] .estimate-total strong, #gross-loss { color: var(--loss); }
.estimate-note { margin-top: .36rem; }
.estimate-note:empty, .field-error:empty { display: none; }

.summary-details, .purchase-details, .purchase-periods {
  margin-top: .65rem;
  color: var(--muted);
  font-size: .9rem;
}

.summary-figures {
  max-width: 27rem;
  margin-top: .42rem;
}

.summary-figures + .summary-figures { margin-top: 0; }

.summary-figures div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .1rem .8rem;
  padding: .35rem 0;
  border-bottom: 1px dashed var(--rule);
}

.summary-figures dd { color: var(--ink); overflow-wrap: anywhere; }

.feedback {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: .4rem .75rem;
  margin-top: .7rem;
  padding: .82rem .9rem;
  border: 1px solid #ebdabc;
  border-left: 3px solid #c79664;
  border-radius: 3px 9px 6px 4px;
  background: #f9efdc;
}

.feedback[data-mood="loss"] {
  background: #f8ebdd;
  border-left-color: #ad7660;
}

.feedback-title {
  color: #523b2c;
  font-family: var(--journal);
  font-size: 1.16rem;
  font-weight: 700;
  line-height: 1.35;
}

.feedback-copy { min-width: 0; color: #5d4a3d; font-size: .9rem; }
.feedback-title + p { margin-top: .18rem; }

.companion-scene {
  position: relative;
  display: grid;
  width: 2.85rem;
  height: 3rem;
  place-items: center;
}

.companion {
  position: relative;
  width: 2.28rem;
  height: 1.95rem;
  border: 1px solid #af763b;
  border-radius: 45% 44% 35% 36%;
  background: radial-gradient(circle at 32% 14%, #f8d89b, #e1a453 62%, #cf8f42);
  box-shadow: inset 0 -.1rem 0 rgb(116 68 28 / .14), 0 .14rem .23rem rgb(105 69 32 / .16);
}

.companion::before {
  content: "";
  position: absolute;
  top: .71rem;
  left: .61rem;
  width: .17rem;
  height: .21rem;
  border-radius: 50%;
  background: #573e2b;
  box-shadow: .67rem 0 #573e2b;
}

.companion::after {
  content: "";
  position: absolute;
  top: .93rem;
  left: 50%;
  width: .34rem;
  height: .23rem;
  border-bottom: 1.5px solid #573e2b;
  border-radius: 0 0 50% 50%;
  transform: translateX(-50%);
}

.feedback[data-mood="loss"] .companion::before { height: .14rem; }
.feedback[data-mood="gain"] .companion { animation: companion-hop .54s ease-out both; }

.companion-spark {
  position: absolute;
  top: .15rem;
  right: 0;
  width: .53rem;
  height: .53rem;
  visibility: hidden;
  background: #a46a2f;
  clip-path: polygon(50% 0, 63% 36%, 100% 50%, 63% 64%, 50% 100%, 37% 64%, 0 50%, 37% 36%);
}

.feedback[data-mood="gain"] .companion-spark { visibility: visible; }

@keyframes companion-hop {
  0%, 100% { transform: translateY(0); }
  38% { transform: translateY(-.22rem) rotate(-4deg); }
}

.roast-controls {
  display: flex;
  grid-column: 2;
  flex-wrap: wrap;
  gap: .28rem .4rem;
}

.roast-button, .roast-pause { min-height: 2rem; font-size: .82rem; }
.roast-button { background: #fff8eb; }
.roast-pause { border-color: transparent; }

.records {
  margin-top: .1rem;
  border-bottom: 1px solid var(--rule);
  background: rgb(255 251 241 / .63);
}

.records-empty { margin-top: .55rem; color: var(--muted); font-size: .92rem; }
.record-list:not(:empty) { margin-top: .65rem; }

.purchase { padding-block: .95rem; border-bottom: 1px dashed var(--rule); }
.purchase:last-child { padding-bottom: 0; border-bottom: 0; }
.purchase-top { align-items: flex-start; }
.purchase-time { min-width: 0; flex: 1 1 11rem; }
.purchase-date { color: var(--ink); font-family: var(--journal); font-size: 1.26rem; font-weight: 650; }
.purchase-periods { max-width: 35rem; margin-top: .24rem; }

.purchase-actions { flex-shrink: 0; gap: .32rem; }
.purchase-actions button { min-height: 2rem; padding: .22rem .58rem; font-size: .84rem; }
.remove-record { color: #844332; }

.purchase-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .24rem 1.05rem;
  margin-top: .45rem;
  color: var(--muted);
  font-size: .92rem;
}

.purchase-result { color: var(--ink); overflow-wrap: anywhere; }
.purchase[data-direction="gain"] .purchase-result strong { color: var(--gain); }
.purchase[data-direction="loss"] .purchase-result strong { color: var(--loss); }

.page-footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .35rem 1.15rem;
  padding: .78rem .1rem 1.7rem;
  color: var(--muted);
  font-size: .84rem;
}

.profile-dialog {
  width: min(36rem, calc(100% - 1.6rem));
  max-height: calc(100% - 1.6rem);
  max-height: calc(100dvh - 1.6rem);
  overflow: auto;
  overscroll-behavior: contain;
  padding: clamp(1.1rem, 4vw, 1.8rem);
  border: 1px solid #d5bda1;
  border-radius: 5px 12px 8px 5px;
  background: var(--page);
  color: var(--ink);
  box-shadow: 0 1.5rem 3.5rem rgb(49 32 20 / .24);
}

.profile-dialog[open] { animation: dialog-in .22s ease-out both; }
.profile-dialog::backdrop { background: rgb(60 42 29 / .46); backdrop-filter: blur(3px); }
body:has(.profile-dialog[open]) { overflow: hidden; }

@keyframes dialog-in {
  from { opacity: .6; transform: translateY(.45rem); }
  to { opacity: 1; transform: translateY(0); }
}

.dialog-header { padding-bottom: .76rem; border-bottom: 1px solid var(--rule); }
.dialog-title h2 { font-family: var(--journal); font-size: 1.35rem; }
.dialog-title .brand-seal { width: 1.65rem; height: 1.62rem; font-size: 1rem; }
.dialog-step { padding-top: .82rem; }
.dialog-step h3 { margin: .12rem 0 .72rem; font-family: var(--journal); font-size: clamp(1.44rem, 4vw, 1.74rem); line-height: 1.35; }
.selected-purpose { margin-bottom: .65rem; }

.purpose-options, .profile-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .62rem;
}

.purpose-other, .purchase-date-field { grid-column: 1 / -1; }

.purpose-option {
  display: grid;
  align-content: center;
  gap: .08rem;
  min-height: 4.1rem;
  padding: .55rem .68rem;
  border: 1px solid #e0cbb0;
  border-radius: 4px 8px 6px 5px;
  background: #f9efdf;
  color: var(--ink);
  text-align: start;
  cursor: pointer;
}

.purpose-option:hover, .purpose-option[aria-pressed="true"] { border-color: #a7714a; background: #f5e3c9; }
.purpose-option strong { font-family: var(--journal); font-size: 1.2rem; }
.purpose-option span, .history-basis, .history-status, .history-sources { color: var(--muted); font-size: .88rem; }
.purpose-other { min-height: 2.85rem; }

.field label { display: block; margin-bottom: .28rem; color: var(--ink); font-size: .93rem; font-weight: 640; }
.optional { margin-left: .24rem; color: var(--muted); font-size: .82rem; font-weight: 400; }

.input-box {
  display: flex;
  align-items: center;
  padding-inline: .66rem;
  border: 1px solid #d9c4ab;
  border-radius: 4px 6px 5px 4px;
  background: #fffaf1;
}

.input-box:focus-within { border-color: #8d573c; box-shadow: 0 0 0 2px rgb(141 87 60 / .16); }
.input-box:has([aria-invalid="true"]) { border-color: var(--gain); }

.input-box input {
  flex: 1;
  min-width: 0;
  min-height: 2.8rem;
  padding: .2rem .35rem .2rem 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: 1rem;
}

.input-box input::placeholder { color: #78695b; opacity: 1; }
.field-unit { color: var(--muted); font-size: .86rem; white-space: nowrap; }
.field-error { margin-top: .28rem; color: var(--gain); font-size: .87rem; }

.history-estimate {
  margin-top: .82rem;
  padding: .65rem .75rem;
  border: 1px solid var(--rule);
  border-radius: 4px 8px 6px 4px;
  background: #f7eddd;
}

.history-estimate h4 { margin-bottom: .24rem; font-size: .97rem; }
.history-basis, .history-sources, .history-sources p { margin-top: .38rem; }

.period-list {
  display: grid;
  gap: .25rem;
  max-height: 10rem;
  overflow: auto;
  margin: .35rem 0;
  padding: 0;
  list-style: none;
}

.period-list li {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .1rem .65rem;
  padding: .28rem 0;
  border-bottom: 1px dashed #dbc6ac;
  color: var(--ink);
  font-size: .88rem;
}

.period-list li span { color: var(--muted); }
.dialog-actions { justify-content: space-between; margin-top: .8rem; }
.dialog-actions p { color: var(--muted); font-size: .86rem; }
#purpose-actions { justify-content: flex-end; }

@media (max-width: 43rem) {
  .layout { width: calc(100% - 1.5rem); }
  .site-header { padding-block: .92rem; }

  .quote { display: flex; flex-direction: column; min-height: 0; }
  .quote-content { width: 100%; padding: 1.2rem 1.2rem .35rem; }
  .quote-art {
    position: relative;
    inset: auto;
    order: 1;
    width: min(100% - 1.6rem, 24rem);
    height: clamp(8rem, 37vw, 12rem);
    margin: -.38rem auto .5rem;
  }

  .workspace { grid-template-columns: 1fr; }
  .position { border-right: 0; border-bottom: 1px solid var(--rule); }
}

@media (max-width: 24rem) {
  .profile-fields { grid-template-columns: 1fr; }
  .feedback { padding-inline: .58rem; column-gap: .4rem; }
}

@media (prefers-reduced-motion: reduce) {
  .primary-button, .secondary-button, .roast-button, .roast-pause { transition: none; }
  .feedback[data-mood="gain"] .companion, .profile-dialog[open] { animation: none; }
}
