/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  min-height: 100dvh;
  overscroll-behavior: none;
}
img { display: block; width: 100%; height: 100%; object-fit: cover; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea { font-family: inherit; }

/* ── Tokens ── */
:root {
  --bg-page:      #f4f3ef;
  --bg-surface:   #ffffff;
  --bg-raised:    #ffffff;
  --bg-muted:     #eeede9;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --text-tertiary:  #999999;
  --border:       rgba(0,0,0,0.10);
  --border-md:    rgba(0,0,0,0.18);
  --border-strong:rgba(0,0,0,0.28);
  --accent:       #1a1a1a;
  --danger:       #cc2200;
  --radius-sm:    6px;
  --radius-md:    10px;
  --radius-lg:    14px;
  --radius-xl:    18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg-page:      #121212;
    --bg-surface:   #1e1e1e;
    --bg-raised:    #252525;
    --bg-muted:     #2a2a2a;
    --text-primary: #f0f0f0;
    --text-secondary:#aaaaaa;
    --text-tertiary: #666666;
    --border:       rgba(255,255,255,0.10);
    --border-md:    rgba(255,255,255,0.18);
    --border-strong:rgba(255,255,255,0.28);
    --accent:       #f0f0f0;
    --danger:       #ff5533;
  }
}

/* ── App shell ── */
#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; }

/* ══════════════════════════════════════════
   HOME VIEW
══════════════════════════════════════════ */
.home { display: flex; flex-direction: column; min-height: 100dvh; }

.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  background: var(--bg-page);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-title { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; color: var(--text-primary); }

.binder-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 8px 20px 40px;
}

.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 80px 20px;
}
.empty-title { font-size: 15px; font-weight: 500; color: var(--text-secondary); }
.empty-sub   { font-size: 13px; color: var(--text-tertiary); text-align: center; line-height: 1.5; }

/* Binder card on home */
.binder-card-wrap { display: flex; flex-direction: column; gap: 6px; }

.binder-cover {
  display: flex;
  border-radius: var(--radius-md);
  overflow: hidden;
  aspect-ratio: 3 / 4;
  height: auto;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  position: relative;
}
.binder-cover:active { transform: scale(0.97); opacity: 0.9; }

.binder-spine {
  width: 18px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.ring {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.3);
}

.binder-face {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 10px 12px;
  background-size: cover;
  background-position: center;
}

/* Label sticker — white bg, red double border (outer + inner via box-shadow) */
.comp-label {
  background: white;
  border: 3px solid #CC0000;
  border-radius: 7px;
  box-shadow:
    inset 0 0 0 2px white,
    inset 0 0 0 4px #CC0000;
  padding: 8px 14px;
  text-align: center;
  width: 84%;
  margin-top: 4px;
}
.comp-title { font-size: 12px; font-weight: 700; color: #111; letter-spacing: 0.05em; }
.comp-sub   { font-size: 9px; color: #444; margin-top: 2px; }

.binder-count {
  margin-top: auto;
  font-size: 10px;
  color: rgba(255,255,255,0.35);
}

.binder-card-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ══════════════════════════════════════════
   BINDER VIEW
══════════════════════════════════════════ */
.binder-view { display: flex; flex-direction: column; min-height: 100dvh; background: var(--bg-page); }

.binder-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg-page);
  border-bottom: 0.5px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.binder-view-title {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-back {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-primary);
  flex-shrink: 0;
}
.btn-back:active { background: var(--bg-muted); }

/* Page stage */
.page-stage {
  flex: 1;
  padding: 16px 16px 0;
  touch-action: pan-y;
  user-select: none;
}

.page-content {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  padding: 14px;
  position: relative;
  overflow: hidden;
  /* notebook line background */
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent calc(100% / 9 - 1px),
    rgba(0,0,0,0.04) calc(100% / 9 - 1px),
    rgba(0,0,0,0.04) calc(100% / 9)
  );
}
@media (prefers-color-scheme: dark) {
  .page-content {
    background-image: repeating-linear-gradient(
      to bottom,
      transparent,
      transparent calc(100% / 9 - 1px),
      rgba(255,255,255,0.04) calc(100% / 9 - 1px),
      rgba(255,255,255,0.04) calc(100% / 9)
    );
  }
}

/* Page-turn flap (half-page paper effect) */
.page-flap {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  background: var(--bg-surface);
  z-index: 20;
  pointer-events: none;
}
.page-flap-fwd {
  right: 0;
  transform-origin: left center;
}
.page-flap-bwd {
  left: 0;
  transform-origin: right center;
}

/* Card grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* Slot */
.pc-slot { display: flex; flex-direction: column; gap: 6px; }

/* Empty slot */
.empty-slot {
  width: 100%;
  aspect-ratio: 2 / 3;
  border: 1.5px dashed var(--border-md);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-muted);
  cursor: pointer;
  transition: background 0.15s;
  color: var(--text-tertiary);
}
.empty-slot:active { background: var(--border); }

/* Photocard flipper */
.pc-flipper {
  width: 100%;
  aspect-ratio: 2 / 3;
  position: relative;
  perspective: 700px;
  cursor: pointer;
}
.pc-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}
.pc-inner.flipped { transform: rotateY(180deg); }

.pc-front, .pc-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-md);
  overflow: hidden;
}
.pc-front {
  background: var(--bg-muted);
  border: 0.5px solid var(--border);
}
.pc-back {
  transform: rotateY(180deg);
  background: var(--bg-surface);
  border: 0.5px solid var(--border-md);
  display: flex;
  flex-direction: column;
  padding: 9px;
  gap: 5px;
}

.pc-img-wrap { width: 100%; height: 100%; overflow: hidden; }
.pc-photo    { width: 100%; height: 100%; object-fit: cover; }
.img-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary);
}

/* Card back */
.back-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.back-id {
  font-size: 8px;
  color: var(--text-tertiary);
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 70%;
}
.back-delete {
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}
.back-delete:active { color: var(--danger); background: rgba(204,34,0,0.08); }

.note-input {
  flex: 1;
  font-size: 10px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-muted);
  border: 0.5px solid var(--border);
  border-radius: 5px;
  padding: 5px;
  resize: none;
  width: 100%;
}
.note-input::placeholder { color: var(--text-tertiary); }

.back-flip-btn {
  font-size: 10px;
  color: var(--text-tertiary);
  text-align: center;
  padding: 4px 0 2px;
  border-top: 0.5px solid var(--border);
  flex-shrink: 0;
}
.back-flip-btn:active { color: var(--text-secondary); }

/* Tags */
.tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  min-height: 22px;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  padding: 2px 7px 2px 6px;
  border-radius: 20px;
  background: var(--bg-muted);
  color: var(--text-secondary);
  border: 0.5px solid var(--border-md);
  cursor: pointer;
  transition: background 0.12s;
  white-space: nowrap;
}
.tag-chip::after { content: '×'; font-size: 11px; color: var(--text-tertiary); margin-left: 1px; }
.tag-chip:active { background: rgba(204,34,0,0.08); color: var(--danger); }

.tag-add-btn {
  font-size: 14px;
  color: var(--text-tertiary);
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 0.5px dashed var(--border-md);
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  flex-shrink: 0;
}
.tag-add-btn:active { background: var(--bg-muted); }

.tag-input {
  font-size: 11px;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 0.5px solid var(--border-strong);
  border-radius: 20px;
  padding: 2px 10px;
  outline: none;
  width: 90px;
}

/* Page nav */
.page-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 16px 8px;
}
.nav-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 0.5px solid var(--border-md);
  background: var(--bg-surface);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
}
.nav-btn:active { background: var(--bg-muted); }
.nav-btn:disabled { opacity: 0.3; pointer-events: none; }

.page-dots { display: flex; gap: 6px; align-items: center; }
.ndot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border-md);
  transition: background 0.2s, width 0.2s;
}
.ndot.on { background: var(--text-secondary); width: 14px; border-radius: 3px; }

.hint-text {
  font-size: 11px;
  color: var(--text-tertiary);
  text-align: center;
  padding: 4px 16px 24px;
}

/* ══════════════════════════════════════════
   FILTER BAR
══════════════════════════════════════════ */
.filter-scroll {
  overflow-x: auto;
  padding: 10px 16px;
  border-bottom: 0.5px solid var(--border);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-shrink: 0;
}
.filter-scroll::-webkit-scrollbar { display: none; }
.filter-bar { display: flex; gap: 6px; width: max-content; }
.filter-chip {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 20px;
  border: 0.5px solid var(--border-md);
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-surface);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.filter-chip.on {
  background: var(--text-primary);
  color: var(--bg-surface);
  border-color: var(--text-primary);
}

/* Filtered results grid (no pagination) */
.filter-results {
  padding: 14px;
  overflow-y: auto;
}

/* ══════════════════════════════════════════
   MODALS
══════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
  animation: overlay-in 0.2s ease;
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  overflow-y: auto;
  animation: sheet-in 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: env(safe-area-inset-bottom, 16px);
}
@keyframes sheet-in {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 0.5px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  z-index: 1;
}
.modal-title { font-size: 16px; font-weight: 600; color: var(--text-primary); }

.modal-body  { padding: 20px; }
.modal-footer {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 0.5px solid var(--border);
}
.modal-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 14px; }

/* Add card options */
.add-opts { display: flex; flex-direction: column; gap: 10px; }
.add-opt {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-primary);
  transition: background 0.12s;
}
.add-opt:active { background: var(--bg-muted); }
.add-opt svg   { flex-shrink: 0; color: var(--text-secondary); }
.opt-name  { font-size: 14px; font-weight: 500; }
.opt-desc  { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ── Form fields ── */
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.required { color: var(--danger); }
.field-input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg-surface);
  outline: none;
  transition: border-color 0.15s;
}
.field-input:focus { border-color: var(--border-strong); }

/* Color palette */
.color-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.cdot {
  width: 26px; height: 26px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.12s;
  flex-shrink: 0;
}
.cdot:hover  { transform: scale(1.1); }
.cdot.sel    { outline: 3px solid var(--border-strong); outline-offset: 2px; }

/* Hex input row */
.hex-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
}
.hex-prev {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 0.5px solid var(--border-md);
  flex-shrink: 0;
}
.hex-hash { font-size: 13px; color: var(--text-tertiary); }
.hex-inp {
  width: 88px;
  height: 32px;
  padding: 0 8px;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: monospace;
  color: var(--text-primary);
  background: var(--bg-surface);
  outline: none;
  text-transform: uppercase;
}
.hex-inp:focus { border-color: var(--border-strong); }
.hex-btn {
  height: 32px;
  padding: 0 12px;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-surface);
  cursor: pointer;
}
.hex-btn:active { background: var(--bg-muted); }

/* ── Buttons ── */
.btn-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-primary);
  transition: background 0.12s;
  flex-shrink: 0;
}
.btn-icon:active { background: var(--bg-muted); }

.btn-primary {
  flex: 1;
  height: 46px;
  border-radius: var(--radius-md);
  background: var(--text-primary);
  color: var(--bg-surface);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.12s;
}
.btn-primary:active { opacity: 0.8; }

.btn-secondary {
  flex: 1;
  height: 46px;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-md);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}
.btn-secondary:active { background: var(--bg-muted); }
.btn-secondary.full-width { width: 100%; flex: none; }

.btn-danger {
  flex: 1;
  height: 46px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 0.5px solid var(--danger);
  color: var(--danger);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}
.btn-danger:active { background: rgba(204,34,0,0.06); }

/* Cover image remove */
.btn-img-remove {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  color: var(--danger);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
}

/* ── Divider ── */
.modal-divider {
  height: 0.5px;
  background: var(--border);
  margin: 18px 0;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--bg-surface);
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 20px;
  white-space: nowrap;
  z-index: 200;
  animation: toast-in 0.2s ease, toast-out 0.2s ease 1.8s forwards;
  pointer-events: none;
}
@keyframes toast-in  { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }
@keyframes toast-out { to   { opacity: 0; transform: translateX(-50%) translateY(8px); } }
