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

:root {
  --bg-primary: #0a0a0b;
  --bg-secondary: #111113;
  --bg-tertiary: #18181b;
  --bg-hover: #1f1f23;
  --bg-active: #27272a;
  --border: #27272a;
  --border-subtle: #1f1f23;
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-dim: rgba(99, 102, 241, 0.15);
  --success: #22c55e;
  --warning: #f59e0b;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --transition: 150ms ease;
}

html {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
}

/* === Topbar === */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(17, 17, 19, 0.85);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.topbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 8px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.logo svg {
  color: var(--accent);
}

/* === Buttons === */
.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--transition);
}

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

.btn-icon.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.btn-icon.btn-sm {
  width: 28px;
  height: 28px;
}

.btn-back {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-back:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* === Gallery View === */
.gallery {
  padding: 80px 24px 40px;
  max-width: 960px;
  margin: 0 auto;
}

.gallery-header {
  margin-bottom: 40px;
}

.gallery-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}

.subtitle {
  color: var(--text-tertiary);
  font-size: 14px;
}

/* === Project Cards === */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.project-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.project-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--card-color, var(--accent));
  opacity: 0;
  transition: opacity var(--transition);
}

.project-card:hover {
  border-color: var(--bg-active);
  background: var(--bg-tertiary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.project-card:hover::before {
  opacity: 1;
}

.project-card-preview {
  height: 140px;
  margin: -20px -20px 16px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-subtle);
  overflow: hidden;
  position: relative;
}

.project-card-preview iframe {
  width: 200%;
  height: 200%;
  border: none;
  transform: scale(0.5);
  transform-origin: top left;
  pointer-events: none;
}

.project-card-preview .overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 60%, var(--bg-secondary));
}

.project-card-info {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.project-card-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.project-card-text {
  flex: 1;
  min-width: 0;
}

.project-card-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 2px;
}

.project-card-description {
  color: var(--text-tertiary);
  font-size: 12px;
  margin-bottom: 12px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.project-card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: var(--text-tertiary);
}

.project-card-meta .count {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* === Project View === */
.project-view {
  padding: 68px 24px 40px;
  max-width: 960px;
  margin: 0 auto;
}

.project-header {
  margin-bottom: 32px;
}

.project-header h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 12px 0 4px;
}

.page-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.page-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text-primary);
}

.page-item:hover {
  background: var(--bg-tertiary);
}

.page-item-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.page-item:hover .page-item-icon {
  background: var(--bg-active);
  color: var(--text-secondary);
}

.page-item-title {
  font-size: 14px;
  font-weight: 500;
}

.page-item-file {
  font-size: 12px;
  color: var(--text-tertiary);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.page-item-arrow {
  margin-left: auto;
  color: var(--text-tertiary);
  opacity: 0;
  transition: opacity var(--transition);
}

.page-item:hover .page-item-arrow {
  opacity: 1;
}

/* === Preview View === */
.preview-view {
  padding-top: 52px;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.preview-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  min-height: 44px;
}

.preview-page-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-indicator {
  font-size: 12px;
  color: var(--text-tertiary);
  min-width: 40px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.preview-header h3 {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 24px;
  background: var(--bg-primary);
  overflow: auto;
  min-height: 0;
}

/* === Device Frame === */
.device-frame {
  width: 100%;
  height: 100%;
  position: relative;
  transition: all 300ms ease;
}

.device-frame.mobile {
  max-width: 375px;
  min-height: 700px;
  border-radius: var(--radius-xl);
  border: 3px solid var(--border);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  align-self: center;
}

.device-frame.tablet {
  max-width: 768px;
  min-height: 700px;
  border-radius: var(--radius-xl);
  border: 3px solid var(--border);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.device-frame.full {
  max-width: 100%;
  border: none;
}

.device-frame iframe {
  width: 100%;
  height: 100%;
  min-height: 600px;
  border: none;
  background: var(--bg-primary);
  border-radius: inherit;
}

/* === Version Bar === */
.version-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
}

.version-info {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 80px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  cursor: default;
}

/* === Page Item Metadata === */
.page-item-modified {
  margin-left: 8px;
  color: var(--text-tertiary);
  font-family: inherit;
  font-size: 11px;
}

.page-item-versions {
  margin-left: 8px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--accent-dim);
  color: var(--accent);
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
}

/* === Empty State === */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
  color: var(--text-tertiary);
}

.empty-state p {
  margin-top: 16px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
}

.empty-state .hint {
  font-size: 13px;
  color: var(--text-tertiary);
  font-weight: 400;
  margin-top: 4px;
}

/* === Skeleton Loading === */
.skeleton {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-hover) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* === Responsive === */
@media (max-width: 640px) {
  .gallery {
    padding: 68px 16px 32px;
  }

  .gallery-header h1 {
    font-size: 22px;
  }

  .projects-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .preview-container {
    padding: 12px;
  }

  .preview-header h3 {
    display: none;
  }
}

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-active);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* === Focus styles === */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus:not(:focus-visible) {
  outline: none;
}
