* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #cc0000;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --text: #1c1c1e;
  --text2: #8e8e93;
  --profit: #34c759;
  --loss: #ff3b30;
  --border: #c6c6c8;
  --shadow: 0 1px 4px rgba(0,0,0,0.12);
  --radius: 12px;
  --nav: 58px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ===== スクリーン ===== */
.screen {
  position: fixed;
  top: 0; left: 0; right: 0;
  bottom: var(--nav);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.screen.active { display: flex; }

/* ===== ヘッダー ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--primary);
  color: white;
  flex-shrink: 0;
  min-height: 54px;
}
.header-title { font-size: 18px; font-weight: 700; }
.btn-icon { background: none; border: none; color: white; font-size: 22px; cursor: pointer; padding: 4px 8px; }
.btn-back { background: none; border: none; color: white; font-size: 24px; cursor: pointer; padding: 4px 8px; line-height: 1; }

/* ===== サマリー ===== */
.summary-card {
  background: var(--primary);
  color: white;
  padding: 4px 16px 16px;
  flex-shrink: 0;
}
.summary-total { text-align: center; margin-bottom: 10px; }
.summary-label { font-size: 11px; opacity: 0.8; margin-bottom: 2px; }
.summary-value { font-size: 34px; font-weight: 700; letter-spacing: -1px; }
.summary-row { display: flex; justify-content: space-around; }
.summary-item { text-align: center; }
.summary-value-sm { font-size: 17px; font-weight: 600; }
.summary-value-sm.profit { color: #a8ff78; }
.summary-value-sm.loss { color: #ffaaaa; }
.last-update { text-align: center; font-size: 11px; opacity: 0.55; margin-top: 6px; }

/* ===== リスト ===== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  flex-shrink: 0;
}
.btn-add-sm {
  background: var(--primary);
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
}

.collection-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 12px;
  -webkit-overflow-scrolling: touch;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 60px 20px;
  color: var(--text2);
  text-align: center;
  font-size: 15px;
}
.empty-icon { font-size: 52px; }

/* ===== カードアイテム ===== */
.card-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 11px 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-thumb {
  width: 48px; height: 67px;
  object-fit: contain;
  border-radius: 6px;
  background: #f0f0f0;
  flex-shrink: 0;
}
.card-thumb-ph {
  width: 48px; height: 67px;
  background: #e8e8e8;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.card-info { flex: 1; min-width: 0; }
.card-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta { font-size: 11px; color: var(--text2); margin-bottom: 3px; }
.card-badges { display: flex; gap: 4px; margin-bottom: 4px; flex-wrap: wrap; }
.badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 700;
}
.badge-raw { background: #e5e5ea; color: #3c3c43; }
.badge-psa9 { background: #007aff; color: white; }
.badge-psa10 { background: #ff9f0a; color: white; }
.badge-box { background: #5856d6; color: white; }

.card-prices { display: flex; gap: 8px; font-size: 11px; flex-wrap: wrap; align-items: center; }
.price-purchase { color: var(--text2); }
.price-current { font-weight: 600; }
.price-pl { font-weight: 700; }
.price-pl.profit { color: var(--profit); }
.price-pl.loss { color: var(--loss); }

.btn-del {
  background: none;
  border: 1px solid #ffcccc;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 11px;
  cursor: pointer;
  color: var(--loss);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ===== 追加タブ ===== */
.add-tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.add-tab {
  flex: 1;
  padding: 13px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 14px;
  cursor: pointer;
  color: var(--text2);
}
.add-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; }

.add-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ===== 検索 ===== */
.search-wrap { padding: 12px 16px; position: relative; }
.search-input {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  background: var(--surface);
  outline: none;
}
.search-input:focus { border-color: var(--primary); }

.search-results {
  position: absolute;
  top: calc(100% - 12px);
  left: 16px; right: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 16px rgba(0,0,0,0.15);
  z-index: 100;
  max-height: 260px;
  overflow-y: auto;
}
.sr-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
}
.sr-item:last-child { border-bottom: none; }
.sr-item:active { background: #f5f5f5; }
.sr-img { width: 34px; height: 48px; object-fit: contain; }
.sr-ph { width: 34px; height: 48px; background: #eee; border-radius: 4px; display: flex; align-items: center; justify-content: center; }
.sr-name { font-size: 13px; font-weight: 600; }
.sr-set { font-size: 11px; color: var(--text2); }

/* ===== 選択カード ===== */
.selected-card {
  margin: 0 16px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.selected-top { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.selected-img { width: 52px; height: 72px; object-fit: contain; border-radius: 6px; }
.selected-name { font-weight: 700; font-size: 15px; }
.selected-sub { font-size: 12px; color: var(--text2); margin-top: 2px; }
.btn-clear { background: none; border: none; font-size: 12px; color: var(--text2); cursor: pointer; margin-bottom: 12px; display: block; }

/* ===== フォーム ===== */
.form-wrap { padding: 0 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--text2); }
.form-input {
  padding: 13px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  background: var(--bg);
  outline: none;
  width: 100%;
}
.form-input:focus { border-color: var(--primary); background: white; }

.price-wrap { display: flex; align-items: center; gap: 8px; }
.price-unit { font-size: 18px; font-weight: 700; color: var(--text2); }

.type-sel { display: flex; gap: 8px; }
.type-btn {
  flex: 1;
  padding: 11px 4px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: white;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text2);
}
.type-btn.active { border-color: var(--primary); background: #fff0f0; color: var(--primary); }

/* ===== ボタン ===== */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 15px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}
.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 13px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
}
.btn-danger {
  background: var(--loss);
  color: white;
  border: none;
  padding: 13px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}

/* ===== 設定 ===== */
.settings-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.settings-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 16px 0;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.settings-title { font-size: 15px; font-weight: 700; }
.settings-desc { font-size: 13px; color: var(--text2); line-height: 1.6; }
.danger-section { border: 1px solid #ffcccc; }
.backup-result {
  background: #f0fff4;
  border: 1px solid #86efac;
  border-radius: 10px;
  padding: 14px;
  text-align: center;
}
.backup-code { font-size: 26px; font-weight: 700; letter-spacing: 3px; margin: 4px 0; color: var(--text); }
.app-info { text-align: center; padding: 24px 16px; color: var(--text2); font-size: 12px; line-height: 2; }

/* ===== ボトムナビ ===== */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text2);
}
.nav-btn.active { color: var(--primary); }
.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { font-size: 10px; font-weight: 600; }

/* ===== トースト ===== */
.toast {
  position: fixed;
  bottom: calc(var(--nav) + 14px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.78);
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 1000;
  white-space: nowrap;
  transition: opacity 0.3s;
  pointer-events: none;
}
.toast.hidden { opacity: 0; }

/* ===== モーダル ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 24px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 320px;
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.modal-body { font-size: 14px; color: var(--text2); margin-bottom: 18px; line-height: 1.5; }
.modal-btns { display: flex; gap: 10px; }
.modal-btns button { flex: 1; }

.hidden { display: none !important; }

/* ===== ローディング ===== */
@keyframes spin {
  to { transform: rotate(360deg); }
}
.spinning { display: inline-block; animation: spin 1s linear infinite; }
