:root {
  color-scheme: dark;
  --bg: #101114;
  --card: #191c22;
  --card-line: #2c313a;
  --text: #f6f3ec;
  --muted: #9aa0ab;
  --soft: #c8ccd4;
  --amber: #f0a202;
  --amber-ink: #1b1403;
  --line: #343a45;
  --input: #101218;
  --green: #3ecf8e;
  --red: #ff6b6b;
  --violet: #c4b5fd;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "WenQuanYi Zen Hei", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

.app {
  width: min(980px, calc(100% - 24px));
  max-width: 100%;
  margin: 0 auto;
  padding: calc(18px + var(--safe-top)) 0 calc(22px + var(--safe-bottom));
}

.banner {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 1;
  object-fit: cover;
  object-position: center;
  margin: 0 0 14px;
  border-radius: 18px;
  border: 1px solid var(--card-line);
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--soft);
}

.icon-btn svg { width: 18px; height: 18px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 14px;
  min-width: 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
}

.form-card, .result-card { padding: 16px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

.field > span, legend, .result-label, .days-row, .hint, .cny-preview, .original, .modal-note {
  color: var(--muted);
}

.field > span, legend {
  font-size: 12px;
  font-weight: 700;
}

.price-row, .date-row, .quote-row, .rate-row {
  display: flex;
  gap: 10px;
  align-items: end;
  min-width: 0;
  max-width: 100%;
}

.grow { flex: 1; }

.currency-field { width: 42%; }

.price-box, .select-box, .money-box, .field > input {
  height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--input);
}

.price-box, .money-box, .select-box {
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 6px;
}

.price-box input, .money-box input, .select-box select {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 0;
}

.field > input {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 0 12px;
  outline: 0;
}

.symbol, .money-box span {
  color: var(--amber);
  font-weight: 800;
  flex: none;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 20px, calc(100% - 9px) 20px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 22px;
}

input:focus, select:focus, .field > input:focus, .price-box:focus-within, .money-box:focus-within, .select-box:focus-within {
  border-color: var(--amber);
}

.cny-preview {
  margin: 8px 0 14px;
  font-size: 13px;
  font-weight: 700;
}

.cycles {
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}

.cycle-list {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.cycle-list label {
  position: relative;
  display: block;
}

.cycle-list input {
  position: absolute;
  opacity: 0;
  inset: 0;
}

.cycle-list span {
  display: grid;
  height: 38px;
  place-items: center;
  border-radius: 11px;
  border: 1px solid var(--line);
  color: var(--soft);
  font-size: 13px;
  font-weight: 700;
}

.cycle-list input:checked + span {
  border-color: var(--amber);
  color: var(--amber-ink);
  background: var(--amber);
}

.cycle-list input:focus-visible + span {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.date-row { margin-bottom: 14px; }

.date-row,
.rate-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: end;
}

.date-row .field { min-width: 0; }

.rate-field,
.rate-row .refresh-btn {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
}

.rate-field input {
  padding: 0 12px;
  font-weight: 800;
  color: var(--amber);
}

.refresh-btn.spin { opacity: 0.55; }

.rate-tip {
  margin: 8px 0 0;
  color: var(--amber);
  font-size: 12px;
  font-weight: 700;
}

.result-card { display: flex; flex-direction: column; }

.result-label {
  margin: 4px 0 0;
  text-align: right;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.amount {
  display: block;
  width: 100%;
  max-width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--amber);
  font-size: clamp(40px, 18vw, 72px);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.amount::before {
  content: "¥";
  margin-right: 4px;
  color: var(--muted);
  font-size: 0.42em;
  font-weight: 500;
  letter-spacing: 0;
}

.original, .hint {
  margin: 8px 0 0;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
}

.days-row {
  display: grid;
  grid-template-columns: auto auto auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  font-weight: 800;
}

.days-row strong {
  color: var(--text);
  font-size: 16px;
}

.unit { letter-spacing: 0.06em; }

.bar {
  height: 7px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--muted) 25%, transparent);
  overflow: hidden;
}

#progressBar {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--amber), #79a8ff);
}

#progressText { color: var(--amber); }

.quote-row { margin-top: 14px; }

.quote-row .field { flex: 1; }

#premium.positive { color: var(--green); }
#premium.negative { color: var(--red); }
#sale.neutral { color: var(--violet); }

.actions, .modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.action {
  flex: 1;
  min-width: 0;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0 2px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--soft);
  text-decoration: none;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.action.primary {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--amber-ink);
}

.action.refresh-btn {
  flex: 1 1 0;
  width: auto;
  height: 46px;
  padding: 0 8px;
  font-size: 13px;
}

.modal[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.72);
}

.modal-panel {
  width: min(560px, 100%);
  max-height: calc(100dvh - 36px);
  overflow: auto;
  padding: 14px;
  border-radius: 18px;
  background: var(--card);
  border: 1px solid var(--card-line);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h2 { margin: 0; font-size: 18px; }

#shareImage {
  display: block;
  width: 100%;
  margin-top: 10px;
  border-radius: 12px;
}

.modal-status, .modal-note {
  margin: 10px 0 0;
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%) translateY(12px);
  opacity: 0;
  pointer-events: none;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--amber);
  color: var(--amber-ink);
  font-size: 13px;
  font-weight: 800;
  transition: 0.2s ease;
}

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

@keyframes spin { to { transform: rotate(-360deg); } }

@media (max-width: 800px) {
  .layout, .cycle-list { grid-template-columns: 1fr 1fr 1fr; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .currency-field { width: 46%; }
  .amount { font-size: clamp(40px, 16vw, 56px); }
}

@media (max-width: 380px) {
  .days-row { grid-template-columns: auto auto auto 1fr; }
  #progressText { grid-column: 1 / -1; text-align: right; }
}
