:root {
  --bg: #f7f7f2;
  --panel: #ffffff;
  --ink: #11120f;
  --muted: #72736a;
  --line: #d9d9cf;
  --soft: #ecece4;
  --accent: #b8ff4d;
  --accent-ink: #0e1605;
  --danger: #ad322b;
  --shadow: 0 20px 60px rgba(20, 22, 18, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Yu Gothic", "YuGothic", "Hiragino Sans", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(17,18,15,0.035) 1px, transparent 1px) 0 0/44px 44px,
    linear-gradient(rgba(17,18,15,0.03) 1px, transparent 1px) 0 0/44px 44px,
    var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(680px, 100%);
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 4px 0 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(38px, 11vw, 72px);
  line-height: 0.9;
  letter-spacing: -0.07em;
  font-weight: 760;
}
h1 span { letter-spacing: -0.055em; }

h2, h3, p { margin-top: 0; }

.hero-card,
.scanner-card,
.preview-card,
.loading-card,
.result-card {
  background: rgba(255,255,255,0.86);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 26px;
  padding: 18px;
  backdrop-filter: blur(10px);
}

.hero-card { padding: 22px; }
.lead {
  margin-bottom: 8px;
  font-size: 22px;
  line-height: 1.45;
  letter-spacing: -0.03em;
  font-weight: 720;
}
.sublead {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.85;
}
.divider {
  height: 1px;
  background: var(--line);
  margin: 22px 0;
}

.actions { display: flex; gap: 10px; }
.actions.two > * { flex: 1; }
.actions.stack { flex-direction: column; margin-top: 14px; }

.primary-btn,
.secondary-btn,
.ghost-btn,
.text-btn {
  min-height: 48px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 0 18px;
  font-weight: 700;
  transition: transform .12s ease, background .12s ease, opacity .12s ease;
}
.primary-btn {
  background: var(--ink);
  color: white;
}
.secondary-btn {
  background: var(--panel);
  color: var(--ink);
}
.ghost-btn {
  min-width: 54px;
  min-height: 42px;
  background: rgba(255,255,255,0.55);
  color: var(--ink);
}
.text-btn {
  min-height: 32px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}
.primary-btn:active,
.secondary-btn:active,
.ghost-btn:active { transform: scale(0.985); }
.primary-btn:disabled,
.secondary-btn:disabled { opacity: .45; cursor: not-allowed; }
.full { width: 100%; }
.file-btn { display: grid; place-items: center; }

.tiny-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
}

.hidden { display: none !important; }

.scanner-card, .preview-card, .loading-card, .result-card { margin-top: 14px; }
.scan-head, .section-title-row, .archive-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.scan-head {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .16em;
}

.camera-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 5;
  border: 1px solid var(--ink);
  border-radius: 18px;
  background: #111;
  margin-bottom: 12px;
}
#cameraVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.corner {
  position: absolute;
  width: 34px;
  height: 34px;
  border-color: var(--accent);
  opacity: .95;
}
.c1 { left: 14px; top: 14px; border-left: 2px solid; border-top: 2px solid; }
.c2 { right: 14px; top: 14px; border-right: 2px solid; border-top: 2px solid; }
.c3 { left: 14px; bottom: 14px; border-left: 2px solid; border-bottom: 2px solid; }
.c4 { right: 14px; bottom: 14px; border-right: 2px solid; border-bottom: 2px solid; }

.preview-image, .result-image {
  width: 100%;
  display: block;
  border: 1px solid var(--line);
  background: var(--soft);
  object-fit: cover;
}
.preview-image {
  aspect-ratio: 1 / 1;
  max-height: min(78vw, 420px);
  border-radius: 18px;
  margin: 10px 0 14px;
}
.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.field-grid label, .key-label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .11em;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  color: var(--ink);
  padding: 12px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--ink); }

.loading-card {
  display: grid;
  place-items: center;
  min-height: 210px;
  text-align: center;
}
.pulse-mark {
  width: 44px;
  height: 44px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  position: relative;
  margin-bottom: 18px;
}
.pulse-mark::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.25s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(.7); opacity: .4; }
  50% { transform: scale(1.08); opacity: 1; }
}
.loading-card p {
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .08em;
}
.loading-card span { color: var(--muted); font-size: 12px; }

.archive-card {
  background: white;
  border: 1px solid var(--ink);
  border-radius: 20px;
  overflow: hidden;
}
.archive-header {
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--ink);
}
.archive-header p {
  margin: 0 0 3px;
  font-size: 10px;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: .13em;
}
.archive-header h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1;
  letter-spacing: -0.04em;
}
#artifactIdBadge {
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 11px;
  font-weight: 800;
}
.result-image {
  aspect-ratio: 1 / 1;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
}
.museum-label { padding: 16px 14px 18px; }
.caption-kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
}
.museum-label h3 {
  margin: 0 0 12px;
  font-size: 26px;
  line-height: 1.25;
  letter-spacing: -0.04em;
}
.meta-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.meta-line span { color: var(--muted); }
.meta-line b { text-align: right; }
.main-copy {
  margin: 14px 0 8px;
  font-size: 15px;
  line-height: 1.85;
  font-weight: 620;
}
.note-copy {
  margin: 0;
  color: #45463f;
  font-size: 13px;
  line-height: 1.8;
}
.copy-area {
  min-height: 160px;
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.65;
  resize: vertical;
}
.status-line {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.status-line.error { color: var(--danger); }

.settings-dialog {
  width: min(560px, calc(100% - 28px));
  padding: 0;
  border: 1px solid var(--ink);
  border-radius: 24px;
  box-shadow: var(--shadow);
  background: white;
  color: var(--ink);
}
.settings-dialog::backdrop { background: rgba(17,18,15,.24); backdrop-filter: blur(4px); }
.settings-panel { padding: 18px; }
.settings-panel h2 { margin: 0; font-size: 24px; }
.dialog-text { color: var(--muted); font-size: 13px; line-height: 1.7; }
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 13px;
}
.check-row input { width: auto; }

@media (max-width: 520px) {
  .app-shell { padding-left: 12px; padding-right: 12px; }
  .hero-card, .scanner-card, .preview-card, .loading-card, .result-card { border-radius: 22px; padding: 14px; }
  .field-grid { grid-template-columns: 1fr; }
  .lead { font-size: 20px; }
  .museum-label h3 { font-size: 23px; }
}
