/* base.css — design tokens and shared components (owned by the lead). Modules add their own css/<module>.css. */
:root {
  --font: "Trebuchet MS", sans-serif;
  --ps: 120;            /* ui-panel 9-slice corner in source px */
  --pb: 16px;           /* ui-panel drawn border width */
  --bs: 110;            /* ui-button 9-slice corner in source px */
  --radius: 16px;
}
body[data-theme="witch"] {
  --bg1: #ffe3f1; --bg2: #eadcff; --bg3: #fff6fb;
  --accent: #ff7eb6; --accent2: #b48cff; --accent3: #8fe3cf;
  --ink: #5a2e5e; --ink-soft: #8a5f8e; --card: rgba(255, 250, 253, 0.94);
  --gold: #ffcf6b; --line: #e7c3e9; --btn-filter: none;
}
body[data-theme="mage"] {
  --bg1: #dfe6ff; --bg2: #d9cfff; --bg3: #f4f6ff;
  --accent: #7b8cff; --accent2: #a68bff; --accent3: #9fd8ff;
  --ink: #2c2a5c; --ink-soft: #5d5b8f; --card: rgba(248, 249, 255, 0.94);
  --gold: #ffd36b; --line: #c9cdf0; --btn-filter: hue-rotate(-75deg) saturate(0.85);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: var(--font); color: var(--ink); font-weight: 700;
  background: linear-gradient(180deg, var(--bg1), var(--bg2));
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
#app { position: fixed; inset: 0; overflow: hidden; }
.hidden { display: none !important; }
.screen-layer { position: absolute; inset: 0; }
img.px, canvas.px, .px img { image-rendering: pixelated; image-rendering: crisp-edges; }

/* ---------- outlined display text ---------- */
.outline {
  color: #fff;
  text-shadow: -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink),
    0 -2px 0 var(--ink), 0 2px 0 var(--ink), -2px 0 0 var(--ink), 2px 0 0 var(--ink), 3px 4px 0 rgba(60, 20, 70, 0.35);
}
.h1 { font-size: 24px; font-weight: 900; letter-spacing: 0.5px; }
.h2 { font-size: 19px; font-weight: 900; }
.h3 { font-size: 16px; font-weight: 900; }
.muted { color: var(--ink-soft); font-size: 14px; }
.small { font-size: 12px; }

/* ---------- pixel card (ui-panel 9-slice) ---------- */
/* ui-panel.webp is 512² with the frame drawn at x 17–498, y 115–397: the slices include those transparent margins
   and border-image-outset pushes them outside the box, so the visible frame sits exactly on the 20px border. */
.pcard, .pmodal {
  border: 20px solid transparent;
  border-image-source: url(../assets/ui-panel.webp);
  border-image-slice: 157 56 157 56 fill;
  border-image-width: 78px 28px 78px 28px;
  border-image-outset: 58px 8px 58px 8px;
  border-image-repeat: stretch;
}
.pcard {
  position: relative;
  padding: 2px 4px; margin: 0 0 12px;
  animation: pop-in 0.26s cubic-bezier(.2, 1.4, .4, 1) both;
}
.pcard > .pcard-title {
  display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 16px; font-weight: 900; color: var(--ink);
}
.pcard > .pcard-title img { width: 26px; height: 26px; image-rendering: pixelated; }
.pcard > .pcard-title .spacer { flex: 1; }
/* soft rounded inner card (gradient), for lists inside panels */
.scard {
  background: linear-gradient(135deg, #ffffff, var(--bg3));
  border: 2px solid var(--line); border-radius: 14px; box-shadow: 0 3px 0 var(--line);
  padding: 10px 12px; margin: 0 0 8px;
}

/* ---------- buttons (ui-button 9-slice) ---------- */
.pbtn {
  all: unset; box-sizing: border-box; cursor: pointer; position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; min-width: 76px; padding: 0 22px; flex: none;
  /* ui-button.webp is 384² with the plate at x 6–378, y 135–245: slices + outset crop the transparent margins */
  border: 0 solid transparent;
  border-image-source: url(../assets/ui-button.webp);
  border-image-slice: 185 70 190 70 fill;
  border-image-width: 74px 28px 76px 28px;
  border-image-outset: 54px 2px 56px 2px;
  border-image-repeat: stretch;
  filter: var(--btn-filter);
  font-family: var(--font); font-size: 15px; font-weight: 900; color: #fff; white-space: nowrap;
  text-shadow: -1.5px -1.5px 0 #7a2f5f, 1.5px -1.5px 0 #7a2f5f, -1.5px 1.5px 0 #7a2f5f, 1.5px 1.5px 0 #7a2f5f, 2px 2px 0 rgba(0,0,0,.2);
  transition: transform 0.12s cubic-bezier(.3, 1.6, .5, 1), filter 0.12s;
}
.pbtn > span, .pbtn > img { position: relative; }
.pbtn img { width: 22px; height: 22px; image-rendering: pixelated; }
.pbtn:hover, .pbtn:focus-visible, .pbtn.focus { transform: scale(1.05); filter: var(--btn-filter) brightness(1.1) drop-shadow(0 0 6px rgba(255,255,255,.9)); outline: none; }
.pbtn:active { transform: scale(0.93, 0.88); }
.pbtn.ghost { filter: var(--btn-filter) grayscale(0.7) brightness(1.15); color: var(--ink); text-shadow: 0 1px 0 #fff; }
.pbtn.danger { filter: hue-rotate(-25deg) saturate(1.4); }
.pbtn.small { min-height: 44px; min-width: 68px; font-size: 13px; padding: 0 14px; }
.pbtn.block { display: flex; width: 100%; }
.pbtn[disabled], .pbtn.disabled { filter: var(--btn-filter) grayscale(1) opacity(0.6); pointer-events: none; }

/* round icon button (no art, soft plate) */
.ibtn {
  all: unset; box-sizing: border-box; cursor: pointer; width: 44px; height: 44px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 35% 30%, #fff, var(--bg2)); border: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink); transition: transform .12s cubic-bezier(.3,1.6,.5,1);
  font-size: 20px; font-weight: 900; color: var(--ink); flex: none;
}
.ibtn img { width: 26px; height: 26px; image-rendering: pixelated; }
.ibtn:hover, .ibtn:focus-visible, .ibtn.focus { transform: scale(1.08); outline: none; filter: brightness(1.06); }
.ibtn:active { transform: scale(0.9); }

/* ---------- form controls ---------- */
.pfield { display: block; margin: 0 0 12px; }
.pfield > .plabel { display: block; font-size: 14px; font-weight: 900; color: var(--ink); margin: 0 0 4px 2px; }
.pinput {
  all: unset; box-sizing: border-box; display: block; width: 100%; min-height: 44px; padding: 10px 12px;
  background: #fffdfd; border: 3px solid var(--ink); border-radius: 12px; box-shadow: inset 0 3px 0 rgba(0,0,0,.06), 0 3px 0 var(--line);
  font-family: var(--font); font-size: 16px; font-weight: 700; color: var(--ink); user-select: text; -webkit-user-select: text;
}
.pinput::placeholder { color: #b9a3bd; }
.pinput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,255,255,.8), 0 0 0 6px var(--accent); }
textarea.pinput { min-height: 80px; resize: none; white-space: pre-wrap; }
.pseg { display: flex; flex-wrap: wrap; gap: 6px; }
.pseg > button {
  all: unset; box-sizing: border-box; cursor: pointer; min-height: 40px; padding: 8px 12px; border-radius: 999px;
  background: #fff; border: 2px solid var(--line); color: var(--ink); font-family: var(--font); font-weight: 900; font-size: 14px;
  box-shadow: 0 2px 0 var(--line); transition: transform .1s;
}
.pseg > button.on { background: linear-gradient(180deg, var(--accent), var(--accent2)); color: #fff; border-color: var(--ink); box-shadow: 0 2px 0 var(--ink); text-shadow: 0 1px 0 rgba(0,0,0,.25); }
.pseg > button:active { transform: scale(.94); }
.pseg > button:focus-visible { outline: 3px solid var(--accent); }
.pcolors { display: flex; flex-wrap: wrap; gap: 8px; }
.pcolors > button {
  all: unset; cursor: pointer; width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line);
  margin: 5px;
}
.pcolors > button.on { box-shadow: 0 0 0 3px var(--ink); transform: scale(1.1); }
.ptoggle {
  all: unset; cursor: pointer; position: relative; width: 58px; height: 32px; border-radius: 999px; flex: none;
  background: #e8dce9; border: 3px solid var(--ink); transition: background .15s;
}
.ptoggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); box-sizing: border-box; transition: left .18s cubic-bezier(.3,1.5,.5,1); }
.ptoggle.on { background: var(--accent); }
.ptoggle.on::after { left: 28px; }
.prow { display: flex; align-items: center; gap: 10px; }
.prow > .grow { flex: 1; min-width: 0; }

/* checkbox-like magic check */
.pcheck {
  all: unset; cursor: pointer; width: 32px; height: 32px; border-radius: 10px; flex: none; margin: 6px;
  border: 3px solid var(--ink); background: #fff; display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 0 var(--line); transition: transform .12s cubic-bezier(.3,1.6,.5,1);
}
.pcheck.on { background: linear-gradient(180deg, var(--accent), var(--accent2)); }
.pcheck.on::after { content: "★"; color: #fff; font-size: 18px; text-shadow: 0 1px 0 var(--ink); }
.pcheck:active { transform: scale(.85); }

/* XP bar */
.xpbar { position: relative; height: 14px; border-radius: 999px; background: #fff; border: 2px solid var(--ink); overflow: hidden; }
.xpbar > i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, var(--accent), var(--gold)); border-radius: 999px; transition: width .5s cubic-bezier(.3,1.2,.5,1); }

/* ---------- modal ---------- */
#modal-root { position: absolute; inset: 0; pointer-events: none; z-index: 50; }
.pmodal-back {
  position: absolute; inset: 0; background: rgba(60, 30, 80, 0.45); pointer-events: auto;
  display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade-in .18s both;
}
.pmodal {
  width: 100%; max-width: 420px; max-height: 92%; display: flex; flex-direction: column;
  animation: pop-in .24s cubic-bezier(.2,1.5,.4,1) both;
}
.pmodal.closing { animation: pop-out .16s ease-in both; }
.pmodal-title { padding: 6px 8px 8px; text-align: center; font-size: 20px; font-weight: 900; }
.pmodal-body { overflow-y: auto; padding: 4px 8px 8px; flex: 1; -webkit-overflow-scrolling: touch; }
.pmodal-actions { display: flex; gap: 8px; justify-content: center; padding: 8px 6px 4px; flex-wrap: wrap; }
.pmodal-actions .pbtn { flex: 1; min-width: 96px; }

/* ---------- toast ---------- */
#toast-root { position: absolute; left: 0; right: 0; top: 112px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 70; }
.ptoast {
  display: flex; align-items: center; gap: 8px; max-width: 86%; padding: 8px 16px; border-radius: 999px;
  background: linear-gradient(180deg, #fff, var(--bg3)); border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink);
  font-size: 15px; font-weight: 900; color: var(--ink); animation: toast-in .3s cubic-bezier(.2,1.5,.4,1) both;
}
.ptoast img { width: 26px; height: 26px; image-rendering: pixelated; }
.ptoast.out { animation: fade-out .3s both; }

/* ---------- effects ---------- */
#fx-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 80; }
.float-text { position: absolute; z-index: 81; pointer-events: none; font-size: 20px; font-weight: 900; animation: float-up 1.1s ease-out both; white-space: nowrap; }
#subtitle {
  position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 75; max-width: 88%;
  padding: 8px 16px; border-radius: 14px; background: rgba(50, 25, 70, 0.78); color: #fff; font-size: 15px; font-weight: 800; text-align: center;
  pointer-events: none; animation: fade-in .2s both;
}

/* character avatar (App.avatar) */
.avatar { position: relative; display: inline-block; }
.avatar canvas { display: block; }
.avatar .av-pet { position: absolute; right: -6%; bottom: 0; }
.avatar .av-prop { position: absolute; left: 0; top: 12%; width: 22%; image-rendering: pixelated; animation: bob 2.4s ease-in-out infinite; }
.outfit-aurora { animation: aurora 6s linear infinite; }

@keyframes pop-in { 0% { transform: scale(.85); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes pop-out { to { transform: scale(.9); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to { opacity: 0; transform: translateY(-8px); } }
@keyframes toast-in { 0% { transform: translateY(-20px) scale(.9); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes float-up { 0% { transform: translate(-50%, 0) scale(.6); opacity: 0; } 15% { transform: translate(-50%, -10px) scale(1.15); opacity: 1; } 100% { transform: translate(-50%, -70px) scale(1); opacity: 0; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes aurora { 0% { filter: hue-rotate(0deg) saturate(1.2) drop-shadow(0 0 6px #fff); } 100% { filter: hue-rotate(360deg) saturate(1.2) drop-shadow(0 0 6px #fff); } }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: .85; } 50% { transform: scale(1.06); opacity: 1; } }
