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

body {
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f3f6fb;
  color: #0f172a;
  min-height: 100vh;
}

/* ── Language Switch ── */
.lang-switch {
  text-align: right;
  padding: 8px 16px 0;
}

.lang-switch a {
  display: inline-block;
  padding: 4px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #64748b;
  text-decoration: none;
  transition: background 0.2s, border-color 0.2s;
}

.lang-switch a:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #3b82f6;
}

/* ── Header ── */
header {
  text-align: center;
  padding: 12px 16px 8px;
}

h1 {
  font-size: 1.4rem;
  font-weight: 800;
  color: #1e293b;
  letter-spacing: 0.02em;
}

.subtitle {
  color: #94a3b8;
  font-size: 0.8rem;
  margin-top: 4px;
}

/* ── Main ── */
main {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

/* ── 3×3 Grid ── */
.grid-3x3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.grid-slot {
  aspect-ratio: 488 / 680;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  border: 2px dashed #cbd5e1;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.grid-slot:hover {
  border-color: #94a3b8;
}

.grid-slot .slot-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #94a3b8;
}

.grid-slot .slot-number {
  position: absolute;
  top: 6px;
  left: 6px;
  background: #e2e8f0;
  color: #64748b;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
}

/* Filled slot */
.grid-slot.filled {
  border: none;
  cursor: grab;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.grid-slot.filled .slot-number {
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
}

.grid-slot.filled img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.grid-slot.filled:hover .card-hover,
.grid-slot.filled .card-hover.active {
  opacity: 1;
}

.card-hover {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

/* Mobile: show overlay on tap */
@media (hover: none) {
  .grid-slot.filled .card-hover {
    opacity: 0;
  }
}

.card-hover-btn {
  padding: 6px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  pointer-events: auto;
}

.card-hover-btn.change {
  background: #fff;
  color: #1e293b;
}

.card-hover-btn.version {
  background: transparent;
  color: #93c5fd;
  border: 1px solid #93c5fd;
}

.card-hover-btn.remove {
  background: transparent;
  color: #fca5a5;
  border: 1px solid #fca5a5;
}

.card-hover-btn.change:hover { background: #f1f5f9; }
.card-hover-btn.version:hover { background: rgba(147, 197, 253, 0.15); }
.card-hover-btn.remove:hover { background: rgba(252, 165, 165, 0.15); }

/* Drag states */
.grid-slot.dragging { opacity: 0.4; cursor: grabbing; }

.grid-slot.drag-over {
  border: 2px solid #3b82f6 !important;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.3);
}

/* ── Status Bar ── */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  padding: 10px 0;
}

.count-label {
  font-size: 0.85rem;
  color: #64748b;
  font-weight: 600;
}

.count-label span {
  color: #3b82f6;
  font-weight: 800;
  font-size: 1rem;
}

.count-hint {
  font-size: 0.75rem;
  color: #94a3b8;
}

.restore-status {
  text-align: center;
  font-size: 0.8rem;
  color: #94a3b8;
  min-height: 1.2em;
  margin-bottom: 4px;
}

.restore-status.error { color: #ef4444; }

/* ── Action Buttons ── */
.actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.btn-action {
  flex: 1;
  padding: 10px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #fff;
  color: #475569;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.btn-action:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-action:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-new { color: #3b82f6; }
.btn-new:hover { background: #eff6ff; border-color: #93c5fd; }

.btn-clear { color: #ef4444; }
.btn-clear:hover:not(:disabled) { background: #fef2f2; border-color: #fecaca; }

.btn-copy:hover:not(:disabled) { color: #3b82f6; border-color: #93c5fd; background: #eff6ff; }

.btn-save:hover:not(:disabled) { color: #10b981; border-color: #6ee7b7; background: #ecfdf5; }

.btn-tweet { color: #000; }
.btn-tweet:hover:not(:disabled) { background: #f0f0f0; border-color: #999; }

.btn-bsky { color: #0085ff; }
.btn-bsky:hover:not(:disabled) { background: #eff8ff; border-color: #7ec4ff; }

.btn-reddit { color: #ff4500; }
.btn-reddit:hover:not(:disabled) { background: #fff5f0; border-color: #ffb89a; }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 540px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
}

.modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #f1f5f9;
  color: #64748b;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.modal-close:hover { background: #e2e8f0; }

.modal-search {
  display: flex;
  gap: 8px;
  padding: 8px 20px 12px;
}

.modal-search input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  color: #1e293b;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-search input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  background: #fff;
}

.modal-search button {
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: #3b82f6;
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.modal-search button:hover { background: #2563eb; }
.modal-search button:disabled { background: #cbd5e1; cursor: not-allowed; }

.modal-options {
  padding: 2px 20px 6px;
}
.option-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #64748b;
  cursor: pointer;
  user-select: none;
}
.option-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: #3b82f6;
  cursor: pointer;
}

.modal-status {
  padding: 0 20px;
  font-size: 0.8rem;
  color: #94a3b8;
  min-height: 1.2em;
}

.modal-status.error { color: #ef4444; }

.modal-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 20px;
}

/* ── Result Cards in Modal ── */
.result-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.result-card:hover { background: #f1f5f9; }
.result-card:active { background: #e2e8f0; }

.result-card .result-img {
  width: 52px;
  flex: 0 0 52px;
  aspect-ratio: 488 / 680;
  border-radius: 6px;
  object-fit: cover;
  background: #e2e8f0;
}

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

.result-card .result-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-card .result-meta {
  font-size: 0.7rem;
  color: #94a3b8;
  margin-top: 2px;
}

.result-card .result-actions {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
}

.result-add-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 8px;
  background: #3b82f6;
  color: #fff;
  font-weight: 700;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.result-add-btn:hover { background: #2563eb; }

.result-add-btn:disabled {
  background: #e2e8f0;
  color: #94a3b8;
  cursor: not-allowed;
}

.result-ver-btn {
  padding: 6px 8px;
  border: none;
  border-radius: 8px;
  background: #f1f5f9;
  color: #64748b;
  font-weight: 600;
  font-size: 0.65rem;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.result-ver-btn:hover { background: #e2e8f0; }
.result-ver-btn.open { color: #3b82f6; }

/* Version row */
.versions-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  margin: 0 10px 4px;
  background: #f8fafc;
  border-radius: 10px;
  min-height: 100px;
}

.versions-row::-webkit-scrollbar { height: 6px; }
.versions-row::-webkit-scrollbar-track { background: #e2e8f0; border-radius: 3px; }
.versions-row::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 3px; }

.ver-item {
  flex: 0 0 auto;
  width: 72px;
  text-align: center;
  cursor: pointer;
  border-radius: 8px;
  padding: 4px;
  transition: background 0.15s;
  scroll-snap-align: start;
}

.ver-item:hover { background: #e2e8f0; }

.ver-item img {
  width: 100%;
  aspect-ratio: 488 / 680;
  object-fit: cover;
  border-radius: 4px;
  display: block;
  background: #e2e8f0;
}

.ver-item .ver-label {
  font-size: 0.55rem;
  color: #94a3b8;
  margin-top: 2px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ver-loading {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  color: #94a3b8;
  font-size: 0.75rem;
}

/* ── No Image placeholder ── */
.no-image {
  width: 52px;
  flex: 0 0 52px;
  aspect-ratio: 488 / 680;
  border-radius: 6px;
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 0.55rem;
}

/* ── Loading ── */
.loading {
  text-align: center;
  padding: 32px;
  color: #94a3b8;
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Load More ── */
.load-more-btn {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #fff;
  color: #3b82f6;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.load-more-btn:hover { background: #eff6ff; border-color: #93c5fd; }
.load-more-btn:disabled { color: #94a3b8; cursor: wait; }

/* ── Ko-fi ── */
.kofi-wrap {
  margin-bottom: 12px;
}

/* ── Footer ── */
footer {
  text-align: center;
  padding: 16px 16px 32px;
}

.footer-credit {
  font-size: 0.7rem;
  color: #b0bec5;
}

.footer-credit a {
  color: #b0bec5;
  text-decoration: none;
}

.footer-links {
  margin-top: 2px;
  font-size: 0.6rem;
}

.footer-links a {
  color: #c0c8d0;
  text-decoration: none;
}

.footer-links a:hover, .footer-credit a:hover, .footer-legal a:hover {
  color: #3b82f6;
  text-decoration: underline;
}

.footer-legal {
  margin-top: 4px;
  font-size: 0.6rem;
  color: #c0c8d0;
  line-height: 1.5;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

.footer-legal a {
  color: #b0bec5;
  text-decoration: none;
}

/* ── Desktop: wider grid ── */
@media (min-width: 600px) {
  main { max-width: 560px; }
  .grid-3x3 { gap: 10px; }
  .modal {
    border-radius: 20px;
    margin-bottom: 40px;
    max-height: 75vh;
  }
  .modal-overlay {
    align-items: center;
  }
}
