:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-subtle: #f4f4f5;
  --hairline: rgba(23, 23, 23, 0.08);
  --hairline-strong: rgba(23, 23, 23, 0.16);
  --text-primary: #171717;
  --text-secondary: #525252;
  --text-muted: #737373;
  --accent: #1e3a5f;
  --accent-hover: #162d4a;
  --accent-soft: #eef2f6;
  --success: #15803d;
  --success-bg: #f0fdf4;
  --success-border: rgba(21, 128, 61, 0.22);
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --danger-border: rgba(185, 28, 28, 0.22);
  --font-sans: "Inter", "Zen Kaku Gothic New", "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  --font-mono: "IBM Plex Mono", "Noto Sans Mono", monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.68;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
}

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

button {
  touch-action: manipulation;
}

.icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

.icon-lg {
  width: 20px;
  height: 20px;
}

.shell {
  width: min(840px, 100%);
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--hairline);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background-color: var(--accent);
  color: #ffffff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-title {
  font-size: 18px;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: 0.01em;
  margin: 0;
}

.brand-sub {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 2px 0 0;
}

.mode-tabs {
  display: inline-flex;
  background-color: var(--surface-subtle);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 4px;
  gap: 4px;
  flex-shrink: 0;
}

.mode-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}

.mode-tab[aria-selected="true"] {
  background-color: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.panel {
  background-color: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.section-label {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text-secondary);
  margin: 0 0 8px;
}

.category-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.category-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: 8px;
  background-color: var(--surface);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease);
}

.category-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.category-btn[aria-pressed="true"] {
  background-color: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.connection-notice {
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 1px solid var(--danger-border);
  border-radius: 8px;
  background-color: var(--danger-bg);
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
}

.assist-box {
  background-color: var(--surface-subtle);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
}

.assist-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.assist-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.field input,
.field select,
.field textarea,
.assist-row input,
.filter-input,
.filter-select {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: 8px;
  background-color: var(--surface);
  font-size: 14px;
  line-height: 1.5;
  outline: none;
  transition: border-color 150ms var(--ease);
}

.field textarea {
  min-height: 84px;
  resize: vertical;
  line-height: 1.65;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.assist-row input:focus,
.filter-input:focus,
.filter-select:focus {
  border-color: var(--accent);
}

.category-btn:focus-visible,
.mode-tab:focus-visible,
.segment-btn:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.btn-ghost:focus-visible,
.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible,
.assist-row input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary,
.btn-secondary,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease);
}

.btn-primary {
  border: 1px solid var(--accent);
  background-color: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-secondary {
  border: 1px solid var(--hairline-strong);
  background-color: var(--surface);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--surface-subtle);
}

.btn-ghost {
  height: 32px;
  padding: 0 12px;
  border: 1px solid transparent;
  background-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background-color: var(--surface-subtle);
  color: var(--text-primary);
}

.btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
}

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

.status-line {
  min-height: 20px;
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--success);
  font-weight: 500;
}

.status-line:empty {
  display: none;
}

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

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

.book-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background-color: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: border-color 150ms var(--ease);
}

.book-card:hover {
  border-color: var(--accent);
}

.book-thumb {
  width: 40px;
  height: 56px;
  flex-shrink: 0;
  border-radius: 4px;
  background-color: var(--surface-subtle);
  border: 1px solid var(--hairline);
  overflow: hidden;
  display: grid;
  place-items: center;
  color: var(--text-muted);
}

.book-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-copy {
  min-width: 0;
}

.book-title {
  display: block;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-primary);
}

.book-meta {
  display: block;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  margin-top: 4px;
}

.preview-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px;
  margin-bottom: 20px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background-color: var(--surface-subtle);
}

.preview-media {
  width: 56px;
  height: 72px;
  border-radius: 6px;
  background-color: var(--surface);
  border: 1px solid var(--hairline);
  overflow: hidden;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: var(--text-muted);
}

.preview-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-info {
  flex: 1 1 auto;
  min-width: 0;
}

.preview-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.45;
  color: var(--text-primary);
  margin: 0;
}

.preview-sub {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 4px 0 0;
  font-variant-numeric: tabular-nums;
}

.record-segment {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.segment-btn {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: 8px;
  background-color: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease);
}

.segment-btn[aria-pressed="true"] {
  background-color: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.field.wide {
  grid-column: 1 / -1;
}

.field label {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text-secondary);
}

.req-badge {
  margin-left: 4px;
  font-size: 12px;
  color: var(--danger);
}

.details-drawer {
  margin-top: 16px;
  border-top: 1px solid var(--hairline);
  padding-top: 16px;
}

.details-drawer summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  list-style: none;
  padding: 4px 0;
}

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

.details-summary-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.details-chevron {
  transition: transform 150ms var(--ease);
}

.details-drawer[open] .details-chevron {
  transform: rotate(180deg);
}

.details-badge {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}

.details-body {
  margin-top: 12px;
}

.submit-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}

.submit-row .btn-primary {
  min-width: 160px;
}

.submit-row .status-line {
  margin-top: 0;
}

.manual-entry-row {
  margin-top: 4px;
  display: flex;
  justify-content: flex-start;
}

.btn-link {
  background: transparent;
  border: 0;
  padding: 4px 0;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 4px;
  transition: color 150ms var(--ease);
}

.btn-link:hover {
  color: var(--accent);
}

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

.register-step2 {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--hairline);
  animation: stepReveal 160ms var(--ease);
}

.step2-label {
  margin-top: 16px;
}

@keyframes stepReveal {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.success-banner {
  display: none;
  margin-top: 16px;
  padding: 12px 16px;
  border: 1px solid var(--success-border);
  border-radius: 8px;
  background-color: var(--success-bg);
  color: var(--success);
  font-size: 14px;
}

.success-banner.show {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.success-banner a {
  color: var(--success);
  font-weight: 500;
}

/* リスト画面（F4） */
.list-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--hairline);
}

.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.list-toolbar .record-segment {
  margin-bottom: 0;
}

.list-toolbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--hairline-strong);
  border-radius: 8px;
  background-color: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease);
}

.icon-btn:hover {
  background-color: var(--surface-subtle);
  color: var(--text-primary);
}

.icon-btn.active {
  background-color: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

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

.list-filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.list-filter-row .filter-select {
  flex: 0 0 auto;
  width: auto;
  min-width: 160px;
}

.list-filter-row .filter-input {
  flex: 1 1 auto;
}

.target-list {
  display: flex;
  flex-direction: column;
}

.target-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
  border-bottom: 1px solid var(--hairline);
}

.target-row:last-child {
  border-bottom: 0;
}

.target-thumb {
  width: 44px;
  height: 56px;
  border-radius: 6px;
  border: 1px solid var(--hairline);
  background-color: var(--surface-subtle);
  overflow: hidden;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: var(--text-muted);
}

.target-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.target-main {
  flex: 1 1 auto;
  min-width: 0;
}

.target-title-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.45;
  color: var(--text-primary);
  text-decoration: none;
}

.target-title-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.target-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.meta-tag {
  padding: 0 8px;
  border-radius: 4px;
  background-color: var(--surface-subtle);
  color: var(--text-secondary);
}

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

.empty-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* モーダル */
dialog {
  border: 1px solid var(--hairline);
  border-radius: 16px;
  padding: 0;
  max-width: min(92vw, 480px);
  width: 100%;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

dialog::backdrop {
  background-color: rgba(23, 23, 23, 0.45);
}

.dialog-body {
  padding: 24px;
  background-color: var(--surface);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.dialog-title {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.4;
  margin: 0;
}

.icon-close-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background-color: var(--surface);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.scanner video {
  width: 100%;
  border-radius: 8px;
  background-color: #171717;
  max-height: 52vh;
}

.permission-card {
  padding: 16px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background-color: var(--surface-subtle);
  margin-bottom: 16px;
}

.permission-card p {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.6;
}

.permission-card .btn-primary {
  width: 100%;
}

.camera-help {
  padding: 16px;
  border: 1px solid var(--danger-border);
  border-radius: 8px;
  background-color: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

.camera-help ol {
  margin: 8px 0 12px;
  padding-left: 20px;
}

.photo-fallback {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.photo-fallback span {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.done-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 640px) {
  .shell {
    padding: 16px 12px 32px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .mode-tabs {
    width: 100%;
  }

  .mode-tab {
    flex: 1 1 0;
    justify-content: center;
  }

  .panel {
    padding: 16px;
  }

  .assist-row {
    flex-wrap: wrap;
  }

  .assist-row input {
    flex: 1 1 100%;
  }

  .assist-row button {
    flex: 1 1 0;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .field.wide {
    grid-column: auto;
  }

  .submit-row {
    flex-direction: column;
    align-items: stretch;
  }

  .submit-row .btn-primary {
    width: 100%;
  }

  .list-filter-row {
    flex-wrap: wrap;
  }

  .list-filter-row .filter-select {
    flex: 1 1 120px;
  }

  .list-filter-row .filter-input {
    flex: 1 1 100%;
  }

  .target-row {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .target-main {
    flex: 1 1 calc(100% - 60px);
  }

  .target-actions {
    width: 100%;
    padding-left: 56px;
  }

  .list-toolbar .segment-btn {
    padding: 0 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .register-step2 {
    animation: none;
  }
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
