:root{
  --bg:#ffffff;
  --text:#111;
  --muted:#555;
  --link:#1a59ff;
  --border:#eaeaea;
  --card-bg:#fafafa;
  --max: 860px;
  --sidebar: 220px;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,.06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
}

/* Dark theme */
[data-theme="dark"] {
  --bg:#0d1117;
  --text:#e6edf3;
  --muted:#8b949e;
  --link:#58a6ff;
  --border:#30363d;
  --card-bg:#161b22;
  --shadow: 0 10px 30px rgba(0,0,0,.3);
}

/* Respect system preference when no theme is set */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#0d1117;
    --text:#e6edf3;
    --muted:#8b949e;
    --link:#58a6ff;
    --border:#30363d;
    --card-bg:#161b22;
    --shadow: 0 10px 30px rgba(0,0,0,.3);
  }
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height:1.65;
}

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

.container{
  width:100%;
  max-width: calc(var(--max) + var(--sidebar));
  margin: 0 auto;
  padding: 42px 20px 80px;
  position: relative;
}

.header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:20px;
  margin-bottom: 34px;
}

.brand{
  display:flex;
  align-items:center;
  gap:12px;
  min-width: 240px;
}
.brand img{
  width:42px;
  height:42px;
  border-radius: 10px;
}
/* Logo switching for dark mode */
.brand .logo-light {
  display: block;
}
.brand .logo-dark {
  display: none;
}
[data-theme="dark"] .brand .logo-light {
  display: none;
}
[data-theme="dark"] .brand .logo-dark {
  display: block;
}
.brand .name{
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.02em;
}
.brand .tagline{
  color: var(--muted);
  font-size: 13px;
  margin-top: -2px;
}

/* Header responsive fix for long taglines */
@media (max-width: 540px) {
  .header {
    gap: 12px;
  }
  .brand {
    min-width: 0;
    flex: 1;
  }
  .brand .tagline {
    font-size: 11px;
  }
  .theme-toggle {
    flex-shrink: 0;
  }
}

.main{
  display:grid;
  grid-template-columns: 1fr var(--sidebar);
  gap: 34px;
}

.content{
  max-width: var(--max);
}

.avatar {
  width: 100%;
  max-width: 220px;        /* controls visible size */
  aspect-ratio: 1 / 1;    /* keeps it square */
  border-radius: 5px;
  overflow: hidden;       /* CRITICAL: crops big images */
  background: var(--card-bg);
  margin-bottom: 12px;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;      /* CRITICAL: fits big images */
  object-position: center;
  display: block;
}


.hero{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap: 28px;
  margin-top: 12px;
}
.hero h1{
  margin:0 0 10px;
  font-size: 44px;
  line-height:1.1;
  letter-spacing: -0.03em;
}
.hero p{
  margin: 8px 0;
  color: var(--muted);
  font-size: 18px;
}
.hero .card{
  width: 220px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px;
}
.hero .card .avatar{
  width:100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
}
.hero .card .avatar span{
  font-family: var(--mono);
  color: var(--muted);
  font-size: 12px;
}
.hero .card .mini{
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
}

.section{
  margin: 34px 0;
  padding-top: 6px;
}
.section h2{
  margin: 0 0 10px;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.section p, .section li{
  color: var(--text);
}
.section .muted{
  color: var(--muted);
}

hr.sep{
  border:0;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}

.list{
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}
.list li{
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.list li:last-child{ border-bottom: 0; }
.list .meta{
  color: var(--muted);
  font-size: 13px;
}
.badges{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top: 8px;
}
.badge{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
}
.badge code{
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

/* Right sidebar navigation (Patrick Collison-ish) */
.sidebar{
  position: sticky;
  top: 28px;
  align-self: start;
}
.navbox{
  padding-left: 16px;
  border-left: 1px solid var(--border);
}
.navbox .navtitle{
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .06em;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.nav{
  list-style:none;
  margin:0;
  padding:0;
}
.nav li{ margin: 8px 0; }
.nav a{
  display:inline-block;
  font-size: 14px;
  color: var(--text);
}
.nav a.active{
  font-weight: 700;
  text-decoration: none;
}
.nav .sub{
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.nav .sub a{
  font-size: 13px;
  color: var(--muted);
}

.footer{
  margin-top: 46px;
  color: var(--muted);
  font-size: 13px;
}
.footer code{
  font-family: var(--mono);
  font-size: 12px;
}

/* Newsletter box */
.newsletter{
  border:1px solid var(--border);
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
}
.newsletter h3{
  margin: 0 0 8px;
  font-size: 15px;
}
.newsletter p{
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 14px;
}
.newsletter .row{
  display:flex;
  gap:8px;
}
.newsletter input{
  flex:1;
  padding: 10px 12px;
  border-radius: 10px;
  border:1px solid var(--border);
  font-size: 14px;
  outline:none;
  background: var(--bg);
  color: var(--text);
}
.newsletter button{
  padding: 10px 12px;
  border-radius: 10px;
  border:1px solid var(--border);
  background: var(--bg);
  cursor:pointer;
  font-weight: 600;
  color: var(--text);
}
.newsletter button:hover{ background: var(--card-bg); }

/* Theme Toggle Switch */
.theme-toggle {
  position: relative;
  width: 56px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  padding: 3px;
}

.theme-toggle:hover {
  border-color: var(--muted);
}

.toggle-thumb {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  left: 2px;
}

[data-theme="dark"] .toggle-thumb,
.theme-toggle.dark .toggle-thumb {
  transform: translateX(28px);
}

.toggle-icon {
  width: 14px;
  height: 14px;
  transition: opacity 0.2s ease, transform 0.3s ease;
}

/* Sun icon */
.icon-sun {
  position: absolute;
  opacity: 1;
  color: #f59e0b;
}

/* Moon icon */
.icon-moon {
  position: absolute;
  opacity: 0;
  color: #6366f1;
}

[data-theme="dark"] .icon-sun,
.theme-toggle.dark .icon-sun {
  opacity: 0;
  transform: rotate(-90deg);
}

[data-theme="dark"] .icon-moon,
.theme-toggle.dark .icon-moon {
  opacity: 1;
  transform: rotate(0deg);
}

/* Indicator icons in track */
.toggle-track {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0 5px;
  pointer-events: none;
}

.track-icon {
  width: 12px;
  height: 12px;
  opacity: 0.4;
}

.track-sun {
  color: #f59e0b;
}

.track-moon {
  color: #6366f1;
}

/* Responsive */
@media (max-width: 940px){
  .main{ grid-template-columns: 1fr; }
  .sidebar{
    position: relative;
    top: 0;
    order: -1;
  }
  .navbox{
    border-left: 0;
    padding-left: 0;
    border-bottom: 1px solid var(--border);
    padding-bottom: 14px;
    margin-bottom: 18px;
  }
  .hero{ flex-direction: column; }
  .hero .card{ width: min(320px, 100%); }
}

/* View Counter */
.view-counter {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow);
  z-index: 100;
}
.view-counter svg {
  width: 14px;
  height: 14px;
  opacity: 0.7;
}
@media (max-width: 940px) {
  .view-counter {
    bottom: 10px;
    right: 10px;
    padding: 6px 10px;
    font-size: 11px;
  }
}

/* Essay Filters */
.essay-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 20px 0 28px;
}

.filter-btn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-btn:hover {
  border-color: var(--muted);
  color: var(--text);
}

.filter-btn.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* Essay List */
.essay-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.essay-item {
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.essay-item:last-child {
  border-bottom: none;
}

.essay-item.hidden {
  display: none;
}

.essay-date {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.essay-tags {
  display: inline-flex;
  gap: 6px;
  margin-left: 12px;
}

.essay-tag {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 999px;
  text-transform: lowercase;
}

.essay-tag.business {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
}

.essay-tag.technology {
  background: rgba(168, 85, 247, 0.15);
  color: #a855f7;
}

.essay-tag.manufacturing {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.essay-tag.philosophy {
  background: rgba(249, 115, 22, 0.15);
  color: #f97316;
}

[data-theme="dark"] .essay-tag.business {
  background: rgba(59, 130, 246, 0.25);
  color: #60a5fa;
}

[data-theme="dark"] .essay-tag.technology {
  background: rgba(168, 85, 247, 0.25);
  color: #c084fc;
}

[data-theme="dark"] .essay-tag.manufacturing {
  background: rgba(34, 197, 94, 0.25);
  color: #4ade80;
}

[data-theme="dark"] .essay-tag.philosophy {
  background: rgba(249, 115, 22, 0.25);
  color: #fb923c;
}

.essay-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 6px 0 4px;
}

.essay-title a {
  color: var(--text);
  text-decoration: none;
}

.essay-title a:hover {
  color: var(--link);
}

.essay-desc {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}

/* Essay Page Content */
.essay-content {
  max-width: 680px;
}

.essay-content h1 {
  font-size: 32px;
  letter-spacing: -0.03em;
  margin: 0 0 8px;
}

.essay-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.essay-content p {
  font-size: 17px;
  line-height: 1.75;
  margin: 0 0 20px;
}

.essay-content h2 {
  font-size: 22px;
  letter-spacing: -0.02em;
  margin: 36px 0 14px;
}

.essay-content ul,
.essay-content ol {
  margin: 0 0 20px;
  padding-left: 24px;
}

.essay-content li {
  font-size: 17px;
  line-height: 1.75;
  margin-bottom: 8px;
}

.essay-content blockquote {
  margin: 24px 0;
  padding: 16px 20px;
  border-left: 3px solid var(--link);
  background: var(--card-bg);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
  color: var(--muted);
}

.essay-content blockquote p {
  margin: 0;
}

@media (max-width: 640px) {
  .essay-filters {
    gap: 6px;
  }
  .filter-btn {
    padding: 6px 12px;
    font-size: 12px;
  }
  .essay-title {
    font-size: 16px;
  }
  .essay-tags {
    display: flex;
    margin-left: 0;
    margin-top: 6px;
  }
}

/* Newsletter CTA Box */
.newsletter-cta {
  margin: 48px 0 24px;
  padding: 28px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.newsletter-cta h3 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.newsletter-cta p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.newsletter-cta .subscribe-form {
  display: flex;
  gap: 10px;
  max-width: 400px;
  margin: 0 auto;
}

.newsletter-cta input[type="email"] {
  flex: 1;
  padding: 12px 16px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease;
}

.newsletter-cta input[type="email"]:focus {
  border-color: var(--link);
}

.newsletter-cta input[type="email"]::placeholder {
  color: var(--muted);
}

.newsletter-cta .subscribe-btn {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--bg);
  background: var(--text);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s ease;
  white-space: nowrap;
}

.newsletter-cta .subscribe-btn:hover {
  opacity: 0.85;
}

.newsletter-cta .substack-link {
  display: inline-block;
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
}

.newsletter-cta .substack-link a {
  color: var(--link);
}

@media (max-width: 480px) {
  .newsletter-cta {
    padding: 20px;
  }
  .newsletter-cta .subscribe-form {
    flex-direction: column;
  }
  .newsletter-cta .subscribe-btn {
    width: 100%;
  }
}

/* Problem Cards */
.problem-card {
  padding: 24px 0;
  border-bottom: 1px solid var(--border);
}
.problem-card:last-child {
  border-bottom: none;
}
.problem-card h3 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.problem-card .question {
  font-size: 15px;
  color: var(--muted);
  font-style: italic;
  margin: 0 0 16px;
}
.problem-card .gap {
  background: var(--card-bg);
  border-left: 3px solid var(--link);
  padding: 12px 16px;
  margin: 16px 0;
  border-radius: 0 8px 8px 0;
}
.problem-card .gap strong {
  color: var(--text);
}
.problem-card h4 {
  margin: 20px 0 10px;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.problem-card p {
  margin: 0 0 12px;
  font-size: 15px;
  line-height: 1.6;
}
.problem-card ul {
  margin: 8px 0 16px;
  padding-left: 20px;
}
.problem-card li {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 6px;
  color: var(--text);
}
.problem-card .exploring {
  font-size: 14px;
  color: var(--muted);
  margin: 16px 0;
  padding: 12px 16px;
  background: var(--card-bg);
  border-radius: 8px;
}
.problem-card .exploring strong {
  color: var(--text);
}
