/* Banner maker (/banner, views/crestPartial.jsx) and the small banners shown
   around the game (.crest-inline). The page sits on the parchment panel like
   /inventory; previews and thumbnails are SVG drawn by public/crest-editor.js. */

:root {
  --crest-accent: #b07a22;
  --crest-tile: rgba(0, 0, 0, 0.05);
  --crest-tile-border: rgba(0, 0, 0, 0.12);
  --crest-selected: #b07a22;
  --crest-ok: #2f7d3c;
  --crest-err: #b3372d;
  --crest-hint: #8a5a10;
  --crest-map-bg: #e9dcb8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --crest-accent: #e0b45a;
    --crest-tile: rgba(255, 255, 255, 0.05);
    --crest-tile-border: rgba(255, 255, 255, 0.14);
    --crest-selected: #e0b45a;
    --crest-ok: #79c987;
    --crest-err: #ee8378;
    --crest-hint: #e9be6a;
    --crest-map-bg: #4a4232;
  }
}
:root[data-theme="dark"] {
  --crest-accent: #e0b45a;
  --crest-tile: rgba(255, 255, 255, 0.05);
  --crest-tile-border: rgba(255, 255, 255, 0.14);
  --crest-selected: #e0b45a;
  --crest-ok: #79c987;
  --crest-err: #ee8378;
  --crest-hint: #e9be6a;
  --crest-map-bg: #4a4232;
}

/* ---- small banner anywhere in the game ---------------------------------- */

.crest-inline {
  display: inline-flex;
  vertical-align: middle;
  flex: none;
  line-height: 0;
}
.crest-inline svg,
.crest-inline img {
  display: block;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

/* ---- page --------------------------------------------------------------- */

.crest-page {
  display: flex;
  justify-content: center;
  padding: 16px 12px 40px;
}
.crest-panel {
  width: 100%;
  max-width: 780px;
  box-sizing: border-box;
}
.crest-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 6px;
}
.crest-heading i {
  color: var(--crest-accent);
}
.crest-intro {
  margin: 0 0 12px;
  opacity: 0.8;
}
.crest-login {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
  border-radius: 8px;
  background: var(--crest-tile);
  border: 1px solid var(--crest-tile-border);
}
.crest-msg {
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 10px;
  font-size: 0.9rem;
  border: 1px solid var(--crest-tile-border);
  background: var(--crest-tile);
}
.crest-msg-ok i { color: var(--crest-ok); }
.crest-msg-err { color: var(--crest-err); }

/* ---- preview stage ------------------------------------------------------ */

.crest-stage {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 14px;
  border-radius: 10px;
  background: var(--crest-tile);
  border: 1px solid var(--crest-tile-border);
}
.crest-preview-big {
  width: 160px;
  height: 160px;
  flex: none;
  margin: 0 auto;
}
.crest-preview-big svg {
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.35));
}
.crest-contexts {
  flex: 1 1 220px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.crest-ctx {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.crest-ctx-label {
  width: 96px;
  flex: none;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.7;
  color: var(--text);
}
/* Mirrors the world map: the banner painted inside the territory, the name
   plate just under it (public/worldmap-blobs.js). */
.crest-ctx-map {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 12px 8px;
  border-radius: 8px;
  background: var(--crest-map-bg);
}
.crest-ctx-hex {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 50px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: rgba(59, 125, 216, 0.3);
  line-height: 0;
}
.crest-ctx-maplabel {
  margin-top: -8px;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  color: #fdf6dc;
  background: rgba(40, 30, 15, 0.85);
}
.crest-ctx-battle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 6px;
  border-radius: 999px;
  color: var(--text);
  background: var(--crest-tile);
  border: 1px solid var(--crest-tile-border);
}
.crest-hint {
  margin: 8px 2px 0;
  font-size: 0.8rem;
  color: var(--crest-hint);
}
.crest-hint[hidden] { display: none; }

/* ---- tabs --------------------------------------------------------------- */

.crest-tabs {
  display: flex;
  gap: 6px;
  margin: 14px 0 6px;
  border-bottom: 1px solid var(--crest-tile-border);
}
.crest-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  opacity: 0.7;
}
.crest-tab.is-active {
  opacity: 1;
  border-bottom-color: var(--crest-accent);
  font-weight: 700;
}
.crest-premium-tag {
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 999px;
  color: #3b2a07;
  background: #f0c060;
}
[data-crest-panel][hidden] { display: none; }

/* ---- rows of options ---------------------------------------------------- */

.crest-row {
  margin-top: 12px;
}
.crest-row-label {
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.crest-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.crest-opt {
  position: relative;
  width: 52px;
  height: 52px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 2px solid var(--crest-tile-border);
  background: var(--crest-tile);
  color: var(--text);
  cursor: pointer;
}
.crest-opt-art {
  line-height: 0;
}
.crest-opt.is-selected {
  border-color: var(--crest-selected);
  box-shadow: 0 0 0 2px var(--crest-selected) inset;
}
.crest-opt-locked .crest-opt-art {
  opacity: 0.5;
}
.crest-opt-lock {
  position: absolute;
  right: -4px;
  bottom: -4px;
  padding: 1px 4px;
  border-radius: 999px;
  font-size: 0.6rem;
  font-weight: 700;
  color: #fdf6dc;
  background: rgba(40, 30, 15, 0.9);
  white-space: nowrap;
}
.crest-opt-none {
  font-size: 1.1rem;
  opacity: 0.7;
}
.crest-emblem-groups {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.crest-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 0.75rem;
  color: var(--text);
}
.crest-group-name {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.75;
}
.crest-pack-buy {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--crest-accent);
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
}
.crest-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.crest-swatch {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.35);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.crest-swatch.is-selected {
  outline: 3px solid var(--crest-selected);
  outline-offset: 2px;
}

.crest-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}
.crest-save[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- buy bar ------------------------------------------------------------ */

.crest-buy-bar {
  position: sticky;
  bottom: 8px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #fdf6dc;
  background: rgba(40, 30, 15, 0.94);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.crest-buy-bar[hidden] { display: none; }
.crest-buy-buttons {
  display: inline-flex;
  gap: 6px;
}
.crest-buy-go[hidden] { display: none; }

/* ---- premium free-form -------------------------------------------------- */

.crest-premium-pitch {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  margin-top: 12px;
  border-radius: 10px;
  background: var(--crest-tile);
  border: 1px solid var(--crest-tile-border);
}
.crest-premium-pitch > i {
  font-size: 1.6rem;
  color: #d9a43a;
}
.crest-premium-pitch p {
  margin: 4px 0 10px;
}
.crest-status {
  margin-top: 10px;
  font-size: 0.85rem;
}
.crest-status-approved i { color: var(--crest-ok); }
.crest-status-rejected { color: var(--crest-err); }
.crest-status-pending i { color: var(--crest-hint); }
.crest-pixel-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin: 12px 0 8px;
}
.crest-pixel-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.crest-pixel-palette .crest-swatch {
  width: 26px;
  height: 26px;
}
.crest-paint-erase {
  background: var(--crest-tile);
}
.crest-pixel-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.crest-pixel-buttons .btn.is-selected {
  outline: 2px solid var(--crest-selected);
}
.crest-pixel-row {
  display: flex;
  justify-content: center;
}
.crest-pixel-grid {
  --crest-grid: 24;
  width: min(100%, 432px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(var(--crest-grid), 1fr);
  border: 2px solid rgba(0, 0, 0, 0.5);
  touch-action: none;
  user-select: none;
  background: #777;
}
.crest-cell {
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.12);
}
.crest-cell.is-out {
  opacity: 0.25;
}
.crest-use-form {
  margin-top: 10px;
  text-align: right;
}

.crest-credit {
  margin: 18px 0 0;
  font-size: 0.7rem;
  opacity: 0.6;
}

/* ---- report button on someone's banner ---------------------------------- */

.crest-report-btn {
  border: 0;
  background: none;
  padding: 2px 4px;
  font-size: 0.7rem;
  color: var(--text);
  opacity: 0.6;
  cursor: pointer;
}
.crest-report-done {
  font-size: 0.7rem;
  opacity: 0.8;
}

@media (max-width: 480px) {
  .crest-opt {
    width: 46px;
    height: 46px;
  }
  .crest-ctx-label {
    width: 100%;
  }
}

/* ---- admin review queue (/admin/crests) --------------------------------- */

.admin-crests {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.admin-crest-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border-radius: 10px;
  background: var(--crest-tile);
  border: 1px solid var(--crest-tile-border);
}
.admin-crest-art {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.admin-crest-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 160px;
  font-size: 0.85rem;
}
.admin-crest-flag { color: var(--crest-err); }
.admin-crest-when,
.admin-crest-id { opacity: 0.6; font-size: 0.75rem; }
.admin-crest-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ---- world map ---------------------------------------------------------- */

/* Home capital banner: above the castle, centred, clear of the corner badges. */
.worldmap-hex-crest-flag {
  position: absolute;
  left: 50%;
  top: -4px;
  width: 20px;
  height: 20px;
  transform: translateX(-50%);
  z-index: 3;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}
/* The territory banner (public/worldmap-blobs.js): one per merged territory,
   painted into the land under the castles and clipped to its border. The
   home flag above does the same job with merged territories off, so it steps
   aside while the territory carries the banner. */
.worldmap-blob-crest {
  opacity: 0.9;
}
.worldmap-blobs-on .worldmap-hex-owned:not(.is-blob-revealed) .worldmap-hex-crest-flag {
  opacity: 0;
}
.worldmap-owner-crest {
  margin-right: 2px;
}
.worldmap-owner-banner-link {
  font-size: 0.75rem;
  color: var(--text);
  opacity: 0.8;
  cursor: pointer;
  white-space: nowrap;
}

/* ---- battle ------------------------------------------------------------- */

.player-hpbar-crest {
  width: 18px;
  height: 18px;
  margin-right: 3px;
}
.vs-splash-crest {
  width: 34px;
  height: 34px;
  vertical-align: middle;
  margin-right: 8px;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
}
.game-over-crest {
  width: 36px;
  height: 36px;
  margin-right: 8px;
  vertical-align: middle;
}

/* ---- links into the banner maker ---------------------------------------- */

.inventory-banner-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin: 0 0 14px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  background: var(--crest-tile);
  border: 1px solid var(--crest-tile-border);
  cursor: pointer;
}
.inventory-banner-link > i:first-child {
  font-size: 1.3rem;
  color: var(--crest-accent);
}
.inventory-banner-link > span {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.inventory-banner-sub {
  font-size: 0.8rem;
  opacity: 0.7;
}
.profile-crest {
  margin-right: 4px;
}
.profile-banner-edit {
  cursor: pointer;
  text-decoration: none;
}
