* { box-sizing: border-box; }

:root {
  color-scheme: dark;
  --bg: #101411;
  --surface: #171d19;
  --surface-soft: #1d241f;
  --ink: #f2eee4;
  --muted: #a9aea5;
  --subtle: #747c74;
  --line: rgba(239, 231, 211, 0.13);
  --line-strong: rgba(239, 231, 211, 0.24);
  --gold: #d2a85c;
  --moss: #8fa88f;
  --danger: #ffb4a8;
  --success: #b4dfbe;
  --radius: 20px;
}

*::selection { background: rgba(210, 168, 92, .3); color: var(--ink); }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Noto Sans SC", "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 78% 8%, rgba(111, 140, 115, .13), transparent 26rem),
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px),
    var(--bg);
  background-size: auto, 48px 48px, 48px 48px, auto;
  color: var(--ink);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(16,20,17,.4), transparent 20%, transparent 80%, rgba(16,20,17,.4));
}
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }

.page { width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: 42px 0 max(36px, env(safe-area-inset-bottom)); }
.card, .result { border-top: 1px solid var(--line-strong); }
.card { display: grid; grid-template-columns: minmax(280px, .82fr) minmax(500px, 1.18fr); gap: clamp(48px, 7vw, 104px); padding: 58px 0 72px; }

.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); font-weight: 700; letter-spacing: .03em; }
.mark { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid rgba(210,168,92,.5); color: var(--gold); border-radius: 50%; font-family: "Songti SC", "STSong", serif; }
.hero { position: sticky; top: 38px; align-self: start; }
.eyebrow { margin: clamp(70px, 9vw, 112px) 0 16px; color: var(--gold); font-size: 13px; letter-spacing: .16em; }
.hero h1 { margin: 0; font-family: "Songti SC", "STSong", "Noto Serif SC", serif; font-size: clamp(54px, 6vw, 86px); font-weight: 500; line-height: 1.06; letter-spacing: -.05em; }
.hero h1 em { color: var(--gold); font-style: normal; }
.lead { max-width: 440px; margin: 26px 0 0; color: #c7c8c1; font-size: 16px; line-height: 1.9; text-wrap: pretty; }
.promise { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 30px; color: var(--muted); font-size: 12px; }
.promise span::before { content: "·"; margin-right: 7px; color: var(--gold); }
.quiet-note { margin: 18px 0 0; padding-top: 18px; border-top: 1px solid var(--line); color: var(--subtle); font-size: 12px; line-height: 1.65; }

.form { display: grid; gap: 28px; padding-top: 2px; }
.form-heading { display: flex; align-items: end; justify-content: space-between; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.form-heading > div, .result-heading > div { display: flex; align-items: center; gap: 12px; }
.step { color: var(--gold); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; letter-spacing: .12em; }
.form-heading h2 { margin: 0; font: 500 25px/1.2 "Songti SC", "STSong", serif; }
.form-heading p { margin: 0; color: var(--subtle); font-size: 11px; }
b { color: var(--gold); }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
legend { width: 100%; margin-bottom: 16px; color: var(--muted); font-size: 12px; letter-spacing: .12em; }
.row { display: grid; gap: 13px; }
.row + .row, fieldset > label + .row { margin-top: 13px; }
.row.two { grid-template-columns: 1fr 1fr; }
.calendar-row { grid-template-columns: 142px 1fr; }
label { min-width: 0; display: grid; gap: 8px; color: #c8cac3; font-size: 12px; }
label small { margin-left: 4px; color: var(--subtle); font-weight: 400; }
input, select {
  width: 100%; height: 52px; padding: 0 15px; border: 1px solid var(--line); border-radius: 10px;
  background: rgba(255,255,255,.035); color: var(--ink); outline: none; transition: border-color .18s, background .18s, box-shadow .18s;
}
input::placeholder { color: #697169; }
input:hover, select:hover { border-color: var(--line-strong); background: rgba(255,255,255,.052); }
input:focus, select:focus { border-color: rgba(210,168,92,.72); background: rgba(210,168,92,.045); box-shadow: 0 0 0 3px rgba(210,168,92,.09); }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid rgba(210,168,92,.86); outline-offset: 3px; }
.date-grid { display: grid; grid-template-columns: 1.3fr .85fr .85fr; gap: 8px; }
.date-grid input { text-align: center; padding: 0 7px; }

.submit-area { display: grid; gap: 10px; margin-top: 2px; }
#generateButton {
  min-height: 58px; padding: 0 9px 0 24px; border: 0; border-radius: 12px; display: flex; align-items: center; justify-content: space-between;
  background: var(--ink); color: #161a17; cursor: pointer; font-weight: 700; transition: transform .18s, background .18s;
}
#generateButton i { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 9px; background: #1b211d; color: var(--ink); font-style: normal; }
#generateButton:hover { transform: translateY(-1px); background: #fffdf7; }
button:disabled { opacity: .62; cursor: wait; transform: none !important; }
.status { min-height: 20px; margin: 0; color: var(--subtle); text-align: center; font-size: 12px; line-height: 1.6; }
.status.error { color: var(--danger); }
.status.ok { color: var(--success); }
.progress { height: 3px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.07); }
.progress.hidden { display: none; }
.progress span { display: block; width: 32%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--moss), var(--gold)); animation: loading 1.25s ease-in-out infinite; }
@keyframes loading { from { transform: translateX(-110%); } to { transform: translateX(340%); } }

.result { padding: 72px 0 80px; }
.result.hidden { display: none; }
.result-heading { margin-bottom: 30px; }
.result-heading > div { color: var(--muted); font-size: 12px; letter-spacing: .1em; }
.result-heading p { margin: 0; }
.result-heading h2 { margin: 10px 0 0; font: 500 clamp(38px, 5vw, 60px)/1.1 "Songti SC", "STSong", serif; letter-spacing: -.04em; }
.result-layout { display: grid; grid-template-columns: minmax(360px, .9fr) minmax(390px, 1.1fr); gap: clamp(40px, 7vw, 96px); align-items: start; }
.portrait-frame { min-width: 0; margin: 0; }
.image-stage { width: 100%; border: 1px solid var(--line-strong); border-radius: 2px; background: #090c0a; box-shadow: 0 28px 80px rgba(0,0,0,.36); }
#wallpaper {
  display: block; width: 100%; height: auto; max-width: 100%; max-height: none; object-fit: contain; object-position: center;
}
.portrait-frame figcaption { margin-top: 12px; color: var(--subtle); font-size: 11px; text-align: center; letter-spacing: .06em; }
.result-content { min-width: 0; padding-top: 8px; }
.result-copy { display: flex; align-items: center; gap: 16px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.swatch { flex: 0 0 auto; width: 52px; height: 52px; border-radius: 50%; background: #36c78e; box-shadow: 0 0 34px rgba(54,199,142,.35); }
.result-copy span, .story-block > span { color: var(--subtle); font-size: 11px; letter-spacing: .12em; }
.result-copy p { margin: 5px 0 1px; font: 500 28px/1.2 "Songti SC", "STSong", serif; }
.result-copy strong { color: var(--gold); font: 400 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.mini { margin: 15px 0 0; color: var(--subtle); font-size: 11px; line-height: 1.7; }
.story-block { margin-top: 32px; }
.story-block h3 {
  margin: 22px 0 10px;
  color: var(--ink);
  font: 500 16px/1.45 "Songti SC", "STSong", "Noto Serif SC", serif;
  letter-spacing: .03em;
}
#matchExplanation, #figureStory {
  margin: 12px 0 0;
  color: #c9ccc4;
  font-size: 14px;
  line-height: 1.9;
  text-wrap: pretty;
}
#matchReasons, #figureSources {
  display: grid;
  gap: 9px;
  margin: 0;
  padding-left: 1.35rem;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.75;
}
#matchReasons li, #figureSources li { padding-left: 4px; }
#matchReasons li::marker, #figureSources li::marker { color: var(--gold); font-size: .88em; }
#figureSources { color: var(--subtle); font-size: 12px; }
#summary, #interpretation { color: #c9ccc4; line-height: 1.85; text-wrap: pretty; }
#summary { margin: 12px 0 0; font-size: 15px; }
#interpretation { margin: 16px 0 0; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.empty { color: var(--subtle) !important; }
.details { display: grid; margin-top: 26px; border-top: 1px solid var(--line); }
.details div { display: grid; grid-template-columns: 66px 1fr; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.details b { font-size: 11px; letter-spacing: .08em; }
.details span { color: var(--muted); font-size: 13px; line-height: 1.65; }
.wallpaper-guide { margin-top: 28px; padding: 22px; border: 1px solid rgba(210,168,92,.25); border-radius: 12px; background: rgba(210,168,92,.055); }
.guide-kicker { color: var(--gold); font-size: 10px; letter-spacing: .14em; }
.wallpaper-guide h3 { margin: 7px 0 17px; font: 500 20px/1.35 "Songti SC", "STSong", serif; }
.wallpaper-guide ol { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.wallpaper-guide li { display: grid; grid-template-columns: 30px 1fr; align-items: center; gap: 10px; color: #c9ccc4; font-size: 13px; }
.wallpaper-guide li b { font: 500 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.wallpaper-guide > p { margin: 17px 0 0; padding-top: 14px; border-top: 1px solid var(--line); color: var(--subtle); font-size: 11px; line-height: 1.6; }
.actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 9px; margin-top: 16px; }
.actions a, .actions button { min-height: 48px; padding: 0 12px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; text-decoration: none; font-size: 13px; font-weight: 650; }
.primary-action { grid-column: 1 / -1; background: var(--ink); color: #151915; }
.secondary-action { border: 1px solid var(--line); background: rgba(255,255,255,.04); color: var(--ink); }
.text-action { grid-column: 1 / -1; border: 0; background: transparent; color: var(--muted); }
.actions a:hover, .actions button:hover { filter: brightness(1.1); }

footer { display: flex; justify-content: space-between; gap: 24px; padding-top: 28px; border-top: 1px solid var(--line); color: var(--subtle); font-size: 11px; line-height: 1.7; }
footer span { color: var(--muted); font-weight: 700; }
footer p { max-width: 620px; margin: 0; text-align: right; }

@media (max-width: 880px) {
  .page { width: min(100% - 36px, 680px); }
  .card { grid-template-columns: 1fr; gap: 48px; padding-top: 34px; }
  .hero { position: static; }
  .eyebrow { margin-top: 54px; }
  .lead { max-width: 580px; }
  .result-layout { grid-template-columns: 1fr; gap: 38px; }
  .portrait-frame { width: min(100%, 560px); margin: 0 auto; }
}

@media (max-width: 560px) {
  .page { width: min(100% - 28px, 680px); padding-top: 20px; }
  .card { padding: 24px 0 54px; gap: 42px; }
  .brand { font-size: 14px; }
  .mark { width: 34px; height: 34px; }
  .eyebrow { margin-top: 42px; font-size: 11px; }
  .hero h1 { font-size: clamp(50px, 16vw, 66px); }
  .lead { margin-top: 21px; font-size: 15px; line-height: 1.8; }
  .promise { display: grid; gap: 8px; }
  .form-heading { align-items: center; }
  .calendar-row, .row.two { grid-template-columns: 1fr; }
  .calendar-field { width: 100%; }
  .date-grid { grid-template-columns: 1.22fr .86fr .86fr; gap: 6px; }
  input, select { height: 54px; font-size: 16px; }
  fieldset { padding-top: 2px; }
  .row + .row, fieldset > label + .row { margin-top: 13px; }
  .result { padding: 52px 0 60px; }
  .result-heading { margin-bottom: 24px; }
  .result-heading h2 { font-size: 42px; }
  .result-layout { gap: 30px; }
  .image-stage { width: calc(100% + 28px); margin-left: -14px; border-left: 0; border-right: 0; }
  .portrait-frame figcaption { font-size: 10px; }
  .result-content { padding-top: 0; }
  .result-copy p { font-size: 25px; }
  .story-block { margin-top: 28px; }
  .story-block h3 { margin-top: 19px; font-size: 15px; }
  #matchExplanation, #figureStory { font-size: 13px; line-height: 1.85; }
  #matchReasons, #figureSources { gap: 8px; padding-left: 1.2rem; font-size: 12px; }
  .actions { grid-template-columns: 1fr 1fr; }
  .primary-action, .text-action { grid-column: 1 / -1; }
  footer { display: block; }
  footer p { margin-top: 7px; text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
