/* X-Archive — ダークテーマ固定のメディアアーカイブ UI */

:root {
  --bg: #0b0e13;
  --bg-soft: #10141c;
  --panel: #151a24;
  --panel-2: #1a2030;
  --panel-hover: #1b2230;
  --border: #232b3a;
  --text: #e7ecf4;
  --text-dim: #9aa7ba;
  --text-faint: #64708a;
  --accent: #5eead4;
  --accent-deep: #14b8a6;
  --accent-ink: #062c26;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #34d399;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", system-ui, -apple-system, sans-serif;
  line-height: 1.6;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(20, 184, 166, 0.12), transparent 60%),
    radial-gradient(900px 400px at 10% -5%, rgba(94, 234, 212, 0.07), transparent 55%),
    var(--bg);
}

/* ===== Header ===== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(11, 14, 19, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.brand-mark { color: var(--accent); }

.header-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.quota-pill {
  font-size: 12.5px;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  white-space: nowrap;
}
.quota-pill strong { color: var(--accent); font-weight: 700; }

.user-area { display: flex; align-items: center; gap: 8px; }
.user-email {
  font-size: 13px;
  color: var(--text-dim);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Buttons ===== */

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  font-family: inherit;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-hover); border-color: #2e3950; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  border: none;
  color: var(--accent-ink);
}
.btn-primary:hover { filter: brightness(1.08); background: linear-gradient(135deg, var(--accent), var(--accent-deep)); }

.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: rgba(248, 113, 113, 0.35); }
.btn-danger:hover { background: rgba(248, 113, 113, 0.08); border-color: var(--danger); }
.btn-sm { font-size: 12.5px; padding: 6px 12px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ===== Hero ===== */

.main { max-width: 1180px; margin: 0 auto; padding: 0 24px 80px; }

.hero { text-align: center; padding: 64px 0 36px; }

.hero-title {
  margin: 0 0 14px;
  font-size: clamp(26px, 4.6vw, 44px);
  font-weight: 850;
  line-height: 1.3;
  letter-spacing: 0.01em;
}
.accent {
  background: linear-gradient(120deg, var(--accent), #7dd3fc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-sub {
  margin: 0 auto 30px;
  max-width: 640px;
  color: var(--text-dim);
  font-size: 15px;
}

.url-form {
  display: flex;
  gap: 10px;
  max-width: 680px;
  margin: 0 auto;
}

.url-input {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 15px;
  padding: 13px 16px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.url-input:focus {
  border-color: var(--accent-deep);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.18);
}
.url-form .btn-primary { font-size: 15px; padding: 13px 26px; border-radius: 12px; white-space: nowrap; }

.hero-hint { margin-top: 14px; font-size: 13px; color: var(--text-faint); min-height: 1.4em; }
.hero-hint a { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* ===== Collection ===== */

.collection-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 26px 0 18px;
}
.collection-head h2 { margin: 0; font-size: 20px; font-weight: 800; }

.filters { display: flex; gap: 8px; }
.filter-input, .filter-select {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 13.5px;
  padding: 8px 12px;
  outline: none;
  font-family: inherit;
}
.filter-input { width: 220px; }
.filter-input:focus, .filter-select:focus { border-color: var(--accent-deep); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.16s, border-color 0.16s, box-shadow 0.16s;
  display: flex;
  flex-direction: column;
}
.card:hover {
  transform: translateY(-3px);
  border-color: #31405c;
  box-shadow: var(--shadow);
}
.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card-thumb {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--bg-soft);
  overflow: hidden;
}
.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-thumb .thumb-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 40px;
  opacity: 0.5;
}

.badge {
  position: absolute;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(8, 10, 14, 0.72);
  backdrop-filter: blur(4px);
  color: #dbe5f1;
}
.badge-kind { left: 8px; top: 8px; }
.badge-count { right: 8px; top: 8px; }
.badge-status { right: 8px; bottom: 8px; }
.badge-status.st-pending, .badge-status.st-processing { color: var(--warn); }
.badge-status.st-failed { color: var(--danger); }

.spinner {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 2px solid rgba(251, 191, 36, 0.35);
  border-top-color: var(--warn);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  vertical-align: -1px;
  margin-right: 5px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card-meta { padding: 11px 13px 13px; }
.card-author {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 13px;
  overflow: hidden;
  white-space: nowrap;
}
.card-author .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.card-author .handle { color: var(--text-faint); font-size: 12px; flex-shrink: 0; }
.card-text {
  margin: 5px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.6em;
}
.card-date { margin-top: 7px; font-size: 11.5px; color: var(--text-faint); }

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 60px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-icon { font-size: 40px; margin-bottom: 10px; }

.load-more-wrap { text-align: center; margin-top: 24px; }

/* ===== Modals ===== */

.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: min(94vw, 560px);
  width: 100%;
}
.detail-modal { max-width: min(96vw, 860px); }

.modal::backdrop {
  background: rgba(5, 7, 10, 0.7);
  backdrop-filter: blur(6px);
}

.modal-body {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
  color: var(--text);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 6px;
}
.modal-close:hover { color: var(--text); }

/* auth modal (Google ログインのみ) */
.auth-title {
  margin: 0 0 16px;
  font-size: 17px;
  font-weight: 800;
}

.auth-notice {
  margin: -6px 0 16px;
  font-size: 13px;
  color: var(--warn);
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: 10px;
  padding: 10px 12px;
}

/* Google のブランドボタン (白地 + G ロゴ)。ダーク背景の中で唯一の明色にして
   ログイン動線を際立たせる。 */
.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #fff;
  color: #1f1f1f;
  font-weight: 700;
  padding: 12px 16px;
}
.btn-google:hover { background: #f1f3f4; }

.auth-note { font-size: 12px; color: var(--text-faint); margin: 12px 0 0; }

/* ゲストのボット確認 (Turnstile)。ウィジェット (300x65) を中央寄せで置く。 */
.turnstile-box {
  display: flex;
  justify-content: center;
  margin: 12px auto 0;
  min-height: 65px;
}
.turnstile-box[hidden] { display: none; }

/* detail modal */
.detail-media { margin: 0 -28px; background: #05070a; }
.detail-media .viewer {
  display: flex;
  align-items: center;
  justify-content: center;
  max-height: 62vh;
  min-height: 200px;
}
.detail-media img, .detail-media video {
  max-width: 100%;
  max-height: 62vh;
  display: block;
}
.media-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 0 2px;
}
.media-dot {
  width: 64px;
  height: 44px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  background: var(--bg-soft);
  padding: 0;
  flex-shrink: 0;
}
.media-dot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-dot.active { border-color: var(--accent); }
.media-dot .dot-icon { font-size: 18px; line-height: 40px; }

.detail-head { display: flex; align-items: baseline; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.detail-head .name { font-weight: 800; font-size: 15px; }
.detail-head .handle { color: var(--text-faint); font-size: 13px; }
.detail-head .date { color: var(--text-faint); font-size: 12.5px; margin-left: auto; }
.detail-text { font-size: 14px; margin: 10px 0 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-error {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--danger);
  background: rgba(248, 113, 113, 0.07);
  border: 1px solid rgba(248, 113, 113, 0.25);
  border-radius: 8px;
  padding: 8px 10px;
  word-break: break-all;
}
.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
  flex-wrap: wrap;
  align-items: center;
}
.detail-actions .spacer { flex: 1; }
.detail-sub { font-size: 12px; color: var(--text-faint); margin-top: 8px; }
.detail-sub a { color: var(--accent); }

/* ===== Toasts ===== */

.toasts {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  width: min(92vw, 480px);
}
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 11px 15px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  animation: toast-in 0.22s ease-out;
}
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.site-footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
  padding: 26px 16px 34px;
  border-top: 1px solid var(--border);
}

@media (max-width: 640px) {
  /* ヘッダーは 2 段組: 1 段目にロゴ、2 段目に統計ピル + ボタン (右寄せ)。
     1 段に詰め込むとボタンが縮んで縦書きに潰れるため。 */
  .site-header { flex-wrap: wrap; padding: 12px 16px; row-gap: 8px; }
  .header-nav { width: 100%; justify-content: flex-end; }
  .hero { padding: 40px 0 28px; }
  .url-form { flex-direction: column; }
  .filters { width: 100%; }
  .filter-input { flex: 1; width: auto; }
  .modal-body { padding: 22px; }
  .detail-media { margin: 0 -22px; }
  .user-email { display: none; }
}
