:root {
  color-scheme: light;
  --bg: #f7f3ed;
  --card: #fffdf9;
  --ink: #2a201b;
  --muted: #746960;
  --line: #e3d8cd;
  --brand: #7a4023;
  --brand-dark: #5f2f18;
  --brand-soft: #f7e7d7;
  --accent: #d38b32;
  --danger: #ad2f27;
  --success: #2c6a4f;
  --shadow: 0 8px 24px rgba(69, 44, 29, .08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  padding-bottom: calc(82px + env(safe-area-inset-bottom));
  color: var(--ink);
  background: var(--bg);
}
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 1.22rem; line-height: 1.2; }
h2 { margin-bottom: 10px; font-size: 1.08rem; }

.app-header {
  position: sticky;
  z-index: 30;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  color: white;
  background: linear-gradient(135deg, #5f2f18, #8d4a27);
  box-shadow: 0 3px 12px rgba(74, 39, 22, .28);
}
.eyebrow, .step-label {
  margin-bottom: 3px;
  font-size: .72rem;
  font-weight: 850;
  letter-spacing: .08em;
}
.eyebrow { color: #f9dcc1; }
.step-label { color: var(--brand); }
.header-badges { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.badge, .mini-status {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 850;
}
.badge { background: rgba(255, 255, 255, .16); }
.badge.db { color: #5e351d; background: #fff0cd; }
.badge.db.ready { color: #1d553e; background: #dff4e9; }
.mini-status { color: var(--muted); background: #f1ebe5; }

main { width: min(100%, 760px); margin: 0 auto; padding: 10px; }
.main-tabs {
  position: sticky;
  z-index: 20;
  top: calc(57px + env(safe-area-inset-top));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 253, 249, .95);
  backdrop-filter: blur(8px);
}
.main-tab, .method-tab {
  min-height: 42px;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  font-weight: 850;
}
.main-tab.selected, .method-tab.selected { color: white; background: var(--brand); }

.card {
  margin-bottom: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.compact-card { padding-bottom: 8px; }
.setup-card { border: 2px solid #d28a35; background: #fff9ed; }
.workbench { border-top: 4px solid var(--brand); }
.info-card { background: #fcf8f2; }
.section-heading, .choice-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.section-heading h2 { margin-bottom: 0; }
.description { margin: 10px 0; color: var(--muted); font-size: .84rem; line-height: 1.55; }

.method-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.method-tab { background: #f1ebe5; }
.barcode-reader {
  overflow: hidden;
  min-height: 145px;
  max-height: 230px;
  border-radius: 12px;
  background: #211914;
}
.barcode-reader video { max-height: 230px !important; object-fit: cover; }
.barcode-reader img { max-height: 190px; object-fit: contain; }

.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.button-stack { display: grid; gap: 7px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 9px 13px;
  border: 1px solid transparent;
  border-radius: 11px;
  text-align: center;
  text-decoration: none;
  font-weight: 850;
}
.button.primary { color: white; background: var(--brand); }
.button.primary:active { background: var(--brand-dark); }
.button.secondary { color: var(--brand-dark); border-color: #cda98e; background: #fff4e9; }
.button.ghost { color: var(--muted); border-color: var(--line); background: white; }
.button.full, .full { width: 100%; }
.button:disabled { cursor: not-allowed; opacity: .45; }

.hint { margin: 8px 0 0; color: var(--muted); font-size: .78rem; line-height: 1.5; }
.notice {
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid #deb35f;
  border-radius: 12px;
  color: #6a4612;
  background: #fff8df;
  font-size: .84rem;
}
.notice.error { border-color: #e6a09a; color: var(--danger); background: #fff0ef; }
.notice.success { border-color: #9acdb4; color: var(--success); background: #eefaf4; }
.field-label { display: block; margin-bottom: 6px; font-size: .8rem; font-weight: 850; }
input, textarea {
  width: 100%;
  min-height: 43px;
  padding: 9px 10px;
  border: 1px solid #c9b8aa;
  border-radius: 10px;
  color: var(--ink);
  background: white;
}
textarea { min-height: 64px; resize: vertical; line-height: 1.45; }
input:focus, textarea:focus { outline: 3px solid #f0d5bd; border-color: var(--brand); }
.manual-row { display: grid; grid-template-columns: 1fr auto; gap: 7px; }

.suggestion-list, .candidate-list { display: grid; gap: 7px; margin-top: 10px; }
.suggestion-button, .candidate-button {
  width: 100%;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  text-align: left;
  color: var(--ink);
  background: white;
}
.suggestion-button strong, .suggestion-button span,
.candidate-button strong, .candidate-button span { display: block; }
.suggestion-button span, .candidate-button span { margin-top: 4px; color: var(--muted); font-size: .74rem; }
.suggestion-button:active, .candidate-button:active { border-color: var(--brand); background: var(--brand-soft); }
.suggestion-message { margin: 0; padding: 9px; border-radius: 9px; color: var(--muted); background: #f6f1ec; font-size: .78rem; }

.match-status { margin: 10px 0 7px; color: var(--muted); font-size: .8rem; }
.match-status.success { color: var(--success); font-weight: 850; }
.match-status.warning { color: #8a5a00; font-weight: 850; }
.book-details {
  margin: 8px 0;
  padding: 10px;
  border-left: 4px solid var(--accent);
  border-radius: 9px;
  background: #fff6e9;
  font-size: .8rem;
  line-height: 1.5;
}
.book-details strong, .book-details span { display: block; }
.book-details span { color: var(--muted); }
.choice-heading { align-items: center; margin-top: 12px; margin-bottom: 7px; font-size: .8rem; font-weight: 850; }
.text-button { min-height: 30px; padding: 3px 5px; border: 0; color: var(--brand); background: transparent; font-size: .76rem; font-weight: 850; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid #cfbfb1;
  border-radius: 999px;
  color: #5f554e;
  background: white;
  font-size: .78rem;
  font-weight: 800;
}
.chip.selected { border-color: var(--brand); color: white; background: var(--brand); }
.chip.database-term::after { content: " ✓"; color: #ffdcae; }

.external-searches { margin-top: 16px; padding-top: 13px; border-top: 1px solid var(--line); }
.market-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.market-button {
  display: flex;
  min-height: 58px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  color: white;
  text-align: center;
  text-decoration: none;
  font-weight: 900;
}
.market-button small { margin-top: 3px; opacity: .86; font-size: .67rem; }
.mercari { background: #e84b63; }
.yahoo { background: #c90000; }
.disabled { pointer-events: none; filter: grayscale(1); opacity: .35; }

.market-dock {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: 0;
  display: grid;
  width: min(100%, 760px);
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  border-top: 1px solid rgba(100, 73, 54, .2);
  background: rgba(255, 253, 249, .96);
  box-shadow: 0 -6px 20px rgba(69, 44, 29, .12);
  backdrop-filter: blur(10px);
}
.dock-button {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  color: white;
  text-decoration: none;
  font-size: .86rem;
  font-weight: 900;
}

.stats { display: grid; gap: 7px; margin: 10px 0 12px; }
.stats div { display: flex; justify-content: space-between; gap: 10px; padding: 8px 9px; border-radius: 9px; background: #f6f1ec; }
.stats dt { color: var(--muted); font-size: .78rem; }
.stats dd { margin: 0; text-align: right; font-size: .78rem; font-weight: 850; overflow-wrap: anywhere; }
.progress-wrap { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; margin-top: 10px; font-size: .75rem; color: var(--muted); }
.progress-wrap progress { width: 100%; }
.add-row { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin: 10px 0; }
.sortable-list { display: grid; gap: 6px; }
.sortable-item { display: grid; grid-template-columns: 1fr auto auto auto; gap: 5px; align-items: center; padding: 7px; border: 1px solid var(--line); border-radius: 10px; }
.sortable-item span { min-width: 0; overflow-wrap: anywhere; font-size: .82rem; font-weight: 800; }
.icon-button { min-width: 34px; min-height: 34px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: white; color: var(--muted); }
.icon-button.delete { color: var(--danger); }
.plain-list { margin: 8px 0; padding-left: 1.2rem; color: var(--muted); font-size: .82rem; line-height: 1.7; }

.dialog { width: min(92vw, 560px); max-height: 85vh; padding: 0; border: 0; border-radius: 18px; box-shadow: 0 20px 70px rgba(0, 0, 0, .25); }
.dialog::backdrop { background: rgba(25, 16, 11, .58); }
.dialog-body { max-height: 85vh; overflow: auto; padding: 16px; }
.dialog-body > p { white-space: pre-line; line-height: 1.55; }

[hidden] { display: none !important; }

@media (max-width: 420px) {
  .app-header { padding-left: 10px; padding-right: 10px; }
  h1 { font-size: 1.05rem; }
  main { padding: 7px; }
  .card { padding: 11px; border-radius: 13px; }
  .main-tabs { top: calc(53px + env(safe-area-inset-top)); }
  .header-badges .badge:first-child { display: none; }
}
