/* ===== Fonts ===== */
@font-face {
  font-family: "Supermolot";
  src: url("fonts/TT-Supermolot-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Supermolot";
  src: url("fonts/TT-Supermolot-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

/* ===== Theme ===== */
:root {
  --bg: #0c0e14;
  --bg-2: #141823;
  --panel: #161b27;
  --panel-2: #1d2433;
  --line: #2a3244;
  --line-2: #38445c;
  --text: #e8ecf4;
  --muted: #8b96ac;
  --accent: #41e0d0;
  --accent-2: #2bb6c8;
  --danger: #ff6b6b;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* the hidden attribute must win over display:flex etc. */

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Supermolot", system-ui, -apple-system, "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, #1a2336 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #18283a 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 14, 20, 0.75);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { color: var(--accent); font-size: 18px; }
.brand h1 {
  font-size: 20px;
  letter-spacing: 4px;
  margin: 0;
  font-weight: 700;
}
.brand-sub { color: var(--muted); font-size: 12px; letter-spacing: 2px; text-transform: uppercase; }
.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== Layout ===== */
.layout {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(360px, 1fr) minmax(240px, 320px);
  gap: 18px;
  padding: 18px;
  align-items: start;
  max-width: 1500px;
  margin: 0 auto;
}
.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.leftcol { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.editor { padding: 18px; }
.preview {
  padding: 18px;
  position: sticky;
  top: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.rightcol { display: flex; flex-direction: column; gap: 18px; min-width: 0; position: sticky; top: 84px; }
.deck { padding: 16px; }
.mydecks { padding: 16px; }

/* ===== Fields ===== */
.field { margin-bottom: 16px; }
.field > label {
  display: block;
  font-size: 13px;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  color: var(--text);
  font-weight: 700;
  text-transform: uppercase;
}
.hint { color: var(--muted); font-weight: 400; font-size: 12px; text-transform: none; letter-spacing: 0; }
.hint.mb { display: block; margin-bottom: 8px; }
.mb { margin-bottom: 8px; }

input[type="text"], textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(43, 182, 200, 0.15);
}

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Rich-text toolbar (panels) */
.rt-toolbar { display: flex; gap: 6px; margin-bottom: 6px; }
.rt-btn {
  width: 30px;
  height: 28px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: background 0.12s, border-color 0.12s;
}
.rt-btn:hover { background: #232c3e; border-color: var(--accent-2); }
/* floating formatting toolbar that pops up above a panel text selection */
.sel-toolbar {
  position: fixed;
  z-index: 120;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  transform: translate(-50%, -100%); /* centred above the anchor point */
}
.sel-toolbar[hidden] { display: none; }
.sel-toolbar .rt-btn { width: 32px; height: 30px; }
code {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  font-size: 11px;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  text-transform: none;
}
.file-name { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }

/* ===== Buttons ===== */
.btn {
  appearance: none;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: #232c3e; border-color: var(--accent-2); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #04212a;
  border-color: transparent;
}
.btn-primary:hover { filter: brightness(1.08); background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%); }
.btn-ghost { background: transparent; }
.btn-danger { border-color: rgba(255, 107, 107, 0.5); color: var(--danger); }
.btn-danger:hover { background: rgba(255, 107, 107, 0.12); border-color: var(--danger); }

/* Top-bar actions: minimalist, flat buttons (like the deck-card icon actions) —
   muted by default, quiet hover, and the save action gets a subtle accent only. */
.topbar-actions .btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 7px 12px;
}
.topbar-actions .btn:hover { background: var(--panel-2); border-color: var(--line-2); color: var(--text); }
.topbar-actions .btn-primary {
  background: transparent;
  border-color: rgba(65, 224, 208, 0.45);
  color: var(--accent);
}
.topbar-actions .btn-primary:hover {
  background: rgba(65, 224, 208, 0.12);
  border-color: var(--accent);
  color: var(--accent);
  filter: none;
}
.topbar-actions .btn-ghost { border-color: transparent; color: var(--muted); }
.topbar-actions .btn-ghost:hover { background: var(--panel-2); border-color: var(--line); color: var(--text); }

/* Segmented toggles (card type, front/back) */
.type-toggle, .seg { display: flex; gap: 0; margin-bottom: 16px; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.side-toggle { max-width: 220px; }
.seg-btn {
  flex: 1;
  background: var(--panel-2);
  border: none;
  border-right: 1px solid var(--line-2);
  color: var(--muted);
  padding: 9px 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%); color: #04212a; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-file { position: relative; overflow: hidden; display: inline-flex; align-items: center; }
.link { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* ===== Divider ===== */
.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 22px 0 6px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }

/* ===== Background picker ===== */
/* Toggle switch (modern on/off control), themed to match the segmented toggles.
   `label.switch` beats `.field > label` (same specificity, declared later) so the
   field-label block/uppercase styles don't leak in and break the flex layout. */
label.switch { display: inline-flex; align-items: center; gap: 10px; margin: 4px 0 12px; cursor: pointer; user-select: none; text-transform: none; font-weight: 400; letter-spacing: normal; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: relative;
  flex: none;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line-2);
  transition: background 0.18s, border-color 0.18s;
}
.switch-slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.18s, background 0.18s;
}
.switch input:checked + .switch-slider { background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%); border-color: transparent; }
.switch input:checked + .switch-slider::after { transform: translateX(16px); background: #04212a; }
.switch input:focus-visible + .switch-slider { box-shadow: 0 0 0 2px rgba(65, 224, 208, 0.45); }

/* Dropdown menu (Export button): same visual language as the custom selects */
.menu-wrap { position: relative; }
.menu-chev { color: var(--accent); font-size: 10px; line-height: 1; margin-left: 2px; transition: transform 0.18s ease; }
.menu-wrap.open .menu-chev { transform: rotate(180deg); }
.dropdown-menu {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0;
  min-width: 240px; margin: 0; padding: 6px;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transform: translateY(-4px) scale(0.99); transform-origin: top left;
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0.14s;
}
.menu-wrap.open .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.dropdown-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  width: 100%; padding: 8px 10px; border: none; border-radius: 6px; background: none;
  font-family: inherit; font-size: 12px; color: var(--text); text-align: left; cursor: pointer;
  transition: background 0.1s;
}
.dropdown-item:hover, .dropdown-item:focus-visible { background: #232c3e; outline: none; }
.dropdown-item small { color: var(--muted); font-size: 11px; }
.dropdown-sep { height: 1px; margin: 6px 4px; background: var(--line); }
.dropdown-note { padding: 4px 10px 6px; color: var(--muted); font-size: 10.5px; line-height: 1.35; }
.dropdown-note b { color: var(--text); font-weight: 600; }
.switch-text { color: var(--muted); font-size: 12px; font-weight: 400; text-transform: none; letter-spacing: normal; transition: color 0.15s; }
.bg-side { max-width: 220px; margin-bottom: 12px; } /* Front/Back bg selector for the compile card */
.switch:hover .switch-text { color: var(--text); }
.switch:hover input:not(:checked) + .switch-slider { border-color: var(--accent-2); }
/* Modern dropdown (glitch presets) */
.select-row { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; }
.select-row-label { color: var(--muted); font-size: 12px; white-space: nowrap; }
.field-select {
  flex: 1;
  appearance: none; -webkit-appearance: none;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2341e0d0' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 28px 8px 10px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.field-select:hover { border-color: var(--line-2); }
.field-select:focus { outline: none; border-color: var(--accent-2); }

/* Custom dropdown (themed popup the native <select> can't provide). The original
   <select> stays in the DOM as the state source but is visually hidden. */
.cselect-native { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.cselect { position: relative; flex: 1; }
.cselect-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; color: var(--text);
  padding: 8px 10px; font-family: inherit; font-size: 12px; cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.cselect-btn:hover { border-color: var(--line-2); }
.cselect.open .cselect-btn, .cselect-btn:focus-visible { outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(65, 224, 208, 0.12); }
.cselect-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cselect-chev { color: var(--accent); font-size: 10px; line-height: 1; transition: transform 0.18s ease; }
.cselect.open .cselect-chev { transform: rotate(180deg); }
.cselect-menu {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; right: 0;
  max-height: 264px; overflow-y: auto; margin: 0; padding: 6px; list-style: none;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transform: translateY(-4px) scale(0.99); transform-origin: top center;
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0.14s;
}
.cselect.open .cselect-menu { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.cselect-opt {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 6px;
  font-size: 12px; color: var(--text); cursor: pointer; transition: background 0.1s;
}
.cselect-opt.active { background: #232c3e; }
.cselect-opt.is-selected { color: var(--accent); font-weight: 700; }
.cselect-opt.is-selected::after { content: "✓"; margin-left: auto; color: var(--accent); }
.cselect-menu::-webkit-scrollbar { width: 8px; }
.cselect-menu::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; }
.bg-tools { display: flex; gap: 10px; margin-bottom: 12px; }
.bg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 4px;
}
.bg-grid::-webkit-scrollbar { width: 8px; }
.bg-grid::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; }
.bg-thumb {
  position: relative;
  aspect-ratio: 744 / 1039;
  border-radius: 7px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  background: var(--bg) center/cover no-repeat;
  padding: 0;
}
.bg-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bg-del {
  position: absolute;
  top: 2px; right: 2px;
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 10, 16, 0.8);
  color: #fff;
  border-radius: 5px;
  font-size: 14px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.12s, background 0.12s;
}
.bg-thumb:hover .bg-del { opacity: 1; }
.bg-del:hover { background: var(--danger); }
.bg-thumb:hover { border-color: var(--line-2); }
.bg-thumb.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(65, 224, 208, 0.35); }

/* ===== Preview stage ===== */
.stage {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background:
    repeating-conic-gradient(#10141d 0% 25%, #0b0e15 0% 50%) 50% / 22px 22px;
  border-radius: 10px;
  padding: 16px;
  border: 1px solid var(--line);
}

/* Reusable small spinner (same animation as the share-gallery loader). */
.spin {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(65, 224, 208, 0.16);
  border-top-color: var(--accent); border-right-color: var(--accent-2);
  animation: loader-spin 0.95s cubic-bezier(0.5, 0.1, 0.4, 0.9) infinite;
}
/* Editor preview loading overlay (heavy card / deck still rendering). */
.preview-loading {
  display: none; position: absolute; inset: 0; z-index: 8;
  align-items: center; justify-content: center;
  background: rgba(8, 10, 16, 0.55); backdrop-filter: blur(2px); border-radius: 10px;
}
.stage.loading .preview-loading { display: flex; }
.card-canvas {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 74vh;
  border-radius: 14px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.6);
  display: block;
  touch-action: none;
}
.card-holder[hidden] { display: none; }
.card-canvas.shift-grab { cursor: grab; } /* only while Shift is held (pan/zoom mode) */
.card-canvas.grabbing { cursor: grabbing; }
.render-hint { color: var(--muted); font-size: 12px; margin: 12px 0 0; min-height: 14px; }

/* ---- In-card editable text overlay ---- */
.card-holder { position: relative; display: inline-block; max-width: 100%; line-height: 0; }
.card-overlay { position: absolute; inset: 0; pointer-events: none; }
.card-overlay .ovl {
  position: absolute;
  display: none; /* shown + positioned per card kind/side by layoutOverlay() */
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent; /* keep typed text invisible (canvas shows it) */
  caret-color: var(--accent);
  pointer-events: auto;
  resize: none;
  overflow: hidden;
  outline: none;
  line-height: 1;
  border-radius: 4px;
  white-space: nowrap;
  transition: background 0.12s, box-shadow 0.12s;
}
.card-overlay .ovl-multiline { white-space: pre-wrap; overflow-wrap: anywhere; }
.card-overlay .ovl-code { text-align: right; text-transform: uppercase; } /* rotated set code; transform + origin set by layoutCodeField */
.card-overlay.panning .ovl,
.card-overlay.panning .ovl-logo { pointer-events: none; } /* let Ctrl+drag/scroll pan the background */
/* clickable logo hotspot over the hexagon */
.card-overlay .ovl-logo {
  position: absolute;
  display: none; /* positioned + shown by layoutOverlay */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15em;
  box-sizing: border-box;
  padding: 0;
  border: 1.5px dashed rgba(65, 224, 208, 0.55);
  border-radius: 14px;
  background: rgba(10, 12, 18, 0.32);
  color: rgba(255, 255, 255, 0.82);
  pointer-events: auto;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
.card-overlay .ovl-logo:hover { background: rgba(65, 224, 208, 0.18); border-color: var(--accent); }
.card-overlay .ovl-logo .ovl-logo-ico { font-size: 1.7em; line-height: 1; font-weight: 700; }
.card-overlay .ovl-logo .ovl-logo-txt { font-size: 0.62em; letter-spacing: 1.5px; text-transform: uppercase; }
/* once a logo is set, stay out of the way until hovered, then offer a swap */
.card-overlay .ovl-logo.has-logo { opacity: 0; border-color: transparent; background: transparent; }
.card-overlay .ovl-logo.has-logo:hover { opacity: 1; background: rgba(10, 12, 18, 0.5); border-style: solid; border-color: var(--accent); }
.card-overlay .ovl-logo.has-logo .ovl-logo-txt { display: none; }
/* contenteditable panels: placeholder + match canvas glyph widths (bold uses the bold face) */
.card-overlay .ovl[contenteditable]:empty::before {
  content: attr(data-placeholder);
  color: rgba(255, 255, 255, 0.34);
  -webkit-text-fill-color: rgba(255, 255, 255, 0.34);
  pointer-events: none;
}
.card-overlay .ovl-multiline b,
.card-overlay .ovl-multiline strong,
.card-overlay .ovl-multiline [style*="font-weight"] { font-weight: normal; font-family: SupermolotB; }
.card-overlay .ovl-multiline u,
.card-overlay .ovl-multiline ins { text-decoration: none; }
/* Briefly toggled on (by the format buttons) to restore NATIVE bold/underline so
   queryCommandState() sees the real formatting and execCommand can toggle it OFF.
   Without this the rules above hide bold/underline from the browser, so re-clicking
   the button could never remove it. Removed again the same tick. */
.card-overlay .ovl-multiline.rt-native b,
.card-overlay .ovl-multiline.rt-native strong { font-weight: bold; }
.card-overlay .ovl-multiline.rt-native u,
.card-overlay .ovl-multiline.rt-native ins { text-decoration: underline; }
.card-overlay .ovl::placeholder { color: rgba(255, 255, 255, 0.34); -webkit-text-fill-color: rgba(255, 255, 255, 0.34); }
.card-overlay .ovl::selection { background: rgba(65, 224, 208, 0.35); }
.card-overlay .ovl:hover { background: rgba(65, 224, 208, 0.08); box-shadow: inset 0 0 0 1px rgba(65, 224, 208, 0.4); cursor: text; }
.card-overlay .ovl:focus { background: rgba(65, 224, 208, 0.12); box-shadow: inset 0 0 0 1.5px var(--accent); }
.edit-tip { color: var(--muted); font-size: 12px; margin: 0 0 14px; padding: 8px 10px; background: var(--panel-2); border: 1px dashed var(--line-2); border-radius: 8px; }

/* ===== Background adjust (pan/zoom) ===== */
.bg-adjust { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.bg-adjust .row { gap: 8px; }
.bg-adjust input[type="range"] {
  flex: 1;
  min-width: 80px;
  accent-color: var(--accent);
  cursor: pointer;
}
#bgZoomVal { min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

/* ===== Edit status ===== */
/* ===== Deck ===== */
.deck-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.deck-head h2 { font-size: 15px; letter-spacing: 2px; margin: 0; text-transform: uppercase; }
.count {
  background: var(--accent);
  color: #04212a;
  border-radius: 20px;
  padding: 1px 8px;
  font-size: 12px;
  margin-left: 6px;
}
.deck-menu { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.deck-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 30px 10px; line-height: 1.6; }
/* align-items:start stops grid items from stretching to the row height. Without
   it, Chrome resizes the aspect-ratio thumbnail to the (stretched) row height
   instead of the column width, which pushed the .dc-actions bar out of the
   overflow:hidden card so the delete/download icons vanished. Firefox was fine. */
.deck-list { display: grid; grid-template-columns: repeat(2, 1fr); align-items: start; gap: 10px; max-height: 70vh; overflow-y: auto; padding-right: 4px; }
.deck-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.deck-card.editing { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(65, 224, 208, 0.4); }
.dc-open {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.dc-open img { width: 100%; display: block; aspect-ratio: 744 / 1039; object-fit: contain; background: #05070c; transition: filter 0.15s; }
.dc-spin { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; background: rgba(8, 10, 16, 0.5); }
.dc-spin .spin { width: 26px; height: 26px; border-width: 3px; }
.dc-open.loading .dc-spin { display: flex; }
.dc-open.loading img { opacity: 0.12; }
.dc-open:hover img { filter: brightness(1.12); }
.deck-card .dc-actions { display: flex; border-top: 1px solid var(--line); }
.deck-card .dc-actions button {
  flex: 1;
  background: var(--panel);
  border: none;
  border-right: 1px solid var(--line);
  color: var(--muted);
  padding: 10px 0;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  transition: background 0.12s, color 0.12s;
}
.deck-card .dc-actions button.dup { font-size: 23px; } /* the ⧉ glyph renders small */
.deck-card .dc-actions button:last-child { border-right: none; }
.deck-card .dc-actions button:hover { background: var(--panel-2); color: var(--text); }
.deck-card .dc-actions button.del { color: var(--danger); }
.deck-card .dc-actions button.del:hover { background: rgba(255, 107, 107, 0.14); color: var(--danger); }

/* "＋ New card" placeholder tile at the end of the deck list */
.deck-card-new {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  aspect-ratio: 744 / 1039;
  border: 2px dashed var(--line-2);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.deck-card-new:hover { border-color: var(--accent-2); color: var(--text); background: rgba(65, 224, 208, 0.05); }
.deck-card-new .dcn-plus { font-size: 34px; line-height: 1; }
.deck-card-new .dcn-txt { font-size: 12px; letter-spacing: 0.5px; }

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr 1fr; }
  .rightcol { grid-column: 1 / -1; position: static; }
  .deck-list { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .preview { position: static; order: -1; }
  .topbar { padding: 12px 14px; }
  .brand h1 { font-size: 17px; }
}

/* small thumbnail preview (uploaded logo) */
.thumb-preview {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: #05070c;
  padding: 2px;
}

/* ===== Shared-deck gallery ===== */
.share-view[hidden] { display: none; }
.share-view {
  position: fixed;
  inset: 0;
  z-index: 90;
  background:
    radial-gradient(1200px 600px at 80% -10%, #1a2336 0%, transparent 60%),
    var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.share-view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 14, 20, 0.8);
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
}
.share-view-title { display: flex; align-items: center; gap: 10px; }
.share-view-title h2 { margin: 0; font-size: 18px; letter-spacing: 1px; }
.share-view-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.share-grid {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px;
}
.sg-protocol { display: flex; flex-wrap: wrap; gap: 22px; justify-content: center; }
.sg-protocol .sg-card { width: min(620px, 100%); }   /* landscape card at a generous size */
.sg-values {
  display: grid;
  grid-template-columns: repeat(3, 1fr); /* 3-wide mosaic (3×2 for six value cards) */
  gap: 0;                                 /* edge to edge so the backgrounds tile */
  align-content: start;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
}
.sg-values .sg-card { background: none; border: none; border-radius: 0; padding: 0; gap: 0; position: relative; }
.sg-values .sg-card img { border-radius: 0; }
.sg-values .sg-card .sg-label {
  position: absolute; top: 6px; left: 6px;
  background: rgba(0, 0, 0, 0.55); color: var(--text);
  padding: 2px 7px; border-radius: 4px;
  opacity: 0; transition: opacity 0.15s;
}
.sg-values .sg-card:hover .sg-label { opacity: 1; }
/* On mobile the 3-wide mosaic is too cramped — show the value cards one per row,
   spaced out, with labels always visible (no hover on touch). */
@media (max-width: 720px) {
  .sg-values { grid-template-columns: 1fr; gap: 14px; max-width: 460px; }
  .sg-values .sg-card .sg-label { opacity: 1; }
}
.share-grid .sg-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.share-grid .sg-card img { width: 100%; height: auto; border-radius: 6px; display: block; background: #05070c; }
.share-grid .sg-card .sg-label { font-size: 11px; color: var(--muted); font-weight: 700; letter-spacing: 0.5px; }
.share-grid .sg-empty { color: var(--muted); padding: 30px; }

/* loading state: hide the header and center a big branded loader */
.share-view.loading .share-view-head { display: none; }
.share-view.loading .share-grid { justify-content: center; align-items: center; }
.loader { display: flex; flex-direction: column; align-items: center; gap: 26px; }
.loader-spin {
  position: relative;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  border: 4px solid rgba(65, 224, 208, 0.14);
  border-top-color: var(--accent);
  border-right-color: var(--accent-2);
  animation: loader-spin 0.95s cubic-bezier(0.5, 0.1, 0.4, 0.9) infinite;
  box-shadow: 0 0 40px rgba(65, 224, 208, 0.18);
}
.loader-diamond {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 38px;
  text-shadow: 0 0 22px rgba(65, 224, 208, 0.85);
  animation: loader-pulse 1.5s ease-in-out infinite;
}
.loader-text {
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
}
.loader-text::after { content: ""; animation: loader-dots 1.4s steps(4, end) infinite; }
@keyframes loader-spin { to { transform: rotate(360deg); } }
@keyframes loader-pulse { 0%, 100% { transform: scale(0.82); opacity: 0.65; } 50% { transform: scale(1.12); opacity: 1; } }
@keyframes loader-dots { 0% { content: ""; } 25% { content: "·"; } 50% { content: "··"; } 75% { content: "···"; } }

/* ===== Modal ===== */
.modal-overlay[hidden] { display: none; }
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.66);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  max-width: 380px;
  width: 100%;
}
.modal h3 { margin: 0 0 8px; font-size: 16px; letter-spacing: 0.5px; }
.modal-body { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 16px; }
.modal-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  margin: 0 0 18px;
}
.modal-input:focus { outline: none; border-color: var(--accent-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* Share modal: deck preview image, copyable next to the link */
.modal:has(.share-preview) { max-width: 520px; }
.share-preview { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.share-preview img {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
.share-preview-actions { display: flex; gap: 8px; }
.share-preview small { color: var(--muted); font-size: 12px; }

/* ===== Mosaic splitter modal ===== */
.mosaic-modal {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  width: min(92vw, 880px);
}
.mosaic-modal h3 { margin: 0 0 6px; font-size: 16px; letter-spacing: 0.5px; }
.mosaic-tools { display: flex; align-items: center; gap: 12px; margin: 12px 0; flex-wrap: wrap; }
.mosaic-tools input[type="range"] { flex: 1; min-width: 120px; }
.mosaic-stage {
  position: relative;
  width: 100%;
  height: min(58vh, 520px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  touch-action: none;
}
.mosaic-img { position: absolute; top: 0; left: 0; transform-origin: 0 0; user-select: none; -webkit-user-drag: none; pointer-events: none; cursor: grab; }
.mosaic-stage.grabbing { cursor: grabbing; }
.mosaic-stage.grabbing .mosaic-img { cursor: grabbing; }
.mosaic-frame {
  position: absolute;
  pointer-events: none;
  box-shadow: 0 0 0 3000px rgba(4, 6, 10, 0.72);
  outline: 2px solid var(--accent);
  background:
    linear-gradient(to right, transparent calc(33.333% - 1px), rgba(65, 224, 208, 0.6) calc(33.333% - 1px), rgba(65, 224, 208, 0.6) calc(33.333% + 1px), transparent calc(33.333% + 1px)),
    linear-gradient(to right, transparent calc(66.666% - 1px), rgba(65, 224, 208, 0.6) calc(66.666% - 1px), rgba(65, 224, 208, 0.6) calc(66.666% + 1px), transparent calc(66.666% + 1px)),
    linear-gradient(to bottom, transparent calc(50% - 1px), rgba(65, 224, 208, 0.6) calc(50% - 1px), rgba(65, 224, 208, 0.6) calc(50% + 1px), transparent calc(50% + 1px));
}
.mosaic-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.mosaic-btn { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ===== Print & play PDF export modal ===== */
.pdf-modal {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  width: min(92vw, 560px);
}
.pdf-modal h3 { margin: 0 0 6px; font-size: 16px; letter-spacing: 0.5px; }
.pdf-preview {
  display: flex; align-items: center; justify-content: center;
  height: min(46vh, 420px);
  margin: 12px 0 4px;
  padding: 16px;
  background:
    repeating-conic-gradient(#171d29 0% 25%, #1c2331 0% 50%) 50% / 22px 22px; /* subtle checkerboard behind the sheet */
  border: 1px solid var(--line);
  border-radius: 8px;
}
.pdf-sheet {
  position: relative;
  height: 100%;
  max-width: 100%;
  background: #fff;
  box-shadow: 0 3px 16px rgba(0, 0, 0, 0.55);
  /* aspect-ratio is set inline from the chosen paper size */
}
.pdf-cell { position: absolute; overflow: hidden; background: #e9edf2 center / cover no-repeat; }
.pdf-cell.empty { background: repeating-linear-gradient(45deg, #eef1f5 0 6px, #e4e8ee 6px 12px); }
.pdf-cut { position: absolute; outline: 1px dashed rgba(10, 20, 40, 0.45); pointer-events: none; }
.pdf-nav { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 8px 0 2px; }
.pdf-nav .btn { padding: 2px 12px; font-size: 18px; line-height: 1; }
.pdf-page-label { color: var(--muted); font-size: 12px; letter-spacing: 0.5px; min-width: 92px; text-align: center; }
.pdf-options { display: flex; gap: 18px; flex-wrap: wrap; margin: 6px 0 2px; }
.pdf-opt { flex: 1 1 200px; min-width: 180px; }
.pdf-opt-label {
  display: block; margin-bottom: 6px;
  color: var(--muted); font-size: 11px; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase;
}
.pdf-opt .seg { margin-bottom: 0; }
.pdf-summary { margin: 4px 0 10px; color: var(--text); font-size: 13px; }
.pdf-summary b { color: var(--accent); }

/* ===== Saved decks library ===== */
.deck-name-row { display: flex; gap: 8px; margin-bottom: 10px; }
.deck-name-row input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  text-transform: uppercase;
}
.deck-name-row input::placeholder { text-transform: none; }
.deck-name-row input:focus { outline: none; border-color: var(--accent-2); }
.saved-decks { margin-bottom: 12px; border: 1px solid var(--line); border-radius: 8px; }
.saved-decks summary {
  cursor: pointer;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
  user-select: none;
}
.saved-decks[open] summary { border-bottom: 1px solid var(--line); }
.saved-list { max-height: 55vh; overflow-y: auto; }
.saved-list:empty::after { content: "No saved decks yet."; display: block; padding: 12px; color: var(--muted); font-size: 12px; }
.saved-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  background-color: var(--panel-2);
  background-size: cover;
  background-position: center;
}
.saved-row:last-child { border-bottom: none; }
.saved-row { cursor: pointer; transition: box-shadow 0.12s; }
.saved-row:hover { box-shadow: inset 0 0 0 2px var(--line-2); }
.saved-row .sd-name { flex: 1; font-size: 14px; font-weight: 700; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9); }
.saved-row .sd-meta { color: #d6dcea; font-size: 11px; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9); }
.saved-row button.del {
  background: rgba(8, 10, 16, 0.7);
  border: 1px solid rgba(255, 107, 107, 0.5);
  color: var(--danger);
  border-radius: 6px; padding: 4px 8px; font-size: 13px; cursor: pointer;
}
.saved-row button.del:hover { background: rgba(255, 107, 107, 0.16); border-color: var(--danger); }
.saved-row.current { box-shadow: inset 0 0 0 2px var(--accent); }
.saved-row.current:hover { box-shadow: inset 0 0 0 2px var(--accent); }
.saved-list::-webkit-scrollbar { width: 8px; }
.saved-list::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; }

/* scrollbar */
.deck-list::-webkit-scrollbar { width: 8px; }
.deck-list::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; }
