/* ─────────────────────────────────────────────────────────────────────────────
   style.css — portfolio stylesheet
   Edit variables in :root to change colours/fonts without touching HTML.
   ───────────────────────────────────────────────────────────────────────────── */

:root {
  --font-sans:  "Inter", system-ui, sans-serif;
  --font-mono:  "JetBrains Mono", "Fira Code", monospace;

  --bg:         #ffffff;
  --bg-subtle:  #f6f6f6;
  --border:     #e5e5e5;
  --text:       #1a1a1a;
  --text-muted: #6b6b6b;
  --accent:     #0057d9;
  --accent-h:   #0046b0;   /* hover */
  --danger:     #c0392b;

  --max-w:      860px;
  --radius:     4px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:         #111111;
    --bg-subtle:  #1c1c1c;
    --border:     #2e2e2e;
    --text:       #e8e8e8;
    --text-muted: #888888;
    --accent:     #4d9fff;
    --accent-h:   #74b3ff;
  }
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */

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

/* ── Base ──────────────────────────────────────────────────────────────────── */

html { font-size: 16px; }

body {
  font-family:      var(--font-sans);
  background-color: var(--bg);
  color:            var(--text);
  line-height:      1.65;
  min-height:       100vh;
  display:          flex;
  flex-direction:   column;
}

main { flex: 1; padding: 2.5rem 1rem; }

/* ── Layout ────────────────────────────────────────────────────────────────── */

.container {
  max-width:  var(--max-w);
  margin:     0 auto;
  width:      100%;
}

.container.narrow {
  max-width: 400px;
}

/* ── Typography ────────────────────────────────────────────────────────────── */

h1 { font-size: 1.75rem; font-weight: 600; letter-spacing: -0.02em; }
h2 { font-size: 1.2rem;  font-weight: 600; margin-top: 2rem; }
h3 { font-size: 1rem;    font-weight: 600; margin-top: 1.5rem; }

p  { margin-top: 0.75rem; }

a  { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-h); text-decoration: underline; }

.muted { color: var(--text-muted); font-size: 0.875rem; }
.mono  { font-family: var(--font-mono); font-size: 0.875rem; }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

/* ── Navigation ────────────────────────────────────────────────────────────── */

header {
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
}

header nav {
  max-width:   var(--max-w);
  margin:      0 auto;
  display:     flex;
  align-items: center;
  justify-content: space-between;
  height:      52px;
  gap:         1rem;
}

.brand {
  font-weight: 600;
  color:       var(--text);
  font-size:   0.95rem;
  white-space: nowrap;
}
.brand:hover { color: var(--accent); text-decoration: none; }

header nav ul {
  display:     flex;
  list-style:  none;
  gap:         1.5rem;
  font-size:   0.9rem;
}

header nav a        { color: var(--text-muted); }
header nav a:hover  { color: var(--text); text-decoration: none; }
header nav a.active { color: var(--text); font-weight: 500; }

/* ── Footer ────────────────────────────────────────────────────────────────── */

footer {
  border-top: 1px solid var(--border);
  padding:    1.25rem 1rem;
  font-size:  0.85rem;
  color:      var(--text-muted);
}

/* ── Home hero ─────────────────────────────────────────────────────────────── */

.hero {
  padding: 3rem 0 1rem;
}

.hero-top {
  display:     flex;
  align-items: baseline;
  gap:         1.25rem;
  flex-wrap:   wrap;
}

.hero-top h1 {
  font-size: 2rem;
  flex-shrink: 0;
}

.hero-links {
  display: flex;
  gap:     0.75rem;
  flex-wrap: wrap;
}

.hero-link {
  font-size:     0.875rem;
  font-weight:   500;
  color:         var(--text-muted);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  padding:       0.2rem 0.6rem;
  white-space:   nowrap;
}
.hero-link:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }

.tagline {
  color:       var(--text-muted);
  font-size:   1.05rem;
  margin-top:  0.35rem;
}

.bio {
  max-width:  540px;
  margin-top: 1rem;
  line-height: 1.7;
}

.visitors {
  font-size:   0.85rem;
  color:       var(--text-muted);
  margin-top:  0.75rem;
}

/* ── Tech stack (categorized) ──────────────────────────────────────────────── */

.stack-section {
  margin-top:  0.75rem;
  display:     flex;
  flex-direction: column;
  gap:         0.6rem;
}

.stack-row {
  display:     flex;
  align-items: baseline;
  gap:         0.75rem;
  flex-wrap:   wrap;
}

.stack-category {
  font-size:   0.78rem;
  font-weight: 500;
  color:       var(--text-muted);
  white-space: nowrap;
  min-width:   200px;
  flex-shrink: 0;
}

.stack-tools {
  display:  flex;
  flex-wrap: wrap;
  gap:       0.35rem;
}

.stack-tag {
  background:    var(--bg-subtle);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  padding:       0.15rem 0.5rem;
  font-size:     0.8rem;
  font-family:   var(--font-mono);
}

/* ── Sections ──────────────────────────────────────────────────────────────── */

.section { margin-top: 2.5rem; }

/* ── Tag list (skills) ─────────────────────────────────────────────────────── */

ul.tags {
  display:    flex;
  flex-wrap:  wrap;
  gap:        0.4rem;
  list-style: none;
  margin-top: 0.75rem;
}

ul.tags li {
  background:    var(--bg-subtle);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  padding:       0.2rem 0.6rem;
  font-size:     0.8rem;
  font-family:   var(--font-mono);
}

.tags-inline { color: var(--text-muted); font-size: 0.82rem; }

/* ── Source badge (Medium vs Note) ─────────────────────────────────────────── */

.source-badge {
  display:       inline-block;
  padding:       0.1rem 0.45rem;
  border-radius: 99px;
  font-size:     0.72rem;
  font-weight:   500;
  vertical-align: middle;
}

.source-medium {
  background: #e8f3ff;
  color:      #0057d9;
  border:     1px solid #b3d4ff;
}

.source-note {
  background: var(--bg-subtle);
  color:      var(--text-muted);
  border:     1px solid var(--border);
}

.source-substack {
  background: #fff0e8;
  color:      #e06c00;
  border:     1px solid #f5c89a;
}

.source-external {
  background: #edfaf1;
  color:      #1a7a3c;
  border:     1px solid #9ddbb5;
}

@media (prefers-color-scheme: dark) {
  .source-medium   { background: #0d2a4a; color: #4d9fff; border-color: #1a4a80; }
  .source-substack { background: #3d1e00; color: #ff9a4d; border-color: #6b3800; }
  .source-external { background: #0d2a1a; color: #4dbb77; border-color: #1a5c36; }
}

/* ── Link list (writing section) ───────────────────────────────────────────── */

ul.link-list {
  list-style: none;
  margin-top: 0.75rem;
}

ul.link-list li {
  padding: 0.25rem 0;
}

/* ── Post list ─────────────────────────────────────────────────────────────── */

ul.post-list {
  list-style: none;
  margin-top: 1.5rem;
}

ul.post-list li {
  border-bottom: 1px solid var(--border);
}

ul.post-list li:first-child { border-top: 1px solid var(--border); }

/* Full-card clickable link */
ul.post-list .card-link {
  display:     block;
  padding:     1rem 0;
  color:       inherit;
  text-decoration: none;
  transition:  background 0.1s;
}

ul.post-list .card-link:hover { text-decoration: none; }

.card-title {
  display:     block;
  font-size:   1rem;
  font-weight: 500;
  color:       var(--text);
  transition:  color 0.15s;
}

ul.post-list .card-link:hover .card-title { color: var(--accent); }

.post-meta {
  display:    flex;
  gap:        1rem;
  margin-top: 0.25rem;
  color:      var(--text-muted);
  font-size:  0.82rem;
}

/* ── Article / prose ───────────────────────────────────────────────────────── */

.post-header { padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
.post-header h1 { margin-bottom: 0.35rem; }

.prose {
  margin-top: 1.75rem;
  line-height: 1.8;
}

.prose h1, .prose h2, .prose h3 {
  margin-top: 2rem;
}

.prose h2 { font-size: 1.15rem; }
.prose h3 { font-size: 1rem; }

.prose p { margin-top: 1rem; }

.prose a { text-decoration: underline; }

.prose ul, .prose ol {
  margin-top:  1rem;
  padding-left: 1.5rem;
}

.prose li { margin-top: 0.35rem; }

.prose code {
  font-family:   var(--font-mono);
  font-size:     0.875em;
  background:    var(--bg-subtle);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  padding:       0.1em 0.3em;
}

.prose pre {
  background:    var(--bg-subtle);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  padding:       1rem;
  overflow-x:    auto;
  margin-top:    1rem;
}

.prose pre code {
  background: none;
  border:     none;
  padding:    0;
  font-size:  0.875rem;
}

.prose blockquote {
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  color:        var(--text-muted);
  margin-top:   1rem;
}

.prose table {
  width:           100%;
  border-collapse: collapse;
  margin-top:      1rem;
  font-size:       0.9rem;
}

.prose th, .prose td {
  border:  1px solid var(--border);
  padding: 0.4rem 0.75rem;
  text-align: left;
}

.prose th { background: var(--bg-subtle); font-weight: 600; }

/* ── Comments ──────────────────────────────────────────────────────────────── */

.comments { margin-top: 1rem; }

ul.comment-list { list-style: none; margin-top: 1.25rem; }

.comment {
  padding:       1rem 0;
  border-bottom: 1px solid var(--border);
}

.comment-meta {
  display:     flex;
  gap:         0.75rem;
  align-items: baseline;
  margin-bottom: 0.35rem;
}

.comment-meta strong { font-size: 0.9rem; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */

.comment-form { margin-top: 2rem; }
.comment-form h3 { margin-top: 0; }

label {
  display:       block;
  margin-top:    1rem;
  font-size:     0.875rem;
  font-weight:   500;
  color:         var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="email"],
textarea {
  display:       block;
  width:         100%;
  margin-top:    0.3rem;
  padding:       0.5rem 0.65rem;
  font-family:   var(--font-sans);
  font-size:     0.9rem;
  background:    var(--bg);
  color:         var(--text);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  outline:       none;
  transition:    border-color 0.15s;
}

input:focus, textarea:focus {
  border-color: var(--accent);
}

button[type="submit"],
button[type="button"],
.button {
  margin-top:    1rem;
  padding:       0.5rem 1.1rem;
  font-family:   var(--font-sans);
  font-size:     0.875rem;
  font-weight:   500;
  background:    var(--accent);
  color:         #fff;
  border:        none;
  border-radius: var(--radius);
  cursor:        pointer;
  transition:    background 0.15s;
}

button:hover { background: var(--accent-h); }

.btn-danger {
  background: transparent;
  color:      var(--danger);
  border:     1px solid var(--danger);
  padding:    0.3rem 0.7rem;
  margin:     0;
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.error {
  background:    #fde8e8;
  border:        1px solid #f5c6c6;
  border-radius: var(--radius);
  padding:       0.6rem 0.9rem;
  color:         var(--danger);
  font-size:     0.875rem;
  margin-top:    1rem;
}

/* ── Admin table ───────────────────────────────────────────────────────────── */

.admin-table {
  width:           100%;
  border-collapse: collapse;
  margin-top:      1.25rem;
  font-size:       0.9rem;
}

.admin-table th {
  text-align:    left;
  padding:       0.5rem 0.75rem;
  border-bottom: 2px solid var(--border);
  font-weight:   600;
  font-size:     0.8rem;
  color:         var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.admin-table td {
  padding:       0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.admin-table .actions {
  display:    flex;
  gap:        0.75rem;
  align-items: center;
}

.admin-table .actions a { font-size: 0.875rem; }

.badge {
  display:       inline-block;
  padding:       0.15rem 0.55rem;
  border-radius: 99px;
  font-size:     0.75rem;
  font-weight:   500;
}

.badge-published { background: #d4edda; color: #1a6630; }
.badge-draft     { background: var(--bg-subtle); color: var(--text-muted); border: 1px solid var(--border); }
.badge-blog      { background: #e8f3ff; color: #0057d9; border: 1px solid #b3d4ff; }
.badge-note      { background: var(--bg-subtle); color: var(--text-muted); border: 1px solid var(--border); }

@media (prefers-color-scheme: dark) {
  .badge-published { background: #1a3d22; color: #5ecf7a; }
}

/* ── Admin editor ──────────────────────────────────────────────────────────── */

.editor-layout { max-width: 100%; }

.editor-top {
  display:     flex;
  gap:         1rem;
  align-items: center;
  padding:     1rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap:   wrap;
}

#post-title {
  flex:        1;
  font-size:   1.2rem;
  font-weight: 600;
  border:      none;
  border-bottom: 2px solid var(--border);
  border-radius: 0;
  padding:     0.25rem 0;
  min-width:   200px;
}

#post-title:focus { border-color: var(--accent); }

.editor-controls {
  display:     flex;
  gap:         0.5rem;
  align-items: center;
  flex-shrink: 0;
}

.editor-controls button { margin-top: 0; }

.toggle-label {
  display:     flex;
  align-items: center;
  gap:         0.4rem;
  font-size:   0.875rem;
  font-weight: 500;
  color:       var(--text-muted);
  cursor:      pointer;
  margin-top:  0;
}

.toggle-label input { width: auto; margin: 0; }

.editor-panes {
  display:    grid;
  gap:        1rem;
  margin-top: 1rem;
  height:     calc(100vh - 180px);
}

.editor-panes.split { grid-template-columns: 1fr 1fr; }

.editor-pane { display: flex; flex-direction: column; overflow: hidden; }

#post-content {
  flex:        1;
  font-family: var(--font-mono);
  font-size:   0.9rem;
  line-height: 1.7;
  resize:      none;
  border:      1px solid var(--border);
  border-radius: var(--radius);
  padding:     1rem;
  height:      100%;
  margin-top:  0;
}

#preview-pane {
  border:        1px solid var(--border);
  border-radius: var(--radius);
  padding:       1rem 1.25rem;
  overflow-y:    auto;
}

.hidden { display: none; }

/* ── Post-type toggle (admin write) ────────────────────────────────────────── */

.post-type-toggle {
  display:     flex;
  gap:         0.5rem;
  align-items: center;
  padding:     0.2rem 0.5rem;
  border:      1px solid var(--border);
  border-radius: var(--radius);
}

/* ── Medium / Substack inline content ──────────────────────────────────────── */

.medium-content img {
  max-width:    100%;
  height:       auto;
  border-radius: var(--radius);
  margin-top:   1rem;
}

.medium-content figure {
  margin-top: 1.5rem;
}

.medium-content figcaption {
  font-size:  0.82rem;
  color:      var(--text-muted);
  margin-top: 0.4rem;
  text-align: center;
}

/* Substack wraps images in <a class="image-link image2"> — strip link styling */
.medium-content a.image-link,
.medium-content a.image-link:hover {
  color:           inherit;
  text-decoration: none;
  display:         block;
}

/* Div Substack injects inside image links renders as a blue bar — hide it */
.medium-content a.image-link > div {
  display: none;
}

/* ── Stats page ────────────────────────────────────────────────────────────── */

.stats-header {
  display:     flex;
  align-items: baseline;
  gap:         1.25rem;
  flex-wrap:   wrap;
  margin-bottom: 1.5rem;
}

.stats-ts { font-size: 0.82rem; }

.stats-grid {
  display:               grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap:                   1rem;
  margin-bottom:         2rem;
}

.stat-card {
  background:    var(--bg-subtle);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  padding:       1rem;
}

.stat-value {
  font-size:   1.75rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.03em;
}

.stat-label {
  font-size:  0.8rem;
  color:      var(--text-muted);
  margin-top: 0.35rem;
}

.stat-sublabel {
  font-size:  0.7rem;
  margin-top: 0.15rem;
}

.stats-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

@media (max-width: 600px) {
  .stats-columns { grid-template-columns: 1fr; }
}

.stats-section { margin-top: 0; }
.stats-section h2 { margin-top: 0; font-size: 1rem; }

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

.stats-table th {
  text-align: left;
  padding: 0.3rem 0.5rem;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.78rem;
  border-bottom: 1px solid var(--border);
}

.stats-table td { padding: 0.3rem 0.5rem; vertical-align: middle; }

/* Bar chart inside table */
.bar-wrap {
  width:  120px;
  height: 6px;
  background: var(--bg-subtle);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  min-width: 2px;
}

/* Hourly column bar chart */
.bar-chart {
  display:     flex;
  align-items: flex-end;
  gap:         4px;
  height:      80px;
  margin-top:  0.75rem;
}

.bar-col {
  display:        flex;
  flex-direction: column;
  align-items:    center;
  flex:           1;
  gap:            2px;
}

.bar-bar {
  width:         100%;
  min-height:    2px;
  background:    var(--accent);
  border-radius: 2px 2px 0 0;
  opacity:       0.8;
}

.bar-lbl {
  font-size:  0.65rem;
  color:      var(--text-muted);
  font-family: var(--font-mono);
}

/* Recent requests table */
.recent-table { font-size: 0.8rem; }

.status-badge {
  display:       inline-block;
  padding:       0.1rem 0.4rem;
  border-radius: var(--radius);
  font-size:     0.75rem;
  font-weight:   500;
  font-family:   var(--font-mono);
}

.status-2xx { background: #d4edda; color: #1a6630; }
.status-3xx { background: #fff3cd; color: #856404; }
.status-4xx { background: #fde8e8; color: var(--danger); }
.status-5xx { background: #fde8e8; color: var(--danger); }

@media (prefers-color-scheme: dark) {
  .status-2xx { background: #1a3d22; color: #5ecf7a; }
  .status-3xx { background: #3d3000; color: #ffd166; }
  .status-4xx, .status-5xx { background: #3d1212; color: #ff8080; }
}

/* World map */
.world-map-wrap {
  position:   relative;
  width:      100%;
  max-width:  var(--max-w);
  margin-top: 0.75rem;
  border:     1px solid var(--border);
  border-radius: var(--radius);
  overflow:   hidden;
  background: var(--bg-subtle);
}

.world-map-img {
  display: block;
  width:   100%;
  height:  auto;
}

.dot-layer {
  position: absolute;
  top:      0;
  left:     0;
  width:    100%;
  height:   100%;
  pointer-events: none;
}

.dot-layer .map-dot {
  pointer-events: all;
  cursor:         default;
  transition:     fill-opacity 0.15s;
}

.dot-layer .map-dot:hover { fill-opacity: 0.95; }

.map-legend {
  display:    flex;
  flex-wrap:  wrap;
  gap:        0.4rem 1rem;
  padding:    0.6rem 0.75rem;
  border-top: 1px solid var(--border);
  font-size:  0.78rem;
  color:      var(--text-muted);
}

.legend-item {
  display:     flex;
  align-items: center;
  gap:         0.35rem;
}

.legend-dot {
  display:       inline-block;
  width:         8px;
  height:        8px;
  border-radius: 50%;
  background:    #4d9fff;
  opacity:       0.8;
  flex-shrink:   0;
}

/* Path column in stats tables */
.path-cell {
  max-width:    220px;
  overflow:     hidden;
  text-overflow: ellipsis;
  white-space:  nowrap;
}
