/* ---------- Theme tokens ---------- */

/* Colors borrowed from Singularity: soft slate and blue by day, slate navy and emerald by night. */
:root {
  --mono: "Geist Mono", ui-monospace, Menlo, Consolas, monospace;
  --bg: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --line: #cbd5e1;
  --surface: #d5dde8;
  --card: #f1f5f9;
  --card-shadow: 0 1px 2px rgb(15 23 42 / 0.05), 0 4px 16px rgb(15 23 42 / 0.06);
  --accent: #2563eb;
  --tag-bg: #f8fafc;
  --tag-border: #cbd5e1;
  --tag-text: #334155;
  --tag-font: inherit;
  --label-font: inherit;
  --label-size: 15px;
  --label-case: none;
  --label-spacing: normal;
  --label-color: var(--text);
  --sun: none;
  --moon: block;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #020617;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --line: #1e293b;
    --surface: #1e293b;
    --card: #0f172a;
    --card-shadow: none;
    --accent: #34d399;
    --tag-bg: #1e293b;
    --tag-border: #334155;
    --tag-text: #e2e8f0;
    --tag-font: var(--mono);
    --label-font: var(--mono);
    --label-size: 12px;
    --label-case: uppercase;
    --label-spacing: 0.08em;
    --label-color: var(--text-muted);
    --sun: block;
    --moon: none;
    color-scheme: dark;
  }
}

/* Checked toggle = the opposite of the OS preference */
:root:has(#theme-toggle:checked) {
  --bg: #020617;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --line: #1e293b;
  --surface: #1e293b;
  --card: #0f172a;
  --card-shadow: none;
  --accent: #34d399;
  --tag-bg: #1e293b;
  --tag-border: #334155;
  --tag-text: #e2e8f0;
  --tag-font: var(--mono);
  --label-font: var(--mono);
  --label-size: 12px;
  --label-case: uppercase;
  --label-spacing: 0.08em;
  --label-color: var(--text-muted);
  --sun: block;
  --moon: none;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:has(#theme-toggle:checked) {
    --bg: #e2e8f0;
    --text: #0f172a;
    --text-muted: #475569;
    --line: #cbd5e1;
    --surface: #d5dde8;
    --card: #f1f5f9;
    --card-shadow: 0 1px 2px rgb(15 23 42 / 0.05), 0 4px 16px rgb(15 23 42 / 0.06);
    --accent: #2563eb;
    --tag-bg: #f8fafc;
    --tag-border: #cbd5e1;
    --tag-text: #334155;
    --tag-font: inherit;
    --label-font: inherit;
    --label-size: 15px;
    --label-case: none;
    --label-spacing: normal;
    --label-color: var(--text);
    --sun: none;
    --moon: block;
    color-scheme: light;
  }
}

/* ---------- Base ---------- */

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

html {
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Poppins", system-ui, sans-serif;
  font-weight: 300;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s ease, color 0.3s ease;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Language ---------- */

/* English shows by default; checking #lang-toggle swaps to Portuguese. */
body [lang="pt-BR"] {
  display: none;
}

:root:has(#lang-toggle:checked) body [lang="pt-BR"] {
  display: revert;
}

:root:has(#lang-toggle:checked) body [lang="en"] {
  display: none;
}

/* ---------- Header ---------- */

.site-header {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 24px 40px;
}

.brand {
  font-weight: 500;
  font-size: 16px;
}

.site-nav {
  display: flex;
  gap: 16px;
  margin-left: auto;
}

.site-nav a {
  font-weight: 400;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}

.site-nav a:hover {
  border-bottom-color: var(--accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 24px;
}

.lang-button {
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 10px;
  border-radius: 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.lang-button:hover {
  background: var(--surface);
}

body:has(#lang-toggle:focus-visible) .lang-button {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.lang-option {
  color: var(--text-muted);
  opacity: 0.6;
}

.lang-separator {
  margin: 0 6px;
  color: var(--text-muted);
  opacity: 0.6;
}

.lang-option-en,
:root:has(#lang-toggle:checked) .lang-option-pt {
  color: var(--text);
  opacity: 1;
}

:root:has(#lang-toggle:checked) .lang-option-en {
  color: var(--text-muted);
  opacity: 0.6;
}

.theme-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.theme-button:hover {
  background: var(--surface);
}

body:has(#theme-toggle:focus-visible) .theme-button {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
}

.icon-sun {
  display: var(--sun);
}

.icon-moon {
  display: var(--moon);
}

/* ---------- Layout ---------- */

.container {
  max-width: 842px;
  margin: 0 auto;
  padding: 16px 16px 64px;
}

.row {
  display: grid;
  grid-template-columns: 210px 1fr;
}

.divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 40px 0;
}

/* ---------- Profile ---------- */

.avatar img {
  width: 136px;
  height: 136px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid var(--bg);
  outline: 1px solid var(--line);
}

h1 {
  font-size: 36px;
  font-weight: 500;
  line-height: 1.2;
  margin: 4px 0 20px;
}

.subtitle {
  margin-bottom: 12px;
}

.link-arrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 400;
  color: var(--accent);
}

.link-arrow::after {
  content: "\2197";
  font-size: 14px;
  transition: transform 0.2s ease;
}

.link-arrow:hover::after {
  transform: translate(2px, -2px);
}

.profile .link-arrow {
  border-bottom: 1px solid currentColor;
  padding-bottom: 2px;
  margin-bottom: 28px;
}

.bio {
  color: var(--text-muted);
  max-width: 60ch;
}

.bio + .bio {
  margin-top: 12px;
}

.inline-link {
  color: var(--accent);
  font-weight: 400;
  border-bottom: 1px solid currentColor;
}

/* ---------- Sections ---------- */

.section {
  margin-bottom: 48px;
}

.section-title {
  font-family: var(--label-font);
  font-size: var(--label-size);
  font-weight: 500;
  text-transform: var(--label-case);
  letter-spacing: var(--label-spacing);
  color: var(--label-color);
  margin-bottom: 32px;
}

.entry {
  padding-bottom: 40px;
}

.entry-date {
  color: var(--text-muted);
}

.entry-body h3 {
  font-size: 22px;
  font-weight: 500;
  line-height: 1.3;
}

.entry-org {
  color: var(--text-muted);
  margin: 2px 0 16px;
}

.entry-body > p {
  color: var(--text-muted);
}

.entry-body > p + p {
  margin-top: 24px;
}

.entry-body > p + .tags {
  margin-top: 16px;
}

/* Separator between consecutive entries, only under the content column */
.entry + .entry .entry-body {
  border-top: 1px solid var(--line);
  padding-top: 40px;
}

.entry + .entry .entry-date {
  padding-top: 40px;
}

/* ---------- Projects ---------- */

.projects {
  display: grid;
  gap: 24px;
}

/* Projects and games share the same card */
.project,
.game-card {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 24px;
  align-items: start;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--card-shadow);
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.project:hover,
.game-card:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  transform: translateY(-2px);
}

.project:focus-visible,
.game-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.project img {
  width: 180px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  transition: opacity 0.2s ease;
}

.project:hover img {
  opacity: 0.85;
}

.project h3 {
  font-size: 17px;
  margin-bottom: 4px;
}

.project:hover h3 {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.project p {
  color: var(--text-muted);
  margin-bottom: 12px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
}

.tags li,
.tags > span {
  font-size: 12px;
  font-weight: 400;
  font-family: var(--tag-font);
  padding: 1px 8px;
  border: 1px solid var(--tag-border);
  border-radius: 6px;
  background: var(--tag-bg);
  color: var(--tag-text);
}

/* ---------- Games ---------- */

.game-card {
  width: 100%;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.game-info {
  display: grid;
  gap: 4px;
  justify-items: start;
}

.game-name {
  font-size: 17px;
  font-weight: 500;
}

.game-card:hover .game-name {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.game-name::after,
.playable::after {
  content: "\25B6";
  margin-left: 10px;
  font-size: 11px;
  color: var(--accent);
}

.game-description {
  color: var(--text-muted);
  margin-bottom: 8px;
}

.game-preview {
  display: grid;
  place-items: center;
  width: 180px;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #020617;
  color: #e2e8f0;
  font-family: var(--mono);
  transition: opacity 0.2s ease;
}

.game-card:hover .game-preview {
  opacity: 0.85;
}

.preview-chess {
  display: grid;
  grid-template-columns: repeat(8, 20px);
  grid-auto-rows: 15px;
  overflow: hidden;
  border-radius: 2px;
  font-size: 13px;
  line-height: 1;
}

.preview-chess i {
  display: grid;
  place-items: center;
  font-style: normal;
  color: #f0abfc;
  background: #475569;
}

.preview-chess i:nth-child(-n + 16) {
  color: #7dd3fc;
}

/* Checkerboard: flip the shade on odd squares of even rows and even squares of odd rows. */
.preview-chess i:nth-child(16n + 2),
.preview-chess i:nth-child(16n + 4),
.preview-chess i:nth-child(16n + 6),
.preview-chess i:nth-child(16n + 8),
.preview-chess i:nth-child(16n + 9),
.preview-chess i:nth-child(16n + 11),
.preview-chess i:nth-child(16n + 13),
.preview-chess i:nth-child(16n + 15) {
  background: #334155;
}

.preview-chess i:nth-child(53) {
  background: #0369a1;
}

.preview-connect-four {
  display: grid;
  grid-template-columns: repeat(7, 14px);
  gap: 4px;
  padding: 6px;
  border: 1px solid #475569;
  border-radius: 2px;
}

.preview-connect-four i {
  aspect-ratio: 1;
  border-radius: 50%;
  background: #1e293b;
}

.preview-connect-four .r {
  background: #ef4444;
}

.preview-connect-four .y {
  background: #facc15;
}

.preview-hangman {
  font-size: 12px;
  line-height: 1.25;
  white-space: pre;
}

.preview-mastermind {
  display: grid;
  gap: 6px;
  font-size: 12px;
}

.preview-mastermind b {
  font-weight: 400;
  color: #22d3ee;
}

.preview-mastermind em {
  font-style: normal;
  color: #ef4444;
}

/* ---------- Game dialog ---------- */

/* A terminal window, dark in both themes so the games' colors always read well. */
.game-dialog {
  width: min(860px, calc(100% - 32px));
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid #1e293b;
  border-radius: 12px;
  background: #0f172a;
  color: #f1f5f9;
  box-shadow: 0 24px 64px rgb(2 6 23 / 0.45);
}

.game-dialog[open] {
  animation: dialog-in 0.2s ease-out;
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

.game-dialog::backdrop {
  background: rgb(2 6 23 / 0.55);
  backdrop-filter: blur(4px);
}

.game-dialog-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 16px;
  border-bottom: 1px solid #1e293b;
}

.window-dots {
  display: flex;
  gap: 6px;
}

.window-dots i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #334155;
}

.game-title {
  margin-right: auto;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 400;
  color: #94a3b8;
}

.game-title::before {
  content: "~/games/";
  color: #34d399;
}

:root:has(#lang-toggle:checked) .game-title::before {
  content: "~/jogos/";
}

.icon-button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: none;
  color: #94a3b8;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.icon-button:hover {
  background: #1e293b;
  color: #f1f5f9;
}

.icon-button:focus-visible {
  outline: 2px solid #34d399;
  outline-offset: 1px;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.game-terminal {
  position: relative;
  padding: 12px 16px;
  background: #020617;
}

.game-screen {
  height: min(520px, 70vh);
  color: #e2e8f0;
}

.game-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #020617;
  color: #94a3b8;
  font-family: var(--mono);
  font-size: 13px;
}

.game-loading::before {
  content: "";
  width: 16px;
  height: 16px;
  border: 2px solid #1e293b;
  border-top-color: #34d399;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.game-loading[hidden] {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .game-dialog[open],
  .game-loading::before {
    animation: none;
  }
}

/* ---------- Detail lists ---------- */

.detail-list {
  display: grid;
  grid-template-columns: minmax(100px, max-content) 1fr;
  column-gap: 24px;
  row-gap: 8px;
}

.entry-body > p + .detail-list {
  margin-top: 20px;
}

.detail-list dt {
  color: var(--text-muted);
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  padding: 24px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- Small screens ---------- */

@media (max-width: 720px) {
  .site-header {
    gap: 16px;
    padding: 20px 16px;
  }

  .header-actions {
    margin-left: 0;
  }

  .row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .profile {
    gap: 24px;
  }

  h1 {
    font-size: 30px;
  }

  .entry + .entry .entry-date {
    border-top: 1px solid var(--line);
  }

  .entry + .entry .entry-body {
    border-top: none;
    padding-top: 0;
  }

  .project,
  .game-card {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .project img {
    width: 100%;
    aspect-ratio: 16 / 9;
  }

  .game-preview {
    width: 100%;
    aspect-ratio: 16 / 9;
  }
}

@media (max-width: 420px) {
  .brand {
    display: none;
  }

  .site-nav {
    margin-left: 0;
  }

  .header-actions {
    margin-left: auto;
  }
}
