/*!
 * Manga Taxonomy Grid — core styles
 * Version: 2.0.0
 *
 * Contains design tokens, the section shell, the shared card, the skins and
 * the default `grid` layout. Every other layout ships in its own file and is
 * only enqueued when a page actually uses it.
 */

/* ==========================================================================
   Tokens
   ========================================================================== */
.mtg-root {
  --mtg-surface: #ffffff;
  --mtg-surface-2: #f4f5f7;
  --mtg-text: #16181d;
  --mtg-text-muted: #666c78;
  --mtg-accent: #0073aa;
  --mtg-border: rgba(0, 0, 0, 0.08);

  --mtg-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  --mtg-shadow-hover: 0 10px 24px rgba(0, 0, 0, 0.14);

  --mtg-radius: 12px;
  --mtg-gap: 20px;
  --mtg-pad: 16px;
  --mtg-min-col: 240px;

  --mtg-duration: 0.25s;
  --mtg-lift: -4px;

  /* Per-card hue, set inline from the term ID. */
  --mtg-hue: 210;

  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  color: var(--mtg-text);
}

/* Dark tokens. Applied when the visitor asks for dark and the site left the
   scheme on "auto", or unconditionally when the admin forced dark. */
@media (prefers-color-scheme: dark) {
  .mtg-root.mtg-scheme--auto {
    --mtg-surface: #1e2126;
    --mtg-surface-2: #14161a;
    --mtg-text: #eef1f5;
    --mtg-text-muted: #9aa3b1;
    --mtg-accent: #64b5f6;
    --mtg-border: rgba(255, 255, 255, 0.1);
    --mtg-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    --mtg-shadow-hover: 0 10px 24px rgba(0, 0, 0, 0.6);
  }
}

.mtg-root.mtg-scheme--dark {
  --mtg-surface: #1e2126;
  --mtg-surface-2: #14161a;
  --mtg-text: #eef1f5;
  --mtg-text-muted: #9aa3b1;
  --mtg-accent: #64b5f6;
  --mtg-border: rgba(255, 255, 255, 0.1);
  --mtg-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  --mtg-shadow-hover: 0 10px 24px rgba(0, 0, 0, 0.6);
}

/* ==========================================================================
   Section
   ========================================================================== */
.mtg-section {
  margin: 0 0 48px;
}

.mtg-section:last-child {
  margin-bottom: 0;
}

.mtg-section-title {
  margin: 0 0 24px;
  font-size: clamp(1.35rem, 3vw, 1.9rem);
  font-weight: 600;
  line-height: 1.25;
  color: var(--mtg-text);
}

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

/* ==========================================================================
   Grid container (shared reset)
   ========================================================================== */
.mtg-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--mtg-gap);
}

.mtg-item {
  margin: 0;
  padding: 0;
  min-width: 0; /* let long names shrink instead of blowing out the track */
}

/* Explicit column counts from the settings screen.
   Doubled-up selector on purpose: these have to outrank `.mtg-layout--*`, which
   also sets grid-template-columns and is defined later here and in the
   per-layout files. */
.mtg-grid.mtg-cols--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mtg-grid.mtg-cols--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mtg-grid.mtg-cols--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mtg-grid.mtg-cols--5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.mtg-grid.mtg-cols--6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }

@media (max-width: 900px) {
  .mtg-grid.mtg-cols--4,
  .mtg-grid.mtg-cols--5,
  .mtg-grid.mtg-cols--6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
  .mtg-grid.mtg-cols--3,
  .mtg-grid.mtg-cols--4,
  .mtg-grid.mtg-cols--5,
  .mtg-grid.mtg-cols--6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ==========================================================================
   Card (shared by grid / manga / bento / masonry)
   ========================================================================== */
.mtg-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--mtg-surface);
  border-radius: var(--mtg-radius);
  overflow: hidden;
  box-shadow: var(--mtg-shadow);
  text-decoration: none;
  color: inherit;
  transition: transform var(--mtg-duration) ease, box-shadow var(--mtg-duration) ease;
}

.mtg-card:hover,
.mtg-card:focus-visible {
  transform: translateY(var(--mtg-lift));
  box-shadow: var(--mtg-shadow-hover);
  color: inherit;
}

.mtg-card:focus-visible {
  outline: 3px solid var(--mtg-accent);
  outline-offset: 2px;
}

.mtg-card:active {
  transform: translateY(-2px);
}

/* --- Thumbnail ----------------------------------------------------------- */
.mtg-thumb {
  display: block;
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--mtg-surface-2);
  overflow: hidden;
  flex: 0 0 auto;
}

.mtg-thumb .mtg-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* WordPress prints intrinsic width/height on the img; the wrapper owns the
     box, so the override cannot reintroduce layout shift. */
  max-width: 100%;
}

/* Browsers without aspect-ratio (Safari < 15). */
@supports not (aspect-ratio: 1 / 1) {
  .mtg-thumb {
    height: 0;
    padding-top: 75%;
  }

  .mtg-thumb .mtg-img,
  .mtg-thumb .mtg-placeholder {
    position: absolute;
    inset: 0;
  }
}

/* --- Placeholder --------------------------------------------------------- */
.mtg-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    135deg,
    hsl(var(--mtg-hue) 62% 62%),
    hsl(calc(var(--mtg-hue) + 40) 58% 44%)
  );
}

.mtg-placeholder::after {
  content: attr(data-initial);
  font-size: clamp(1.75rem, 5vw, 3rem);
  font-weight: 700;
  line-height: 1;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* --- Body ---------------------------------------------------------------- */
.mtg-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--mtg-pad);
  text-align: center;
  flex: 1 1 auto;
  justify-content: center;
}

.mtg-name {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--mtg-accent);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.mtg-count {
  font-size: 0.875rem;
  color: var(--mtg-text-muted);
}

.mtg-desc {
  font-size: 0.85rem;
  color: var(--mtg-text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ==========================================================================
   Layout: grid (default)
   ========================================================================== */
.mtg-layout--grid {
  grid-template-columns: repeat(auto-fill, minmax(min(var(--mtg-min-col), 100%), 1fr));
}

/* ==========================================================================
   Skins
   ========================================================================== */
.mtg-skin--soft .mtg-card {
  --mtg-radius: 20px;
  background: color-mix(in srgb, var(--mtg-surface) 88%, hsl(var(--mtg-hue) 70% 55%));
  box-shadow: none;
  border: 1px solid var(--mtg-border);
}

.mtg-skin--soft .mtg-card:hover {
  box-shadow: var(--mtg-shadow);
}

.mtg-skin--glass .mtg-card {
  background: color-mix(in srgb, var(--mtg-surface) 55%, transparent);
  border: 1px solid var(--mtg-border);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
}

.mtg-skin--neon {
  --mtg-surface: #12141a;
  --mtg-surface-2: #0b0d12;
  --mtg-text: #f2f5ff;
  --mtg-text-muted: #9aa3c0;
  --mtg-accent: #7cf3ff;
}

.mtg-skin--neon .mtg-card {
  border: 1px solid hsl(var(--mtg-hue) 80% 60% / 0.35);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.mtg-skin--neon .mtg-card:hover,
.mtg-skin--neon .mtg-card:focus-visible {
  border-color: hsl(var(--mtg-hue) 90% 65%);
  box-shadow: 0 0 22px hsl(var(--mtg-hue) 90% 60% / 0.45);
}

.mtg-skin--neon .mtg-name {
  color: #ffffff;
}

.mtg-skin--minimal .mtg-card {
  background: transparent;
  box-shadow: none;
  border-radius: 8px;
}

.mtg-skin--minimal .mtg-card:hover,
.mtg-skin--minimal .mtg-card:focus-visible {
  transform: none;
  box-shadow: none;
}

.mtg-skin--minimal .mtg-thumb {
  border-radius: 8px;
}

.mtg-skin--minimal .mtg-body {
  padding: 10px 2px 0;
  text-align: left;
}

/* `color-mix()` is recent; fall back to the plain surface where unsupported. */
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .mtg-skin--soft .mtg-card,
  .mtg-skin--glass .mtg-card {
    background: var(--mtg-surface);
  }
}

/* ==========================================================================
   Accessibility & media
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .mtg-card {
    transition: none;
  }

  .mtg-card:hover,
  .mtg-card:focus-visible,
  .mtg-card:active {
    transform: none;
  }
}

@media (forced-colors: active) {
  .mtg-card {
    border: 1px solid CanvasText;
  }

  .mtg-card:focus-visible {
    outline: 3px solid Highlight;
  }
}

@media (max-width: 768px) {
  .mtg-root {
    --mtg-gap: 16px;
    --mtg-min-col: 180px;
    padding: 0 16px;
  }

  .mtg-section {
    margin-bottom: 36px;
  }

  .mtg-section-title {
    margin-bottom: 18px;
  }
}

@media (max-width: 480px) {
  .mtg-root {
    --mtg-gap: 12px;
    --mtg-min-col: 150px;
    --mtg-pad: 12px;
    padding: 0 12px;
  }

  .mtg-name {
    font-size: 0.95rem;
  }

  .mtg-count {
    font-size: 0.8rem;
  }
}

@media print {
  .mtg-root {
    max-width: 100%;
    padding: 0;
  }

  .mtg-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }

  .mtg-card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ddd;
    transform: none;
  }
}
