/* Real MTG card fonts, hotlinked from Card Conjurer via jsDelivr (CORS-enabled, so
   PNG export stays untainted). Beleren = titles/type/P-T; MPlantin = rules text. */
@font-face {
  font-family: "Beleren";
  font-weight: 700;
  src: url("https://cdn.jsdelivr.net/gh/Investigamer/cardconjurer@master/fonts/beleren-b.ttf")
    format("truetype");
}
@font-face {
  font-family: "MPlantin";
  src: url("https://cdn.jsdelivr.net/gh/Investigamer/cardconjurer@master/fonts/mplantin.ttf")
    format("truetype");
}

:root {
  --bg: #1a1a1f;
  --panel: #24242c;
  --text: #e8e8ec;
  --accent: #c08a3e;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid #000;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
}

.toolbar button,
.toolbar-file {
  background: var(--accent);
  color: #1a1a1f;
  border: none;
  border-radius: 5px;
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.toolbar button:hover,
.toolbar-file:hover {
  filter: brightness(1.08);
}

/* A link styled as a toolbar button (e.g. the Gallery link). */
.toolbar-link {
  background: var(--accent);
  color: #1a1a1f;
  border-radius: 5px;
  padding: 0.45rem 0.9rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.toolbar-link:hover {
  filter: brightness(1.08);
}

/* The label is the styled button; the real file input is hidden. */
.toolbar-file input {
  display: none;
}

/* Work-in-progress strip pinned above the header on every page. */
.wip-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.45rem 1.25rem;
  background: #3a2c4a;
  color: #e6d8f3;
  font-size: 0.82rem;
  border-bottom: 1px solid #000;
}

.wip-banner a {
  color: #d9b8ff;
  font-weight: 600;
  text-decoration: none;
}

.wip-banner a:hover {
  text-decoration: underline;
}

.disclaimer {
  padding: 0.5rem 1.25rem;
  background: #4a2a18;
  color: #f3d8c6;
  font-size: 0.8rem;
  border-bottom: 1px solid #000;
}

.frame-notes {
  padding: 0.45rem 1.25rem;
  background: #2e2a14;
  color: #f0e4b0;
  font-size: 0.8rem;
  border-bottom: 1px solid #000;
}

.editor-stage {
  flex: 1;
  display: flex;
  min-height: 0;
}

.editor-panel {
  width: 460px;
  flex-shrink: 0;
  padding: 1.1rem 1.4rem;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid #000;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  /* Allow the field to shrink below its input's intrinsic width inside a row. */
  min-width: 0;
}

/* Only fields inside a row share horizontal space; stacked fields keep their
   natural height instead of stretching to fill the panel. */
.field-row {
  display: flex;
  gap: 0.6rem;
}

.field-row .field {
  flex: 1;
}

.field-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #a8a4ac;
}

.field input,
.field textarea,
.field select {
  background: #15151a;
  border: 1px solid #3a3a44;
  border-radius: 5px;
  color: var(--text);
  padding: 0.4rem 0.5rem;
  font: inherit;
  font-size: 0.9rem;
  /* Fill the field and shrink with it rather than overflowing the panel. */
  width: 100%;
  min-width: 0;
}

.field textarea {
  resize: vertical;
  font-family: "Georgia", serif;
}

/* Collapsible cheat-sheet of {...} symbol tokens under the rules field. */
.symbol-ref {
  background: #15151a;
  border: 1px solid #3a3a44;
  border-radius: 5px;
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
}

.symbol-ref summary {
  cursor: pointer;
  color: #a8a4ac;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  user-select: none;
}

.symbol-ref[open] summary {
  margin-bottom: 0.5rem;
}

.symbol-ref-group + .symbol-ref-group {
  margin-top: 0.55rem;
}

.symbol-ref-group-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #76737c;
  margin-bottom: 0.3rem;
}

.symbol-ref-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.25rem 0.8rem;
}

.symbol-ref-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.symbol-ref-icon {
  width: 1.1em;
  text-align: center;
  font-size: 1.05rem;
}

.symbol-ref-code {
  color: var(--accent);
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
}

.symbol-ref-label {
  color: #8a8a92;
  font-size: 0.78rem;
}

.face-switcher {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
}

.face-tab {
  flex: 1;
  padding: 0.4rem;
  background: #15151a;
  border: 1px solid #3a3a44;
  border-radius: 5px;
  color: #bbb;
  cursor: pointer;
}

.face-tab.active {
  background: var(--accent);
  color: #1a1a1f;
  border-color: var(--accent);
}

.viewport {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: radial-gradient(circle at 50% 40%, #2c2c34 0%, #16161b 70%);
  cursor: grab;
}

.viewport:active {
  cursor: grabbing;
}

/* The stage carries the pan/zoom/rotate transform; the card stays upright inside
   its own coordinate space, so export is unaffected by the viewing angle. */
.viewport-stage {
  transform-origin: center;
}

.viewport-controls {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.35rem;
}

.viewport-controls button {
  background: #24242c;
  border: 1px solid #3a3a44;
  color: var(--text);
  border-radius: 5px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 0.95rem;
}

.viewport-controls button:hover {
  background: #32323c;
}

/* ---- Card rendering ----
   Inline styles carry only geometry (--x/--y/--w/--h) and a few genuinely dynamic
   values (fitted font-size, masks); everything static lives here. */
.card-view {
  position: relative;
  width: var(--w);
  height: var(--h);
  background: #000;
  border-radius: 36px;
  transform: rotate(var(--rot, 0deg));
}

/* Absolute position + size from the inline geometry vars. */
.card-region {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--w);
  height: var(--h);
}

.card-art {
  overflow: hidden;
}
.card-art-img {
  position: absolute;
  left: 50%;
  top: 50%;
  min-width: 100%;
  min-height: 100%;
}

/* Mana cost: right-aligned row of pips. */
.card-mana {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
}

/* Set symbol, centered. */
.card-set {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #222;
}

/* A text box: vertically aligned via --justify; inner element holds the text. */
.card-textbox {
  display: flex;
  flex-direction: column;
  justify-content: var(--justify, center);
  overflow: hidden;
}
.card-text {
  width: 100%;
  line-height: 1.08;
  white-space: pre-wrap;
}

.font-display {
  font-family: "Beleren", "Georgia", serif;
}
.font-body {
  font-family: "MPlantin", "Georgia", serif;
}

/* ---- Frame gallery (?gallery) ---- */
.gallery {
  padding: 1.25rem 1.5rem;
  background: var(--bg);
  min-height: 100vh;
}

.gallery-topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.gallery-back {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #3a3a44;
  border-radius: 5px;
  padding: 0.4rem 0.8rem;
  text-decoration: none;
  font-size: 0.85rem;
}

.gallery-back:hover {
  background: #32323c;
}

.gallery-head {
  font-size: 1.1rem;
  font-weight: 600;
}

.gallery-section {
  margin-bottom: 2.75rem;
}

.gallery-section-title {
  font-size: 1rem;
  font-weight: 600;
  border-bottom: 1px solid #3a3a44;
  padding-bottom: 0.35rem;
  margin-bottom: 0.4rem;
}

.gallery-section-desc {
  color: #a8a4ac;
  font-size: 0.82rem;
  max-width: 72ch;
  margin-bottom: 1.1rem;
}


.gallery-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1.75rem;
}

.gallery-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.gallery-pair {
  display: flex;
  gap: 8px;
}

/* 745x1040 card-space scaled to a thumbnail. */
.mini-wrap {
  width: 248px;
  height: 346px;
  overflow: hidden;
}

/* `zoom`, not `transform: scale()`: zoom re-rasterizes at the final size, so the
   pips' drop-shadow filter (and the SVG symbols) stay crisp. A transform would
   bitmap-scale the already-painted filter buffer and soften the cost. */
.mini-scale {
  zoom: 0.3329;
}

.mini-real {
  width: 248px;
  height: 346px;
  border-radius: 12px;
}

/* Off-design match: a real card with no on-design printing (older frame / un-set /
   unmodeled type), shown for reference with a corner warning so it never reads as a
   clean fidelity comparison. */
.mini-real-wrap {
  position: relative;
  width: 248px;
  height: 346px;
}

.mini-warn {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(28, 28, 34, 0.85);
  border: 1px solid #5a4a2a;
  color: #d8b86a;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: help;
}

.gallery-label {
  color: #cfcfd6;
  font-size: 0.85rem;
}

/* Right-panel placeholder: loading "…", confirmed "no real card", or "⟳ rate-limited"
   (the .mini-note modifier) — the same footprint as a real card image. */
.mini-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 248px;
  height: 346px;
  border: 1px dashed #3a3a44;
  color: #6a6a74;
  font-size: 0.8rem;
  font-style: italic;
  background: #1c1c22;
}

/* Rate-limited: distinct (amber) so a failed lookup never reads as confirmed-absent. */
.mini-placeholder.mini-note {
  border-color: #5a4a2a;
  color: #b59a5a;
}

/* ---- About / features page (?about) ---- */
.about-lede {
  color: #d2d2d8;
  font-size: 0.95rem;
  line-height: 1.5;
  max-width: 78ch;
  margin: 0 0 2.25rem;
}

.philosophy {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  max-width: 78ch;
}

.philosophy-point-title {
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.2rem;
}

.philosophy-point p {
  margin: 0;
  color: #b8b8c0;
  font-size: 0.88rem;
  line-height: 1.5;
}

.feature-group {
  margin-bottom: 1.6rem;
}

.feature-group-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #a8a4ac;
  margin-bottom: 0.55rem;
}

.feature-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 30ch), 1fr));
  gap: 0.45rem 1.5rem;
}

.feature {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
}

.feature-mark {
  flex-shrink: 0;
  font-weight: 700;
  width: 1em;
  text-align: center;
}

.feature.done .feature-mark {
  color: #6fbf73;
}

/* Unchecked rows draw an empty box in CSS so we don't depend on a checkbox glyph
   being present in the system font. */
.feature.todo .feature-mark::before {
  content: "";
  display: inline-block;
  width: 0.62em;
  height: 0.62em;
  border: 1.5px solid #6a6a74;
  border-radius: 2px;
  vertical-align: middle;
  position: relative;
  top: -0.06em;
}

.feature.todo .feature-label {
  color: #9a9aa2;
}

.feature-text {
  display: flex;
  flex-direction: column;
}

.feature-label {
  font-size: 0.9rem;
  color: var(--text);
}

.feature-note {
  font-size: 0.78rem;
  color: #8a8a92;
}

/* Official Scryfall symbol images, sized relative to surrounding text. */
.card-symbol {
  width: auto;
}

.card-mana .card-symbol {
  height: 0.92em;
  vertical-align: -0.11em;
  filter: drop-shadow(-1px 2.5px 0px rgb(0, 0, 0));
}

.card-inline-symbol {
  height: 0.84em;
  vertical-align: -0.07em;
  margin: 0 0.02em;
}
