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

:root {
  --line-height: 1.7;
  --bg-color: #f6eed6;
  --text-color: #222222;
  --secondary-color: #625d50;
  --accent-color: #a04000;
  --border-color: #e5dcc3;
  --scrollbar-thumb: rgba(0, 0, 0, 0.25);
  --scrollbar-thumb-hover: rgba(0, 0, 0, 0.4);
  --link-underline: rgba(34, 34, 34, 0.2);
}

[data-theme="dark"] {
  --bg-color: #121212;
  --text-color: #e3e3e3;
  --secondary-color: #a0a0a0;
  --accent-color: #e68a4d;
  --border-color: #2a2a2a;
  --scrollbar-thumb: rgba(255, 255, 255, 0.1);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.2);
  --link-underline: rgba(227, 227, 227, 0.2);
}

html {
  width: 100%;
  margin: 0;
  padding: 0;
  scrollbar-gutter: stable;
}

body {
  font-family: "Charter", "Bitstream Charter", "Georgia", serif;
  font-variant-ligatures: common-ligatures;
  font-feature-settings: "kern", "liga", "clig", "calt";
  text-rendering: optimizeLegibility;
  text-align: center;
  background-color: var(--bg-color);
  color: var(--text-color);
  padding: 1.5rem 2ch;
  width: 100%;
  max-width: 80ch;
  margin: 0 auto;
  line-height: var(--line-height);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Accessibility: Focus Rings */
:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
  border-radius: 2px;
}

header a:focus-visible, 
.footer-right a:focus-visible, 
.footer-right button:focus-visible {
  border-radius: 4px;
}

#theme-toggle:focus-visible {
  border-radius: 50%;
}

main img:focus-visible {
  border-radius: 8px;
  outline-offset: 4px;
}

/* Stable Entrance */
header, main, footer {
  animation: fadeIn 0.5s cubic-bezier(0.2, 0, 0.2, 1) both;
}

/* Minimal Scrollbar - More Visible */
::-webkit-scrollbar {
  width: 8px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 10px;
  border: 2px solid var(--bg-color);
}

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

/* Physical Feedback */
header a:active, main a:active, .footer-right a:active, .footer-right button:active {
  transform: scale(0.98);
  transition: transform 0.1s;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

::selection {
  background-color: rgba(160, 64, 0, 0.15);
  color: var(--text-color);
}

[data-theme="dark"] ::selection {
  background-color: rgba(60, 60, 60, 0.85);
  color: #ffffff;
}

header {
  position: relative;
  text-align: left;
  padding-top: 1rem;
  margin-bottom: 1rem;
  font-family: system-ui, -apple-system, sans-serif;
  letter-spacing: -0.01em;
}

#theme-toggle {
  position: absolute;
  top: 1rem;
  right: 0;
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.2s;
  color: var(--secondary-color);
  background: none;
  border: none;
}

#theme-toggle:hover {
  background-color: rgba(160, 64, 0, 0.1);
  color: var(--accent-color);
}

[data-theme="dark"] #theme-toggle:hover {
  background-color: rgba(255, 157, 77, 0.1);
}

#theme-toggle svg {
  width: 1.2rem;
  height: 1.2rem;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

header a {
  font-size: 1.1rem;
  margin-right: 1.5rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  opacity: 0.8;
}

header a.current-page, header a[aria-current="page"] {
  color: var(--accent-color);
  font-weight: 500;
  opacity: 1;
}

header a:hover {
  opacity: 1;
}

main {
  font-size: 1.1rem;
  line-height: var(--line-height);
  text-align: left;
  width: 100%;
}

main p {
  margin-bottom: 1.25rem;
}

.date {
  font-family: system-ui, -apple-system, sans-serif;
  color: var(--secondary-color);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  display: block;
}

footer {
  margin-top: 1rem;
  padding-top: 1rem;
  padding-bottom: 2rem;
  width: 100%;
  border-top: 1px solid var(--border-color);
  font-family: system-ui, -apple-system, sans-serif;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--secondary-color);
}

#progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 1px;
  background: var(--accent-color);
  width: 0%;
  z-index: 1000;
  transition: opacity 0.3s ease;
  opacity: 0;
}

#email-link.copied {
  color: var(--accent-color);
}

.footer-right a, .footer-right button {
  margin-left: 1.5rem;
  color: inherit;
  text-decoration: none;
  transition: transform 0.2s ease, color 0.2s ease;
  cursor: pointer;
  display: inline-block;
  background: none;
  border: none;
  font: inherit;
  padding: 0;
  letter-spacing: inherit;
  text-transform: inherit;
}

.footer-right a:hover, .footer-right button:hover {
  color: var(--text-color);
  transform: translateY(-1px);
}

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

/* Blockquotes & Code */
blockquote {
  margin: 2rem 0;
  padding-left: 1.5rem;
  border-left: 2px solid var(--accent-color);
  font-style: italic;
  color: var(--secondary-color);
  text-align: left;
}

code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.8em;
  background: rgba(0, 0, 0, 0.02);
  padding: 0.2em 0.4em;
  border-radius: 4px;
  tab-size: 2;
  -moz-tab-size: 2;
}

pre {
  background: rgba(0, 0, 0, 0.02);
  padding: 1rem;
  overflow-x: auto;
  border-radius: 6px;
  text-align: left;
  margin: 1.5rem 0;
  border: 1px solid rgba(0, 0, 0, 0.03);
  tab-size: 2;
  -moz-tab-size: 2;
  line-height: 1.45;
}

[data-theme="dark"] code {
  background: rgba(255, 255, 255, 0.02);
}

[data-theme="dark"] pre {
  background: rgba(255, 255, 255, 0.02);
  border-color: rgba(255, 255, 255, 0.04);
}

pre code {
  background: none !important;
  padding: 0;
}

pre code .code-comment {
  color: #9aa3ad;
}

[data-theme="dark"] pre code .code-comment {
  color: #6f7882;
}

/* Rest of your functional styles */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  letter-spacing: -0.01em;
}

.no-indent {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.no-indent li {
  margin-bottom: 0.5rem;
}

header a:link, header a:visited, header a:hover, header a:active {
  color: inherit;
  text-decoration: none;
}

main a {
  color: var(--text-color);
  text-decoration: none;
  border-bottom: 1px solid var(--link-underline);
  transition: all 0.2s ease;
}

[data-theme="dark"] #lightbox img {
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

main a:visited {
  color: var(--text-color);
}

main a:hover, main a:active {
  color: var(--accent-color);
  border-bottom-color: var(--accent-color);
}

/* Media & Lightbox */
img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  transition: transform 0.1s;
}

img {
  cursor: zoom-in;
}

img:active {
  transform: scale(0.99);
}

iframe {
  display: block;
  width: min(100%, 56rem);
  aspect-ratio: 16 / 9;
  height: auto;
  margin: 1.5rem auto;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

#lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(246, 238, 214, 0.98);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  cursor: zoom-out;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

[data-theme="dark"] #lightbox {
  background: rgba(18, 18, 18, 0.98);
}

#lightbox.active {
  opacity: 1;
  pointer-events: auto;
}

#lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  width: auto;
  height: auto;
  border: none;
  border-radius: 0;
  box-shadow: 0 20px 50px rgba(0,0,0,0.1);
  cursor: zoom-out;
}

.hover-underline-animation {
  display: inline-block;
  position: relative;
}

.hover-underline-animation::after {
  content: "";
  position: absolute;
  width: 100%;
  transform: scaleX(0);
  height: 1px;
  bottom: 0;
  left: 0;
  background-color: var(--text-color);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.hover-underline-animation:hover::after {
  transform: scaleX(1);
}

.hover-underline-animation.left::after {
  transform-origin: bottom right;
}

.hover-underline-animation.left:hover::after {
  transform-origin: bottom left;
}
