:root {
  color-scheme: light;
  --ink: #19221c;
  --muted: #68756c;
  --line: #dce4de;
  --paper: #fbfcfa;
  --surface: #ffffff;
  --soft: #f1f6f2;
  --green: #187b55;
  --green-dark: #0e5c3d;
  --green-soft: #dff1e7;
  --orange: #f47b20;
  --orange-soft: #fff0df;
  --shadow: 0 20px 60px rgba(20, 45, 30, 0.1);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 15% -10%, rgba(36, 151, 101, 0.15), transparent 32rem),
    radial-gradient(circle at 95% 6%, rgba(244, 123, 32, 0.11), transparent 25rem),
    var(--paper);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
.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; }
.app-shell { width: min(1320px, 100%); margin: 0 auto; padding: 18px 24px 40px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; min-height: 70px; }
.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px; color: #fff; background: linear-gradient(145deg, var(--green), #0c5236); box-shadow: 0 10px 24px rgba(24, 123, 85, 0.25); font-size: 18px; font-weight: 900; }
.brand > span:last-child { display: grid; gap: 1px; }
.brand small { color: var(--muted); font-size: 11px; }
.brand strong { font-size: 17px; }
.top-actions { display: flex; gap: 9px; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; border: 1px solid var(--line); border-radius: 12px; padding: 0 15px; color: var(--ink); background: #fff; font-weight: 800; }
.button:hover, .button:focus-visible { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(24, 123, 85, 0.12); }
.button-primary { border-color: var(--green); color: #fff; background: var(--green); }
.button-primary:hover, .button-primary:focus-visible { background: var(--green-dark); }
.button-quiet { background: rgba(255, 255, 255, 0.74); }
.button-search { min-width: 142px; border-color: #1b1f1c; color: #fff; background: #1b1f1c; }

.search-stage { display: grid; grid-template-columns: minmax(280px, 0.74fr) minmax(520px, 1.26fr); gap: 34px; align-items: center; margin-top: 22px; padding: 42px; border: 1px solid rgba(24, 123, 85, 0.16); border-radius: 30px; background: rgba(255, 255, 255, 0.84); box-shadow: var(--shadow); backdrop-filter: blur(16px); }
.stage-copy { display: grid; gap: 12px; }
.eyebrow { margin: 0; color: var(--green); font-size: 12px; font-weight: 900; letter-spacing: 0.08em; text-transform: uppercase; }
h1, h2, p { margin: 0; }
h1 { max-width: 520px; font-size: clamp(38px, 5vw, 66px); line-height: 0.98; letter-spacing: -0.055em; }
.stage-copy > p:last-child { max-width: 500px; color: var(--muted); font-size: 16px; line-height: 1.75; }
.intent-search { display: grid; gap: 12px; }
.search-input-wrap { position: relative; }
.search-input-wrap textarea { width: 100%; min-height: 126px; resize: vertical; border: 2px solid #cad7ce; border-radius: 22px; padding: 21px 138px 21px 21px; color: var(--ink); background: #fff; font-size: 17px; line-height: 1.6; outline: none; }
.search-input-wrap textarea:focus { border-color: var(--green); box-shadow: 0 0 0 5px rgba(24, 123, 85, 0.1); }
.voice-button { position: absolute; top: 16px; right: 16px; display: inline-flex; align-items: center; gap: 7px; min-height: 40px; border: 0; border-radius: 999px; padding: 0 13px; color: var(--green-dark); background: var(--green-soft); font-size: 13px; font-weight: 900; }
.voice-button > span:first-child { color: #e34242; font-size: 9px; }
.voice-button.is-listening { color: #fff; background: #d83f3f; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(216, 63, 63, 0.12); } }
.search-actions { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 7px; }
.suggestions button, .filters button { min-height: 34px; border: 1px solid var(--line); border-radius: 999px; padding: 0 11px; color: var(--muted); background: #fff; font-size: 12px; }
.suggestions button:hover, .filters button:hover, .filters button[aria-pressed="true"] { border-color: var(--green); color: var(--green-dark); background: var(--green-soft); }

.match-section, .library-section { margin-top: 24px; border: 1px solid var(--line); border-radius: 24px; padding: 26px; background: rgba(255, 255, 255, 0.8); }
.match-section { border-color: rgba(244, 123, 32, 0.24); background: linear-gradient(145deg, rgba(255, 240, 223, 0.76), rgba(255, 255, 255, 0.94)); }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.section-heading > div { display: grid; gap: 6px; }
.section-heading h2 { font-size: clamp(24px, 3vw, 34px); line-height: 1.1; letter-spacing: -0.035em; }
.text-button { border: 0; color: var(--green); background: transparent; font-size: 13px; font-weight: 900; }
.match-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; }
.match-card { display: grid; gap: 12px; border: 1px solid #f0d6ba; border-radius: 18px; padding: 17px; background: #fff; box-shadow: 0 10px 30px rgba(92, 51, 13, 0.07); }
.match-rank { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.match-number { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 10px; color: #fff; background: var(--orange); font-weight: 900; }
.confidence { color: #a45b1e; font-size: 12px; font-weight: 900; }
.match-card h3 { margin: 0; font-size: 18px; line-height: 1.35; }
.match-card p { color: var(--muted); font-size: 13px; line-height: 1.65; }
.match-reason { min-height: 34px; border-radius: 10px; padding: 8px 10px; color: #8a501e !important; background: var(--orange-soft); }
.match-card .button { width: 100%; }
.match-note { margin-top: 12px; color: var(--muted); font-size: 12px; }

.library-heading { margin-bottom: 14px; }
.count-pill { border-radius: 999px; padding: 7px 11px; color: var(--green-dark); background: var(--green-soft); font-size: 12px; font-weight: 900; }
.library-tools { display: grid; grid-template-columns: minmax(260px, 0.7fr) minmax(0, 1.3fr); gap: 12px; align-items: center; margin-bottom: 10px; }
.library-search { display: flex; align-items: center; gap: 8px; min-height: 44px; border: 1px solid var(--line); border-radius: 12px; padding: 0 13px; background: #fff; }
.library-search:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(24, 123, 85, 0.09); }
.library-search span { color: var(--muted); font-size: 20px; }
.library-search input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; }
.filters { display: flex; gap: 7px; overflow-x: auto; padding: 3px 0; }
.filters button { flex: 0 0 auto; }
.cloud-status { min-height: 22px; margin: 8px 0 10px; color: var(--muted); font-size: 12px; }
.cloud-status.is-ok { color: var(--green); }
.cloud-status.is-error { color: #b74242; }
.card-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.prompt-card { overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: #fff; transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease; }
.prompt-card:hover { transform: translateY(-2px); border-color: rgba(24, 123, 85, 0.45); box-shadow: 0 15px 34px rgba(24, 47, 32, 0.1); }
.card-cover { position: relative; display: grid; place-items: center; aspect-ratio: 16 / 8.5; overflow: hidden; color: #fff; background: linear-gradient(145deg, #143728, #219068); }
.card-cover[data-tone="orange"] { background: linear-gradient(145deg, #201710, #f47b20); }
.card-cover[data-tone="blue"] { background: linear-gradient(145deg, #172639, #3f83c8); }
.card-cover[data-tone="purple"] { background: linear-gradient(145deg, #2f1e3d, #8c59b2); }
.card-cover[data-tone="red"] { background: linear-gradient(145deg, #41191f, #ca4755); }
.card-cover[data-tone="green"] { background: linear-gradient(145deg, #071711, #16845d); }
.card-cover img { width: 100%; height: 100%; object-fit: cover; }
.cover-fallback { display: grid; gap: 5px; text-align: center; padding: 14px; }
.cover-icon { font-size: 30px; }
.cover-label { max-width: 220px; font-size: 13px; font-weight: 900; opacity: 0.92; }
.source-chip { position: absolute; top: 10px; left: 10px; border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 999px; padding: 4px 8px; background: rgba(10, 20, 15, 0.55); backdrop-filter: blur(8px); font-size: 10px; font-weight: 800; }
.card-body { display: grid; gap: 10px; padding: 15px; }
.card-category { color: var(--green); font-size: 11px; font-weight: 900; }
.card-body h3 { min-height: 45px; margin: 0; font-size: 16px; line-height: 1.4; }
.card-purpose { display: -webkit-box; min-height: 57px; overflow: hidden; color: var(--muted); font-size: 12px; line-height: 1.6; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.invocation-box { border-radius: 11px; padding: 10px; color: #2f4939; background: var(--soft); font-size: 12px; line-height: 1.55; }
.card-actions { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.card-actions .button { min-height: 38px; padding: 0 10px; font-size: 12px; }
.icon-action { width: 38px; border: 1px solid var(--line); border-radius: 11px; color: var(--muted); background: #fff; font-weight: 900; }
.empty-state { display: grid; place-items: center; gap: 6px; min-height: 240px; color: var(--muted); }
.empty-state strong { color: var(--ink); }
.footer { display: flex; justify-content: space-between; gap: 18px; padding: 26px 4px 0; color: var(--muted); font-size: 12px; }

dialog { padding: 0; border: 0; color: var(--ink); background: transparent; }
dialog::backdrop { background: rgba(8, 15, 10, 0.56); backdrop-filter: blur(5px); }
.detail-dialog { width: min(820px, calc(100% - 24px)); max-height: calc(100vh - 24px); }
.dialog-shell, .editor-shell { border: 1px solid var(--line); border-radius: 24px; background: #fff; box-shadow: 0 26px 90px rgba(0, 0, 0, 0.24); }
.dialog-shell { display: grid; gap: 18px; padding: 24px; }
.dialog-head, .editor-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog-head > div, .editor-head > div { display: grid; gap: 7px; }
.dialog-head h2, .editor-head h2 { margin: 0; font-size: 27px; line-height: 1.18; }
.dialog-close { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); background: #fff; font-size: 24px; }
.detail-purpose { color: var(--muted); line-height: 1.7; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.detail-tags span { border-radius: 999px; padding: 5px 9px; color: var(--green-dark); background: var(--green-soft); font-size: 11px; font-weight: 800; }
.detail-section { display: grid; gap: 8px; }
.detail-section h3 { margin: 0; font-size: 13px; }
.detail-section ul { margin: 0; padding-left: 20px; color: var(--muted); line-height: 1.7; }
.detail-invocation { border-left: 4px solid var(--orange); border-radius: 12px; padding: 13px 14px; background: var(--orange-soft); font-weight: 800; line-height: 1.7; }
.prompt-block { max-height: 300px; overflow: auto; margin: 0; border: 1px solid var(--line); border-radius: 14px; padding: 15px; color: #dce8e0; background: #172019; font: 13px/1.75 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.detail-actions .danger { color: #b13b3b; }

.editor-dialog { width: min(900px, calc(100% - 24px)); max-height: calc(100vh - 24px); }
.editor-shell { padding: 24px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; max-height: calc(100vh - 230px); overflow: auto; margin-top: 20px; padding-right: 4px; }
.field { display: grid; gap: 6px; }
.field-wide { grid-column: 1 / -1; }
.field > span { font-size: 12px; font-weight: 900; }
.field input, .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; color: var(--ink); background: #fbfcfa; outline: none; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(24, 123, 85, 0.09); }
.upload-field small { color: var(--muted); }
.editor-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; }
.editor-actions > div { display: flex; gap: 8px; }
#editorStatus { color: var(--muted); font-size: 12px; }
#editorStatus.is-error { color: #b74242; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 100; max-width: min(360px, calc(100% - 40px)); transform: translateY(18px); opacity: 0; pointer-events: none; border-radius: 13px; padding: 12px 15px; color: #fff; background: #18251d; box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2); transition: 160ms ease; }
.toast.is-visible { transform: translateY(0); opacity: 1; }

@media (max-width: 1060px) {
  .search-stage { grid-template-columns: 1fr; padding: 32px; }
  .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .match-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-shell { padding: 12px 12px 30px; }
  .topbar { align-items: flex-start; }
  .brand small { display: none; }
  .top-actions .button { min-height: 38px; padding: 0 10px; font-size: 12px; }
  .search-stage { margin-top: 10px; padding: 22px 16px; border-radius: 22px; }
  h1 { font-size: 42px; }
  .search-input-wrap textarea { min-height: 145px; padding: 17px; padding-top: 62px; font-size: 16px; }
  .voice-button { left: 14px; right: auto; top: 14px; }
  .search-actions { display: grid; }
  .button-search { width: 100%; }
  .match-section, .library-section { padding: 18px 14px; border-radius: 20px; }
  .library-tools { grid-template-columns: 1fr; }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .section-heading { align-items: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .editor-actions { align-items: stretch; flex-direction: column; }
  .editor-actions > div { display: grid; grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .brand strong { font-size: 14px; }
  .brand-mark { width: 36px; height: 36px; border-radius: 11px; }
  .top-actions { gap: 5px; }
  .top-actions .button-quiet { display: none; }
  .card-grid { grid-template-columns: 1fr; }
  .prompt-card { display: grid; grid-template-columns: 122px 1fr; }
  .card-cover { aspect-ratio: auto; min-height: 100%; }
  .card-body h3 { min-height: auto; }
  .card-purpose { min-height: auto; -webkit-line-clamp: 2; }
  .invocation-box { display: none; }
  .footer { flex-direction: column; }
}
