/* ===========================
   Reset & Base
   =========================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --radius: 8px;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.2);
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 2rem;
  --font-sm: 0.85rem;
  --font-md: 0.9rem;
  --font-lg: 1.8rem;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  transition: background-color 0.3s ease, color 0.3s ease;
  display: flex;
  flex-direction: column;
  min-block-size: 100vh;
}

/* Accessibility: reduce motion */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* ===========================
   Layout
   =========================== */
header,
footer {
  background: var(--bg-secondary);
  padding: var(--space-md) var(--space-lg);
  box-shadow: var(--shadow-sm);
  text-align: center;
  font-size: var(--font-sm);
  color: var(--text-secondary);
}

main {
  flex: 1;
  max-inline-size: 800px;
  margin: var(--space-lg) auto;
  padding: var(--space-lg);
  background: var(--bg-secondary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

h1 {
  font-size: var(--font-lg);
  margin-block-end: var(--space-sm);
  color: var(--accent-primary);
}

p {
  margin-block-end: var(--space-md);
}

/* ===========================
   Controls (buttons, selects)
   =========================== */
nav {
  display: flex;
  flex-direction: column; /* stack controls and ul vertically */
  align-items: center; /* center horizontally */
  gap: 1rem; /* space between controls and list */
}

.nav-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-sm);
  width: 90%;
}

.primary-nav {
  display: flex;
  gap: 1.5rem;
  list-style: none;
  padding: 0;
  margin: 0;
  justify-content: center;
}

select,
button {
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 2px solid var(--text-secondary);
  padding: 0.4rem 0.6rem; /* smaller padding */
  border-radius: var(--radius);
  cursor: pointer;
  font-size: var(--font-sm);
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease,
    box-shadow 0.2s ease;
}

select:hover,
button:hover,
select:focus,
button:focus {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
  outline: none;
  box-shadow: 0 0 6px var(--accent-primary);
}

/* ===========================
   Components
   =========================== */

/* Visit Counter */
#visitCounter {
  display: inline-block;
  margin-block-start: var(--space-sm);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius);
  background: var(--accent-primary);
  color: #fff;
  font-size: var(--font-md);
  box-shadow: var(--shadow-lg);
}

/* Assets grid */
.assets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-md);
}
.assets img {
  width: 100%;
  border-radius: var(--radius);
  object-fit: contain;
}

/* Markdown blocks (README, docs) */
.readme,
.doc {
  margin-top: var(--space-md);
  padding: var(--space-md);
  background: var(--bg-secondary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.readme h1,
.doc h1,
.readme h2,
.doc h2,
.readme h3,
.doc h3 {
  color: var(--accent-primary);
  margin-top: var(--space-md);
}

/* Code blocks */
pre {
  background: var(--bg-secondary);
  padding: var(--space-md);
  border-radius: var(--radius);
  overflow-x: auto;
}
code {
  font-family: "Fira Code", monospace;
  font-size: var(--font-md);
}

/* Navigation controls */
.nav-controls {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  margin-block-start: var(--space-sm);
}
.nav-controls input[type="search"] {
  flex: 1;
  min-width: 160px;
  padding: var(--space-sm);
  border-radius: var(--radius);
  border: 1px solid var(--text-secondary);
}

/* Active nav link */
.primary-nav a.active {
  color: var(--accent-primary);
  text-decoration: underline;
}

/* Collapsibles */
.collapsible {
  margin: var(--space-md) 0;
  border: 1px solid var(--text-secondary);
  border-radius: var(--radius);
  overflow: hidden;
}
.collapsible summary {
  cursor: pointer;
  padding: 0.6rem 0.8rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-weight: 600;
  user-select: none;
}
.collapsible > *:not(summary) {
  padding: var(--space-md);
}

/* Section highlight on deep-link */
.highlight-section {
  outline: 2px solid var(--accent-primary);
  border-radius: var(--radius);
}

/* Code wrap tools */
.code-wrap {
  position: relative;
}
.block-tools {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

/* Textures grid */
.assets.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-sm);
}
.texture-item {
  text-align: center;
}
.texture-item img {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--text-secondary);
}

/* Texture filter input */
.texture-filter {
  width: 100%;
  margin-bottom: var(--space-sm);
  padding: var(--space-sm);
  border-radius: var(--radius);
  border: 1px solid var(--text-secondary);
}

/* Image modal */
.image-modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  background: var(--bg-secondary);
  color: var(--text-primary);
  max-width: 90vw;
}
.image-modal img {
  display: block;
  max-width: 90vw;
  max-height: 80vh;
}
.modal-close {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
}

/* Permalink icon */
.permalink {
  margin-left: var(--space-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 700;
}
.permalink:hover {
  color: var(--accent-primary);
}

/* Busy state on summary */
.collapsible summary[aria-busy="true"]::after {
  content: " • loading…";
  font-weight: normal;
  color: var(--text-secondary);
}

/* Dialog backdrop tint */
::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

/* ===========================
   Themes
   =========================== */
[data-theme="light"] {
  --bg-primary: #fafafa;
  --bg-secondary: #ffffff;
  --text-primary: #212121;
  --text-secondary: #757575;
  --accent-primary: #2962ff;
}

[data-theme="dark"] {
  --bg-primary: #121212;
  --bg-secondary: #1e1e2e;
  --text-primary: #f5f5f5;
  --text-secondary: #b0b0c0;
  --accent-primary: #bb86fc;
}

[data-theme="retro"] {
  --bg-primary: #2d2a32;
  --bg-secondary: #3c3a45;
  --text-primary: #ffeb99;
  --text-secondary: #ffb48a;
  --accent-primary: #ff6f61;
}

[data-theme="cosmic"] {
  --bg-primary: #0b0c10;
  --bg-secondary: #1f2833;
  --text-primary: #c5c6c7;
  --text-secondary: #66fcf1;
  --accent-primary: #45a29e;
}

[data-theme="sunset"] {
  --bg-primary: #1e1e2e;
  --bg-secondary: #3c2a3e;
  --text-primary: #ffd580;
  --text-secondary: #ff9f68;
  --accent-primary: #ff6b6b;
}

[data-theme="earth"] {
  --bg-primary: #2e2d2b;
  --bg-secondary: #3b3a36;
  --text-primary: #d9cbbf;
  --text-secondary: #a3b18a;
  --accent-primary: #588157;
}

[data-theme="ocean"] {
  --bg-primary: #001f3f;
  --bg-secondary: #003566;
  --text-primary: #e0f7fa;
  --text-secondary: #90caf9;
  --accent-primary: #00bcd4;
}

[data-theme="solarized"] {
  --bg-primary: #002b36;
  --bg-secondary: #073642;
  --text-primary: #839496;
  --text-secondary: #93a1a1;
  --accent-primary: #b58900;
}
