@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Noto+Serif+SC:wght@500;600;700&family=Noto+Sans+SC:wght@400;500;600;700&display=swap');

:root {
  --ink: #202523;
  --muted: #717a75;
  --paper: #f5f1e8;
  --surface: #fcfaf5;
  --line: #dcd7ca;
  --acid: #d9ee59;
  --orange: #fd7b4a;
  --deep: #26332d;
  --serif: 'Noto Serif SC', 'Songti SC', serif;
  --sans: 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  background-image: radial-gradient(circle at 10% 0%, rgba(217, 238, 89, .22), transparent 22rem), linear-gradient(90deg, rgba(38, 51, 45, .035) 1px, transparent 1px), linear-gradient(rgba(38, 51, 45, .035) 1px, transparent 1px);
  background-size: auto, 26px 26px, 26px 26px;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.shell { max-width: 1320px; margin: 0 auto; padding: 52px 32px 64px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.eyebrow, .section-kicker { margin: 0; color: var(--muted); font: 500 11px/1.2 'DM Mono', monospace; letter-spacing: .08em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin: 8px 0 0; font: 700 clamp(34px, 5vw, 58px)/1.08 var(--serif); letter-spacing: -.055em; }
h2 { margin: 7px 0 0; font: 700 22px/1.2 var(--serif); letter-spacing: -.03em; }
.intro { max-width: 600px; margin: 28px 0 42px; font-size: 16px; line-height: 1.75; }
.intro p { margin-bottom: 5px; }
.fine-print { color: var(--muted); font-size: 13px; }
.workspace { display: grid; grid-template-columns: minmax(300px, .75fr) minmax(0, 1.35fr); gap: 18px; align-items: start; }
.panel { border: 1px solid var(--ink); background: rgba(252, 250, 245, .94); box-shadow: 5px 5px 0 rgba(38, 51, 45, .12); }
.trends-panel { min-height: 650px; }
.composer-panel { padding: 30px; }
.panel-heading, .output-head, .output-footer, .dialog-heading, .dialog-actions { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.trends-panel .panel-heading { padding: 25px 24px 17px; }
.button { min-height: 42px; padding: 0 17px; border: 1px solid var(--ink); border-radius: 0; font-weight: 700; transition: transform .15s ease, box-shadow .15s ease; }
.button:hover:not(:disabled) { transform: translate(-2px, -2px); box-shadow: 3px 3px 0 var(--ink); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.ghost { background: transparent; }
.primary { background: var(--acid); color: var(--ink); }
.dark { background: var(--deep); color: #fff; border-color: var(--deep); }
.icon-button, .dialog-close { width: 37px; height: 37px; border: 1px solid var(--line); background: transparent; color: var(--ink); font-size: 25px; line-height: 1; }
.icon-button:hover, .dialog-close:hover { background: var(--acid); }
.source-tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.source-tab { min-height: 42px; border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 12px; }
.source-tab:last-child { border-right: 0; }
.source-tab.active { background: var(--deep); color: #fff; font-weight: 700; }
.status-line { min-height: 42px; padding: 14px 24px 0; color: var(--muted); font-size: 12px; }
.trend-list { padding: 12px; display: grid; gap: 8px; }
.trend-card { width: 100%; padding: 13px 12px; border: 1px solid transparent; background: transparent; text-align: left; transition: background .15s, border-color .15s; }
.trend-card:hover { border-color: var(--line); background: #fffdf7; }
.trend-card.active { border-color: var(--ink); background: var(--acid); }
.trend-source { display: block; margin-bottom: 5px; color: var(--muted); font: 500 10px/1.2 'DM Mono', monospace; letter-spacing: .03em; }
.trend-title { display: block; font-size: 15px; line-height: 1.45; }
.trend-summary { display: -webkit-box; overflow: hidden; margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.55; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.length-select { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; }
.length-select select { min-height: 36px; padding: 0 8px; border: 1px solid var(--line); background: #fffdf7; color: var(--ink); }
.selected-trend { display: flex; gap: 13px; margin: 32px 0 20px; padding: 18px; border: 1px solid var(--line); background: #fffdf7; }
.selected-trend.empty { color: var(--muted); }
.selection-dot { flex: 0 0 auto; width: 10px; height: 10px; margin-top: 6px; border-radius: 50%; background: var(--orange); }
.selected-label { margin-bottom: 5px; color: var(--muted); font: 500 11px/1.2 'DM Mono', monospace; }
.selected-title { margin-bottom: 0; font: 600 16px/1.55 var(--serif); }
.generate { width: 100%; min-height: 52px; font-size: 15px; }
.generate.loading { background: repeating-linear-gradient(-45deg, var(--acid), var(--acid) 12px, #eaf58d 12px, #eaf58d 24px); }
.generate-hint { margin: 11px 0 35px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.generate-hint.error { color: #b53418; font-weight: 700; }
.output-head { margin-bottom: 14px; }
.count-badge { padding: 5px 9px; background: var(--ink); color: #fff; font: 500 11px/1.2 'DM Mono', monospace; }
.result { display: block; width: 100%; min-height: 355px; padding: 17px; resize: vertical; border: 1px solid var(--line); border-radius: 0; outline: none; background: #fffdf7; color: var(--ink); font: 16px/1.85 var(--serif); }
.result:focus { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.result::placeholder { color: #a7aaa3; }
.output-footer { margin-top: 14px; }
.polish-status { color: var(--muted); font-size: 12px; }
.output-actions { display: flex; align-items: center; gap: 12px; }
.text-button { padding: 6px 0; border: 0; border-bottom: 1px solid currentColor; background: none; color: var(--ink); font-size: 13px; }
.text-button:disabled { cursor: not-allowed; opacity: .4; }
.settings-dialog { width: min(540px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--ink); background: var(--surface); box-shadow: 7px 7px 0 rgba(38, 51, 45, .18); }
.settings-dialog::backdrop { background: rgba(32, 37, 35, .48); backdrop-filter: blur(3px); }
.settings-dialog form { padding: 28px; }
.dialog-note { margin: 22px 0 18px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.settings-dialog label { display: grid; gap: 7px; margin-top: 14px; color: var(--muted); font-size: 12px; }
.settings-dialog input { width: 100%; min-height: 43px; padding: 0 11px; border: 1px solid var(--line); outline: none; background: #fffdf7; color: var(--ink); }
.settings-dialog input:focus { border-color: var(--ink); }
.dialog-actions { margin-top: 25px; }
@media (max-width: 820px) { .shell { padding: 30px 16px 42px; } .workspace { grid-template-columns: 1fr; } .trends-panel { min-height: 0; } .composer-panel { padding: 22px; } }
@media (max-width: 480px) { h1 { font-size: 36px; } .topbar { align-items: center; } .topbar .button { padding: 0 11px; font-size: 12px; } .panel-heading, .output-head { align-items: flex-start; } .length-select { flex-direction: column; align-items: flex-end; gap: 4px; } .output-footer { align-items: flex-start; flex-direction: column; } }

/* Mobile-first overrides */
@media (max-width: 820px) {
  html { min-width: 320px; background: var(--paper); }
  body { min-height: 100dvh; overflow-x: hidden; }
  button, select, input, textarea { -webkit-tap-highlight-color: transparent; }
  .shell {
    padding: max(24px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  .workspace { grid-template-columns: 1fr; gap: 16px; }
  .trends-panel { min-height: 0; }
  .composer-panel { padding: 22px; }
}

@media (max-width: 600px) {
  body { background-image: radial-gradient(circle at 10% 0%, rgba(217, 238, 89, .2), transparent 19rem); }
  .shell { padding-top: max(18px, env(safe-area-inset-top)); }
  .topbar { align-items: center; gap: 12px; }
  .eyebrow { font-size: 10px; }
  h1 { margin-top: 5px; font-size: clamp(31px, 10vw, 42px); line-height: 1.12; }
  h2 { font-size: 20px; }
  .topbar .button { min-height: 44px; padding: 0 12px; font-size: 12px; white-space: nowrap; }
  .intro { margin: 18px 0 26px; font-size: 14px; line-height: 1.7; }
  .fine-print { font-size: 12px; }

  .panel { box-shadow: 3px 3px 0 rgba(38, 51, 45, .12); }
  .trends-panel { order: 1; }
  .composer-panel { order: 2; padding: 18px 15px; }
  .trends-panel .panel-heading { padding: 18px 15px 13px; }
  .panel-heading, .output-head { gap: 12px; }
  .icon-button, .dialog-close { width: 44px; height: 44px; }
  .source-tab { min-height: 46px; font-size: 13px; }
  .status-line { min-height: 36px; padding: 10px 15px 0; }
  .trend-list {
    max-height: min(52svh, 430px);
    padding: 9px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .trend-card { min-height: 72px; padding: 12px; }
  .trend-title { font-size: 16px; line-height: 1.4; }
  .trend-summary { -webkit-line-clamp: 1; }

  .composer-panel .panel-heading { align-items: flex-start; }
  .length-select { gap: 5px; align-items: flex-end; }
  .length-select select { min-height: 42px; font-size: 14px; }
  .selected-trend { margin: 22px 0 16px; padding: 15px 13px; gap: 10px; }
  .selected-title { font-size: 15px; line-height: 1.5; }
  .generate { min-height: 54px; font-size: 16px; }
  .generate-hint { margin: 10px 1px 26px; }
  .output-head { align-items: center; margin-bottom: 12px; }
  .count-badge { flex: 0 0 auto; }
  .result { min-height: 44svh; padding: 14px; font-size: 16px; line-height: 1.8; resize: vertical; }
  .output-footer { align-items: stretch; flex-direction: column; gap: 13px; }
  .polish-status { line-height: 1.55; }
  .output-actions { justify-content: space-between; gap: 14px; }
  .output-actions .button, .text-button { min-height: 44px; }

  .settings-dialog { width: calc(100vw - 24px); max-height: calc(100dvh - 24px); }
  .settings-dialog form { max-height: calc(100dvh - 24px); padding: 22px 17px; overflow-y: auto; }
  .settings-dialog input { min-height: 46px; font-size: 16px; }
  .dialog-actions { align-items: stretch; flex-direction: column-reverse; gap: 12px; }
  .dialog-actions .button { min-height: 46px; }
}

@media (max-width: 360px) {
  .shell { padding-left: 10px; padding-right: 10px; }
  .source-tab { font-size: 12px; }
  .topbar .button { padding: 0 9px; }
  .length-select span { display: none; }
  .result { min-height: 40svh; }
}

@media (hover: none) {
  .button:hover:not(:disabled) { transform: none; box-shadow: none; }
  .trend-card:hover { border-color: transparent; background: transparent; }
  .trend-card.active:hover { border-color: var(--ink); background: var(--acid); }
}
