/* ============================================================
   Wawai Cards — screen + print styles
   Card geometry is expressed in inches/points so that what you
   see at 100% zoom is exactly what the printer produces.
   ============================================================ */

:root {
  --card-w: 2.5in;
  --card-h: 3.5in;
  --card-radius: 0.115in;
  --frame: 0.085in;              /* outer coloured border thickness */
  --pad: 0.055in;                /* inner gutter */

  --gold-1: #f7e7a8;
  --gold-2: #d9b64a;
  --gold-3: #a97f22;
  --gold-4: #f3dc93;

  --ink: #17130c;
  --ink-soft: #4a4034;
  --rule: #c9ac62;
  --panel: #fdf8ea;
  --panel-2: #f6eed6;

  --ui-bg: #14161a;
  --ui-panel: #1d2027;
  --ui-line: #2e333d;
  --ui-text: #e7e9ee;
  --ui-dim: #9aa1ae;
  --ui-accent: #d9b64a;

  --cut: #c8c8c8;
}

/* Single warm accent — energy pips, placeholder tile, card-face wash */
.card { --accent: #d9b96a; --accent-wash: #f7efd9; --accent-ink: #6b5218; }

/* ---------------- App chrome (screen only) ---------------- */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ui-bg);
  color: var(--ui-text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--ui-panel);
  border-bottom: 1px solid var(--ui-line);
  padding: 10px 16px;
}

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

.brand {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ui-accent);
}

.spacer { flex: 1 1 auto; }

.ctrl {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--ui-dim);
}

.ctrl.checkbox { cursor: pointer; }

.ctrl select,
.ctrl input[type="range"] {
  accent-color: var(--ui-accent);
}

.ctrl select {
  background: var(--ui-bg);
  color: var(--ui-text);
  border: 1px solid var(--ui-line);
  border-radius: 6px;
  padding: 5px 8px;
  font: inherit;
  font-size: 12px;
}

#zoom-out { min-width: 3.5em; color: var(--ui-text); }

.btn {
  font: inherit;
  font-size: 12px;
  border-radius: 6px;
  padding: 7px 13px;
  cursor: pointer;
  border: 1px solid var(--ui-line);
  background: var(--ui-bg);
  color: var(--ui-text);
}
.btn:hover { border-color: var(--ui-accent); }
.btn.primary {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: #1a1509;
  font-weight: 600;
}
.btn.sm { padding: 4px 10px; }

.status {
  margin: 8px 0 0;
  font-size: 12px;
  color: #f0c05a;
}

.editor { margin-top: 12px; }

.editor-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--ui-dim);
  margin-bottom: 6px;
}
.editor-actions { margin-left: auto; display: flex; gap: 8px; }

#json-input {
  width: 100%;
  height: 320px;
  resize: vertical;
  background: var(--ui-bg);
  color: var(--ui-text);
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  tab-size: 2;
}

.json-error {
  margin: 8px 0 0;
  color: #ff8f7a;
  font-size: 12px;
  font-family: ui-monospace, monospace;
}

.hint { margin: 8px 0 0; font-size: 11px; color: var(--ui-dim); }

.preview {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 26px;
  padding: 28px 24px 60px;
}

/* Zoom without reflowing the card's internal inch-based geometry */
.preview .card-slot {
  transform: scale(var(--zoom, 1));
  transform-origin: top left;
  width: calc(var(--card-w) * var(--zoom, 1));
  height: calc(var(--card-h) * var(--zoom, 1));
}
.preview .card-slot > .card {
  transform-origin: top left;
}

.drop-hint {
  position: fixed;
  inset: auto 0 20px 0;
  margin: auto;
  width: max-content;
  background: var(--ui-accent);
  color: #1a1509;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 50;
}

.card.drop-target { outline: 3px solid #6fd08c; outline-offset: 3px; }

/* ---------------- The card ---------------- */

.card {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--card-radius);
  padding: var(--frame);
  overflow: hidden;
  flex: none;

  /* Gold gradient border */
  background:
    linear-gradient(135deg,
      var(--gold-1) 0%,
      var(--gold-2) 22%,
      var(--gold-4) 40%,
      var(--gold-3) 62%,
      var(--gold-2) 80%,
      var(--gold-1) 100%);

  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  color: var(--ink);
  font-family: "Gill Sans", "Gill Sans MT", "Futura", "Trebuchet MS", sans-serif;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.card-inner {
  position: relative;
  z-index: 1;
  height: 100%;
  border-radius: calc(var(--card-radius) - 0.03in);
  background: linear-gradient(180deg, var(--accent-wash) 0%, var(--panel) 45%, var(--panel-2) 100%);
  border: 0.5pt solid rgba(120, 92, 30, 0.55);
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: 0.035in;
  overflow: hidden;
}

/* --- header --- */

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.05in;
  line-height: 1;
  flex: none;
}

.name {
  margin: 0;
  font-size: 9.5pt;
  font-weight: 700;
  letter-spacing: -0.005em;
  line-height: 0.95;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.head-right {
  display: flex;
  align-items: baseline;
  gap: 0.02in;
  flex: none;
}

.hp-label {
  font-size: 4.6pt;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.hp {
  font-size: 9.5pt;
  font-weight: 700;
  line-height: 1;
}

/* --- photo --- */

/*
 * With one attack and no weakness/resistance/retreat row, the photo absorbs
 * all the slack instead of leaving dead space above the footer.
 */
.photo-frame {
  position: relative;
  flex: 1 1 auto;
  min-height: 1.35in;
  border: 0.045in solid transparent;
  border-radius: 0.03in;
  background:
    linear-gradient(#000, #000) padding-box,
    linear-gradient(135deg, var(--gold-1), var(--gold-3) 45%, var(--gold-4) 70%, var(--gold-2)) border-box;
  overflow: hidden;
}

.photo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30pt;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.75);
  background: linear-gradient(150deg, var(--accent), var(--accent-ink));
  letter-spacing: 0.02em;
}

/* --- subtitle bar --- */

.subtitle-bar {
  display: flex;
  justify-content: center;
  gap: 0.06in;
  font-size: 4.8pt;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: linear-gradient(90deg, transparent, rgba(201, 172, 98, 0.32), transparent);
  border-top: 0.4pt solid var(--rule);
  border-bottom: 0.4pt solid var(--rule);
  padding: 0.018in 0.03in;
  flex: none;
}
.subtitle-bar span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- attacks --- */

.attacks {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 0.028in;
  overflow: hidden;
}

.attack { padding: 0.012in 0; }
.attack + .attack { border-top: 0.4pt solid rgba(201, 172, 98, 0.6); }

.attack-line {
  display: flex;
  align-items: baseline;
  gap: 0.04in;
}

.cost {
  display: flex;
  gap: 0.012in;
  flex: none;
  align-self: center;
}

.pip {
  width: 0.062in;
  height: 0.062in;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #ffffffcc 0%, transparent 58%), var(--accent);
  border: 0.4pt solid rgba(0, 0, 0, 0.3);
}

.attack-name {
  font-size: 7pt;
  font-weight: 700;
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.damage {
  font-size: 8.4pt;
  font-weight: 700;
  flex: none;
  letter-spacing: -0.02em;
}

.attack-text {
  font-size: 5pt;
  line-height: 1.3;
  color: var(--ink-soft);
  margin: 1pt 0 0;
  padding-left: 0.02in;
}

/* --- flavor + footer --- */

.flavor {
  flex: none;
  font-size: 4.8pt;
  line-height: 1.3;
  font-style: italic;
  color: var(--ink-soft);
  padding: 0.02in 0.03in;
  background: rgba(201, 172, 98, 0.14);
  border-radius: 0.02in;
  margin: 0;
}

.card-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.05in;
  font-size: 3.9pt;
  letter-spacing: 0.03em;
  color: rgba(74, 64, 52, 0.85);
  padding-top: 0.012in;
}

.rarity {
  font-size: 5.4pt;
  letter-spacing: 0.06em;
  color: #8a6d1c;
}

.card-foot .num { flex: none; font-weight: 700; }

/* ---------------- Variants ---------------- */

/* holo — shimmer restricted to the photo frame */
.holo-overlay { display: none; }

.card.holo .photo-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      115deg,
      rgba(255, 0, 128, 0.55) 0px,
      rgba(255, 200, 0, 0.55) 14px,
      rgba(0, 255, 170, 0.55) 28px,
      rgba(0, 170, 255, 0.55) 42px,
      rgba(170, 0, 255, 0.55) 56px,
      rgba(255, 0, 128, 0.55) 70px
    ),
    linear-gradient(115deg, rgba(255,255,255,0) 40%, rgba(255,255,255,0.45) 50%, rgba(255,255,255,0) 60%);
  background-size: 200% 200%, 300% 300%;
  /* soft-light tints the photo instead of bleaching it the way overlay does */
  mix-blend-mode: soft-light;
  opacity: 0.55;
  animation: holo-drift 6s ease-in-out infinite alternate;
}

.card.holo .card-inner {
  background:
    linear-gradient(115deg, rgba(255, 210, 255, 0.30), rgba(210, 240, 255, 0.18) 40%, rgba(255, 245, 200, 0.30) 75%),
    linear-gradient(180deg, var(--accent-wash) 0%, var(--panel) 45%, var(--panel-2) 100%);
}

@keyframes holo-drift {
  from { background-position: 0% 50%, 0% 50%; }
  to   { background-position: 100% 50%, 100% 50%; }
}

@media (prefers-reduced-motion: reduce) {
  .card.holo .photo-frame::after { animation: none; }
}

/* fullart — photo becomes the whole card, text sits on a scrim */
.card.fullart .card-inner {
  background: #101010;
  padding: 0;
  gap: 0;
}

.card.fullart .photo-frame {
  position: absolute;
  inset: 0;
  min-height: 0;
  border: none;
  border-radius: 0;
  z-index: 0;
}

.card.fullart .photo-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.55) 0%,
    rgba(0, 0, 0, 0.10) 26%,
    rgba(0, 0, 0, 0.42) 46%,
    rgba(0, 0, 0, 0.86) 68%
  );
}

.card.fullart .card-head,
.card.fullart .subtitle-bar,
.card.fullart .attacks,
.card.fullart .flavor,
.card.fullart .card-foot {
  position: relative;
  z-index: 1;
  color: #fdfbf4;
}

.card.fullart .card-head { padding: var(--pad) var(--pad) 0; }
.card.fullart .hp-label,
.card.fullart .attack-text,
.card.fullart .flavor,
.card.fullart .card-foot { color: rgba(255, 255, 255, 0.86); }

.card.fullart .subtitle-bar {
  margin-top: auto;
  background: rgba(0, 0, 0, 0.35);
  border-color: rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.85);
}

.card.fullart .attacks {
  background: rgba(8, 8, 10, 0.62);
  padding: 0.04in var(--pad);
  backdrop-filter: blur(2px);
}

.card.fullart .attack + .attack { border-top-color: rgba(255, 255, 255, 0.22); }

.card.fullart .flavor {
  background: rgba(8, 8, 10, 0.62);
  border-radius: 0;
  padding: 0.02in var(--pad);
}

.card.fullart .card-foot {
  background: rgba(8, 8, 10, 0.72);
  padding: 0.02in var(--pad) 0.03in;
}

.card.fullart .rarity { color: #f0d68a; }

/* ---------------- Flip-through viewer ---------------- */

.link {
  color: var(--ui-accent);
  text-decoration: none;
  font-size: 12px;
}
.link:hover { text-decoration: underline; }

.viewer-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.viewer {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 4vw, 48px);
  padding: 24px 16px 8px;
}

.stage-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/*
 * The card keeps its true 2.5x3.5in geometry; --view-scale only magnifies it,
 * so nothing inside reflows as you resize.
 */
.stage {
  position: relative;
  width: calc(var(--card-w) * var(--view-scale, 2));
  height: calc(var(--card-h) * var(--view-scale, 2));
  perspective: 1600px;
  touch-action: pan-y;
}

/*
 * Centred in the stage, then magnified about its own centre. `translate` and
 * `scale` are individual transform properties, so the flip keyframes below are
 * free to use `transform` without clobbering either.
 */
.stage > .card {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  scale: var(--view-scale, 2);
  transform-origin: center;
  cursor: grab;
  backface-visibility: hidden;
}

.stage > .card:active { cursor: grabbing; }

@keyframes flip-out-left {
  to { transform: translateX(-14%) rotateY(-75deg); opacity: 0; }
}
@keyframes flip-out-right {
  to { transform: translateX(14%) rotateY(75deg); opacity: 0; }
}
@keyframes flip-in-right {
  from { transform: translateX(14%) rotateY(75deg); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
@keyframes flip-in-left {
  from { transform: translateX(-14%) rotateY(-75deg); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.stage > .flip-out-left  { animation: flip-out-left  260ms ease-in forwards; }
.stage > .flip-out-right { animation: flip-out-right 260ms ease-in forwards; }
.stage > .flip-in-right  { animation: flip-in-right  300ms ease-out backwards; }
.stage > .flip-in-left   { animation: flip-in-left   300ms ease-out backwards; }

@media (prefers-reduced-motion: reduce) {
  .stage > .card { animation: none !important; }
}

.counter {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ui-dim);
}

.nav-btn {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--ui-line);
  background: var(--ui-panel);
  color: var(--ui-text);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  transition: border-color 120ms, color 120ms;
}
.nav-btn:hover { border-color: var(--ui-accent); color: var(--ui-accent); }

.filmstrip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 16px;
  scrollbar-width: thin;
  justify-content: flex-start;
}

.strip-item {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--ui-line);
  background: var(--ui-panel);
  color: var(--ui-dim);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}
.strip-item:hover { border-color: var(--ui-accent); color: var(--ui-text); }

.strip-item.variant-holo    { box-shadow: inset 0 -3px 0 #7fd0e8; }
.strip-item.variant-fullart { box-shadow: inset 0 -3px 0 #e0a94a; }

.strip-item.current {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: #1a1509;
  font-weight: 700;
}

.keyhint {
  margin: 0;
  padding: 0 16px 20px;
  text-align: center;
  font-size: 11px;
  color: var(--ui-dim);
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--ui-line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--ui-panel);
  font-family: ui-monospace, monospace;
  font-size: 10px;
  color: var(--ui-text);
}

/* ---------------- Print sheets ---------------- */

.print-only { display: none; }

.sheet {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), var(--card-w));
  grid-auto-rows: var(--card-h);
  justify-content: center;
  align-content: start;
  gap: 0;
}

.card-slot {
  width: var(--card-w);
  height: var(--card-h);
  position: relative;
}

/* Cut guides sit exactly on the card boundary and add no layout size */
body.guides .sheet .card-slot::after {
  content: "";
  position: absolute;
  inset: 0;
  outline: 0.5pt dashed var(--cut);
  outline-offset: 0;
  pointer-events: none;
  z-index: 5;
}

@media print {
  body {
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .no-print { display: none !important; }
  .print-only { display: block; }

  .card { box-shadow: none; }
  .card.holo .photo-frame::after { animation: none; background-position: 30% 50%, 40% 50%; }

  .sheet { break-after: page; page-break-after: always; }
  .sheet:last-child { break-after: auto; page-break-after: auto; }
  .card-slot { break-inside: avoid; page-break-inside: avoid; }
}
