/*
 * app.css — app shell only.
 * Avatar/wardrobe internals are styled by src/avatar.css (owned elsewhere).
 * Mobile-first, designed against a 390px viewport.
 */

:root {
  --bg: #15102a;
  --bg-2: #1e1740;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-2: rgba(255, 255, 255, 0.1);
  --line: rgba(255, 255, 255, 0.12);
  --ink: #f4f1ff;
  --ink-dim: #b4abd6;
  --ink-faint: #8a81ad;
  --accent: #ffc247;
  --accent-ink: #3a2a00;
  --good: #5fe3a1;
  --bad: #ff7a93;
  --radius: 18px;
  --radius-sm: 12px;
  --tabbar-h: 62px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tap: 46px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
}

body {
  background:
    radial-gradient(120% 70% at 50% 0%, #2a2056 0%, rgba(42, 32, 86, 0) 60%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 55%, #0f0b1f 100%);
  background-attachment: fixed;
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* --------------------------------------------------------------- layout */

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-top) + 10px) calc(var(--safe-right) + 16px) 10px
    calc(var(--safe-left) + 16px);
  background: linear-gradient(180deg, rgba(21, 16, 42, 0.95), rgba(21, 16, 42, 0.72));
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar__title {
  font-size: 17px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chip--coins {
  color: var(--accent);
}

.chip--coins.is-bumping {
  animation: coinBump 620ms ease-out;
}

@keyframes coinBump {
  0% { transform: scale(1); }
  30% { transform: scale(1.22); background: rgba(255, 194, 71, 0.22); }
  100% { transform: scale(1); }
}

.views {
  flex: 1 1 auto;
  padding: 0 calc(var(--safe-right) + 16px)
    calc(var(--tabbar-h) + var(--safe-bottom) + 24px) calc(var(--safe-left) + 16px);
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.view {
  display: none;
  padding-top: 16px;
}

.view.is-active {
  display: block;
  animation: viewIn 220ms ease-out;
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------- tab bar */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  padding: 0 calc(var(--safe-right) + 8px) var(--safe-bottom) calc(var(--safe-left) + 8px);
  background: rgba(16, 12, 33, 0.92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1 1 0;
  min-height: var(--tabbar-h);
  min-width: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px;
  color: var(--ink-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: color 160ms ease;
}

.tab__glyph {
  font-size: 20px;
  line-height: 1;
}

.tab[aria-selected='true'] {
  color: var(--ink);
}

.tab[aria-selected='true'] .tab__glyph {
  transform: translateY(-1px) scale(1.08);
}

.tab:active {
  background: var(--surface);
  border-radius: 14px;
}

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.card + .card {
  margin-top: 12px;
}

.section-title {
  margin: 20px 2px 10px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}

.muted {
  color: var(--ink-dim);
}

.empty {
  padding: 22px 16px;
  text-align: center;
  color: var(--ink-dim);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  font-size: 14px;
}

/* ------------------------------------------------------------------ home */

.stage {
  position: relative;
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
  aspect-ratio: 4 / 5; /* matches the avatar viewBox (160x200) */
  max-height: 58vh;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

/* The avatar module adds .av-stage here and owns the artwork's own styling;
   these rules only fit it to the stage box. */
#avatarHost {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 6px;
}

#avatarHost > svg,
#avatarHost .av-root {
  width: 100%;
  height: auto;
  max-height: 100%;
}

.stage.is-poked {
  animation: pokePulse 420ms ease-out;
}

@keyframes pokePulse {
  0% { transform: scale(1); }
  35% { transform: scale(0.976); }
  100% { transform: scale(1); }
}

.stage__hint {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 12px;
  color: var(--ink-faint);
  pointer-events: none;
}

.bubble {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  margin: 0 auto;
  width: fit-content;
  max-width: calc(100% - 24px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #231a3d;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: none;
}

.bubble.is-shown {
  opacity: 1;
  transform: none;
}

.progress {
  margin-top: 14px;
}

.progress__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.progress__count {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.bar__fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--good), #9ef7c8);
  transition: width 420ms cubic-bezier(0.22, 1, 0.36, 1);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}

.stat__value {
  font-size: 19px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.stat__label {
  font-size: 11px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

.up-next {
  display: flex;
  align-items: center;
  gap: 12px;
}

.up-next__text {
  flex: 1 1 auto;
  min-width: 0;
}

.up-next__title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ----------------------------------------------------------------- tasks */

.tasklist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  touch-action: pan-y;
}

.task__swipe {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 18px;
  background: linear-gradient(90deg, rgba(255, 122, 147, 0.12), rgba(255, 122, 147, 0.42));
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.task__row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 10px 12px 12px;
  background: #1b1538;
  transform: translateX(0);
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.task.is-dragging .task__row {
  transition: none;
}

.task.is-done .task__row {
  background: #19143080;
}

.task__check {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  display: grid;
  place-items: center;
  color: transparent;
  font-size: 17px;
  font-weight: 900;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease,
    transform 180ms ease;
}

/* 44px+ target without a 44px box: an invisible hit area around the box. */
.task__checkbtn {
  flex: 0 0 auto;
  min-width: var(--tap);
  min-height: var(--tap);
  display: grid;
  place-items: center;
  margin: -8px 0 -8px -2px;
}

.task.is-done .task__check {
  background: var(--good);
  border-color: var(--good);
  color: #0c2a1c;
}

.task__checkbtn:active .task__check {
  transform: scale(0.88);
}

.task__body {
  flex: 1 1 auto;
  min-width: 0;
}

.task__title {
  font-weight: 600;
  word-break: break-word;
}

.task.is-done .task__title {
  color: var(--ink-faint);
  text-decoration: line-through;
}

.task__meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--ink-faint);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.task__notes {
  margin-top: 3px;
  font-size: 13px;
  color: var(--ink-dim);
  word-break: break-word;
}

.iconbtn {
  flex: 0 0 auto;
  min-width: var(--tap);
  min-height: var(--tap);
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--ink-faint);
  font-size: 17px;
}

.iconbtn:active {
  background: var(--surface-2);
  color: var(--ink);
}

.fab {
  position: fixed;
  right: calc(var(--safe-right) + 16px);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  z-index: 25;
  min-width: 56px;
  min-height: 56px;
  border-radius: 20px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 26px;
  font-weight: 700;
  display: none;
  place-items: center;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.42);
}

.fab.is-shown {
  display: grid;
}

.fab:active {
  transform: scale(0.94);
}

/* -------------------------------------------------------------- wardrobe */

.cattabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 2px 0 10px;
  scroll-snap-type: x proximity;
}

.cattabs::-webkit-scrollbar {
  display: none;
}

.cattab {
  flex: 0 0 auto;
  min-height: var(--tap);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  font-size: 14px;
  font-weight: 600;
  text-transform: capitalize;
  scroll-snap-align: start;
}

.cattab[aria-selected='true'] {
  background: var(--ink);
  border-color: var(--ink);
  color: #1a1333;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

@media (min-width: 420px) {
  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  min-height: 132px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: left;
  transition: border-color 160ms ease, transform 160ms ease;
}

.item:active {
  transform: scale(0.97);
}

.item.is-equipped {
  border-color: var(--good);
  box-shadow: inset 0 0 0 1px var(--good);
}

.item.is-locked {
  opacity: 0.78;
}

.item__art {
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  min-height: 62px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.item__art svg {
  width: 100%;
  height: 100%;
  max-height: 86px;
  display: block;
}

.item__swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
}

.item__name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  word-break: break-word;
}

.item__tag {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.item__tag--owned {
  color: var(--ink-faint);
}

.item__tag--equipped {
  color: var(--good);
}

.item__lock {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 13px;
  opacity: 0.85;
}

/* ----------------------------------------------------------------- sheet */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(8, 5, 18, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.scrim.is-open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  background: #221a47;
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  border-top: 1px solid var(--line);
  padding: 8px calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 16px)
    calc(var(--safe-left) + 16px);
  transform: translateY(102%);
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
  max-height: 86vh;
  overflow-y: auto;
}

.sheet.is-open {
  transform: none;
}

.sheet__grab {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 6px auto 12px;
}

.sheet__title {
  font-size: 18px;
  margin-bottom: 14px;
}

.field {
  display: block;
  margin-bottom: 12px;
}

.field__label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  margin-bottom: 6px;
}

.input,
.textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.24);
  font-size: 16px; /* 16px stops iOS zoom-on-focus */
}

.textarea {
  min-height: 70px;
  resize: vertical;
}

.input:focus,
.textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.segmented {
  display: flex;
  gap: 8px;
}

.segmented__opt {
  flex: 1 1 0;
  min-height: var(--tap);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-dim);
  font-size: 14px;
  font-weight: 600;
}

.segmented__opt[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn {
  width: 100%;
  min-height: 50px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 700;
}

.btn:active {
  transform: scale(0.985);
}

.btn--ghost {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn--danger {
  background: transparent;
  color: var(--bad);
  border: 1px solid rgba(255, 122, 147, 0.4);
}

.btn[disabled] {
  opacity: 0.5;
}

.btnrow {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

/* ----------------------------------------------------- toast + confetti */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 18px);
  z-index: 50;
  transform: translate(-50%, 12px);
  max-width: calc(100vw - 48px);
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(244, 241, 255, 0.96);
  color: #1d1536;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
}

.toast.is-shown {
  opacity: 1;
  transform: translate(-50%, 0);
}

.confetti {
  position: fixed;
  inset: 0;
  z-index: 45;
  pointer-events: none;
  overflow: hidden;
}

.confetti__bit {
  position: absolute;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  will-change: transform, opacity;
  animation: confettiFall var(--dur, 1100ms) cubic-bezier(0.2, 0.6, 0.4, 1) forwards;
}

@keyframes confettiFall {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--dx, 0px), var(--dy, 60vh), 0) rotate(var(--rot, 540deg));
    opacity: 0;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .confetti {
    display: none;
  }
}

/* Inline-SVG glyphs replacing emoji UI chrome: emoji needs a font the
   WebView may not have, and renders as tofu boxes without it. */
.gl{width:1em;height:1em;display:inline-block;vertical-align:-.13em;flex:none}
