:root {
  color-scheme: light;
  --bg: #f5f5f4;
  --surface: #ffffff;
  --text: #1f1f1e;
  --muted: #5f5f5b;
  --line: #deded9;
  --accent: #2b2b29;
  --accent-text: #ffffff;
  --danger: #a32a1f;
  --radius: 10px;
  --gutter: 16px;
  --bottom-inset: 0px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.65;
  padding-bottom: calc(var(--bottom-inset) + env(safe-area-inset-bottom, 0px));
}

body.overlay-open { overflow: hidden; }
body.busy button { pointer-events: none; opacity: .6; }

h1, h2, p { margin: 0; }

button, textarea { font: inherit; color: inherit; }

button {
  min-height: 44px;
  border-radius: var(--radius);
  cursor: pointer;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 12px var(--gutter);
}

.site-header h1 {
  max-width: 880px;
  margin: 0 auto;
  font-size: 16px;
  font-weight: 600;
}

.view {
  max-width: 880px;
  margin: 0 auto;
  padding: 20px var(--gutter) 32px;
}

.narrow { max-width: 560px; margin: 0 auto; }
.stack > * + * { margin-top: 16px; }

.page-title { font-size: 20px; line-height: 1.4; font-weight: 600; }

.btn {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.btn-secondary { background: transparent; color: var(--text); border-color: var(--line); font-weight: 400; }
.btn:disabled { opacity: .4; cursor: default; }
.actions > * + * { margin-top: 10px; }

/* S1 */
.prompt-field {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.prompt-prefix { font-weight: 600; }

.prompt-field textarea {
  display: block;
  width: 100%;
  min-height: 112px;
  margin-top: 6px;
  padding: 0;
  border: 0;
  outline: 0;
  resize: vertical;
  background: transparent;
  font-size: 16px; /* iOS 低于 16px 会在聚焦时缩放页面 */
}

.prompt-field:focus-within { border-color: var(--accent); }
.form-error { color: var(--danger); font-size: 14px; }

/* S2 */
.list-hint { color: var(--muted); margin-bottom: 16px; }

.product-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

@media (min-width: 600px) {
  .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.product-card {
  display: block;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-align: left;
}

.product-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.card-art, .card-text > span { display: block; }
.placeholder-art { display: block; width: 100%; height: auto; }
.detail-art { width: 120px; margin: 0 auto 12px; }
.card-name { font-size: 17px; font-weight: 600; }
.card-price { margin-top: 2px; }
.card-line { margin-top: 6px; color: var(--muted); font-size: 14px; }

/* S3 */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  background: var(--surface);
}

.detail {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: var(--surface);
  outline: 0;
}

.detail-top {
  flex: none;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}

.detail-back {
  padding: 0 8px;
  border: 0;
  background: none;
}

.detail-back::before { content: "‹"; margin-right: 6px; }

.detail-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px var(--gutter) 24px;
}

.detail-name { font-size: 20px; line-height: 1.4; font-weight: 600; }
.detail-price { margin-top: 2px; font-weight: 600; }

.detail-facts { margin: 12px 0 0; }
.detail-facts p { color: var(--muted); font-size: 15px; }

.detail-section { margin-top: 18px; }
.detail-section h3 { margin: 0 0 4px; font-size: 16px; font-weight: 400; color: var(--text); }
.detail-section p { font-size: 16px; font-weight: 400; color: var(--text); }

.detail-foot {
  flex: none;
  padding: 12px var(--gutter) calc(12px + var(--bottom-inset) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
}

.confirm-question { margin-bottom: 10px; font-weight: 600; }

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

@media (min-width: 600px) {
  .overlay { align-items: center; padding: 32px; background: rgba(31, 31, 30, .45); }
  .detail { max-width: 560px; height: auto; max-height: 100%; border-radius: 12px; overflow: hidden; }
  .detail-foot { padding-bottom: 12px; }
}

/* S4 */
.option {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-align: left;
}

.option[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }
.options > * + * { margin-top: 10px; }

/* S5 */
.completion-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  letter-spacing: .08em;
  white-space: nowrap;
  -webkit-user-select: all;
  user-select: all;
}

.btn.copied::after { content: " ✓"; }

/* 等待与重试 */
.spinner {
  width: 28px;
  height: 28px;
  margin: 48px auto;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
}

.net-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--bottom-inset) + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px var(--gutter);
  background: var(--surface);
  border-top: 2px solid var(--danger);
}

.net-bar[hidden] { display: none; }
.net-bar span { flex: 1; min-width: 0; color: var(--danger); }
.net-bar .btn { width: auto; flex: none; }

/* 仅本地 mock 模式 */
body.mock { --bottom-inset: 46px; }

.mock-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: #20201f;
  color: #ecece8;
  font-size: 13px;
  line-height: 1.5;
}

.mock-panel summary {
  min-height: 46px;
  padding: 12px var(--gutter);
  cursor: pointer;
  overflow-wrap: anywhere;
}

.mock-body { max-height: 45vh; overflow-y: auto; padding: 0 var(--gutter) 12px; }
.mock-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }

.mock-buttons button {
  padding: 0 12px;
  border: 1px solid #6a6a66;
  background: transparent;
  color: inherit;
}

.mock-buttons button[aria-pressed="true"] { background: #a32a1f; border-color: #a32a1f; }
.mock-meta { margin-bottom: 8px; color: #b9b9b3; overflow-wrap: anywhere; }

.mock-log { margin: 0; padding: 0; list-style: none; }
.mock-log li { padding: 6px 0; border-top: 1px solid #3a3a37; }
.mock-log code { display: block; color: #b9b9b3; font-size: 12px; overflow-wrap: anywhere; white-space: pre-wrap; }
