/* ===== The tool around the artwork =====

   Phone first, and it has to work turned either way:

     portrait  — preview on top capped at 46vh so the controls under it are
                 reachable with a thumb; the download button rides a fixed bar
                 at the bottom of the screen.
     landscape — a phone has almost no height, so the preview moves beside the
                 controls and each side scrolls on its own.

   Desktop is just the landscape rule with a wider panel. Colours and type come
   from the Craftfiti BKK identity. */

:root {
  /* Craftfiti BKK design system (Oct 2026). --gold is the accent slot the UI
     was built around; it now holds ink, and --mustard holds the marker red. */
  --parchment: #ede8dd;
  --parchment-lift: #f6f2ea;
  --ink: #15110d;
  --ink-soft: #3a3128;
  --gold: #15110d;
  --mustard: #a3232b;
  --yellow: #f5d547;
  --muted: #5a5146;
  --line: #d6cdbd;
  --surface: #f6f2ea;
  --tap: 46px;              /* nothing tappable is smaller than this */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: rgba(245, 213, 71, .3); }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--parchment);
  color: var(--ink);
  font-family: Prompt, Poppins, sans-serif;
  font-size: 16px;                       /* 16px keeps iOS from zooming on focus */
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

#root { display: flex; flex-direction: column; min-height: 100%; }

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

.preview-wrap {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding: 8px 8px 6px; background: var(--parchment-lift);
  border-bottom: 1px solid var(--line);
}
/* As big as the screen can give it. The cap is a height budget, not a fixed
   width: the board is 4:5, so its width is whatever is left after the controls
   below it have their room. */
.preview-scaler {
  width: 100%; max-width: min(100%, calc((100vh - 200px) * 0.8));
  aspect-ratio: 1080 / 1350; position: relative;
  box-shadow: 0 2px 14px rgba(17, 17, 17, .10);
}
@supports (height: 100dvh) {
  .preview-scaler { max-width: min(100%, calc((100dvh - 200px) * 0.8)); }
}
/* story 9:16 — same height budget, narrower board */
.preview-scaler.story { aspect-ratio: 1080 / 1920;
  max-width: min(100%, calc((100vh - 200px) * 0.5625)); }
@supports (height: 100dvh) {
  .preview-scaler.story { max-width: min(100%, calc((100dvh - 200px) * 0.5625)); }
}
#artwork { position: absolute; top: 0; left: 0; transform-origin: top left; }

.preview-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; max-width: 460px; font-size: 14px; color: var(--muted);
}
.preview-bar .status { flex: 1 1 auto; min-width: 0; line-height: 1.3; }

/* ---------- panel ---------- */

.panel {
  flex: 1 1 auto; padding: 14px 12px 96px; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.panel-title {
  display: flex; align-items: flex-end; gap: 9px; margin: 0 0 14px; line-height: 1;
}
.panel-title .wordmark {
  font-family: 'Playfair Display', Georgia, serif; font-weight: 900;
  font-size: 22px; letter-spacing: .06em;
}
.panel-title .bkk {
  font-family: 'Permanent Marker', cursive; font-size: 22px; color: var(--mustard);
  transform: rotate(-5deg);
}
.panel-title .dim {
  font-family: Poppins, Prompt, sans-serif; font-weight: 600; font-size: 12px; letter-spacing: .5px;
  text-transform: uppercase; color: var(--muted); padding-bottom: 3px;
}

.tool-group {
  border: 1px solid var(--line); border-radius: 4px; margin-bottom: 10px;
  background: var(--surface);
}
.tool-group > summary {
  cursor: pointer; padding: 0 14px; min-height: var(--tap);
  display: flex; align-items: center; gap: 9px;
  font-family: Poppins, Prompt, sans-serif; font-weight: 600; font-size: 13px; letter-spacing: .5px;
  text-transform: uppercase; color: var(--ink-soft);
  list-style: none; user-select: none;
}
.tool-group > summary::-webkit-details-marker { display: none; }
.tool-group > summary::after {
  content: '+'; margin-left: auto; font-size: 19px; color: var(--gold); line-height: 1;
}
.tool-group[open] > summary::after { content: '–'; }
.tool-group-body { padding: 4px 14px 16px; border-top: 1px solid var(--line); }

.field { margin: 14px 0; }
.field > label {
  display: block; font-size: 12px; letter-spacing: .5px; text-transform: uppercase;
  color: var(--muted); margin-bottom: 7px;
}
input[type=text], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 3px; background: #fff;
  color: var(--ink); font: inherit; font-size: 16px;
}
/* The object text box takes real line breaks, so it has to be a textarea —
   vertical resize only, a horizontal one would break out of the panel. */
textarea { resize: vertical; line-height: 1.4; }

/* A lower-case aside inside an upper-case label. */
.field > label .hint { text-transform: none; letter-spacing: .04em; color: var(--gold); }
.hint { font-size: 12px; color: var(--muted); align-self: center; }
.btn.on { background: var(--gold); border-color: var(--gold); color: var(--yellow); }
input[type=file] { width: 100%; font-size: 14px; }
select { appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--gold) 50%),
                    linear-gradient(135deg, var(--gold) 50%, transparent 50%);
  background-position: right 18px center, right 12px center;
  background-size: 6px 6px, 6px 6px; background-repeat: no-repeat;
  padding-right: 34px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.note { font-size: 14px; color: var(--muted); line-height: 1.5; margin: 8px 0; }

/* template chooser — big tappable rows, not radio dots */
.tpl-list { display: flex; flex-direction: column; gap: 7px; margin: 10px 0 2px; }
.tpl-opt {
  display: flex; align-items: center; gap: 12px; min-height: 58px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 3px;
  background: #fff; cursor: pointer;
}
.tpl-opt input { position: absolute; opacity: 0; pointer-events: none; }
.tpl-opt .num {
  flex: 0 0 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: var(--muted);
}
.tpl-opt .nm { font-family: 'Playfair Display', Georgia, serif; font-weight: 900;
  font-size: 19px; letter-spacing: .09em; }
.tpl-opt .sub { font-size: 13px; color: var(--muted); margin-top: 1px; }
.tpl-opt.on { border-color: var(--gold); background: #f1e2a0; }
.tpl-opt.on .num { border-color: var(--gold); background: var(--gold); color: var(--yellow); }

.fixture-list { display: flex; flex-direction: column; gap: 7px; }
.fixture-row {
  display: flex; align-items: center; gap: 11px; min-height: var(--tap);
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 3px;
  background: #fff; cursor: pointer; font-size: 15px; line-height: 1.3;
}
.fixture-row.on { border-color: var(--gold); background: #f1e2a0; }
.fixture-row .t {
  flex: 0 0 62px; font-family: 'Permanent Marker', cursive; font-size: 15px;
  color: var(--mustard);
}
.fixture-row .g { flex: 1 1 auto; min-width: 0; }
.fixture-row .rank { flex: 0 0 auto; font-size: 12px; color: var(--muted); letter-spacing: .1em; }

.slot-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.slot { border: 1px solid var(--line); border-radius: 3px; padding: 11px; background: #fff; }
.slot-head { display: flex; align-items: baseline; gap: 9px; }
.slot-head .n { font-size: 12px; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); }
.slot-head .team { font-family: 'Playfair Display', Georgia, serif; font-weight: 900;
  font-size: 18px; letter-spacing: .08em; }
.slot-ctl { display: flex; gap: 8px; margin-top: 9px; flex-wrap: wrap; }
.slot-ctl select { flex: 1 1 190px; }
.slot-ctl .btn { flex: 0 0 auto; }
.slot-warn { color: #a3391c; font-size: 13px; margin-top: 7px; line-height: 1.4; }
.slot-noart { color: var(--mustard); font-size: 13px; margin-top: 7px; }
.slot-ok { color: #5d7a45; font-size: 13px; margin-top: 7px; }

.lib-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.lib-row {
  display: flex; align-items: center; gap: 11px; min-height: var(--tap);
  border: 1px solid var(--line); border-radius: 3px; padding: 8px 11px; background: #fff;
}
.lib-thumb { width: 38px; height: 38px; flex: 0 0 auto; background: #EDE6D8;
  border-radius: 2px; overflow: hidden; }
.lib-thumb img { width: 100%; height: 100%; object-fit: contain; }
.lib-row .grow { flex: 1 1 auto; min-width: 0; }
.lib-row .nm { font-size: 16px; }
.lib-row .look { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* ---------- buttons ---------- */

.btn { white-space: nowrap;
  min-height: var(--tap); padding: 0 18px; border: 1px solid var(--ink);
  border-radius: 3px; background: transparent; color: var(--ink);
  font-family: Poppins, Prompt, sans-serif; font-weight: 600; font-size: 13px; letter-spacing: .5px;
  text-transform: uppercase; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  text-decoration: none;
}
.btn:active { background: rgba(17, 17, 17, .06); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--yellow); font-weight: 700; }
.btn.primary:active { background: var(--mustard); border-color: var(--mustard); }
.btn.sm { min-height: 38px; padding: 0 13px; font-size: 12px; letter-spacing: .3px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

/* fixed action bar — always in thumb reach, whichever way the phone is held */
.action-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(247, 243, 235, .96); border-top: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.action-bar .status { flex: 1 1 auto; min-width: 0; font-size: 13px; color: var(--muted);
  line-height: 1.3; }
.action-bar .btn { flex: 0 0 auto; }

/* ---------- landscape phone + anything wide ---------- */

@media (orientation: landscape) and (max-height: 560px), (min-width: 860px) {
  #root { flex-direction: row; height: 100vh; height: 100dvh; overflow: hidden; }

  .preview-wrap {
    flex: 1 1 auto; justify-content: center; min-width: 0; height: 100%;
    padding: 12px; border-bottom: 0; border-right: 1px solid var(--line);
    overflow: hidden;
  }
  /* height, not width, is what runs out in landscape */
  .preview-scaler { max-width: min(100%, calc((100vh - 40px) * 0.8)); }
  .preview-scaler.story { max-width: min(100%, calc((100vh - 40px) * 0.5625)); }

  .panel { flex: 0 0 min(50vw, 400px); height: 100%; padding: 16px 14px 92px; }

  .action-bar { left: auto; width: min(50vw, 400px); right: 0; }
}

@media (min-width: 860px) {
  .preview-scaler { max-width: min(560px, calc((100vh - 56px) * 0.8)); }
  .preview-scaler.story { max-width: min(560px, calc((100vh - 56px) * 0.5625)); }
  .panel { flex: 0 0 400px; }
  .action-bar { width: 400px; }
}

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line);
  cursor: pointer; padding: 0; }
.swatch.on { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(245, 213, 71, .6); }
.slot-frame { display: flex; align-items: center; gap: 10px; margin-top: 9px; }
.slot-frame label { flex: 0 0 auto; font-size: 12px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--muted); }
.slot-frame input[type=range] { flex: 1 1 auto; min-height: 40px; accent-color: var(--mustard); }

/* pose switcher — one button per cut-out a player has */
.pose-row { display: flex; align-items: center; gap: 7px; margin-top: 9px; flex-wrap: wrap; }
.pose-row .lbl { font-size: 12px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--muted); }
.pose { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: #fff; font: inherit; font-size: 15px; color: var(--ink); cursor: pointer; }
.pose.on { border-color: var(--gold); background: var(--gold); color: #fff; }

/* the search hint: exact name to look for, plus a copy button */
.slot-guide { display: flex; align-items: center; gap: 8px; margin-top: 7px; flex-wrap: wrap; }
.slot-guide .q { flex: 1 1 auto; min-width: 0; font-size: 14px; color: var(--ink-soft);
  background: #F4EFE4; border: 1px dashed var(--line); border-radius: 3px; padding: 6px 9px; }
.btn.ghost { border-style: dashed; color: var(--muted); }

/* A brief bar across the preview, for feedback about the artwork that belongs
   next to the artwork rather than down in the action bar. */
.toast {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 12px 14px; background: rgba(17, 17, 17, .86); color: var(--parchment);
  font-size: 14px; letter-spacing: .06em; text-align: center;
  opacity: 0; transform: translateY(100%); pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
}
.toast.on { opacity: 1; transform: translateY(0); }

/* ---------- the manual ---------- */

.panel-title { position: relative; }
.help-btn {
  margin-left: auto; width: 34px; height: 34px; flex: 0 0 auto;
  border: 1px solid var(--gold); border-radius: 50%; background: transparent;
  color: var(--mustard); font-family: 'Playfair Display', Georgia, serif;
  font-size: 19px; line-height: 1; cursor: pointer;
}
.help-btn:active { background: var(--gold); color: #fff; }
.help-btn.fb { margin-left: auto; font-size: 15px; }
.help-btn.fb + .help-btn { margin-left: 8px; }

.help-table { border-collapse: collapse; width: 100%; font-size: 14px; }
.help-table td { padding: 4px 6px 4px 0; vertical-align: top; border-bottom: 1px dashed var(--line); }
.help-table td:first-child { white-space: nowrap; width: 1%; padding-right: 12px; }

/* feedback sheet */
#fb-text { width: 100%; box-sizing: border-box; font: inherit; font-size: 16px; padding: 10px;
  border: 1px solid var(--line); border-radius: 4px; background: #fff; resize: vertical; }
.fb-ctx { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 6px 0 10px; }
.fb-list { margin-top: 16px; font-size: 14px; }
.fb-list .fb-item { padding: 8px 0; border-top: 1px solid var(--line); }
.fb-list .fb-item small { display: block; color: var(--muted); font-size: 12px; }
.fb-list .fb-item.done { opacity: .5; text-decoration: line-through; }

.help-sheet {
  position: fixed; inset: 0; z-index: 40; display: flex;
  align-items: flex-end; justify-content: center;
  background: rgba(17, 17, 17, .45);
}
/* An explicit display beats the hidden attribute's UA rule, so say it here or
   the close button sets hidden and nothing happens. */
.help-sheet[hidden] { display: none; }
.help-card {
  width: 100%; max-width: 560px; max-height: 88vh; display: flex; flex-direction: column;
  background: var(--parchment-lift); border: 1px solid var(--line);
  border-radius: 6px 6px 0 0;
}
.help-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  font-family: Poppins, Prompt, sans-serif; font-weight: 600; font-size: 13px; letter-spacing: .5px;
  text-transform: uppercase; color: var(--ink-soft);
}
.help-close {
  width: 40px; height: 40px; border: 0; background: transparent;
  font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer;
}
.help-body {
  padding: 4px 18px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  font-size: 15px; line-height: 1.65;
}
.help-body h3 {
  font-family: 'Playfair Display', Georgia, serif; font-weight: 900;
  font-size: 20px; letter-spacing: .06em; margin: 20px 0 6px;
  padding-bottom: 5px; border-bottom: 1px solid var(--line);
}
.help-body ol, .help-body ul { margin: 6px 0; padding-left: 20px; }
.help-body li { margin: 6px 0; }
.help-body p { margin: 8px 0; }
.help-note { color: var(--muted); font-size: 14px; }

@media (orientation: landscape) and (max-height: 560px), (min-width: 860px) {
  .help-sheet { align-items: center; }
  .help-card { border-radius: 6px; max-height: 84vh; }
}

/* ---------- quick bar ----------
   Everything you reach for while looking at the artwork — who is in the panel,
   which pose, add or drop a photo — sits directly under the preview. Scrolling
   down to the players group to change a face broke the rhythm of the work. */

.quick {
  width: 100%; max-width: 100%; display: flex; flex-direction: column; gap: 7px;
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--surface);
}
.quick-row { display: flex; align-items: center; gap: 7px; }
.quick-row select { flex: 1 1 auto; min-width: 0; min-height: 42px; }
.quick-badge {
  flex: 0 0 34px; height: 34px; border-radius: 50%; overflow: hidden;
  background: #EDE6D8; display: flex; align-items: center; justify-content: center;
}
.quick-badge img { width: 100%; height: 100%; object-fit: contain; }
.quick-pose {
  flex: 0 0 auto; min-width: 46px; text-align: center; font-size: 14px;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.quick .btn.sm { flex: 0 0 auto; min-height: 42px; white-space: nowrap; padding: 0 10px; }
.quick #quick-paste, .quick #quick-add { flex: 1 1 auto; }
.btn.danger { border-color: #a3391c; color: #a3391c; }
.btn.danger:active { background: rgba(163, 57, 28, .1); }

/* the panel the artwork currently has selected */
/* "this panel is selected" — a dashed line inside the tile, never in the PNG.
   Solid red read as part of the design (Singh, 24 Oct). */
#artwork.editing .slot-box.picked,
#artwork.editing .camp-half.picked,
#artwork.editing .duel-side.picked,
#artwork.editing .derby-side.picked { outline: 3px dashed rgba(21, 17, 13, .55); outline-offset: -10px; }
#artwork.editing.dark .slot-box.picked,
#artwork.editing.dark .camp-half.picked,
#artwork.editing.dark .derby-side.picked { outline-color: rgba(245, 213, 71, .7); }

@media (orientation: landscape) and (max-height: 560px), (min-width: 860px) {
  .quick { max-width: 560px; }
}

.quick-warn { font-size: 13px; line-height: 1.4; color: #a3391c; padding: 0 2px; }
