* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #090d16;
  color: #f1f5f9;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  touch-action: manipulation;
}

input, select {
  user-select: text;
  -webkit-user-select: text;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
  background: #0b101b;
  position: relative;
}

/* Header */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px;
  background: rgba(11, 16, 27, 0.95);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 20;
  flex-shrink: 0;
}

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

.brand-badge {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  white-space: nowrap;
}

.brand-title {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.status-pill {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
  border: 1px solid rgba(52, 211, 153, 0.3);
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(30, 41, 59, 0.8);
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.chip-btn.active {
  background: rgba(16, 185, 129, 0.2);
  border-color: #10b981;
  color: #6ee7b7;
}

.chip-btn .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #64748b;
}

.chip-btn.active .dot {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.icon-btn {
  width: 32px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(30, 41, 59, 0.75);
  color: #f8fafc;
  font-size: 14px;
  cursor: pointer;
}

/* Scanner Stage */
.scanner-stage {
  position: relative;
  flex: 1 1 56%;
  min-height: 250px;
  background: #05070c;
  overflow: hidden;
}

.camera-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hud-top-left {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: 68%;
  pointer-events: none;
}

.pipeline-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.mini-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.78);
  color: #cbd5e1;
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(4px);
}

.mini-tag.ok {
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.35);
}

.quality-meter {
  background: rgba(15, 23, 42, 0.78);
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(4px);
}

.quality-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #e2e8f0;
  margin-bottom: 3px;
}

.quality-bar-bg {
  width: 150px;
  height: 5px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 99px;
  overflow: hidden;
}

.quality-bar-fill {
  height: 100%;
  width: 20%;
  background: #38bdf8;
  transition: width 0.12s ease, background-color 0.15s ease;
}

.hud-top-right {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 10;
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid rgba(56, 189, 248, 0.5);
  border-radius: 8px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.hud-top-right canvas {
  width: 58px;
  height: 81px;
  border-radius: 4px;
  background: #000;
}

.crop-caption {
  font-size: 9px;
  color: #7dd3fc;
  margin-top: 2px;
  font-weight: 700;
}

/* Guide Frame */
.guide-box {
  position: absolute;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(4, 7, 15, 0.44);
  pointer-events: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  overflow: hidden;
}

.guide-box.ready {
  border-color: #34d399;
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.35), 0 0 0 9999px rgba(4, 7, 15, 0.44);
}

.guide-box.scanning {
  border-color: #38bdf8;
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.5), 0 0 0 9999px rgba(4, 7, 15, 0.44);
}

.corner {
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: #fbbf24;
  border-style: solid;
}
.corner.tl { top: -2px; left: -2px; border-width: 4px 0 0 4px; border-top-left-radius: 12px; }
.corner.tr { top: -2px; right: -2px; border-width: 4px 4px 0 0; border-top-right-radius: 12px; }
.corner.bl { bottom: -2px; left: -2px; border-width: 0 0 4px 4px; border-bottom-left-radius: 12px; }
.corner.br { bottom: -2px; right: -2px; border-width: 0 4px 4px 0; border-bottom-right-radius: 12px; }

.guide-zone-top,
.guide-zone-bottom {
  position: absolute;
  left: 8px;
  right: 8px;
  font-size: 10px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.72);
  text-align: center;
  padding: 2px 4px;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.42);
}
.guide-zone-top { top: 6px; border-bottom: 1px dashed rgba(251, 191, 36, 0.45); }
.guide-zone-bottom { bottom: 6px; border-top: 1px dashed rgba(56, 189, 248, 0.45); }

.scan-laser {
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, #38bdf8, #fbbf24, #38bdf8, transparent);
  box-shadow: 0 0 12px #38bdf8;
  animation: laserMove 1.15s ease-in-out infinite alternate;
}

@keyframes laserMove {
  from { top: 6%; }
  to { top: 92%; }
}

/* Toasts & Price Popup */
.scanning-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 15;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(56, 189, 248, 0.65);
  color: #e0f2fe;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(56, 189, 248, 0.3);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.reject-toast {
  position: absolute;
  bottom: 58px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 16;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(251, 191, 36, 0.55);
  color: #fde68a;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
}

.price-popup {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 54px;
  z-index: 18;
  background: linear-gradient(160deg, rgba(15, 23, 42, 0.96), rgba(6, 78, 59, 0.95));
  border: 1.5px solid #10b981;
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(10px);
  animation: popIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.price-popup.high-value {
  background: linear-gradient(160deg, rgba(28, 20, 8, 0.97), rgba(120, 53, 15, 0.95));
  border: 2px solid #fbbf24;
  box-shadow: 0 0 28px rgba(251, 191, 36, 0.45), 0 14px 35px rgba(0, 0, 0, 0.75);
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.popup-badges {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.rarity-pill {
  background: #fbbf24;
  color: #111827;
  font-size: 11px;
  font-weight: 900;
  padding: 2px 7px;
  border-radius: 6px;
}

.verify-pill {
  background: rgba(16, 185, 129, 0.22);
  color: #6ee7b7;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
}

.model-pill {
  font-size: 10px;
  color: #94a3b8;
}

.popup-close {
  background: transparent;
  border: none;
  color: #cbd5e1;
  font-size: 16px;
  padding: 2px 6px;
  cursor: pointer;
}

.popup-title {
  font-size: 17px;
  font-weight: 900;
  color: #fff;
  line-height: 1.25;
}

.popup-sub {
  font-size: 11px;
  color: #cbd5e1;
  margin-top: 2px;
}

.popup-price-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 6px;
}

.price-prefix {
  font-size: 12px;
  font-weight: 700;
  color: #a7f3d0;
}

.popup-price {
  font-size: 30px;
  font-weight: 900;
  color: #fde047;
  letter-spacing: -0.02em;
  text-shadow: 0 2px 10px rgba(250, 204, 21, 0.35);
}

.popup-range {
  font-size: 11px;
  color: #d1fae5;
  margin-top: 1px;
}

.popup-variants {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.variant-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(15, 23, 42, 0.65);
  color: #f8fafc;
  cursor: pointer;
}

.popup-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 9px;
}

.btn-subtle {
  flex: 1;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(15, 23, 42, 0.65);
  color: #e2e8f0;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.btn-subtle.danger {
  border-color: rgba(248, 113, 113, 0.45);
  color: #fca5a5;
}

/* Camera Start Overlay */
.camera-overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  background: rgba(9, 13, 22, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.overlay-card {
  background: #131b2e;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  padding: 22px 18px;
  text-align: center;
  max-width: 340px;
}

.overlay-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.overlay-card h2 {
  font-size: 17px;
  margin-bottom: 8px;
}

.overlay-card p {
  font-size: 12px;
  color: #94a3b8;
  line-height: 1.5;
  margin-bottom: 16px;
}

.btn-primary-lg {
  display: block;
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  margin-bottom: 10px;
}

.btn-secondary-lg {
  display: block;
  width: 100%;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(30, 41, 59, 0.8);
  color: #e2e8f0;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

/* Camera Toolbar */
.camera-toolbar {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.tool-left, .tool-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tool-chip {
  height: 30px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(15, 23, 42, 0.82);
  color: #e2e8f0;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.file-label {
  cursor: pointer;
}

.btn-scan-now {
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, #38bdf8, #2563eb);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

/* Inventory Panel */
.inventory-panel {
  flex: 1 1 44%;
  min-height: 210px;
  max-height: 46dvh;
  background: #0f172a;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  flex-direction: column;
  z-index: 22;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transition: max-height 0.22s ease, flex-basis 0.22s ease;
}

.inventory-panel.expanded {
  flex: 1 1 76%;
  max-height: 76dvh;
}

.inventory-summary-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  background: #131d33;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.summary-label {
  font-size: 10px;
  font-weight: 700;
  color: #94a3b8;
}

.summary-total-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.summary-total-yen {
  font-size: 24px;
  font-weight: 900;
  color: #fbbf24;
  letter-spacing: -0.02em;
}

.count-badge {
  font-size: 11px;
  font-weight: 800;
  background: rgba(56, 189, 248, 0.16);
  color: #7dd3fc;
  padding: 2px 8px;
  border-radius: 999px;
}

.summary-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mode-btn, .expand-btn {
  height: 30px;
  padding: 0 9px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(30, 41, 59, 0.9);
  color: #e2e8f0;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.inventory-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.search-input {
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 0 9px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #090d16;
  color: #f8fafc;
  font-size: 12px;
}

.sort-select {
  height: 30px;
  padding: 0 6px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #090d16;
  color: #e2e8f0;
  font-size: 11px;
}

.mini-action-btn {
  height: 30px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(30, 41, 59, 0.8);
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.danger-text {
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.3);
}

.inventory-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-state {
  text-align: center;
  color: #64748b;
  font-size: 12px;
  line-height: 1.6;
  padding: 26px 12px;
}

.card-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #162036;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 8px 10px;
}

.card-item.high-tier {
  border-color: rgba(251, 191, 36, 0.45);
  background: linear-gradient(90deg, #162036, rgba(120, 53, 15, 0.25));
}

.card-thumb {
  width: 44px;
  height: 62px;
  border-radius: 6px;
  object-fit: cover;
  background: #090d16;
  border: 1px solid rgba(255, 255, 255, 0.15);
  flex-shrink: 0;
}

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

.card-top-line {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 2px;
}

.card-rarity-tag {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(251, 191, 36, 0.2);
  color: #fcd34d;
}

.card-code-text {
  font-size: 11px;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-name-text {
  font-size: 14px;
  font-weight: 800;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-price-edit {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  font-size: 15px;
  font-weight: 900;
  color: #34d399;
  cursor: pointer;
}

.card-price-edit small {
  font-size: 10px;
  color: #64748b;
  font-weight: 600;
}

.btn-detach {
  height: 34px;
  padding: 0 11px;
  border-radius: 9px;
  border: 1px solid rgba(248, 113, 113, 0.45);
  background: rgba(127, 29, 29, 0.35);
  color: #fecaca;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-detach:active {
  transform: scale(0.96);
  background: rgba(185, 28, 28, 0.6);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4, 7, 15, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  background: #131d33;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 16px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-head h3 {
  font-size: 15px;
}

.setting-block {
  margin-bottom: 14px;
}

.setting-title {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: #cbd5e1;
  margin-bottom: 6px;
}

.health-box {
  background: #090d16;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 10px;
  font-size: 12px;
  line-height: 1.55;
  color: #cbd5e1;
}

.passcode-row, .cache-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
