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

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-hover: #1c1c1c;
  --surface-active: #252525;
  --border: #222;
  --border-hover: #333;
  --text: #e5e5e5;
  --text-secondary: #888;
  --accent: #6c5ce7;
  --accent-hover: #5a4bd1;
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --shadow: 0 2px 20px rgba(0,0,0,0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 280px;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10,10,10,0.8);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

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

.count {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--surface-hover);
  border-color: var(--border-hover);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8125rem;
}

.btn-full {
  width: 100%;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s;
  line-height: 1;
}

.btn-icon:hover {
  color: var(--text);
  background: var(--surface-hover);
}

/* Gallery Grid */
.gallery {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.gallery-card {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.3s, box-shadow 0.3s;
}

.gallery-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 30px rgba(108,92,231,0.15);
}

.gallery-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s;
}

.gallery-card:hover img {
  transform: scale(1.05);
}

.gallery-card .card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 50%);
  opacity: 0;
  transition: opacity 0.3s;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 16px;
}

.gallery-card:hover .card-overlay {
  opacity: 1;
}

.gallery-card .card-time {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.7);
}

/* Empty State */
.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 24px;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%;
  max-width: 500px;
  box-shadow: var(--shadow);
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-body {
  padding: 20px 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 24px 20px;
}

/* Drop Zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(108,92,231,0.05);
}

.drop-zone.has-file .drop-zone-content {
  opacity: 0;
  pointer-events: none;
}

.drop-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.drop-zone p {
  font-size: 0.9375rem;
  font-weight: 500;
  margin-bottom: 4px;
}

.drop-hint {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.drop-zone-preview {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.drop-zone-preview img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

/* Upload Status */
.upload-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ─── DANBOORU-STYLE WATCH PAGE ─── */

#watchView {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
}

.watch-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.watch-back {
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}

.watch-back:hover {
  background: var(--surface-hover);
}

.watch-position {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  flex: 1;
}

.watch-header-actions {
  display: flex;
  gap: 8px;
}

.watch-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.watch-image-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-width: 0;
  background: #0d0d0d;
}

.watch-image-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  width: 100%;
  overflow: hidden;
}

.watch-image-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 2px 24px rgba(0,0,0,0.5);
}

.watch-nav {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  flex-shrink: 0;
}

.watch-nav-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 8px 24px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.watch-nav-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.watch-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  border-color: var(--border);
}

/* Sidebar */
.watch-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.watch-sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.watch-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-active);
}

.watch-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.watch-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
}

.stat-row:last-child {
  border-bottom: none;
}

.stat-label {
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-value {
  color: var(--text);
  text-align: right;
  word-break: break-all;
  max-width: 160px;
}

.btn-download {
  width: 100%;
  padding: 12px 20px;
  font-size: 0.9375rem;
  font-weight: 600;
}

/* Embed Modal */
.modal-embed {
  max-width: 560px;
}

.embed-info {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
}

.embed-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.embed-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.embed-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.embed-copy-row {
  display: flex;
  gap: 8px;
}

.embed-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 0.75rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.embed-input:focus {
  border-color: var(--accent);
}

.embed-input::selection {
  background: var(--accent);
  color: #fff;
}

.embed-footer {
  margin-top: 16px;
  font-size: 0.6875rem;
  color: var(--text-secondary);
  text-align: center;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 0.875rem;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: all 0.4s;
  z-index: 300;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Responsive */
@media (max-width: 768px) {
  .watch-body {
    flex-direction: column;
  }

  .watch-sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 200px;
  }

  .watch-thumb {
    display: none;
  }

  .watch-image-panel {
    padding: 12px;
  }

  .watch-header {
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
    padding: 12px;
  }

  .header-inner {
    padding: 12px 16px;
  }

  .logo {
    font-size: 1rem;
  }

  .btn {
    padding: 8px 14px;
    font-size: 0.8125rem;
  }
}
