:root {
  --bg: #f6f3ef;
  --bg-accent: #fff1e8;
  --card: #ffffff;
  --text: #241c17;
  --muted: #7b7068;
  --border: #e9e1da;
  --accent: #ff6633;
  --accent-dark: #e85322;
  --accent-soft: #fff0e8;
  --success: #18794e;
  --success-soft: #e9f8ef;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --warning-soft: #fff8e6;
  --warning-border: #f2d48b;
  --shadow: 0 18px 50px rgba(74, 48, 33, 0.09);
  --radius: 20px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: pan-y;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding-right: env(safe-area-inset-right);
  padding-left: env(safe-area-inset-left);
  color: var(--text);
  background:
    radial-gradient(circle at 12% 0%, var(--bg-accent), transparent 34rem),
    linear-gradient(180deg, #fbf9f6 0%, var(--bg) 100%);
  font-family:
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
  overscroll-behavior-x: none;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}

img {
  display: block;
  max-width: 100%;
}

button,
a,
input,
textarea,
summary,
label {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.page {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: calc(44px + env(safe-area-inset-top)) 0 calc(32px + env(safe-area-inset-bottom));
}

.hero {
  padding: 0 4px 28px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  color: #fff;
  background: linear-gradient(135deg, #ff8a4c, var(--accent));
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  box-shadow: 0 6px 14px rgba(255, 102, 51, 0.28);
}

.hero h1 {
  margin: 18px 0 8px;
  font-size: clamp(32px, 5vw, 54px);
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.hero p {
  max-width: 620px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.card {
  padding: 24px;
  border: 1px solid rgba(233, 225, 218, 0.9);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field > span,
.field-group summary {
  font-size: 14px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  color: var(--text);
  background: #fffdfb;
  font: inherit;
  font-size: 14px;
  outline: none;
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 102, 51, 0.12);
}

textarea {
  resize: vertical;
  min-height: 108px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12.5px;
  line-height: 1.55;
}

.field-group {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fffdfb;
}

.field-group summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.field-group summary::-webkit-details-marker {
  display: none;
}

.field-group summary::after {
  content: "+";
  margin-left: auto;
  color: var(--muted);
  font-weight: 400;
}

.field-group[open] summary::after {
  content: "−";
}

.details-body {
  padding: 0 14px 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 1px 8px;
  border-radius: 999px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 11px;
  font-weight: 700;
}

.badge.ok {
  color: var(--success);
  background: var(--success-soft);
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

button,
.result-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 0 18px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    background 0.15s ease,
    box-shadow 0.15s ease;
}

button:active,
.result-actions a:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.primary {
  color: #fff;
  background: linear-gradient(135deg, #ff7b42, var(--accent));
  box-shadow: 0 8px 18px rgba(255, 102, 51, 0.22);
}

.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #ff6b2c, var(--accent-dark));
}

.secondary {
  color: var(--text);
  background: #f3eee9;
}

.secondary:hover {
  background: #ebe3dc;
}

#extract-btn {
  width: 100%;
  margin-top: 18px;
  min-height: 50px;
  font-size: 15px;
}

.card > form > .primary {
  width: 100%;
  margin-top: 16px;
}

.status {
  min-height: 24px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.status.loading {
  color: var(--accent-dark);
}

.status.success {
  color: var(--success);
}

.status.error {
  color: var(--danger);
}

.result {
  margin-top: 26px;
  padding: 24px;
  border: 1px solid rgba(233, 225, 218, 0.9);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.result-title-wrap {
  min-width: 0;
}

.result h2 {
  margin: 0 0 6px;
  font-size: clamp(20px, 3vw, 28px);
  line-height: 1.3;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

.result-actions .primary,
.result-actions .secondary {
  min-height: 40px;
  padding: 0 14px;
  font-size: 13px;
}

.warnings {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--warning-border);
  border-radius: 12px;
  color: #7a5200;
  background: var(--warning-soft);
  font-size: 13px;
}

.warnings ul {
  margin: 0;
  padding-left: 18px;
}

.caption {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fbf8f5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.85;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.grid figure {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #f2ece6;
}

.grid a {
  display: block;
  aspect-ratio: 3 / 4;
  overflow: hidden;
}

.grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}

.grid a:hover img {
  transform: scale(1.025);
}

.grid figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 9px;
  color: var(--muted);
  background: #fff;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.grid figcaption span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grid figcaption .mini {
  flex-shrink: 0;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 700;
  box-shadow: none;
}

.grid figcaption .mini:hover {
  background: #ffe3d6;
}

.footer {
  padding: 26px 4px 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.footer p {
  margin: 2px 0;
}

.footer-tip {
  max-width: 680px;
  margin: 8px auto 0 !important;
  line-height: 1.7;
}

.footer a {
  color: var(--accent-dark);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* Admin */
.admin-page {
  width: min(860px, calc(100% - 32px));
}

.admin-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.admin-head h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.admin-actions button {
  flex: 1 1 180px;
}

.danger {
  color: #fff;
  background: linear-gradient(135deg, #e35d5d, #b42318);
  box-shadow: 0 8px 18px rgba(180, 35, 24, 0.18);
}

.danger:hover:not(:disabled) {
  background: linear-gradient(135deg, #d94b4b, #9f1f15);
}

.admin-cookie-state {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 14px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbf8f5;
  font-size: 13px;
}

.admin-cookie-state strong {
  color: var(--text);
}

.admin-cookie-state .ok {
  color: var(--success);
}

.admin-cookie-state .warn {
  color: var(--danger);
}

.admin-cookie-state a {
  color: var(--accent-dark);
  text-decoration: none;
}

.admin-cookie-state a:hover {
  text-decoration: underline;
}

.admin-page .status {
  min-height: 24px;
}

@media (max-width: 640px) {
  .admin-page {
    width: min(100% - 20px, 860px);
  }

  .admin-head {
    flex-direction: column;
  }

  .admin-head .secondary {
    width: 100%;
  }

  .admin-actions button {
    flex-basis: 100%;
  }
}

@media (max-width: 1024px) {
  input,
  textarea {
    font-size: 16px;
  }
}

@media (max-width: 640px) {
  .page {
    width: min(100% - 20px, 1080px);
    padding-top: calc(26px + env(safe-area-inset-top));
  }

  input,
  textarea {
    /* iOS/WeChat will zoom into fields whose font-size is below 16px. */
    font-size: 16px;
  }

  .card,
  .result {
    padding: 18px;
    border-radius: 16px;
  }

  .result-head {
    flex-direction: column;
  }

  .result-actions {
    width: 100%;
  }

  .result-actions .primary,
  .result-actions .secondary {
    flex: 1;
    min-width: 0;
  }

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