:root {
  color-scheme: light;
  --ink: #1d211d;
  --muted: #6f746e;
  --line: #dadbd4;
  --paper: #fbfaf6;
  --canvas: #f1f0ea;
  --green: #285a44;
  --green-soft: #e5eee8;
  --amber: #9a632b;
  --amber-soft: #f6ead9;
  --red: #a2433a;
  --red-soft: #f5e5e2;
  --blue: #3e5f78;
  --shadow: 0 18px 55px rgba(35, 38, 32, 0.09);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.page-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .18;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.08'/%3E%3C/svg%3E");
}

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

[hidden] { display: none !important; }

.app-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding-bottom: max(56px, env(safe-area-inset-bottom));
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(29, 33, 29, .12);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 750;
  letter-spacing: -.02em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  font-family: Georgia, serif;
}

.topbar-actions { display: flex; align-items: center; gap: 16px; }
.sync-state { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.sync-state i { width: 7px; height: 7px; border-radius: 50%; background: #4b8b65; box-shadow: 0 0 0 4px rgba(75,139,101,.12); }
.text-button { appearance: none; border: 0; background: none; padding: 8px 0; color: var(--muted); cursor: pointer; }
.text-button:hover { color: var(--ink); }

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 40px;
  padding: 62px 0 36px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .17em;
}

.hero h1 {
  margin: 0;
  max-width: 670px;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(34px, 5vw, 61px);
  font-weight: 500;
  line-height: 1.08;
  letter-spacing: -.045em;
}

.hero-copy {
  max-width: 610px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.8;
}

.button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .18s ease, background .18s ease, border-color .18s ease;
}
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .55; cursor: wait; }
.button.primary { background: var(--ink); color: white; }
.button.primary:hover { background: #363b35; }
.button.secondary { background: var(--green-soft); color: var(--green); }
.button.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.button.danger { background: var(--red); color: white; }
.button.wide { width: 100%; }
.add-button { flex: 0 0 auto; min-height: 50px; padding-inline: 24px; }
.add-button span { font-size: 22px; font-weight: 400; line-height: 1; }

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 2fr;
  gap: 12px;
}

.summary-card {
  min-height: 142px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(251,250,246,.72);
  display: flex;
  flex-direction: column;
}
.summary-card.accent { background: var(--green); border-color: var(--green); color: white; }
.summary-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.summary-card.accent .summary-label { color: rgba(255,255,255,.7); }
.summary-card strong { margin-top: auto; font-family: Georgia, "Songti SC", serif; font-size: 42px; font-weight: 500; line-height: 1; }
.summary-card.wide-summary strong { font-family: inherit; font-size: clamp(19px, 2.2vw, 29px); font-weight: 720; line-height: 1.2; letter-spacing: -.03em; }
.summary-card small { margin-top: 8px; color: var(--muted); font-size: 12px; }
.summary-card.accent small { color: rgba(255,255,255,.72); }

.toolbar {
  margin: 28px 0 22px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  align-items: center;
  gap: 12px;
}

.search-box {
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
}
.search-box span { font-size: 22px; transform: translateY(-1px); }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }

.filter-chips { display: flex; align-items: center; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
  appearance: none;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}
.chip.active { border-color: var(--ink); background: var(--ink); color: white; }

.sort-control select {
  min-height: 42px;
  max-width: 190px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 36px 0 14px;
  background-color: var(--paper);
  color: var(--ink);
}

.section-heading { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 13px; }
.section-heading h2, .rules-card h2 { margin: 0; font-family: Georgia, "Songti SC", serif; font-weight: 500; letter-spacing: -.025em; }
.section-heading h2 { font-size: 25px; }
.section-heading span { color: var(--muted); font-size: 13px; }

.listing-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

.listing-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 320px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(251,250,246,.9);
  box-shadow: 0 1px 0 rgba(255,255,255,.7) inset;
}
.listing-card.priority { border-color: rgba(40,90,68,.5); }
.listing-card.excluded { background: rgba(248,244,240,.82); }
.listing-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.rank-badge { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 14px; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .08em; }
.rank-badge::before { content: ""; width: 16px; height: 1px; background: currentColor; }
.listing-card h3 { margin: 0; max-width: 390px; font-size: 21px; line-height: 1.28; letter-spacing: -.025em; }
.community { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.score-ring {
  flex: 0 0 auto;
  width: 69px;
  height: 69px;
  display: grid;
  place-items: center;
  border: 5px solid var(--green-soft);
  border-top-color: var(--green);
  border-radius: 50%;
  font-family: Georgia, serif;
  font-size: 25px;
  line-height: 1;
}
.excluded .score-ring { border-color: var(--red-soft); border-top-color: var(--red); color: var(--red); }

.listing-facts {
  margin: 23px 0 18px;
  padding: 17px 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.fact { min-width: 0; padding: 0 13px; border-right: 1px solid var(--line); }
.fact:first-child { padding-left: 0; }
.fact:last-child { padding-right: 0; border-right: 0; }
.fact span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 10px; font-weight: 750; }
.fact strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }

.score-breakdown { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
.score-item { padding: 9px 4px; border-radius: 9px; background: var(--canvas); text-align: center; }
.score-item strong { display: block; font-family: Georgia, serif; font-size: 17px; }
.score-item span { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }

.listing-note { margin: 15px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.listing-note.reason { color: var(--red); }
.listing-card-footer { margin-top: auto; padding-top: 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.status-pill { display: inline-flex; align-items: center; min-height: 27px; padding: 0 10px; border-radius: 999px; font-size: 11px; font-weight: 750; }
.status-pill.priority { background: var(--green-soft); color: var(--green); }
.status-pill.backup { background: #e7edf1; color: var(--blue); }
.status-pill.caution { background: var(--amber-soft); color: var(--amber); }
.status-pill.rejected { background: var(--red-soft); color: var(--red); }
.status-pill.neutral { background: #e8e8e2; color: var(--muted); }
.card-actions { display: flex; align-items: center; gap: 7px; }
.small-action {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.small-action:hover { color: var(--ink); border-color: #9ea19a; }

.empty-state { padding: 72px 20px; border: 1px dashed #c9cac3; border-radius: var(--radius-lg); text-align: center; }
.empty-state > div { font-size: 40px; color: var(--green); }
.empty-state h2 { margin: 12px 0 6px; font-family: Georgia, "Songti SC", serif; font-weight: 500; }
.empty-state p { margin: 0 0 20px; color: var(--muted); }

.rules-card {
  margin-top: 52px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--paper);
}
.rules-card h2 { font-size: 28px; }
.rules-grid { margin-top: 24px; display: grid; grid-template-columns: repeat(4, 1fr); }
.rules-grid > div { padding: 0 22px; border-left: 1px solid var(--line); }
.rules-grid > div:first-child { padding-left: 0; border-left: 0; }
.rules-grid strong { display: block; font-family: Georgia, serif; font-size: 25px; color: var(--green); }
.rules-grid span { display: block; margin-top: 4px; font-weight: 750; }
.rules-grid small { display: block; margin-top: 6px; color: var(--muted); line-height: 1.45; }
.rules-note { margin: 24px 0 0; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(430px, 100%);
  padding: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(251,250,246,.95);
  box-shadow: var(--shadow);
}
.back-link { display: inline-block; margin-bottom: 32px; color: var(--muted); font-size: 13px; text-decoration: none; }
.login-mark { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 22px; border-radius: 50%; background: var(--green); color: white; font-family: "Songti SC", serif; font-size: 22px; }
.login-card h1 { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 38px; font-weight: 500; }
.login-intro { margin: 12px 0 25px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.login-form { display: grid; gap: 15px; }
.login-form label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.login-form input { min-height: 48px; border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; background: white; outline: 0; font-size: 16px; }
.login-form input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(40,90,68,.1); }
.form-error { min-height: 18px; margin: -3px 0 0; color: var(--red); font-size: 12px; }

dialog { color: var(--ink); }
.sheet {
  width: min(720px, calc(100% - 28px));
  max-height: min(92vh, 900px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 26px;
  background: var(--paper);
  box-shadow: 0 28px 90px rgba(20, 25, 21, .28);
}
.sheet::backdrop, .confirm-dialog::backdrop { background: rgba(21, 26, 22, .52); backdrop-filter: blur(3px); }
.sheet-form { display: flex; flex-direction: column; max-height: min(92vh, 900px); }
.sheet-header { flex: 0 0 auto; display: flex; align-items: flex-start; justify-content: space-between; padding: 25px 28px 17px; border-bottom: 1px solid var(--line); }
.sheet-header h2 { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 29px; font-weight: 500; }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%; background: transparent; font-size: 24px; line-height: 1; cursor: pointer; }
.live-score { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 14px 28px; background: var(--green-soft); border-bottom: 1px solid rgba(40,90,68,.14); }
.live-score > div { display: flex; align-items: baseline; gap: 13px; }
.live-score > div > span { color: var(--green); font-size: 12px; font-weight: 750; }
.live-score strong { font-family: Georgia, serif; color: var(--green); font-size: 28px; }
.live-score strong small { margin-left: 4px; font-family: inherit; color: var(--muted); font-size: 12px; }
.form-scroll { overflow-y: auto; overscroll-behavior: contain; padding: 0 28px; }
.form-section { padding: 26px 0; border-bottom: 1px solid var(--line); }
.form-section:last-child { border-bottom: 0; }
.form-section-title { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.form-section-title > span { color: var(--green); font-family: Georgia, serif; font-size: 12px; }
.form-section-title h3 { margin: 0; font-size: 15px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.field { display: grid; gap: 7px; min-width: 0; }
.field.span-2 { grid-column: span 2; }
.field > span { color: var(--muted); font-size: 12px; font-weight: 700; }
.field em { color: var(--red); font-style: normal; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: white;
  color: var(--ink);
  outline: 0;
  font-size: 16px;
}
.field input, .field select { min-height: 47px; padding: 0 13px; }
.field textarea { resize: vertical; min-height: 100px; padding: 12px 13px; line-height: 1.55; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(40,90,68,.09); }
.check-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.check-card { position: relative; }
.check-card input { position: absolute; opacity: 0; pointer-events: none; }
.check-card span { min-height: 45px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 11px; background: white; color: var(--muted); font-size: 13px; cursor: pointer; }
.check-card input:checked + span { border-color: var(--green); background: var(--green-soft); color: var(--green); font-weight: 750; }
.check-card input:focus-visible + span { outline: 3px solid rgba(40,90,68,.18); }
.field-hint { margin: 11px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.sheet-footer { flex: 0 0 auto; display: flex; justify-content: flex-end; gap: 10px; padding: 16px 28px max(16px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--paper); }

.confirm-dialog { width: min(440px, calc(100% - 30px)); padding: 0; border: 0; border-radius: 22px; background: var(--paper); box-shadow: var(--shadow); }
.confirm-dialog > div { padding: 28px; }
.confirm-dialog h2 { margin: 0; font-family: Georgia, "Songti SC", serif; font-weight: 500; }
.confirm-dialog p:not(.eyebrow) { color: var(--muted); line-height: 1.6; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 25px; }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  padding: 11px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: white;
  font-size: 13px;
  box-shadow: var(--shadow);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

:focus-visible { outline: 3px solid rgba(40,90,68,.28); outline-offset: 2px; }

@media (max-width: 850px) {
  .toolbar { grid-template-columns: 1fr auto; }
  .filter-chips { grid-column: 1 / -1; grid-row: 2; }
  .listing-grid { grid-template-columns: 1fr; }
  .rules-grid { grid-template-columns: 1fr 1fr; row-gap: 24px; }
  .rules-grid > div:nth-child(3) { padding-left: 0; border-left: 0; }
}

@media (max-width: 640px) {
  .app-shell { width: min(100% - 24px, 540px); }
  .topbar { min-height: 64px; }
  .sync-state { display: none; }
  .hero { display: block; padding: 40px 0 24px; }
  .hero h1 { font-size: 38px; }
  .hero-copy { font-size: 14px; }
  .add-button { width: 100%; margin-top: 24px; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-card { min-height: 120px; padding: 17px; }
  .summary-card strong { font-size: 36px; }
  .summary-card.wide-summary { grid-column: 1 / -1; min-height: 106px; }
  .summary-card.wide-summary strong { font-size: 20px; }
  .toolbar { grid-template-columns: 1fr; margin-top: 20px; }
  .sort-control { grid-row: 2; }
  .sort-control select { width: 100%; max-width: none; }
  .filter-chips { grid-row: 3; }
  .listing-card { min-height: 0; padding: 18px; border-radius: 19px; }
  .listing-card h3 { font-size: 19px; }
  .score-ring { width: 61px; height: 61px; font-size: 22px; }
  .listing-facts { margin: 18px 0 15px; }
  .fact { padding-inline: 9px; }
  .fact strong { font-size: 13px; }
  .score-breakdown { gap: 4px; }
  .score-item strong { font-size: 16px; }
  .listing-card-footer { align-items: flex-end; }
  .card-actions { gap: 5px; }
  .small-action { padding-inline: 10px; }
  .rules-card { margin-top: 36px; padding: 22px 18px; }
  .rules-grid { grid-template-columns: 1fr 1fr; }
  .rules-grid > div { padding: 0 12px; }
  .rules-grid > div:nth-child(odd) { padding-left: 0; border-left: 0; }
  .rules-grid > div:nth-child(3) { padding-left: 0; }
  .login-view { padding: 14px; }
  .login-card { padding: 28px 22px; }
  .sheet { width: 100%; max-width: none; max-height: 96dvh; margin: auto 0 0; border-radius: 24px 24px 0 0; }
  .sheet-form { max-height: 96dvh; }
  .sheet-header { padding: 20px 18px 14px; }
  .live-score { padding: 12px 18px; }
  .form-scroll { padding: 0 18px; }
  .field-grid { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: auto; }
  .check-grid { grid-template-columns: 1fr 1fr; }
  .sheet-footer { padding: 13px 18px max(13px, env(safe-area-inset-bottom)); }
  .sheet-footer .button { flex: 1; }
}

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