:root {
  --bg: #f5f3ea;
  --ink: #1f2c3a;
  --brand: #bf3f34;
  --brand-2: #1f6e8c;
  --card: #fffcf1;
  --line: #cbb89e;
  --accent: #f7b267;
  --ok: #2f9e44;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Outfit", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 20%, #ffe7b8 0, transparent 34%),
    radial-gradient(circle at 85% 10%, #ffd7d1 0, transparent 38%),
    linear-gradient(130deg, #f9f6ed 0%, #f0ebdf 44%, #efe6d6 100%);
  min-height: 100vh;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.25;
  background-image: repeating-radial-gradient(circle at 0 0, transparent 0 3px, #00000014 4px 4px);
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.8rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: rgba(255, 252, 241, 0.82);
  backdrop-filter: blur(8px);
  border: 2px solid var(--line);
  border-top: 0;
  border-radius: 0 0 14px 14px;
}

.logo {
  font-family: "Press Start 2P", cursive;
  font-size: 0.9rem;
  color: var(--brand);
  text-decoration: none;
  letter-spacing: -0.04em;
}

.site-nav {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.site-nav a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  transition: background 120ms ease;
}

.site-nav a:hover {
  background: rgba(191, 63, 52, 0.1);
}

.menu-toggle {
  display: none;
  padding: 0.4rem 0.6rem;
  font-size: 1.1rem;
}

/* Hero */
.hero {
  padding: 2.5rem 1.2rem 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
  animation: rise 420ms ease;
}

.eyebrow {
  margin: 0 0 0.8rem;
  font-family: "Press Start 2P", cursive;
  font-size: 0.7rem;
  color: var(--brand-2);
  letter-spacing: 0.04em;
}

h1 {
  margin: 0;
  font-size: clamp(1.7rem, 4.8vw, 3rem);
  line-height: 1.08;
}

.sub {
  margin-top: 0.8rem;
  max-width: 66ch;
  font-size: 1rem;
  color: #41566a;
}

.hero-actions {
  margin-top: 1.2rem;
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
}

button,
.btn-link,
.btn-primary {
  border: 2px solid var(--line);
  background: var(--card);
  padding: 0.55rem 0.9rem;
  border-radius: 11px;
  cursor: pointer;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  transition: transform 110ms ease, box-shadow 140ms ease, background 140ms ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover,
.btn-link:hover,
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 0 #d8c4ab;
}

button:active,
.btn-link:active,
.btn-primary:active {
  transform: translateY(1px);
  box-shadow: 0 3px 0 #d8c4ab;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

button.ghost {
  background: #f2ede3;
}

/* Home layout */
.home-layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem 2.5rem;
  display: grid;
  gap: 1.4rem;
}

.module {
  border: 2px solid var(--line);
  border-radius: 16px;
  background: color-mix(in oklab, var(--card), white 18%);
  padding: 1.1rem;
  animation: rise 420ms ease;
}

.module-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.module h2 {
  margin: 0;
  font-size: 1.15rem;
}

.module-tag {
  font-size: 0.72rem;
  font-weight: 700;
  background: #f7e6cc;
  border: 1px solid #e8cc9b;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
}

.module-more {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--brand-2);
  text-decoration: none;
}

.module-more:hover {
  text-decoration: underline;
}

/* Card grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.9rem;
}

.card {
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fffdf7;
  overflow: hidden;
  display: grid;
  animation: rise 320ms ease;
}

.card-link {
  display: block;
}

.card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: linear-gradient(45deg, #f8f4eb 25%, #f1ebdf 25%, #f1ebdf 50%, #f8f4eb 50%, #f8f4eb 75%, #f1ebdf 75%, #f1ebdf 100%);
  background-size: 12px 12px;
  transition: transform 160ms ease;
}

.card-link:hover img {
  transform: scale(1.04);
}

.card .info {
  padding: 0.58rem;
  display: grid;
  gap: 0.25rem;
}

.card .title {
  font-weight: 700;
  font-size: 0.9rem;
}

.meta-line {
  font-size: 0.78rem;
  color: #6b7882;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
}

.tag {
  font-size: 0.72rem;
  background: #f7e6cc;
  border: 1px solid #e8cc9b;
  border-radius: 999px;
  padding: 0.1rem 0.38rem;
}

.hover-lift {
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.hover-lift:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(31, 44, 58, 0.08);
}

/* Featured */
.featured-card {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 1.2rem;
  align-items: center;
}

.featured-link {
  border: 2px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #fffdf7;
}

.featured-link img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  display: block;
}

.featured-info h3 {
  margin: 0 0 0.4rem;
  font-size: 1.4rem;
}

.featured-info p {
  margin: 0 0 0.6rem;
  color: #41566a;
}

.featured-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
}

/* Tutorials */
.tutorial-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.9rem;
}

.tutorial-card {
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fffdf7;
}

.tutorial-link {
  display: block;
  padding: 0.9rem;
  color: var(--ink);
  text-decoration: none;
}

.tutorial-category {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--brand-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tutorial-card h3 {
  margin: 0.35rem 0 0.3rem;
  font-size: 1.05rem;
}

.tutorial-card p {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: #41566a;
}

.tutorial-card time {
  font-size: 0.78rem;
  color: #6b7882;
}

/* Categories */
.category-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.category-chip {
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  background: #fffdf7;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

/* CTA */
.cta {
  text-align: center;
  padding: 2rem 1.1rem;
}

.cta h2 {
  margin: 0 0 0.4rem;
  font-size: 1.5rem;
}

.cta p {
  margin: 0 auto 1.1rem;
  max-width: 50ch;
  color: #41566a;
}

.cta-actions {
  display: flex;
  justify-content: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

/* Workbench */
.workbench-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

.panel {
  border: 2px solid var(--line);
  border-radius: 14px;
  background: color-mix(in oklab, var(--card), white 18%);
  padding: 1rem;
}

.panel h3 {
  margin-top: 0;
  font-size: 1rem;
}

.filters {
  grid-column: span 3;
}

.gallery {
  grid-column: span 6;
}

.upload {
  grid-column: span 3;
}

.draw {
  grid-column: span 12;
}

label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
  margin-bottom: 0.6rem;
}

input,
select {
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 0.48rem 0.58rem;
  font: inherit;
  background: #fffdf6;
}

.quick-ops {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.meta {
  color: #6b7882;
  font-size: 0.86rem;
  margin-bottom: 0;
}

.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.8rem;
}

.actions {
  display: flex;
  gap: 0.4rem;
}

.actions a,
.actions button {
  font-size: 0.75rem;
  padding: 0.28rem 0.4rem;
}

.draw-toolbar {
  display: flex;
  gap: 0.7rem;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 0.8rem;
}

#pixelCanvas {
  width: min(100%, 512px);
  height: auto;
  border: 3px solid var(--ink);
  border-radius: 8px;
  image-rendering: pixelated;
  background: #fff;
}

/* Footer */
.site-footer {
  text-align: center;
  font-size: 0.8rem;
  color: #5d6a75;
  padding: 0.6rem 1rem 2rem;
}

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

/* Template list & detail extras */
.hero.compact {
  padding-bottom: 0.5rem;
}

.filter-bar {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  align-items: end;
}

.filter-bar input,
.filter-bar select {
  min-width: 180px;
}

.card-grid.large {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.card-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.btn-link.small,
.btn-primary.small {
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
  border-radius: 8px;
}

.detail-layout {
  max-width: 900px;
}

.back-link {
  display: inline-block;
  margin-bottom: 0.8rem;
  color: var(--brand-2);
  text-decoration: none;
  font-weight: 600;
}

.back-link:hover {
  text-decoration: underline;
}

.detail-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.6rem;
  align-items: start;
}

.detail-media {
  border: 2px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: #fffdf7;
}

.detail-media img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  display: block;
}

.detail-info h1 {
  margin: 0.2rem 0 0.6rem;
  font-size: clamp(1.4rem, 3.5vw, 2rem);
}

.detail-meta {
  color: #41566a;
  margin: 0 0 0.4rem;
}

.detail-author {
  color: #6b7882;
  font-size: 0.9rem;
  margin: 0 0 0.8rem;
}

.detail-tags {
  margin: 0.6rem 0;
}

.detail-tags .meta {
  display: block;
  margin-bottom: 0.3rem;
}

.detail-actions {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  margin-top: 1.2rem;
}

/* Mobile */
@media (max-width: 960px) {
  .site-header {
    flex-wrap: wrap;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .site-nav {
    display: none;
    width: 100%;
    flex-direction: column;
    padding-top: 0.5rem;
  }

  .site-nav.open {
    display: flex;
  }

  .featured-card,
  .detail-card {
    grid-template-columns: 1fr;
  }

  .filters,
  .gallery,
  .upload,
  .draw {
    grid-column: span 12;
  }
}
/* Blog extras */
.article-layout {
  max-width: 780px;
}

.blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.blog-card {
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fffdf7;
  overflow: hidden;
}

.blog-link {
  color: var(--ink);
  text-decoration: none;
  display: grid;
}

.blog-link img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #f1ebdf;
}

.blog-info {
  padding: 0.9rem;
  display: grid;
  gap: 0.35rem;
}

.blog-info h2 {
  margin: 0;
  font-size: 1.1rem;
}

.blog-info p {
  margin: 0;
  font-size: 0.9rem;
  color: #41566a;
}

.blog-category {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--brand-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.blog-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.4rem;
}

.blog-footer time {
  font-size: 0.78rem;
  color: #6b7882;
}

.article {
  padding: 1.4rem;
}

.article-header {
  margin-bottom: 1rem;
}

.article-header h1 {
  margin: 0.4rem 0 0.5rem;
  font-size: clamp(1.4rem, 3.5vw, 2rem);
}

.article-meta {
  color: #6b7882;
  font-size: 0.9rem;
  margin: 0;
}

.article-cover {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 1.2rem;
  border: 2px solid var(--line);
}

.article-body {
  line-height: 1.7;
  color: #2c3a47;
}

.article-body h2 {
  font-size: 1.2rem;
  margin-top: 1.4rem;
  margin-bottom: 0.5rem;
}

.article-body p,
.article-body ul {
  margin: 0.6rem 0;
}

.article-body ul {
  padding-left: 1.3rem;
}

.article-tags {
  margin: 1.2rem 0;
}

.article-actions {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.search-filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.7rem;
  align-items: end;
}

.share-box {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 2px dashed var(--line);
  display: grid;
  gap: 0.5rem;
}

.share-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.qr-code {
  width: 120px;
  height: 120px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.draw-layout {
  max-width: 900px;
}

.draw-panel {
  display: grid;
  gap: 1rem;
}

.draw-topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.draw-topbar h1 {
  margin: 0;
  font-size: 1.5rem;
}

.canvas-wrap {
  display: flex;
  justify-content: center;
  background: #fffdf7;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
}

.canvas-wrap canvas {
  width: min(100%, 512px);
  height: auto;
  image-rendering: pixelated;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #fff;
}

/* Mobile-first improvements */
#pixelCanvas,
.canvas-wrap canvas {
  touch-action: none;
}

button,
.btn-primary,
.btn-link,
input,
select {
  min-height: 44px;
}

@media (max-width: 960px) {
  .hero {
    padding: 1.6rem 1rem 1rem;
  }

  .home-layout {
    padding: 0 0.8rem 2rem;
    gap: 1rem;
  }

  .module {
    padding: 0.9rem;
  }

  .filter-bar,
  .draw-toolbar {
    gap: 0.55rem;
  }

  .filter-bar input,
  .filter-bar select {
    min-width: 100%;
  }

  .card-grid,
  .card-grid.large {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .blog-grid {
    grid-template-columns: 1fr;
  }

  .detail-actions,
  .article-actions,
  .cta-actions,
  .share-actions {
    width: 100%;
  }

  .btn-primary,
  .btn-link,
  button {
    flex: 1 1 auto;
  }

  .canvas-wrap {
    padding: 0.5rem;
  }
}

/* Auth header widget */
.auth-header-widget {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  font-size: 0.88rem;
  font-weight: 600;
}

.auth-header-widget a {
  color: var(--ink);
  text-decoration: none;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  transition: background 120ms ease;
}

.auth-header-widget a:hover {
  background: rgba(191, 63, 52, 0.1);
}

.auth-register-link {
  background: var(--brand);
  border: 2px solid var(--brand);
  color: #fff !important;
}

.auth-register-link:hover {
  background: #a5362d;
}

.auth-logout-btn {
  padding: 0.35rem 0.55rem;
  font-size: 0.85rem;
  border-radius: 8px;
  min-height: auto;
}

/* Community actions */
.community-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 2px dashed var(--line);
}

.community-actions button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  padding: 0.4rem 0.7rem;
  min-height: auto;
}

.community-actions button.active {
  background: #fff0f0;
  border-color: var(--brand);
  color: var(--brand);
}

.community-count {
  font-weight: 700;
}

/* Comments section */
.comments-section {
  margin-top: 1.5rem;
}

.comments-section h3 {
  margin: 0 0 0.8rem;
  font-size: 1.1rem;
}

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.comment-form textarea {
  width: 100%;
  min-height: 80px;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem;
  font: inherit;
  resize: vertical;
}

.comment-form button {
  align-self: flex-start;
}

.comments-list {
  display: grid;
  gap: 0.7rem;
}

.comment {
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  background: #fffdf7;
}

.comment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.comment-author {
  font-weight: 700;
  font-size: 0.9rem;
}

.comment-time {
  font-size: 0.78rem;
  color: #6b7882;
}

.comment-body {
  margin: 0;
  line-height: 1.5;
  color: #2c3a47;
}

.comment-actions {
  margin-top: 0.5rem;
}

.comment-actions button {
  font-size: 0.78rem;
  padding: 0.2rem 0.4rem;
  min-height: auto;
  color: #c0392b;
}

/* Profile page extras */
.profile-form {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.profile-form label {
  margin-bottom: 0;
}

.favorites-grid {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.8rem;
}

.favorite-card {
  border: 2px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fffdf7;
}

.favorite-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: #f1ebdf;
}

.favorite-card .info {
  padding: 0.5rem;
}

.favorite-card .title {
  font-size: 0.85rem;
  font-weight: 700;
}

@media (max-width: 960px) {
  .auth-header-widget {
    width: 100%;
    justify-content: flex-end;
    margin-top: 0.3rem;
  }
}
