/* ===== Theme Variables ===== */
:root {
  --primary: #64B5F6;
  --primary-dark: #42A5F5;
  --font-family: 'Inter UI', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --bg: #272B34;
  --bg-alt: #272B34;
  --text: #eee;
  --text-muted: #999;
  --border: #595959;
  --nav-bg: #232525;
  --nav-text: #eee;
  --code-color: #e2777a;
  --code-bg: #272B34;
  --kbd-color: #7ec699;
  --code-rendered: #ccc;
  --hr-color: #eee;
  --selection-text: #181818;
  --progress-color: #64B5F6;
}

[data-theme="light"] {
  --bg: #fafafa;
  --bg-alt: #f0f0f0;
  --text: #1a1a1a;
  --text-muted: #666;
  --border: #ddd;
  --nav-bg: #0A91B3;
  --nav-text: #fff;
  --code-color: #d63384;
  --code-bg: #f0f0f0;
  --kbd-color: #198754;
  --code-rendered: #333;
  --hr-color: #ddd;
  --selection-text: #fff;
  --progress-color: #f9c412;
}

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

html {
  font-family: var(--font-family);
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-family);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.6;
  transition: background 0.3s ease, color 0.3s ease;
}

::selection {
  background: var(--primary);
  color: var(--selection-text);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-family);
  line-height: 1.25;
  margin-bottom: 0.5em;
}

h1 {
  font-size: 1.6rem;
  line-height: 1.8rem;
  margin-bottom: 1rem;
}

h2 {
  font-size: 1.3rem;
  line-height: 1.6rem;
  margin-bottom: 1rem;
  font-style: italic;
}

h3 {
  font-size: 1.1rem;
  line-height: 1.4rem;
  margin-bottom: 1rem;
}

h4 {
  font-size: 1rem;
  line-height: 1.3rem;
  margin-bottom: 0.8rem;
  font-style: italic;
}

h5, h6 {
  font-size: 0.95rem;
  line-height: 1.3rem;
  margin-bottom: 0.8rem;
}

h6 {
  font-style: italic;
}

@media (min-width: 600px) {
  h1 {
    font-size: 2rem;
    line-height: 2.4rem;
    margin-bottom: 1rem;
  }
  h2 {
    font-size: 1.5rem;
    line-height: 1.8rem;
    margin-bottom: 1rem;
  }
  h3 {
    font-size: 1.25rem;
    line-height: 1.5rem;
    margin-bottom: 1rem;
  }
  h4 {
    font-size: 1.1rem;
    line-height: 1.4rem;
    margin-bottom: 0.8rem;
  }
  h5, h6 {
    font-size: 1rem;
    line-height: 1.3rem;
    margin-bottom: 0.8rem;
  }
  body, ol, p, pre, ul {
    font-size: 1.1rem;
    line-height: 1.6;
  }
  ol, p, pre, ul {
    margin-bottom: 1.496rem;
  }
}

@media (min-width: 1200px) {
  h1 {
    font-size: 2.2rem;
    line-height: 2.6rem;
    margin-bottom: 1rem;
  }
  h2 {
    font-size: 1.7rem;
    line-height: 2rem;
    margin-bottom: 1rem;
  }
  h3 {
    font-size: 1.4rem;
    line-height: 1.7rem;
    margin-bottom: 1rem;
  }
  h4 {
    font-size: 1.2rem;
    line-height: 1.5rem;
    margin-bottom: 0.8rem;
  }
  h5, h6 {
    font-size: 1.1rem;
    line-height: 1.4rem;
    margin-bottom: 0.8rem;
  }
  body, ol, p, pre, ul {
    font-size: 1.2rem;
    line-height: 1.6;
  }
  ol, p, pre, ul {
    margin-bottom: 1.632rem;
  }
}

/* Links */
a {
  color: var(--primary);
  text-decoration: none;
  position: relative;
}

a::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 1px;
  background: var(--primary);
  transition: width 0.3s ease;
}

a:hover::after {
  width: 100%;
}

a:hover {
  text-decoration: none;
}

/* Paragraphs & Lists */
ol, p, pre, ul {
  margin-bottom: 1.36rem;
}

ol, ul {
  margin-top: 0;
}

li dl, li ol, li ul {
  margin-bottom: 0;
}

img, video {
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

hr {
  border-bottom: 1px solid var(--hr-color);
}

small {
  color: var(--text-muted);
}

/* Code */
code, kbd {
  border-radius: 0.3em;
  color: var(--code-color);
  padding: 0 0.3em;
  font-family: Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace;
  font-size: 90%;
  background: var(--code-bg);
}

kbd {
  color: var(--kbd-color);
}

pre {
  font-family: Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace;
  background: var(--code-bg);
  padding: 1em;
  margin: 0.5em 0;
  overflow: auto;
  border-radius: 0.3em;
}

pre code {
  color: var(--code-rendered);
  padding: 0;
  overflow-x: scroll;
  background: none;
}

pre code:not([class]) {
  color: var(--code-rendered);
}

mark {
  background: var(--primary);
  padding: 0 0.3em;
}

/* Tables */
table {
  display: table;
  overflow-x: auto;
  width: 100%;
  border-collapse: collapse;
}

td, th {
  border-bottom: 1px solid var(--border);
  overflow: auto;
  padding: 0.75em;
  text-align: left;
  vertical-align: top;
}

thead th {
  border-bottom: 1px solid var(--primary);
}

th {
  font-weight: 600;
}

/* Blockquote */
blockquote {
  border-left: 1px solid var(--primary);
  padding: 0 1.5em;
  margin: 1.5em 0 1.5em 1.5em;
}

blockquote footer {
  background: none;
  display: block;
  color: var(--text-muted);
  padding: 0.75em 0;
  font-size: 90%;
  text-align: start;
}

/* Figure / Images */
figure {
  margin: 1.5em;
}

figure img {
  display: block;
}

figcaption {
  color: var(--text-muted);
  margin-top: 0.75em;
  font-size: 80%;
}

/* Definition list */
dl {
  display: inline-block;
  margin: 0 0 1.5em;
}

dt {
  font-weight: 600;
  padding-top: 0.75em;
  padding-left: 0.75em;
}

dd {
  padding-bottom: 0.75em;
  margin-left: 2.25em;
}

dd + dt {
  border-top: 1px solid var(--primary);
}

/* Header / Navigation */
header {
  padding: 4.5em 1.5em 3em;
  width: 55em;
  margin: 0 auto;
  text-align: center;
  max-width: 100%;
  display: flex;
  align-items: center;
  flex-direction: column;
}

header p {
  margin-top: 0;
}

header nav {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  padding: 0.375em 1.5em;
  background: var(--nav-bg);
  font-weight: 200;
  z-index: 10;
  transition: background 0.3s ease;
}

header nav h1 {
  font-size: inherit;
  line-height: inherit;
  margin: 0;
  margin-right: auto;
}

header nav a {
  font-weight: 700;
  text-decoration: none;
  font-family: var(--font-family);
  color: var(--nav-text);
  margin-left: 1.5em;
}

header aside {
  font-style: italic;
}

/* Main content */
main {
  max-width: 70rem;
  margin: 0 auto;
  border-top: 0.5px solid var(--border);
}

article {
  max-width: 100%;
  padding: 1.5em;
  width: 55em;
  margin: 0 auto;
}

/* Section (for homepage) */
section {
  margin-left: auto;
  margin-right: auto;
  width: 900px;
  max-width: 100%;
  padding: 0 1.5em;
}

/* Posts list */
#posts li {
  margin-bottom: 0.5em;
}

.post-list {
  list-style: none;
  padding-left: 0;
}

.post-list li {
  margin-bottom: 0.5em;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.post-list li a {
  flex: 1;
}

.post-list time {
  font-size: 0.85em;
  color: var(--text-muted);
  margin-left: 1em;
  white-space: nowrap;
}

/* Footer */
footer {
  background: var(--bg-alt);
  color: var(--text);
  padding: 3em;
  text-align: center;
  transition: background 0.3s ease;
}

footer > * {
  margin: 1.5em;
}

footer nav, footer p {
  font-size: 90%;
}

footer nav a img {
  vertical-align: middle;
}

/* Nav z-index for progress bar layering */
#nav {
  z-index: 100;
  position: relative;
  display: flex;
  align-items: center;
}

/* Reading progress bar */
#reading-progress {
  z-index: 1;
  background-color: var(--progress-color);
  width: 100vw;
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  transform: translate(-100vw, 0);
  will-change: transform;
  pointer-events: none;
}

/* Prism.js theme */
code[class*="language-"],
pre[class*="language-"] {
  color: var(--code-rendered);
  background: none;
  font-family: Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace;
  text-align: left;
  white-space: pre;
  word-spacing: normal;
  word-break: normal;
  word-wrap: normal;
  line-height: 1.5;
  tab-size: 4;
  hyphens: none;
}

code[class*="language-"] {
  padding: 0;
}

pre[class*="language-"] {
  padding: 1em;
  margin: 0.5em 0;
  overflow: auto;
}

:not(pre) > code[class*="language-"],
pre[class*="language-"] {
  background: var(--code-bg);
}

:not(pre) > code[class*="language-"] {
  padding: 0.1em;
  border-radius: 0.3em;
  white-space: normal;
}

.token.comment, .token.block-comment, .token.prolog, .token.doctype, .token.cdata {
  color: #999;
}
.token.punctuation { color: #ccc; }
.token.tag, .token.attr-name, .token.namespace, .token.deleted { color: #e2777a; }
.token.function-name { color: #6196cc; }
.token.boolean, .token.number, .token.function { color: #f08d49; }
.token.property, .token.class-name, .token.constant, .token.symbol { color: #f8c555; }
.token.selector, .token.important, .token.atrule, .token.keyword, .token.builtin { color: #cc99cd; }
.token.string, .token.char, .token.attr-value, .token.regex, .token.variable { color: #7ec699; }
.token.operator, .token.entity, .token.url { color: #67cdcc; }
.token.bold, .token.important { font-weight: 700; }
.token.italic { font-style: italic; }
.token.entity { cursor: help; }
.token.inserted { color: green; }

/* Form elements */
button, input, select, textarea {
  border-radius: 0.3em;
  display: inline-block;
  padding: 0.75em;
  max-width: 100%;
  font-family: inherit;
  font-size: 100%;
  line-height: 1.15;
  margin: 0;
}

button, input[type="reset"], input[type="submit"] {
  background: var(--primary);
  color: #181818;
  cursor: pointer;
  display: inline-block;
  padding: 0.75em 1.5em;
  text-align: center;
  margin: 0 0.75em 1.5em 0;
}

button:hover, input[type="submit"]:hover {
  background: var(--primary-dark);
  color: #000;
}

/* Scrollbar */
::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* ===== Theme Toggle ===== */
#theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  margin: 0 0 0 1.5em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  border-radius: 50%;
  transition: background 0.2s ease;
}

#theme-toggle:hover {
  background: rgba(128, 128, 128, 0.15);
}

#theme-toggle svg {
  width: 18px;
  height: 18px;
  stroke: var(--nav-text);
  stroke-width: 2;
  fill: none;
  transition: transform 0.4s ease, stroke 0.3s ease;
}

#theme-toggle:active svg {
  transform: rotate(30deg);
}

#theme-toggle .icon-moon {
  display: none;
}

[data-theme="light"] #theme-toggle .icon-sun {
  display: none;
}

[data-theme="light"] #theme-toggle .icon-moon {
  display: block;
}

/* ===== About Page ===== */

.about-page {
  max-width: 100%;
}

.about-intro {
  font-size: 1.15rem;
  line-height: 1.8;
}

.about-section {
  margin-top: 2.5em;
}

.about-section h3 {
  font-size: 1.1rem;
  margin-bottom: 1em;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3em;
}

.about-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.2em;
}

.about-card {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.2em;
  transition: border-color 0.2s ease;
}

.about-card:hover {
  border-color: var(--primary);
}

.about-card h4 {
  font-size: 0.95rem;
  margin: 0 0 0.5em 0;
  font-style: normal;
  color: var(--primary);
}

.about-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}

.skills-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
}

.skills-tags span {
  padding: 0.35em 0.8em;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.skills-tags span:hover {
  border-color: var(--primary);
  color: var(--primary);
}

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

/* ===== Homepage Modules ===== */

.motto {
  text-align: center;
  border: none;
  border-left: none;
  padding: 1.5em 0;
  margin: 0 0 2em 0;
  opacity: 0.7;
}

.motto p {
  font-style: italic;
  font-size: 0.95rem;
  line-height: 1.8;
  color: var(--text-muted);
  max-width: 500px;
  margin: 0 auto 0.8em;
}

.motto footer {
  background: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 0;
  font-style: normal;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2em;
  margin: 0 0 2em 0;
}

.two-col h2 {
  font-size: 1.1rem;
  margin-bottom: 0.8em;
}

@media (max-width: 600px) {
  .two-col {
    grid-template-columns: 1fr;
    gap: 1em;
  }
}

/* ===== Animations & Interactions ===== */

/* Reading progress bar glow */
#reading-progress {
  box-shadow: 0 0 8px var(--progress-color), 0 0 2px var(--progress-color);
  height: 3px;
}

/* Fade-in on scroll */
.fade-in {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.fade-in.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Staggered list items */
.fade-in li {
  opacity: 0;
  transform: translateY(15px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.fade-in.visible li {
  opacity: 1;
  transform: translateY(0);
}

.fade-in.visible li:nth-child(1) { transition-delay: 0.1s; }
.fade-in.visible li:nth-child(2) { transition-delay: 0.2s; }
.fade-in.visible li:nth-child(3) { transition-delay: 0.3s; }
.fade-in.visible li:nth-child(4) { transition-delay: 0.4s; }
.fade-in.visible li:nth-child(5) { transition-delay: 0.5s; }
.fade-in.visible li:nth-child(6) { transition-delay: 0.6s; }
.fade-in.visible li:nth-child(7) { transition-delay: 0.7s; }
.fade-in.visible li:nth-child(8) { transition-delay: 0.8s; }

/* Post list hover */
#posts li {
  transition: transform 0.2s ease, padding-left 0.2s ease;
  padding-left: 0;
}

#posts li:hover {
  transform: translateX(8px);
  padding-left: 0;
}

#posts time {
  transition: color 0.2s ease;
}

#posts li:hover time {
  color: var(--primary);
}

/* Typing cursor */
.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--primary);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Section headings hover */
article h2 {
  transition: color 0.3s ease;
}

article h2:hover {
  color: var(--primary);
}

/* Hero title handwriting animation */
#hero-title-container {
  text-align: center;
  min-height: 120px;
  padding: 0 1.5em;
}

.hero-title-svg {
  width: 100%;
  max-width: 700px;
  height: auto;
  margin: 0 auto;
  display: block;
  overflow: visible;
}

.hero-title-svg path {
  fill: none;
  stroke: #64B5F6;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hero-title {
  font-family: 'Caveat', cursive;
  letter-spacing: 0.02em;
  font-weight: 400;
}

/* Responsive */
@media (max-width: 767px) {
  header {
    padding: 3em 1em 2em;
  }

  article {
    padding: 1em;
  }

  section {
    padding: 0 1em;
  }
}

/* ===== Hero Long-Press Feedback ===== */

.hero-pressing {
  filter: drop-shadow(0 0 12px rgba(100, 181, 246, 0.5));
  transition: filter 0.3s ease;
}

/* ===== Auth Modal ===== */

.auth-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-modal[hidden] {
  display: none;
}

.auth-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.auth-modal-content {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2em 2.5em;
  text-align: center;
  min-width: 280px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}

.auth-hint {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 1em;
}

.auth-modal-content input[type="password"] {
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6em 1em;
  font-size: 1rem;
  width: 100%;
  text-align: center;
  outline: none;
  transition: border-color 0.2s ease;
}

.auth-modal-content input[type="password"]:focus {
  border-color: var(--primary);
}

#auth-submit {
  display: block;
  width: 100%;
  margin-top: 0.8em;
  padding: 0.5em;
  background: var(--primary);
  color: #181818;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

#auth-submit:hover {
  background: var(--primary-dark);
}

#auth-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.auth-error {
  color: #ef5350;
  font-size: 0.85rem;
  margin: 0.8em 0 0;
}

/* Shake animation */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.shake {
  animation: shake 0.4s ease;
}
