/* The Mix-Up Machine — comic style matching the book cover:
   sunburst sky, chunky rounded type, red + yellow accents. */

* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

:root {
  --red: #e23b2e;
  --red-dark: #b02418;
  --yellow: #ffc93c;
  --yellow-dark: #e0a800;
  --sky: #3fa9f5;
  --sky-deep: #1b7fd4;
  --orange: #ff9d2e;
  --ink: #2b2340;
  --cream: #fff8ec;
  --steel: #8d9db0;
  --steel-dark: #5d6b7c;
  --green: #3cb96a;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Nunito', sans-serif;
  color: var(--ink);
  background:
    repeating-conic-gradient(from 0deg at 50% 18%,
      rgba(255,255,255,0.14) 0deg 9deg, rgba(255,255,255,0) 9deg 18deg),
    linear-gradient(180deg, var(--sky) 0%, #7cc4f8 38%, var(--orange) 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

.stage {
  max-width: 480px;
  margin: 0 auto;
  padding: 14px 16px 90px;
  position: relative;
  min-height: 100vh;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; margin-bottom: 10px;
}
.rank-chip, .wrench-chip {
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 5px 14px;
  font-family: 'Fredoka', sans-serif;
  font-weight: 600; font-size: 0.85rem;
  box-shadow: 0 3px 0 rgba(0,0,0,0.25);
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.wrench-chip { background: var(--yellow); }

/* ---------- title ---------- */
.app-title {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  text-align: center;
  font-size: clamp(2rem, 9vw, 2.7rem);
  line-height: 0.95;
  color: #fff;
  -webkit-text-stroke: 6px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--ink), 0 7px 14px rgba(0,0,0,0.25);
  letter-spacing: 0.5px;
  margin-top: 4px;
  transform: rotate(-2deg);
}
.app-title span {
  display: block; font-size: 0.42em; letter-spacing: 4px;
  transform: rotate(1deg) translateY(4px);
}
.tagline {
  text-align: center;
  font-weight: 800;
  color: var(--ink);
  background: var(--yellow);
  border: 3px solid var(--ink);
  border-radius: 12px;
  display: block;
  width: fit-content;
  margin: 12px auto 18px;
  padding: 4px 14px;
  transform: rotate(1.2deg);
  box-shadow: 0 3px 0 rgba(0,0,0,0.25);
  font-size: 0.9rem;
}

/* ---------- machine ---------- */
.machine-wrap { display: flex; flex-direction: column; align-items: center; }

.machine { width: min(320px, 82vw); position: relative; }
.machine.shaking { animation: shake 0.45s linear infinite; }
@keyframes shake {
  0% { transform: translate(0,0) rotate(0deg); }
  20% { transform: translate(-3px,1px) rotate(-1deg); }
  40% { transform: translate(3px,-1px) rotate(1deg); }
  60% { transform: translate(-2px,-2px) rotate(-0.6deg); }
  80% { transform: translate(2px,2px) rotate(0.8deg); }
  100% { transform: translate(0,0) rotate(0deg); }
}

.machine-top { position: relative; height: 46px; }
.funnel {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: -4px;
  width: 90px; height: 44px;
  background: linear-gradient(180deg, var(--steel), var(--steel-dark));
  border: 3px solid var(--ink);
  border-bottom: none;
  clip-path: polygon(0 0, 100% 0, 72% 100%, 28% 100%);
}
.pipe {
  position: absolute; bottom: -6px;
  width: 26px; height: 34px;
  background: linear-gradient(180deg, #aab8c6, var(--steel-dark));
  border: 3px solid var(--ink);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}
.pipe-a { left: 14%; }
.pipe-b { right: 14%; height: 26px; }

.machine-body {
  position: relative;
  background: linear-gradient(180deg, #b9c7d6 0%, var(--steel) 55%, var(--steel-dark) 100%);
  border: 4px solid var(--ink);
  border-radius: 22px;
  padding: 14px 14px 18px;
  box-shadow: 0 8px 0 rgba(0,0,0,0.3);
}
.machine-plate {
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 10px 12px 12px;
  display: flex; align-items: center; gap: 10px;
}
.gauge { flex: 1; }
.gauge-label {
  font-family: 'Fredoka', sans-serif; font-weight: 700;
  font-size: 0.62rem; letter-spacing: 2px; margin-bottom: 4px;
}
.gauge-track {
  height: 14px; border: 2.5px solid var(--ink); border-radius: 999px;
  background: #fff; overflow: hidden;
}
.gauge-fill {
  height: 100%; width: 0%;
  background: repeating-linear-gradient(45deg, var(--red) 0 8px, var(--yellow) 8px 16px);
  border-radius: 999px;
  transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.lights { display: flex; flex-direction: column; gap: 5px; }
.light {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--ink); display: block;
}
.l1 { background: var(--green); } .l2 { background: var(--yellow); } .l3 { background: var(--red); }
.machine.shaking .light { animation: blink 0.3s alternate infinite; }
.machine.shaking .l2 { animation-delay: 0.1s; }
.machine.shaking .l3 { animation-delay: 0.2s; }
@keyframes blink { from { filter: brightness(0.5); } to { filter: brightness(1.4); } }

.machine-mouth {
  margin-top: 12px;
  background: var(--ink);
  border-radius: 12px;
  border: 3px solid var(--ink);
  min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  position: relative;
}
.mouth-status {
  color: var(--yellow);
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 1.5px;
  padding: 8px 10px;
  text-align: center;
}

.bolt {
  position: absolute; width: 11px; height: 11px; border-radius: 50%;
  background: #d7e0e9; border: 2.5px solid var(--ink);
}
.bolt-tl { top: 8px; left: 8px; } .bolt-tr { top: 8px; right: 8px; }
.bolt-bl { bottom: 8px; left: 8px; } .bolt-br { bottom: 8px; right: 8px; }

.machine-feet { display: flex; justify-content: space-between; padding: 0 34px; }
.machine-feet span {
  width: 34px; height: 16px;
  background: var(--steel-dark);
  border: 3px solid var(--ink); border-top: none;
  border-radius: 0 0 10px 10px;
}

/* ---------- big red button ---------- */
.button-block { text-align: center; margin-top: 16px; }
.warn-label {
  font-family: 'Fredoka', sans-serif; font-weight: 700;
  background: var(--yellow);
  border: 3px solid var(--ink);
  display: inline-block;
  padding: 3px 12px; border-radius: 8px;
  font-size: 0.8rem; letter-spacing: 1px;
  transform: rotate(-1.5deg);
  box-shadow: 0 3px 0 rgba(0,0,0,0.25);
  margin-bottom: 10px;
}
.big-red-button {
  display: block; margin: 0 auto;
  width: 118px; height: 118px;
  border-radius: 50%;
  border: 5px solid var(--ink);
  background: radial-gradient(circle at 35% 30%, #ff7a6e, var(--red) 55%, var(--red-dark));
  box-shadow: 0 9px 0 var(--red-dark), 0 12px 18px rgba(0,0,0,0.35);
  cursor: pointer;
  font-family: 'Fredoka', sans-serif;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  touch-action: manipulation;
}
.big-red-button:active, .big-red-button.pressed {
  transform: translateY(7px);
  box-shadow: 0 2px 0 var(--red-dark), 0 4px 8px rgba(0,0,0,0.35);
}
.big-red-button:disabled { filter: saturate(0.5) brightness(0.9); cursor: wait; }
.btn-face {
  color: #fff; font-weight: 700; font-size: 1.25rem; letter-spacing: 2px;
  text-shadow: 0 2px 0 rgba(0,0,0,0.35);
}

/* ---------- ticket ---------- */
.ticket-area { margin-top: 22px; }
.ticket {
  background: var(--cream);
  border: 3.5px solid var(--ink);
  border-radius: 16px 16px 4px 4px;
  padding: 12px 16px 6px;
  box-shadow: 0 6px 0 rgba(0,0,0,0.28);
  transform: rotate(-0.8deg);
  animation: ticketOut 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes ticketOut {
  from { transform: translateY(-28px) rotate(-3deg); opacity: 0; }
  to   { transform: translateY(0) rotate(-0.8deg); opacity: 1; }
}
.ticket-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; flex-wrap: wrap;
  border-bottom: 2.5px dashed var(--ink);
  padding-bottom: 8px; margin-bottom: 10px;
}
.ticket-brand {
  font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 0.72rem;
  letter-spacing: 1.5px;
}
.ticket-zone {
  background: var(--sky); color: #fff;
  border: 2.5px solid var(--ink); border-radius: 999px;
  font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 0.72rem;
  padding: 2px 10px;
}
.ticket-text { font-size: 1.02rem; font-weight: 600; line-height: 1.5; padding-bottom: 10px; }
.ticket-tear {
  height: 10px;
  background:
    radial-gradient(circle at 6px -2px, transparent 6px, var(--cream) 6.5px);
  background-size: 16px 10px;
  margin: 0 -16px -6px;
}

/* ---------- fix round ---------- */
.fix-block { margin-top: 18px; }
.fix-title {
  font-family: 'Fredoka', sans-serif; font-weight: 700;
  color: #fff; -webkit-text-stroke: 4px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--ink);
  text-align: center; font-size: 1.5rem; transform: rotate(-1deg);
}
.fix-sub { text-align: center; font-weight: 700; margin: 4px 0 12px; font-size: 0.9rem; }
.fix-options { display: flex; flex-direction: column; gap: 10px; }
.fix-btn {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 12px 14px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700; font-size: 0.95rem; line-height: 1.4;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.25);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s;
  color: var(--ink);
}
.fix-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.25); }
.fix-btn:hover { background: var(--cream); }

/* ---------- reply ---------- */
.reply-block { margin-top: 16px; }
.reply-card {
  border: 3.5px solid var(--ink);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: 0 5px 0 rgba(0,0,0,0.28);
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  background: #fff;
}
.reply-card.best { background: #e8f8ee; border-color: var(--green); box-shadow: 0 5px 0 #1f7a43; }
.reply-card.meh { background: #fff6dd; }
.reply-card.chaos { background: #fdeae8; }
@keyframes popIn { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.reply-award {
  font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 1.05rem;
  margin-bottom: 6px;
}
.reply-text { font-weight: 600; line-height: 1.5; font-size: 0.95rem; }

.after-row { display: flex; gap: 10px; margin-top: 14px; justify-content: center; flex-wrap: wrap; }
.pill-btn {
  font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 0.95rem;
  border: 3px solid var(--ink); border-radius: 999px;
  padding: 10px 18px; cursor: pointer;
  background: #fff; color: var(--ink);
  box-shadow: 0 4px 0 rgba(0,0,0,0.25);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.pill-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.25); }
.again-btn { background: var(--yellow); }
.save-btn.saved { background: var(--green); color: #fff; }

.book-plug {
  text-align: center; margin-top: 14px;
  font-weight: 800; font-size: 0.85rem;
  color: var(--ink);
  background: rgba(255,255,255,0.75);
  border-radius: 10px; padding: 6px 10px;
}

/* ---------- rank up + max chaos ---------- */
.rankup, .maxchaos {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(43,35,64,0.65);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.rankup-card, .maxchaos-card {
  background: var(--cream);
  border: 4px solid var(--ink); border-radius: 20px;
  padding: 26px 22px; text-align: center; max-width: 340px;
  box-shadow: 0 8px 0 rgba(0,0,0,0.3);
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.rankup-card h2, .maxchaos-card h2 {
  font-family: 'Fredoka', sans-serif; font-size: 1.6rem; margin-bottom: 10px;
}
.rankup-burst { font-size: 2.4rem; }
.rankup-card p, .maxchaos-card p { font-weight: 700; margin-bottom: 12px; line-height: 1.45; }
.maxchaos-note { font-size: 0.85rem; opacity: 0.8; }

/* ---------- footer ---------- */
.footbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: center; gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(43,35,64,0), rgba(43,35,64,0.25));
  z-index: 40;
}
.foot-link {
  font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 0.9rem;
  background: var(--cream); border: 3px solid var(--ink);
  border-radius: 999px; padding: 9px 16px; cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.3);
}
.foot-link:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.3); }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(43,35,64,0.65);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
.modal-card {
  background: var(--cream);
  border: 4px solid var(--ink); border-radius: 20px;
  width: 100%; max-width: 420px;
  max-height: 82vh; overflow-y: auto;
  padding: 18px;
  box-shadow: 0 8px 0 rgba(0,0,0,0.3);
  animation: popIn 0.3s ease;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.modal-head h2 { font-family: 'Fredoka', sans-serif; font-size: 1.3rem; }
.close-x {
  border: 3px solid var(--ink); background: #fff; border-radius: 50%;
  width: 34px; height: 34px; font-weight: 800; cursor: pointer; font-size: 0.95rem;
}
.modal-sub { font-weight: 700; font-size: 0.85rem; margin-bottom: 12px; opacity: 0.85; }

.log-list { display: flex; flex-direction: column; gap: 10px; }
.log-item {
  background: #fff; border: 3px solid var(--ink); border-radius: 12px;
  padding: 10px 12px; position: relative;
}
.log-item .log-zone { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 0.7rem; opacity: 0.75; }
.log-item p { font-weight: 600; font-size: 0.88rem; line-height: 1.45; margin-top: 4px; }
.log-del {
  position: absolute; top: 6px; right: 8px;
  border: none; background: none; cursor: pointer; font-size: 0.9rem; opacity: 0.55;
}
.log-empty { text-align: center; font-weight: 700; opacity: 0.7; padding: 18px 0; }

.grownup-body p { font-weight: 600; font-size: 0.9rem; line-height: 1.55; margin-bottom: 10px; }
.grownup-row { margin: 14px 0; }
.sound-toggle { display: flex; align-items: center; gap: 8px; font-weight: 800; cursor: pointer; }
.sound-toggle input { width: 20px; height: 20px; accent-color: var(--red); }
.grownup-contact { font-size: 0.82rem; opacity: 0.85; }
.grownup-contact a { color: var(--sky-deep); font-weight: 800; }

/* springs confetti */
.spring {
  position: fixed; z-index: 65; font-size: 1.6rem; pointer-events: none;
  animation: springFall 1.6s ease-in forwards;
}
@keyframes springFall {
  from { transform: translateY(-40px) rotate(0deg); opacity: 1; }
  to   { transform: translateY(105vh) rotate(720deg); opacity: 0.9; }
}

@media (min-width: 560px) {
  .stage { padding-top: 24px; }
}
