/* =========================================================================
   Scratchy — game.css
   HUD chips, XP, toasts, paper dialogs, achievements, badges,
   quests, and the level-up celebration. Reuses theme.css papercut vars.
   ========================================================================= */

/* =========================================================================
   HUD chips (topbar right)
   ========================================================================= */
.hud-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .3px;
  color: var(--ink);
  border: none;
  border-radius: 11px;
  background: linear-gradient(180deg, var(--paper-card), var(--paper-card-2));
  box-shadow: 0 0 0 1.5px var(--cut-edge) inset, var(--shadow-hard-sm);
  transition: transform .09s, box-shadow .09s, background .12s;
  transform: rotate(var(--tilt-a));
}
.hud-chip:nth-child(even) { transform: rotate(var(--tilt-b)); }
button.hud-chip:hover { background: #fffdf6; transform: rotate(0) translateY(-1px); }
button.hud-chip:active {
  transform: translate(1px,2px) rotate(0);
  box-shadow: 0 0 0 1.5px var(--cut-edge) inset, 1px 1px 0 rgba(58,50,38,.16);
}
.hud-icon {
  font-size: 15px;
  color: var(--yellow-d);
  filter: drop-shadow(1px 1px 0 rgba(58,50,38,.15));
}

/* level chip carries an XP track */
#hud-level { padding-right: 14px; }
#hud-level-num {
  min-width: 14px;
  text-align: center;
  font-weight: 900;
  font-size: 15px;
}
.xp-track {
  position: relative;
  width: 66px;
  height: 8px;
  border-radius: 5px;
  background: #e6dcc4;
  box-shadow: inset 0 0 0 1px var(--cut-edge), inset 0 1px 2px rgba(58,50,38,.18);
  overflow: hidden;
}
.xp-fill {
  height: 100%;
  width: 0%;              /* JS sets inline width */
  border-radius: 5px;
  background:
    linear-gradient(180deg, #ffd34d, var(--yellow) 60%, var(--yellow-d));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5);
  transition: width .4s cubic-bezier(.4,1.3,.5,1);
}
/* candy-stripe shimmer on the fill */
.xp-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(-45deg,
    rgba(255,255,255,.25) 0 5px, transparent 5px 10px);
}

/* =========================================================================
   Toast dock
   ========================================================================= */
#toast-dock {
  position: fixed;
  top: 70px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 240px;
  max-width: 320px;
  padding: 11px 14px;
  color: var(--ink);
  background: linear-gradient(180deg, var(--paper-card), var(--paper-card-2));
  border-radius: 12px;
  box-shadow: 0 0 0 1.5px var(--cut-edge) inset, var(--shadow-hard-lg);
  border-left: 6px solid var(--blue);
  transform-origin: top right;
  animation: toast-flutter .5s cubic-bezier(.2,1.4,.4,1) both;
}
.toast.out { animation: toast-out .35s ease-in forwards; }

.toast-icon {
  flex: 0 0 auto;
  font-size: 24px;
  filter: drop-shadow(1px 1px 0 rgba(58,50,38,.2));
}
.toast-title {
  display: block;
  font-size: 13.5px;
  font-weight: 900;
  letter-spacing: .2px;
}
.toast-desc {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.25;
}

/* accent variants by toast type */
.toast-achievement { border-left-color: var(--yellow); }
.toast-badge       { border-left-color: var(--purple); }
.toast-quest       { border-left-color: var(--green); }
.toast-levelup     { border-left-color: var(--red); }
.toast-info        { border-left-color: var(--blue); }

@keyframes toast-flutter {
  0%   { opacity: 0; transform: translateX(120%) rotate(6deg); }
  60%  { opacity: 1; transform: translateX(-6%)  rotate(-2deg); }
  80%  { transform: translateX(3%) rotate(1deg); }
  100% { opacity: 1; transform: translateX(0)    rotate(-0.5deg); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(120%) rotate(5deg); }
}

/* =========================================================================
   Paper dialogs
   ========================================================================= */
.paper-dialog {
  width: min(680px, 92vw);
  max-height: 82vh;
  padding: 0;
  border: none;
  color: var(--ink);
  background: linear-gradient(180deg, var(--paper-card) 0%, var(--paper-card-2) 100%);
  border-radius: 16px;
  box-shadow: 6px 9px 0 rgba(58,50,38,.28), 0 0 0 2px var(--cut-edge) inset;
  overflow: hidden;
  transform: rotate(-0.4deg);
}
.paper-dialog[open] { animation: dlg-drop .38s cubic-bezier(.2,1.3,.4,1) both; }
.paper-dialog::backdrop {
  background:
    radial-gradient(120% 120% at 50% 0%, rgba(58,50,38,.35), rgba(58,50,38,.6));
  backdrop-filter: blur(1.5px);
}
/* torn top edge strip */
.paper-dialog::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 10px;
  background: var(--paper-card);
  clip-path: polygon(
    0 100%, 4% 30%, 8% 90%, 12% 20%, 16% 85%, 20% 25%, 24% 92%, 28% 18%,
    32% 80%, 36% 28%, 40% 88%, 44% 22%, 48% 82%, 52% 30%, 56% 90%, 60% 20%,
    64% 84%, 68% 26%, 72% 88%, 76% 18%, 80% 80%, 84% 28%, 88% 90%, 92% 22%,
    96% 84%, 100% 30%, 100% 100%);
  pointer-events: none;
  z-index: 3;
}

@keyframes dlg-drop {
  0%   { opacity: 0; transform: translateY(-30px) rotate(2deg) scale(.94); }
  100% { opacity: 1; transform: translateY(0)    rotate(-0.4deg) scale(1); }
}

.dlg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 2.5px dashed var(--cut-edge-2);
}
.dlg-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: .5px;
  text-shadow: 1px 1px 0 #fff;
}
.dlg-close {
  width: 34px; height: 34px;
  font-size: 16px;
  border: none;
  border-radius: 10px;
  color: #fff;
  background: var(--red);
  box-shadow: 0 0 0 2px var(--red-d) inset, var(--shadow-hard-sm);
  transition: transform .08s, box-shadow .08s;
}
.dlg-close:hover { transform: rotate(-6deg) translateY(-1px); }
.dlg-close:active {
  transform: translate(1px,2px);
  box-shadow: 0 0 0 2px var(--red-d) inset, 1px 1px 0 rgba(58,50,38,.16);
}

.dlg-body {
  max-height: 60vh;
  overflow-y: auto;
  padding: 16px 18px 20px;
}
.dlg-body::-webkit-scrollbar { width: 10px; }
.dlg-body::-webkit-scrollbar-thumb {
  background: var(--cut-edge); border-radius: 6px; border: 2px solid var(--paper-card);
}

/* =========================================================================
   Achievements / Badges grids
   ========================================================================= */
#ach-grid, #badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}

.ach-card, .badge-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 5px;
  padding: 16px 10px 12px;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--paper-card), var(--paper-card-2));
  box-shadow: 0 0 0 1.5px var(--cut-edge) inset, var(--shadow-hard);
  overflow: hidden;
  transition: transform .12s;
}
.ach-card:nth-child(even), .badge-card:nth-child(even) { transform: rotate(var(--tilt-b)); }
.ach-card:nth-child(odd),  .badge-card:nth-child(odd)  { transform: rotate(var(--tilt-a)); }
.ach-card:hover, .badge-card:hover { transform: rotate(0) translateY(-2px) scale(1.02); }

.ach-icon, .badge-icon {
  font-size: 34px;
  line-height: 1;
  filter: drop-shadow(2px 2px 0 rgba(58,50,38,.18));
}
.ach-name, .badge-name {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .2px;
}
.ach-desc, .badge-desc {
  font-size: 11px;
  color: var(--ink-soft);
  line-height: 1.25;
}

/* unlocked: full color + corner sticker star */
.ach-card.unlocked, .badge-card.unlocked { }
.ach-card.unlocked::after, .badge-card.unlocked::after {
  content: "★";
  position: absolute;
  top: -6px; right: -6px;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  font-size: 13px;
  color: #fff;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--paper-card), 2px 2px 0 rgba(58,50,38,.2);
  transform: rotate(12deg);
}

/* locked: desaturated, dashed outline, dimmed icon */
.ach-card.locked, .badge-card.locked {
  background: repeating-linear-gradient(45deg,
      #efe8d6 0 8px, #e9e1cd 8px 16px);
  box-shadow: 0 0 0 2px var(--cut-edge-2) inset;
  border: 2.5px dashed var(--cut-edge-2);
  filter: grayscale(.7);
}
.ach-card.locked .ach-icon, .badge-card.locked .badge-icon { opacity: .35; }
.ach-card.locked .ach-name, .badge-card.locked .badge-name { color: var(--ink-soft); }

/* tier corner ribbons */
.ach-tier, .badge-tier {
  position: absolute;
  top: 9px; left: -24px;
  width: 84px;
  padding: 2px 0;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1px;
  text-transform: uppercase;
  text-align: center;
  color: #fff;
  transform: rotate(-45deg);
  box-shadow: 0 1px 0 rgba(58,50,38,.25);
  text-shadow: 1px 1px 0 rgba(58,50,38,.3);
}
.ach-tier.bronze, .badge-tier.bronze { background: linear-gradient(180deg,#d38a4f,#b06d34); }
.ach-tier.silver, .badge-tier.silver { background: linear-gradient(180deg,#c9cdd4,#9aa0aa); color:#3a3226; text-shadow:1px 1px 0 rgba(255,255,255,.4); }
.ach-tier.gold,   .badge-tier.gold   { background: linear-gradient(180deg,#ffd455,#e3a900); color:#3a3226; text-shadow:1px 1px 0 rgba(255,255,255,.4); }
/* label the ribbon from its tier class when JS leaves the node empty */
.ach-tier.bronze:empty::before, .badge-tier.bronze:empty::before { content: "Bronze"; }
.ach-tier.silver:empty::before, .badge-tier.silver:empty::before { content: "Silver"; }
.ach-tier.gold:empty::before,   .badge-tier.gold:empty::before   { content: "Gold"; }

/* =========================================================================
   Quests
   ========================================================================= */
#quest-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.quest-row {
  position: relative;
  display: grid;
  grid-template-columns: 40px 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 6px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--paper-card), var(--paper-card-2));
  box-shadow: 0 0 0 1.5px var(--cut-edge) inset, var(--shadow-hard);
  border-left: 6px solid var(--blue);
  transform: rotate(var(--tilt-a));
  transition: transform .12s;
}
.quest-row:nth-child(even) { transform: rotate(var(--tilt-b)); }
.quest-row:hover { transform: rotate(0); }

.quest-row .quest-icon,
.quest-row > :first-child {
  grid-row: 1 / span 2;
  font-size: 26px;
  text-align: center;
  filter: drop-shadow(1px 1px 0 rgba(58,50,38,.18));
}
.quest-title {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: .2px;
}
.quest-desc {
  font-size: 11.5px;
  color: var(--ink-soft);
  grid-column: 2;
}

/* progress bar reuses xp-track/fill look */
.quest-progress {
  position: relative;
  grid-column: 2;
  height: 10px;
  border-radius: 6px;
  background: #e6dcc4;
  box-shadow: inset 0 0 0 1px var(--cut-edge), inset 0 1px 2px rgba(58,50,38,.18);
  overflow: hidden;
}
.quest-progress > .quest-fill,
.quest-progress > .xp-fill,
.quest-fill {
  height: 100%;
  width: 0%;              /* JS sets inline width */
  border-radius: 6px;
  background: linear-gradient(180deg,#7ad47a,var(--green) 60%,var(--green-d));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4);
  transition: width .4s cubic-bezier(.4,1.3,.5,1);
}

/* completed quests */
.quest-row.done {
  border-left-color: var(--green);
  background: linear-gradient(180deg,#eef7e6,#e4f0d6);
}
.quest-row.done .quest-title {
  text-decoration: line-through;
  text-decoration-color: var(--green-d);
  text-decoration-thickness: 2px;
  color: var(--ink-soft);
}
.quest-row.done::after {
  content: "✓";
  position: absolute;
  top: 8px; right: 12px;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 900;
  color: #fff;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 2px 2px 0 rgba(58,50,38,.2);
  transform: rotate(-8deg);
}

/* =========================================================================
   Level-up celebration
   ========================================================================= */
.paper-dialog.levelup {
  width: min(440px, 90vw);
  text-align: center;
  overflow: visible;               /* let confetti spill */
  background:
    radial-gradient(circle at 50% 34%,
      #fff6d8 0%, #ffe9a8 22%, var(--paper-card) 46%, var(--paper-card-2) 100%);
}
/* paper-burst rays behind the number */
.paper-dialog.levelup::before {
  content: "";
  position: absolute;
  inset: -20% ;
  background:
    repeating-conic-gradient(from 0deg at 50% 42%,
      rgba(255,191,0,.22) 0deg 12deg,
      transparent 12deg 24deg);
  z-index: 0;
  animation: burst-spin 14s linear infinite;
  pointer-events: none;
}
.paper-dialog.levelup #levelup-body {
  position: relative;
  z-index: 2;
  padding: 34px 26px 30px;
}
.paper-dialog.levelup #levelup-body h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--red);
  text-shadow: 1px 1px 0 #fff;
}
.paper-dialog.levelup .levelup-num,
.paper-dialog.levelup #levelup-body .big {
  font-size: 84px;
  font-weight: 900;
  line-height: 1;
  color: var(--ink);
  text-shadow: 3px 4px 0 rgba(58,50,38,.18), 0 0 0 #fff;
}
.paper-dialog.levelup #levelup-body p { color: var(--ink-soft); font-weight: 700; }

@keyframes burst-spin { to { transform: rotate(360deg); } }

/* confetti — JS injects <i class="confetti c1..c12"></i> */
.confetti {
  position: absolute;
  top: -8%;
  left: 50%;
  width: 9px; height: 14px;
  border-radius: 2px;
  opacity: 0;
  z-index: 3;
  animation: confetti-fall 1.5s ease-in forwards;
}
.confetti::after { content: ""; }
.confetti.c1  { left:12%; background:var(--red);    animation-delay:.02s; }
.confetti.c2  { left:22%; background:var(--blue);   animation-delay:.14s; }
.confetti.c3  { left:33%; background:var(--green);  animation-delay:.06s; }
.confetti.c4  { left:41%; background:var(--yellow); animation-delay:.22s; }
.confetti.c5  { left:52%; background:var(--purple); animation-delay:.10s; }
.confetti.c6  { left:60%; background:var(--pink);   animation-delay:.28s; }
.confetti.c7  { left:69%; background:var(--red);    animation-delay:.04s; }
.confetti.c8  { left:76%; background:var(--blue);   animation-delay:.18s; }
.confetti.c9  { left:84%; background:var(--green);  animation-delay:.12s; }
.confetti.c10 { left:28%; background:var(--yellow); animation-delay:.32s; }
.confetti.c11 { left:47%; background:var(--pink);   animation-delay:.24s; }
.confetti.c12 { left:64%; background:var(--purple); animation-delay:.36s; }

@keyframes confetti-fall {
  0%   { opacity: 0; transform: translateY(-10px) rotate(0deg); }
  10%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(360px) rotate(540deg); }
}

/* =========================================================================
   Reduced motion
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
  .toast, .paper-dialog[open], .paper-dialog.levelup::before,
  .confetti { animation: none !important; }
  .confetti { display: none; }
  .hud-chip, .ach-card, .badge-card, .quest-row { transform: none !important; }
  .xp-fill, .quest-fill, .quest-progress > .xp-fill { transition: none; }
}
