/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0a0a12;
  --bg-card:     #12121e;
  --bg-raised:   #1a1a2e;
  --bg-hover:    #22223a;
  --border:      #2a2a45;
  --accent:      #6c63ff;
  --accent-dim:  rgba(108,99,255,.15);
  --text:        #e8e8f0;
  --text-muted:  #8888aa;
  --error:       #ef4444;
  --success:     #22c55e;
  --radius:      12px;
  --radius-sm:   8px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

/* ── Views ─────────────────────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: flex; flex-direction: column; min-height: 100vh; }
.view.center {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  gap: 1rem;
}

/* ── Loading ───────────────────────────────────────────────────────────────── */
.spinner-large {
  width: 44px; height: 44px;
  border: 3px solid rgba(108,99,255,.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.5rem; }

/* ── Error ─────────────────────────────────────────────────────────────────── */
.error-icon { color: var(--error); margin-bottom: 0.25rem; }
.error-icon svg { width: 52px; height: 52px; }
#view-error h2 { font-size: 1.3rem; }
.error-sub { color: var(--text-muted); font-size: 0.9rem; max-width: 360px; }

/* ── Error view extras ─────────────────────────────────────────────────────── */
.btn-primary-sm {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary-sm:hover { opacity: .85; }

/* ── Paste-token card (no-token view) ──────────────────────────────────────── */
#view-no-token { background: radial-gradient(ellipse at 50% 0%, rgba(108,99,255,.1) 0%, transparent 70%); }

.paste-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  box-shadow: 0 4px 24px rgba(0,0,0,.5);
}

.paste-icon {
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.paste-card h2 { font-size: 1.4rem; font-weight: 700; }

.paste-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.55;
  margin-bottom: 0.5rem;
}

.paste-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.25rem;
}

.paste-textarea {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.7rem 0.85rem;
  font-size: 0.8rem;
  font-family: 'SFMono-Regular', 'Consolas', monospace;
  resize: vertical;
  min-height: 90px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.paste-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.paste-textarea::placeholder { color: var(--text-muted); }

.paste-error {
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.3);
  color: #fca5a5;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.82rem;
}

.btn-open {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.72rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, box-shadow 0.15s;
}
.btn-open:hover { opacity: .9; box-shadow: 0 0 0 3px var(--accent-dim); }
.btn-open:active { opacity: .8; }

.paste-divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 0.5rem;
  position: relative;
}
.paste-divider::before,
.paste-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 36%;
  height: 1px;
  background: var(--border);
}
.paste-divider::before { left: 0; }
.paste-divider::after  { right: 0; }

.paste-url-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.paste-url-hint code {
  background: var(--bg-raised);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-family: monospace;
  color: var(--accent);
  font-size: 0.85em;
}

/* ── Viewer header ─────────────────────────────────────────────────────────── */
.viewer-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.viewer-title {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}
.folder-title {
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
}

.file-name-label {
  font-size: 0.925rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-size-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--bg-raised);
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }

.btn-secondary {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background 0.15s, border-color 0.15s;
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--accent); }

.badge {
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 99px;
  padding: 0.1rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 700;
}

/* ── Single media view ─────────────────────────────────────────────────────── */
#view-single { display: none; }
#view-single.active { display: flex; }

.media-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
  position: relative;
}

.media-container video {
  width: 100%;
  height: 100%;
  max-height: calc(100vh - 60px);
  object-fit: contain;
}

.media-container img {
  max-width: 100%;
  max-height: calc(100vh - 60px);
  object-fit: contain;
  display: block;
}

/* ── Folder / Grid view ────────────────────────────────────────────────────── */
#view-folder { display: none; }
#view-folder.active { display: flex; }

.folder-main {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

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

.grid-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
}
.grid-item:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

.grid-thumb {
  aspect-ratio: 16/9;
  background: var(--bg-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

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

.grid-thumb .thumb-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
}

.grid-thumb .type-badge {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.grid-info {
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.grid-name {
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.grid-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.grid-play-btn {
  position: absolute;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(108,99,255,.85);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: transform 0.15s, background 0.15s;
}
.grid-item:hover .grid-play-btn { transform: scale(1.1); background: var(--accent); }

/* ── Media overlay ─────────────────────────────────────────────────────────── */
.media-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0 0.5rem;
}
.media-overlay.hidden { display: none; }

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.88);
  backdrop-filter: blur(4px);
}

/* ── Prev / Next arrows ──────────────────────────────────────────────────────*/
.overlay-nav {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  backdrop-filter: blur(4px);
}
.overlay-nav:hover { background: rgba(108,99,255,.6); transform: scale(1.05); }
.overlay-nav:active { transform: scale(.96); }

/* Slightly larger click target on mobile */
@media (max-width: 600px) {
  .overlay-nav { width: 36px; height: 36px; }
}

.overlay-content {
  position: relative;
  z-index: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  /* leave room for arrows on sides */
  max-width: min(calc(96vw - 120px), 1200px);
  max-height: 95vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 64px rgba(0,0,0,.7);
}

@media (max-width: 600px) {
  .overlay-content { max-width: calc(96vw - 96px); }
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 0.5rem;
}

.overlay-title-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  flex: 1;
}

.overlay-counter {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  white-space: nowrap;
  flex-shrink: 0;
}

.overlay-media {
  flex: 1;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 200px;
  max-height: calc(95vh - 56px);
}

.overlay-media video {
  max-width: 100%;
  max-height: calc(95vh - 56px);
  object-fit: contain;
}

.overlay-media img {
  max-width: 100%;
  max-height: calc(95vh - 56px);
  object-fit: contain;
}

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.75rem; }
  .folder-main { padding: 1rem; }
}
