/* A class that sets display beats the UA [hidden] rule, so make it win. */
[hidden] { display: none !important; }

/* SwapX web app — mobile first.
   Extends the site design system in /assets/css/main.css.
   81% of traffic is mobile, so every control is sized for a thumb. */

.app-body {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 12px var(--pad);
  padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(10,10,15,.9);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

/* A button, not a label — it opens the shop. */
.credits {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: .85rem; font-weight: 600; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 100px;
  font-family: inherit; cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
}
.credits:hover, .credits:focus-visible { border-color: var(--accent); color: var(--text); }
.credits.is-empty { color: var(--text); border-color: var(--accent); }
.credits__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex-shrink: 0; }
.credits.is-empty .credits__dot { background: var(--warn); }

/* ---------- layout ---------- */
.app {
  flex: 1;
  width: 100%; max-width: 560px;
  margin-inline: auto;
  padding: 24px var(--pad) 40px;
}

.pane { animation: rise .25s ease both; }
.pane--center { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 18px; padding-top: 48px; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .pane { animation: none; } }

.pane__head { margin-bottom: 22px; }
.pane__badge {
  display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--accent); background: var(--accent-soft);
  padding: 5px 12px; border-radius: 100px; margin-bottom: 12px;
}
.pane__title { font-size: clamp(1.45rem, 5vw, 1.9rem); margin-bottom: 8px; }
.pane__hint { color: var(--muted); font-size: .98rem; }

.pane__actions { margin-top: 26px; }
.pane__actions--split { display: grid; grid-template-columns: auto 1fr; gap: 12px; }
.btn--block { width: 100%; }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

/* ---------- upload drop ---------- */
.drop {
  position: relative; display: block; width: 100%;
  aspect-ratio: 3 / 4; max-height: 54svh;
  border: 2px dashed var(--line-strong); border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer; overflow: hidden;
  transition: border-color .2s, background .2s;
}
.drop--sm { aspect-ratio: 4 / 3; max-height: 40svh; }
.drop:hover, .drop:focus-visible, .drop.is-over { border-color: var(--accent); background: var(--surface-2); }
.drop.has-image { border-style: solid; border-color: var(--line); }

.drop__empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 24px; text-align: center;
}
.drop__icon { width: 44px; height: 44px; color: var(--accent); margin-bottom: 6px; }
.drop__label { font-weight: 700; font-size: 1.05rem; }
.drop__sub { color: var(--muted); font-size: .9rem; max-width: 28ch; }
.drop__preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

.drop__clear {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.65); color: #fff; font-size: 1.3rem; line-height: 1;
  cursor: pointer; backdrop-filter: blur(6px);
}
.drop__clear:hover { background: rgba(0,0,0,.85); }

/* ---------- tips ---------- */
.tips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.tip {
  font-size: .8rem; font-weight: 600; padding: 6px 12px; border-radius: 100px;
  border: 1px solid var(--line); color: var(--muted);
}
.tip--good { color: var(--ok); border-color: rgba(52,211,153,.3); }
.tip--bad  { color: var(--muted-2); }

/* ---------- tabs ---------- */
.tabs {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 100px; padding: 4px; margin-bottom: 20px;
}
.tab {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; font-size: .95rem;
  padding: 11px 10px; border-radius: 100px; cursor: pointer;
  transition: background .2s, color .2s;
  white-space: nowrap;
}
.tab.is-active { background: var(--accent); color: #fff; }

/* ---------- template grid ---------- */
.tpl-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 480px) { .tpl-grid { grid-template-columns: repeat(4, 1fr); } }

.tpl {
  position: relative; aspect-ratio: 3 / 4; border-radius: var(--radius-sm);
  overflow: hidden; cursor: pointer; border: 2px solid transparent;
  background: var(--surface-2); padding: 0;
  transition: border-color .15s, transform .15s;
}
.tpl img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tpl:hover { transform: translateY(-2px); }
.tpl.is-selected { border-color: var(--accent); }
.tpl.is-selected::after {
  content: "✓"; position: absolute; top: 6px; right: 6px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: .75rem; display: grid; place-items: center;
}
.tpl__name {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 14px 8px 6px; font-size: .72rem; font-weight: 600;
  background: linear-gradient(transparent, rgba(0,0,0,.8));
  text-align: center;
}

/* ---------- summary ---------- */
.summary {
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; gap: 14px; margin-bottom: 24px;
}
.summary__item { margin: 0; }
.summary__item img, .summary__item video {
  width: 100%; aspect-ratio: 3 / 4; object-fit: cover;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
}
.summary__item figcaption {
  margin-top: 8px; text-align: center; font-size: .82rem;
  color: var(--muted); font-weight: 600;
}
.summary__arrow { width: 26px; height: 26px; color: var(--accent); }

/* ---------- consent ---------- */
.consent {
  display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 16px; cursor: pointer;
}
.consent input { position: absolute; opacity: 0; width: 0; height: 0; }
.consent__box {
  width: 22px; height: 22px; border-radius: 6px; margin-top: 1px;
  border: 2px solid var(--line-strong); flex-shrink: 0;
  display: grid; place-items: center; transition: background .15s, border-color .15s;
}
.consent input:checked + .consent__box { background: var(--accent); border-color: var(--accent); }
.consent input:checked + .consent__box::after { content: "✓"; color: #fff; font-size: .8rem; font-weight: 700; }
.consent input:focus-visible + .consent__box { outline: 2px solid var(--accent); outline-offset: 2px; }
.consent__text { font-size: .9rem; color: var(--muted); line-height: 1.5; }
.consent__text a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

.fineprint { margin-top: 14px; text-align: center; font-size: .85rem; color: var(--muted-2); }

/* ---------- processing ---------- */
.spinner { display: flex; gap: 7px; }
.spinner span {
  width: 11px; height: 11px; border-radius: 50%; background: var(--accent);
  animation: bounce 1.1s infinite ease-in-out;
}
.spinner span:nth-child(2) { animation-delay: .15s; }
.spinner span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }

.progress {
  width: 100%; max-width: 300px; height: 5px;
  background: var(--surface-2); border-radius: 100px; overflow: hidden;
}
.progress__bar {
  height: 100%; width: 0%; background: var(--accent);
  border-radius: 100px; transition: width .4s ease;
}

/* ---------- result ---------- */
.result {
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line); background: var(--surface);
  margin-bottom: 20px;
}
.result img, .result video { width: 100%; display: block; }
.result__actions { display: grid; gap: 10px; }

/* ---------- shop ---------- */
.packs { display: grid; gap: 12px; }
@media (min-width: 520px) { .packs { grid-template-columns: repeat(3, 1fr); } }

.pack {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 22px 16px 18px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--text);
  font-family: inherit; cursor: pointer; text-align: center;
  transition: border-color .15s ease, transform .15s ease;
}
.pack:hover, .pack:focus-visible { border-color: var(--accent); transform: translateY(-2px); }
.pack--best { border-color: var(--accent); }

.pack__tag {
  position: absolute; top: -10px; left: 50%; translate: -50% 0;
  background: var(--accent); color: #fff;
  font-size: .68rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
  padding: 4px 10px; border-radius: 100px; white-space: nowrap;
}
.pack__coins { font-size: 1.15rem; font-weight: 800; }
.pack__price { font-size: 1.9rem; font-weight: 900; color: var(--accent); line-height: 1.1; }
.pack__note  { font-size: .82rem; color: var(--muted-2); }

.rates {
  margin-top: 22px; padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.rates__row {
  display: flex; justify-content: space-between;
  font-size: .88rem; color: var(--muted);
  padding: 5px 0;
}
.rates__row + .rates__row { border-top: 1px solid var(--line); }

/* ---------- recovery code ---------- */
.codebox {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
  padding: 18px;
  background: var(--surface-2); border: 1px solid var(--accent);
  border-radius: var(--radius); margin-bottom: 14px;
}
.codebox code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: clamp(1.05rem, 4.4vw, 1.35rem);
  font-weight: 700; letter-spacing: .06em;
  color: var(--text);
  /* It gets written down and retyped, so it has to be selectable. */
  user-select: all;
}

/* ---------- text field ---------- */
.field { display: block; margin-bottom: 4px; }
.field__label {
  display: block; font-size: .85rem; font-weight: 600;
  color: var(--muted); margin-bottom: 8px;
}
.field__input {
  width: 100%;
  padding: 15px 16px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text); font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.05rem; letter-spacing: .06em;
}
.field__input:focus { outline: none; border-color: var(--accent); }
.field__input::placeholder { color: var(--muted-2); letter-spacing: .04em; }

.fineprint.err { color: var(--accent); }

/* ---------- error ---------- */
.err-icon {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 1.6rem; font-weight: 800;
}

/* ---------- footer ---------- */
.app-footer {
  border-top: 1px solid var(--line);
  padding: 24px var(--pad) calc(24px + env(safe-area-inset-bottom));
  text-align: center;
}
.app-footer nav { display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; margin-bottom: 12px; }
.app-footer a { color: var(--muted); font-size: .9rem; }
.app-footer a:hover { color: var(--accent); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  translate: -50% 0; z-index: 200;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  color: var(--text); font-size: .92rem; font-weight: 500;
  padding: 13px 20px; border-radius: 100px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  animation: toastIn .25s ease both;
  max-width: calc(100vw - 32px);
}
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
