/*
 * Aquest programa és programari lliure: pots redistribuir-lo i/o modificar-lo
 * sota els termes de la GNU General Public License (GPLv3).
*/

/* --- Variables & Dark Mode (Sincronizadas con style.css) --- */
:root {
    --bg: #FAF9F5;  
    --font-serif: 'Cormorant Garamond', 'Garamond', serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;  
    --text-main: #1A1C20; 
    --text-muted: #8B949E;
    --text-description: #52585F;
    --border: #E0D8D0;
    --card-hover: #EFE8E0;
    --accent: #000000;
    --bento-bg: #F4EFEA; 
    --selection-bg: #171717;
    --selection-text: #FAFAF9;
    --code-color: #1A1C20;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1A1816; 
        --text-main: #EFE8E0;
        --text-muted: #A39D98;
        --text-description: #C9C2BC;
        --border: #332F2A;
        --card-hover: #2A2622;
        --accent: #EFE8E0;
        --bento-bg: #221F1C;
        --selection-bg: #EFE8E0;
        --selection-text: #1A1816;
        --code-color: #EFE8E0;
    }
}
body.dark-mode,
body:has(.toggle:checked) {
    --bg: #1A1816; 
    --text-main: #EFE8E0;
    --text-muted: #A39D98;
    --text-description: #C9C2BC;
    --border: #332F2A;
    --card-hover: #2A2622;
    --accent: #EFE8E0;
    --bento-bg: #221F1C;
    --selection-bg: #EFE8E0;
    --selection-text: #1A1816;
    --code-color: #EFE8E0;
}

/* --- Base & Typo --- */
html, body {
  font-family: var(--font-serif);
  font-size: 1.1rem; /* Un poco más grande para Garamond, ya que tiende a verse pequeña */
  line-height: 1.7;
  background-color: var(--bg);
  color: var(--text-main);
  transition: background-color 0.5s ease, color 0.5s ease;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6, th { font-weight: 600; }
h1, h2, h3 { line-height: 1.2; margin: 1.5rem 0 1rem; }
h1 {
  font-family: var(--font-serif);
  font-size: 2.2rem;
  text-transform: none;
  text-align: center;
  color: var(--text-main);
  letter-spacing: -0.04em;
}
h2 { 
  font-family: var(--font-serif);
  font-size: 1.8rem;
  text-transform: none;
  border-bottom: solid 1px var(--border);  
  color: var(--text-main);
  padding-bottom: 0.5rem;
  letter-spacing: -0.02em;
}
h3 {
  font-size: 1.5rem;
  text-transform: none;
  color: var(--text-main);
  border-bottom: solid 1px var(--border);
  padding-bottom: 0.3rem;
}
h4 {
  font-size: 1.2rem;
  text-transform: none;
  color: var(--text-main);
  border-bottom: dotted 1px var(--border);
}
h5 {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: dashed 1px var(--border);
}
h6 {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0.8;
}
small, sup, sub { font-size: 0.833em; }
sup, sub { line-height: 1em; }

p, ul, ol, dl, table, blockquote, pre { margin: 1.5rem 0 0; }

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

/* --- Links --- */
a, header nav a:visited, a code {
  color: var(--accent);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 3px;
  transition: all 0.3s ease;
}

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

mark {
  color: inherit;
  background-color: var(--card-hover);
  padding: 1px 4px;
  border-radius: 4px;
}

ins {
  border-bottom: 1px solid var(--text-main);
  text-decoration: none;
}

/* --- CODE, PRE, SAMP, KBD --- */
code, pre, samp, kbd {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--code-color);
}
kbd { font-weight: 600; }

/* Code+Table */
code, pre, samp, thead, tfoot { background-color: var(--bento-bg); }

code, samp {
  border: solid 1px var(--border);
  border-radius: 4px;
  padding: 0.2em 0.4em;
  white-space: nowrap;
}

pre {
  border: solid 1px var(--border);
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
  margin-top: calc(1.5rem - 1px);
  margin-bottom: -1px;
  text-wrap: stable;
  max-height: 150px;
  overflow: hidden;
  position: relative;
  transition: max-height 0.5s ease-in-out;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

pre code {
  border: none;
  padding: 0;
  background-color: transparent;
  white-space: inherit;
}

pre::after {
  content: "\276F"; 
  display: block; 
  transform: rotate(90deg); 
  font-size: 28px;       
  font-weight: bold;     
  color: var(--text-muted);           
  position: absolute;
  bottom: 10px;          
  left: 0;
  right: 0;              
  margin: 0 auto;        
  width: 40px;           
  height: 40px;
  line-height: 40px;     
  text-align: center;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: rotate(90deg) scale(1); opacity: 0.7; }
  50% { transform: rotate(90deg) scale(1.3); opacity: 1; } 
  100% { transform: rotate(90deg) scale(1); opacity: 0.7; }
}

pre:hover,
pre:focus-within {
  max-height: 3000px;
}

pre:hover::after,
pre:focus-within::after {
  opacity: 0;
  pointer-events: none;
}

/* nav */
.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  width: 100vw;
  position: relative;
  left: 50%;
  right: 50%;
  margin-left: -50vw;
  margin-right: -50vw;
  box-sizing: border-box;
  padding: 15px calc(50vw - 50%);
  margin-top: 0; 
  margin-bottom: 3rem;
}
.site-title {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1;
  border: none !important;
  padding: 0 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
}
.nav-header {
  display: flex;
  gap: 15px;
  margin: 0;
  padding: 0;
  font-size: 0;
}
.nav-header a {
  display: inline-block;
  font-size: 16px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 5px 10px;
  text-decoration: none !important;
  color: var(--text-main);
  transition: color 0.2s ease;
  border: none !important;
  background: none !important;
}
.nav-header a:hover,
.nav-header a.active {
  color: var(--text-muted) !important;
  cursor: pointer;
}

/* --- Layout --- */
body > header { text-align: center; }

main, body > footer {
  flex-grow: 1; 
  width: 100%;
  max-width: 700px; /* Igualamos el ancho a style.css (700px) */
  margin: 0 auto; 
}

main figure, main aside {
  float: right;
  margin: 1.5rem 0 0 1ch;
}

main aside {
  max-width: 26ch;
  border-left: 2px solid var(--border);
  padding: 0 0 0 1rem;
  font-size: 0.95rem;
  color: var(--text-muted);
}

blockquote {
  border-left: 2px solid var(--border);
  margin-right: 3ch;
  margin-left: 1.5ch;
  padding: 0 0 0 1.5rem;
  font-style: italic;
  color: var(--text-muted);
}

hr {
  border-top: medium none;
  border-bottom: 1px solid var(--border);
}

img { 
  max-width: 100%; 
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

/* --- Lists --- */
ul, ol, dd { padding: 0; }
ul ul, ol ol, ul ol, ol ul { margin: 0; }
dd { margin: 0; }
ul > li { list-style-type: disc; list-style-position: inside; padding-left: 1.15rem; margin-left: 0; }
li ul > li { list-style-type: circle; }
li li ul > li { list-style-type: square; }
ol > li { list-style-type: decimal; list-style-position: inside; padding-left: 1.15rem; }
li ol > li { list-style-type: lower-roman; }
li li ol > li { list-style-type: lower-alpha; }

nav ul { padding: 0; list-style-type: none; }
nav ul li { display: inline; padding-left: 1ch; white-space: nowrap; }
nav ul li:first-child { padding-left: 0; }

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  overflow-x: auto;
  line-height: calc(1.5rem - 1px);
  margin-bottom: -1px;
}
th, td {
  border: solid 1px var(--border);
  padding: 0.5rem 1rem;
}

/* Toggle Light-Dark */
.toggle {
  --size: 20px;
  appearance: none;
  outline: none;
  cursor: pointer;
  width: var(--size);
  height: var(--size);
  box-shadow: inset calc(var(--size) * 0.33) calc(var(--size) * -0.25) 0;
  border-radius: 999px;
  color: var(--text-main);
  transition: all 500ms;
  position: relative; 
}

.toggle:checked {
  --ray-size: calc(var(--size) * -0.4);
  --offset-orthogonal: calc(var(--size) * 0.65);
  --offset-diagonal: calc(var(--size) * 0.45);
  transform: scale(0.75);
  color: hsl(40, 100%, 50%);
  box-shadow: 
    inset 0 0 0 var(--size),
    calc(var(--offset-orthogonal) * -1) 0 0 var(--ray-size),
    var(--offset-orthogonal) 0 0 var(--ray-size),
    0 calc(var(--offset-orthogonal) * -1) 0 var(--ray-size),
    0 var(--offset-orthogonal) 0 var(--ray-size),
    calc(var(--offset-diagonal) * -1) calc(var(--offset-diagonal) * -1) 0 var(--ray-size),
    var(--offset-diagonal) var(--offset-diagonal) 0 var(--ray-size),
    calc(var(--offset-diagonal) * -1) var(--offset-diagonal) 0 var(--ray-size),
    var(--offset-diagonal) calc(var(--offset-diagonal) * -1) 0 var(--ray-size);
}

/* --- Index List --- */
.post-list-container {
  display: grid;
  grid-template-columns: 100px 1fr;
  list-style: none;
  padding: 0;
  margin: 0;
}

.description-header {
  font-size: 0.9rem;
  color: var(--text-main);
  line-height: 1.6;
  background-color: var(--bento-bg); 
  padding: 1.5rem; 
  border-radius: 12px; 
  border: 1px solid var(--border); 
  margin-bottom: 2.5rem;
}

.year-header {
  grid-column: 1; 
  padding: 12px 0; 
  margin: 0;
  font-weight: 500;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.post-row {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center; 
  padding: 12px 16px;
  box-sizing: border-box;
  transition: background-color 0.2s ease, transform 0.2s ease;
  border-radius: 8px;
}

.post-row:hover {
  background-color: var(--bento-bg);
  cursor: pointer;
  transform: scale(1.01);
}

.post-entry-title {
  order: 1;
  flex: 1;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  align-items: center; 
  font-weight: 500;
}

.post-entry-title::after {
  content: "";
  flex: 1; 
  border-bottom: 1px dashed var(--border); 
  margin: 0 15px; 
}

.post-entry-meta {
  order: 2;
  margin: 0;
  text-align: right;
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-main);
}

.post-entry-description {
  order: 3;
  width: 100%; 
  margin: 8px 0 0 0;
  font-size: 1rem;
  color: var(--text-description);
  display: none;
}

.post-row:hover .post-entry-description {
  display: block;
}

/* --- Articles --- */
.post-title {
  margin-top: 0;
  margin-bottom: 0.5rem;
  line-height: 1.1;
}
.post-description {
  font-size: 1.2rem;
  color: var(--text-description);
  margin-top: 0;
  line-height: 1.4;
  font-style: italic;
  text-align: center;
}
.post-meta {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  justify-content: center;
  text-transform: uppercase;
}

/* Footer-Nav */
.footer-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  border-top: 1px solid var(--border);
  width: 100vw;
  position: relative;
  left: 50%;
  right: 50%;
  margin-left: -50vw;
  margin-right: -50vw;
  margin-top: 4rem;
  box-sizing: border-box;
  padding: 20px calc(50vw - 50%);
}
.footer-nav .nav-left, .footer-nav .nav-center a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
}
.footer-nav .nav-left { gap: 15px; display: flex; }
.footer-nav .nav-left a { display: flex; }
.footer-nav .nav-center a { margin: 0 10px; }
.footer-nav .nav-right { display: flex; gap: 15px; }
.footer-nav .nav-right a {
  color: var(--text-main);
  display: flex;
  align-items: center;
  text-decoration: none;
  transition: color 0.2s;
}
.footer-nav .nav-right a:hover { color: var(--text-muted); transform: translateY(-2px); }

/* Contact email */
.contact-toggle {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin-left: 0.5ch;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.3s;
}
.contact-toggle:hover {
  color: var(--accent);
}
.contact-toggle input {
  display: none; 
}
.contact-toggle span {
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  opacity: 0;
  margin-left: 0;
  font-weight: normal;
  color: var(--text-main);
  transition: all 0.4s ease-in-out;
}
.contact-toggle input:checked ~ span {
  max-width: 300px;
  opacity: 1;
  margin-left: 10px;
}

/* --- Syntax Highlighting Editorial (Se mantiene igual pero con sutiles mejoras) --- */
.hl-comment, .hl-quote { font-style: italic; color: var(--text-muted); }
.hl-keyword, .hl-selector-tag, .hl-subst { font-weight: 600; color: #8959a8; }
.hl-string, .hl-attribute, .hl-symbol, .hl-bullet, .hl-addition { color: #718c00; font-style: italic; }
.hl-function, .hl-section, .hl-title, .hl-tag, .hl-name { font-weight: 600; color: #c00000; }
.hl-variable, .hl-template-variable, .hl-attribute, .hl-attr { color: #4271ae; }
.hl-number, .hl-literal, .hl-type, .hl-built_in, .hl-builtin-name { color: #eab700; }
.hl-meta, .hl-preprocessor, .hl-annotation { color: #3e999f; font-weight: 600; }
.hl-deletion, .hl-error { color: #c00000; text-decoration: underline; }
.hl-link { color: var(--text-muted); text-decoration: underline; }

/* --- Responsive --- */
@media screen and (max-width: 900px) {
  main, body > footer { width: 90%; margin-top: 2rem; margin-bottom: 2rem; }
  main figure, main aside { float: none; display: block; width: 100%; margin: 1.5rem 0; }
  main aside { border-left-width: 4px; background-color: var(--bento-bg); padding: 1rem; }
  blockquote { margin-right: 0; margin-left: 0; }
  .item-flex { flex-direction: column; align-items: flex-start; }
  .item-flex span { margin-left: 0; margin-top: 0.5rem; }
  nav ul li { display: inline-block; white-space: normal; margin-bottom: 0.5rem; }
}

@media screen and (max-width: 600px) {
  .footer-nav { flex-direction: column; gap: 1.5rem; }
  .nav-left, .nav-center, .nav-right { width: 100%; justify-content: center; text-align: center; }
  code, samp { white-space: normal; overflow-wrap: break-word; word-break: break-word; }
  pre code { white-space: inherit; overflow-wrap: normal; }
  .post-list-container { grid-template-columns: 1fr; }
  .year-header { grid-column: 1; padding: 20px 10px 8px 10px; font-size: 1.1rem; }
  .post-row { grid-column: 1; padding: 12px 10px; }
  .post-entry-description { font-size: 0.95rem; }
}