/* ==========================================================================
   CouchMeta — Dark gaming aesthetic
   Merged: AoE4World + AgeOfRTS dark palette × Impact meme culture
   Impeccable design process: Committed color strategy, OKLCH palette,
   modular type scale, spatial rhythm, dark-mode typography compensation
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Inter:wght@400;500;600&display=swap');

:root {
  /* ── Palette (OKLCH, tinted neutrals — never pure black/white) ── */
  --color-void:       oklch(8% 0.008 250);    /* deepest bg */
  --color-surface-0:  oklch(12% 0.008 250);   /* page bg */
  --color-surface-1:  oklch(16% 0.008 250);   /* cards, nav */
  --color-surface-2:  oklch(20% 0.008 250);   /* hover, inputs */
  --color-border:     oklch(25% 0.008 250);   /* subtle dividers */
  --color-border-strong: oklch(32% 0.01 250);

  --color-text:       oklch(92% 0.005 250);   /* primary text — not pure white */
  --color-text-dim:   oklch(68% 0.005 250);   /* secondary */
  --color-text-muted: oklch(48% 0.005 250);   /* tertiary */

  /* Accent: teal (from AgeOfRTS) */
  --color-teal:       oklch(72% 0.14 190);
  --color-teal-bright:oklch(80% 0.16 190);
  --color-teal-dim:   oklch(72% 0.14 190 / 0.15);
  --color-teal-soft:  oklch(72% 0.14 190 / 0.25);

  /* Accent: gold (from AoE4/RTS world) */
  --color-gold:       oklch(76% 0.14 85);
  --color-gold-bright:oklch(84% 0.16 85);
  --color-gold-dim:   oklch(76% 0.14 85 / 0.15);

  /* Semantic */
  --color-danger:     oklch(60% 0.2 25);
  --color-danger-hover: oklch(52% 0.2 25);

  /* ── Typography — modular scale (perfect fourth 1.333) ── */
  --font-display: "Bebas Neue", "Arial Narrow", Impact, sans-serif;
  --font-body:    "Inter", system-ui, -apple-system, sans-serif;
  --font-impact:  Impact, "Arial Black", "Helvetica Neue", sans-serif;

  --text-xs:   0.75rem;     /* 12px — captions */
  --text-sm:   0.875rem;    /* 14px — metadata */
  --text-base: 1rem;        /* 16px — body */
  --text-lg:   1.25rem;     /* 20px — subheading */
  --text-xl:   1.75rem;     /* 28px — section heads */
  --text-2xl:  2.75rem;     /* 44px — page titles */
  --text-hero: clamp(3rem, 6vw + 1rem, 5.5rem); /* hero */

  /* ── Spacing — 4px base, rhythm through contrast ── */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-8: 48px;
  --sp-10: 64px;
  --sp-12: 80px;
  --sp-16: 120px;

  /* ── Layout ── */
  --width-max: 1200px;
  --width-content: 800px;
  --nav-height: 56px;

  /* ── Motion ── */
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --dur-fast: 0.15s;
  --dur-base: 0.3s;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-surface-0);
  /* Dark-mode compensation: bump line-height + letter-spacing */
  line-height: 1.65;
  letter-spacing: 0.01em;
  min-height: 100vh;
}

/* ── Display type — Cinzel, uppercase, AgeOfRTS style ── */
h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 400;  /* Bebas Neue only has 400 */
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.05;
  color: var(--color-text);
}

h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

/* Teal and gold accent spans — like AgeOfRTS hero type */
.accent-teal { color: var(--color-teal); }
.accent-gold { color: var(--color-gold); }

p {
  max-width: 65ch;
  color: var(--color-text-dim);
}

a {
  color: var(--color-teal);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease-out);
}
a:hover { color: var(--color-teal-bright); }

/* ── Eyebrow / Label ── */
.label {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-teal);
}

/* ==========================================================================
   Navigation
   ========================================================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-5);
  max-width: var(--width-max);
  margin: 0 auto;
  background: oklch(12% 0.008 250 / 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
}

.site-logo {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.site-logo .logo-slash {
  color: var(--color-teal);
  font-weight: 900;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
}

.site-nav a {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-dim);
  letter-spacing: 0.02em;
  padding: var(--sp-1) 0;
  border-bottom: 2px solid transparent;
  transition: color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}

.site-nav a:hover {
  color: var(--color-text);
}

.site-nav a.active {
  color: var(--color-teal);
  border-bottom-color: var(--color-teal);
}

/* ==========================================================================
   Hero — meme stage
   ========================================================================== */

.hero {
  padding: var(--sp-10) var(--sp-5) var(--sp-8);
  text-align: center;
  max-width: var(--width-max);
  margin: 0 auto;
}

.hero h1 {
  font-size: var(--text-hero);
  margin-bottom: var(--sp-8);
}

/* Meme display */
.meme-stage {
  max-width: 680px;
  margin: 0 auto var(--sp-6);
}

.meme-canvas-wrap {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: var(--color-void);
  line-height: 0;
  /* Subtle glow */
  box-shadow:
    0 0 0 1px var(--color-border),
    0 4px 24px oklch(0% 0 0 / 0.4),
    0 0 80px oklch(72% 0.14 190 / 0.06);
}

.meme-canvas-wrap canvas {
  width: 100%;
  height: auto;
  display: block;
}

.meme-canvas-wrap.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: oklch(8% 0.008 250 / 0.6);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  transition: all var(--dur-base) var(--ease-out);
  text-decoration: none;
}

.btn--primary {
  background: var(--color-teal);
  color: var(--color-void);
  padding: 14px 28px;
  border-radius: 4px;
}

.btn--primary:hover {
  background: var(--color-teal-bright);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px oklch(72% 0.14 190 / 0.3);
}

.btn--primary:active {
  transform: translateY(0);
}

.btn--ghost {
  background: transparent;
  color: var(--color-teal);
  padding: 10px 18px;
  border: 1px solid var(--color-border-strong);
  border-radius: 4px;
}

.btn--ghost:hover {
  background: var(--color-teal-dim);
  border-color: var(--color-teal-soft);
  color: var(--color-teal-bright);
}

.btn--small {
  font-size: var(--text-xs);
  padding: 8px 14px;
}

.btn--danger {
  background: var(--color-danger);
  color: var(--color-text);
  padding: 8px 14px;
  border-radius: 4px;
}

.btn--danger:hover {
  background: var(--color-danger-hover);
}

.actions {
  display: flex;
  justify-content: center;
  gap: var(--sp-4);
  margin-top: var(--sp-6);
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
  padding: var(--sp-8) var(--sp-5);
  text-align: center;
  border-top: 1px solid var(--color-border);
  margin-top: var(--sp-12);
  max-width: var(--width-max);
  margin-left: auto;
  margin-right: auto;
}

.site-footer p {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0 auto;
}

/* ==========================================================================
   Admin
   ========================================================================== */

.admin-layout {
  padding: var(--sp-8) var(--sp-5);
  max-width: var(--width-content);
  margin: 0 auto;
}

.admin-layout h1 {
  margin-bottom: var(--sp-2);
}

.admin-layout .subtitle {
  color: var(--color-text-muted);
  margin-bottom: var(--sp-8);
}

/* Template grid */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--sp-5);
  margin-bottom: var(--sp-8);
}

.template-card {
  background: var(--color-surface-1);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  overflow: hidden;
  transition: border-color var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}

.template-card:hover {
  border-color: var(--color-border-strong);
  box-shadow: 0 4px 24px oklch(0% 0 0 / 0.3);
}

.template-card img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-bottom: 1px solid var(--color-border);
}

.template-card-body {
  padding: var(--sp-4);
}

.template-card-body h3 {
  font-size: var(--text-base);
  margin-bottom: var(--sp-1);
  text-transform: none;
  letter-spacing: 0;
}

.template-card-body .meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--sp-3);
}

.template-card-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.template-card-actions a {
  font-size: var(--text-sm);
  font-weight: 500;
}

/* Admin sections */
.admin-section {
  margin-bottom: var(--sp-8);
}

.admin-section h2 {
  font-size: var(--text-lg);
  margin-bottom: var(--sp-5);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--color-border);
}

/* Forms */
.form-row {
  display: flex;
  gap: var(--sp-4);
  align-items: flex-end;
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  flex: 1;
  min-width: 160px;
}

.form-group label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.form-group input,
.form-group textarea {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-surface-2);
  color: var(--color-text);
  transition: border-color var(--dur-fast) var(--ease-out);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-teal);
  box-shadow: 0 0 0 3px var(--color-teal-dim);
}

.form-group input::placeholder {
  color: var(--color-text-muted);
}

.form-group input.upcase {
  text-transform: uppercase;
}

/* Phrase list */
.phrase-list {
  list-style: none;
}

.phrase-item {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-4);
  border-bottom: 1px solid var(--color-border);
  transition: background var(--dur-fast) var(--ease-out);
}

.phrase-item:hover {
  background: var(--color-surface-1);
}

.phrase-item:last-child {
  border-bottom: none;
}

.phrase-text {
  flex: 1;
  min-width: 0;
}

.phrase-text .top {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--color-text-dim);
}

.phrase-text .bottom {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--color-text);
  font-weight: 600;
}

.phrase-text .empty {
  color: var(--color-text-muted);
  font-style: italic;
}

.phrase-actions {
  display: flex;
  gap: var(--sp-2);
  flex-shrink: 0;
}

/* Inline edit */
.edit-form {
  display: none;
  gap: var(--sp-2);
  align-items: flex-end;
  flex: 1;
}

.edit-form.active { display: flex; }

.phrase-item.editing .phrase-text,
.phrase-item.editing .phrase-actions { display: none; }

.phrase-item.editing .edit-form { display: flex; }

/* Template detail header */
.template-header {
  display: flex;
  gap: var(--sp-6);
  align-items: flex-start;
  margin-bottom: var(--sp-8);
}

.template-header img {
  width: 200px;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--color-border);
}

.template-header-info {
  flex: 1;
}

.template-header-info h1 {
  margin-bottom: var(--sp-2);
}

.template-header-info .meta {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--sp-8) 0;
}

.back-link {
  font-size: var(--text-sm);
  color: var(--color-teal);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  margin-bottom: var(--sp-5);
}

.back-link:hover {
  color: var(--color-teal-bright);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 640px) {
  .hero { padding: var(--sp-8) var(--sp-4) var(--sp-6); }
  .hero .subtitle { margin-bottom: var(--sp-6); }
  .template-header { flex-direction: column; }
  .template-header img { width: 100%; max-width: 300px; }
  .form-row { flex-direction: column; }
  .phrase-item { flex-direction: column; align-items: flex-start; }
  .site-header { padding: 0 var(--sp-4); }
}
