/* ==========================================================================
   Tokens
   ========================================================================== */
:root {
  --bg:          #10141a;
  --bg-raised:   #161c24;
  --bg-panel:    #1b222c;
  --bg-code:     #0f141b;
  --border:      #2a3340;
  --border-soft: #212a35;

  --text:        #e8e6df;
  --text-dim:    #939cab;
  --text-faint:  #626c7c;

  --orange:      #ff7a3d;
  --orange-dim:  #d9611f;
  --teal:        #34d6c2;
  --teal-dim:    #219c8d;

  --radius:      5px;
  --radius-lg:   8px;

  --font-ui:   'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;
}

/* ==========================================================================
   Reset & base
   ========================================================================== */
* { box-sizing: border-box; }
html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}

h1, h2, h3 { font-family: var(--font-ui); font-weight: 600; margin: 0 0 0.5em; letter-spacing: -0.01em; }
p { margin: 0 0 1em; color: var(--text-dim); }

code, pre { font-family: var(--font-mono); }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ==========================================================================
   Site header
   ========================================================================== */
.site-header {
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-raised);
}
.site-header .container {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-top: 22px;
  padding-bottom: 22px;
}
.site-title {
  font-size: 1.25rem;
  margin: 0;
}
.site-title a { color: var(--text); }
.site-title a:hover { text-decoration: none; color: var(--teal); }
.site-title .dot { color: var(--orange); }

.site-tagline {
  color: var(--text-faint);
  font-size: 0.9rem;
  margin: 0;
}

/* ==========================================================================
   Project list (home)
   ========================================================================== */
.page-intro { padding: 56px 0 8px; }
.page-intro h1 { font-size: 1.7rem; }

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 24px 0 64px;
}

.project-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s ease;
}
.project-card:hover { border-color: var(--teal-dim); }

.project-card h2 {
  font-size: 1.08rem;
  margin-bottom: 8px;
}
.project-card h2 a { color: var(--text); }
.project-card h2 a:hover { color: var(--teal); text-decoration: none; }

.project-card p {
  font-size: 0.92rem;
  flex-grow: 1;
  margin-bottom: 16px;
}

.project-card .card-link {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--teal);
}
.project-card .card-link-demo {
  display: block;
  margin-bottom: 6px;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  color: var(--text-faint);
}

/* ==========================================================================
   Badges (public / private status)
   ========================================================================== */
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  vertical-align: middle;
}
.badge-public { color: var(--teal); border-color: var(--teal-dim); }
.badge-private { color: var(--orange); border-color: var(--orange-dim); }
.badge-note {
  color: var(--text-faint);
  font-size: 0.76rem;
  margin-left: 6px;
}
.project-card h2 .badge,
.project-header h1 .badge {
  font-size: 0.62rem;
  margin-left: 8px;
  transform: translateY(-2px);
}

/* ==========================================================================
   Project detail page
   ========================================================================== */
.project-header {
  padding: 56px 0 28px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}
.project-header-main { min-width: 0; }
.project-header h1 { font-size: 1.8rem; }
.project-header .description { font-size: 1.02rem; max-width: 62ch; margin-bottom: 0; }
.project-header .demo-link { margin: 8px 0 0; font-size: 0.92rem; }
.project-header .demo-link a { font-weight: 600; }
.project-header-actions { flex-shrink: 0; padding-top: 4px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 11px 20px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }

.btn-download {
  background: var(--orange);
  color: #1a0e06;
  margin: 0;
  white-space: nowrap;
}
.btn-download:hover { background: var(--orange-dim); }
.btn-download .size { opacity: 0.75; font-weight: 500; }

.btn-secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 6px 12px;
}
.btn-secondary:hover { border-color: var(--teal-dim); color: var(--teal); }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 28px;
}
.gallery-thumb {
  display: block;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  overflow: hidden;
  cursor: zoom-in;
  aspect-ratio: 16 / 10;
}
.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.15s ease;
}
.gallery-thumb:hover { border-color: var(--teal-dim); }
.gallery-thumb:hover img { transform: scale(1.04); }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  z-index: 100;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.lightbox-close {
  position: absolute;
  top: 20px;
  right: 24px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}
.lightbox-close:hover { border-color: var(--orange); color: var(--orange); }

.instructions {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--teal);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 32px;
}
.instructions h2 {
  font-size: 0.82rem;
  text-transform: none;
  color: var(--text);
  margin-bottom: 10px;
}
.instructions p:last-child { margin-bottom: 0; }

.notice {
  border: 1px solid var(--border);
  border-left: 3px solid var(--orange);
  background: var(--bg-panel);
  border-radius: var(--radius);
  padding: 14px 18px;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

/* ==========================================================================
   File browser
   ========================================================================== */
.browser {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 64px;
  height: 70vh;
  min-height: 420px;
}

.tree-pane {
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  padding: 14px 8px;
  height: 100%;
  overflow-y: auto;
}

.tree-empty { color: var(--text-faint); font-size: 0.85rem; padding: 8px 10px; }

ul.tree {
  list-style: none;
  margin: 0;
  padding-left: 14px;
  font-size: 0.87rem;
}
ul.tree:first-child { padding-left: 4px; }

.tree-dir summary {
  cursor: pointer;
  color: var(--text-dim);
  padding: 4px 6px;
  border-radius: var(--radius);
  list-style: none;
}
.tree-dir summary::-webkit-details-marker { display: none; }
.tree-dir summary::before {
  content: '›';
  display: inline-block;
  width: 0.9em;
  color: var(--text-faint);
  transition: transform 0.12s ease;
}
.tree-dir details[open] > summary::before { transform: rotate(90deg); }
.tree-dir summary:hover { color: var(--teal); }

.tree-file .file-link {
  display: block;
  padding: 4px 10px;
  margin: 1px 0;
  border-radius: var(--radius);
  border-left: 2px solid transparent;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.83rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree-file .file-link:hover {
  color: var(--teal);
  background: rgba(52, 214, 194, 0.08);
  text-decoration: none;
}
.tree-file .file-link.active {
  color: var(--orange);
  border-left-color: var(--orange);
  background: rgba(255, 122, 61, 0.08);
}

.viewer-pane {
  display: flex;
  flex-direction: column;
  background: var(--bg-code);
  min-width: 0;
  height: 100%;
  min-height: 0;
}

.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  font-family: var(--font-mono);
  font-size: 0.83rem;
  color: var(--text-dim);
  flex-shrink: 0;
}
.viewer-bar .viewer-actions { display: flex; gap: 8px; }

.viewer-body {
  flex-grow: 1;
  min-height: 0;
  overflow: auto;
  padding: 0;
}

.viewer-placeholder {
  color: var(--text-faint);
  font-size: 0.92rem;
  padding: 16px 20px;
}

.viewer-body pre {
  margin: 0;
  padding: 0px 0px;
  font-size: 0.85rem;
  line-height: 1.6;
}
.viewer-body code {
  font-family: var(--font-mono);
  white-space: pre;
}

/* ==========================================================================
   Site footer
   ========================================================================== */
.site-footer {
  border-top: 1px solid var(--border-soft);
  padding: 24px 0 40px;
  color: var(--text-faint);
  font-size: 0.83rem;
}
.site-footer p:last-child { margin-bottom: 0; }
.site-footer a { color: var(--text-faint); }
.site-footer a:hover { color: var(--teal); }

/* ==========================================================================
   Admin
   ========================================================================== */
.admin-shell { min-height: 100vh; }
.admin-topbar {
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-raised);
}
.admin-topbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
}
.admin-topbar .brand { font-weight: 600; }
.admin-topbar .brand .dot { color: var(--orange); }
.admin-topbar nav a { color: var(--text-dim); margin-left: 18px; font-size: 0.9rem; }
.admin-topbar nav a:hover { color: var(--teal); }

.admin-main { padding: 36px 0 64px; }
.admin-main h1 { font-size: 1.5rem; }

.flash {
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
}
.flash-success { border-left: 3px solid var(--teal); }
.flash-error { border-left: 3px solid var(--orange); }

table.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  font-size: 0.92rem;
}
table.admin-table th, table.admin-table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
}
table.admin-table th {
  color: var(--text-faint);
  font-weight: 600;
  font-size: 0.78rem;
}
table.admin-table tr:last-child td { border-bottom: none; }
table.admin-table td.actions { white-space: nowrap; text-align: right; }
table.admin-table td.actions a, table.admin-table td.actions button {
  font-size: 0.85rem;
  margin-left: 14px;
}
table.admin-table .muted { color: var(--text-faint); font-family: var(--font-mono); font-size: 0.82rem; }

.link-btn {
  background: none;
  border: none;
  color: var(--orange);
  cursor: pointer;
  padding: 0;
  font-family: var(--font-ui);
}
.link-btn:hover { text-decoration: underline; }

.top-actions { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }

/* Forms */
.form-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 640px;
}
.field { margin-bottom: 20px; }
.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field .hint {
  display: block;
  font-size: 0.78rem;
  color: var(--text-faint);
  margin-top: 5px;
}
.field input[type=text],
.field input[type=password],
.field textarea {
  width: 100%;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  font-family: var(--font-ui);
  font-size: 0.94rem;
}
.field input[type=text]:focus,
.field input[type=password]:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--teal-dim);
}
.field textarea { resize: vertical; min-height: 90px; font-family: var(--font-ui); }
.field.mono input { font-family: var(--font-mono); font-size: 0.87rem; }

.form-actions { display: flex; gap: 12px; align-items: center; margin-top: 8px; }

.radio-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-weight: 400 !important;
  color: var(--text) !important;
  font-size: 0.92rem;
  margin-bottom: 10px;
  cursor: pointer;
}
.radio-label input { margin-top: 3px; accent-color: var(--teal); }

.input-row { display: flex; gap: 8px; }
.input-row input { flex-grow: 1; }
.input-row .btn-secondary { flex-shrink: 0; padding: 0 14px; }

dialog#visibility-dialog {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 460px;
  width: 90vw;
}
dialog#visibility-dialog::backdrop {
  background: rgba(8, 10, 14, 0.7);
}
dialog#visibility-dialog h2 {
  font-size: 1.05rem;
  margin-bottom: 18px;
}
dialog#visibility-dialog[open] { display: block; }

.btn-primary {
  background: var(--teal);
  color: #062421;
  border: none;
}
.btn-primary:hover { background: var(--teal-dim); color: #eafffb; }

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 360px;
}
.login-card h1 { font-size: 1.2rem; text-align: center; margin-bottom: 24px; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 720px) {
  .browser { grid-template-columns: 1fr; grid-template-rows: 200px 1fr; height: 80vh; }
  .tree-pane { border-right: none; border-bottom: 1px solid var(--border); }
  .admin-topbar .container { flex-direction: column; align-items: flex-start; gap: 8px; }
  .admin-topbar nav a { margin-left: 0; margin-right: 16px; }
  .project-header { flex-direction: column; }
  .project-header-actions { padding-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
