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

:root {
  --page-bg: var(--themes-page-bg);
  --panel-bg: var(--themes-panel-bg);
  --border: var(--themes-border);
  --text: var(--themes-text, #0f172a);
  --text-muted: var(--themes-text-muted, #64748b);
  --accent: var(--themes-accent, #2563eb);
  --radius: 16px;

  --themes-text: #0f172a;
  --themes-text-muted: #475569;
  --themes-accent: var(--portal-accent, #1d4ed8);
}

html {
  -webkit-font-smoothing: antialiased;
}

body.themes-page-body {
  background: var(--themes-page-bg);
  color: var(--themes-text);
  /* Keep themes slightly narrower than designs for denser browsing. */
  --ecard-preview-fit-max-w: 340px;
  --ecard-preview-device-max-w: 320px;
  --ecard-preview-fit-max-h: 620px;
}

.mkt-page--themes.themes-page-body {
  background: transparent;
}

.mkt-page--themes .themes-page {
  background: transparent;
}

.mkt-page--themes .themes-main {
  width: 100%;
  max-width: min(1200px, 100%);
  margin: 0 auto;
  padding-top: 0;
}

.themes-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.themes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(16px, env(safe-area-inset-top)) 20px 16px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.themes-header__brand {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.themes-header__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.themes-back-btn,
.themes-menu-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.themes-back-btn:hover,
.themes-menu-btn:hover {
  background: #f8fafc;
}

.themes-main {
  flex: 1;
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 28px 20px 40px;
}

.themes-intro {
  margin-bottom: 28px;
}

.themes-intro h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  margin-bottom: 8px;
}

.themes-intro p {
  color: var(--text-muted);
  line-height: 1.5;
  max-width: 52ch;
}

.themes-signin {
  padding: 20px;
  border-radius: var(--radius);
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  margin-bottom: 24px;
}

.themes-tabs-wrap {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 24px;
  margin-left: -20px;
  margin-right: -20px;
  padding: 0 20px 4px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}

@media (hover: none), (pointer: coarse) {
  .themes-tabs-wrap {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .themes-tabs-wrap::-webkit-scrollbar {
    display: none;
    height: 0;
  }
}

@media (hover: hover) and (pointer: fine) {
  .themes-tabs-wrap {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  }

  .themes-tabs-wrap::-webkit-scrollbar {
    height: 6px;
  }

  .themes-tabs-wrap::-webkit-scrollbar-track {
    background: var(--scrollbar-track, transparent);
  }

  .themes-tabs-wrap::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb, color-mix(in srgb, var(--accent, #2563eb) 45%, var(--page-bg, #f8fafc)));
    border-radius: 999px;
  }
}

.themes-tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  flex: 0 0 auto;
}

.themes-tab {
  appearance: none;
  flex: 0 0 auto;
  scroll-snap-align: start;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background 0.18s ease,
    color 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.themes-tab:hover {
  background: #f8fafc;
  color: var(--text);
}

.themes-tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(29, 78, 216, 0.28);
}

.themes-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.themes-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--portal-space-9, 48px) var(--portal-space-6, 24px);
  border-radius: var(--radius);
  background: var(--portal-surface-muted, #f8f9fb);
  border: 1px dashed var(--border);
}

.themes-empty__title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.themes-empty__text {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
  max-width: 36ch;
  margin: 0 auto;
}

.themes-gallery-head {
  margin-bottom: 8px;
}

.themes-gallery-head p {
  font-size: 14px;
  color: var(--text-muted);
}

.themes-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 28px;
}

@media (min-width: 640px) {
  .themes-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
  }
}

@media (min-width: 1100px) {
  .themes-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 28px;
  }
}

.theme-card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
  content-visibility: auto;
  contain-intrinsic-size: auto 640px;
  transition:
    transform 0.22s ease,
    box-shadow 0.22s ease;
}

.theme-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.12);
}

.theme-card.is-active {
  border-color: rgba(29, 78, 216, 0.45);
  box-shadow:
    0 0 0 2px rgba(29, 78, 216, 0.18),
    0 20px 48px rgba(29, 78, 216, 0.1);
}

.theme-card__body {
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.theme-card__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.theme-card__title {
  font-size: 1rem;
  font-weight: 700;
}

.theme-card__badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--portal-accent-soft, rgba(29, 78, 216, 0.12));
  padding: 4px 10px;
  border-radius: 999px;
}

.theme-card__desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
}

.theme-card__actions {
  display: flex;
  gap: 10px;
}

.theme-card__apply {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 11px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
}

.theme-card__apply {
  background: #e2e8f0;
  color: #64748b;
}

.theme-card__apply:not(:disabled) {
  background: var(--accent);
  color: #fff;
}

.theme-card__apply:disabled {
  cursor: default;
}

#themes-toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--portal-duration, 0.22s) ease, transform var(--portal-duration, 0.22s) ease;
  background: var(--portal-surface, #fff);
  color: var(--portal-text, #0f172a);
  border: 1px solid var(--portal-border, rgba(0, 0, 0, 0.08));
  padding: 13px 20px;
  border-radius: var(--portal-radius-sm, 10px);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--portal-shadow-lg, 0 16px 48px rgba(15, 23, 42, 0.1));
  z-index: 2000;
}

#themes-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#themes-toast.is-error {
  background: color-mix(in srgb, #dc2626 8%, var(--portal-surface, #fff));
  border-color: color-mix(in srgb, #dc2626 35%, var(--portal-border, rgba(0, 0, 0, 0.08)));
  color: var(--portal-text, #0f172a);
}

/* Dropdown layout/animation: theme-app.css (avoid duplicate positioning here) */

.menu-dropdown__item {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.menu-dropdown__item:hover {
  background: #f1f5f9;
}

.menu-dropdown__item[hidden] {
  display: none !important;
}

.themes-header__actions .menu-control {
  position: relative;
  flex-shrink: 0;
}

.menu-dropdown__divider {
  height: 1px;
  margin: 4px 6px;
  background: var(--border);
}
