/* Moron Match — shell styled as a messaging app: a thread header, a pinned
   goal chip, and a composer at the bottom with the snail in it. */

@font-face {
  font-family: 'Baloo 2';
  src: url('../assets/fonts/baloo2-700.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --plum: #2b1250;
  --plum-deep: #160a28;
  --pink: #ff5fa2;
  --gold: #ffd23f;
  --mint: #5fe3b0;
  --ink: #1a0d2e;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --ui: 'Baloo 2', 'Trebuchet MS', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--plum-deep);
  color: #fff;
  font-family: var(--ui);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; display: flex; flex-direction: column; overflow: hidden; }

#scene, #scene svg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; display: block; }

#gl {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; z-index: 1; touch-action: none;
}

/* -------------------------------------------------------------------- hud */
#hud {
  position: relative; z-index: 3;
  display: flex; flex-direction: column; gap: 7px;
  padding: calc(8px + var(--safe-t)) 12px 0;
  pointer-events: none;
  transition: opacity 0.22s;
}
body:not([data-screen="play"]) #hud,
body:not([data-screen="play"]) #foot { opacity: 0; pointer-events: none; }

.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.who { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1 1 auto; }
.lvl-badge {
  width: 42px; height: 42px; flex: 0 0 42px;
  border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #ffdd80, #ffa91f);
  color: #3a1e00; font-size: 20px; font-weight: 800; line-height: 1;
  box-shadow: 0 3px 0 #9c6100, inset 0 1px 0 rgba(255,255,255,0.65);
  font-variant-numeric: tabular-nums;
}
.who-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.who-name {
  font-size: 12.5px; font-weight: 700; opacity: 0.9;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.who-score { font-size: 16px; font-weight: 800; color: #ffe9a8; font-variant-numeric: tabular-nums; }

.hud-row > .icon-btn { pointer-events: auto; flex: 0 0 auto; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.16);
  color: #fff; font-family: var(--ui); font-size: 18px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,0.28), inset 0 1px 0 rgba(255,255,255,0.14);
  backdrop-filter: blur(6px);
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.28); }
.icon-btn.ghost {
  width: 38px; height: 38px; border-radius: 50%;
  background: rgba(10,4,22,0.34); font-size: 16px;
}
.icon-btn.off { opacity: 0.4; text-decoration: line-through; }

.hud-row.two { align-items: stretch; }

.goal-pill {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: row; align-items: center; gap: 9px;
  padding: 7px 11px 8px;
  background: rgba(10,4,22,0.46);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 15px 15px 15px 4px;
  backdrop-filter: blur(6px);
}
.goals { display: flex; align-items: center; gap: 6px; min-height: 26px; flex: 0 0 auto; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,0.10);
  border-radius: 99px; padding: 1px 10px 1px 2px;
}
.chip img { width: 24px; height: 24px; object-fit: contain; display: block; }
.chip b { font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }
.chip.done { background: rgba(72,214,140,0.26); }
.chip.done b { color: #9dfbbf; }
.chip.bump { animation: bump 0.3s cubic-bezier(.2,1.7,.4,1); }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.22); } 100% { transform: scale(1); } }

.goal-pill .bar { flex: 1 1 auto; }
.bar {
  height: 5px; border-radius: 99px; overflow: hidden;
  background: rgba(255,255,255,0.09);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.45);
}
.bar i {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, #6ee7ff, var(--mint));
  border-radius: 99px;
  transition: width 0.32s cubic-bezier(.2,.9,.3,1);
  box-shadow: 0 0 8px rgba(110,231,255,0.65);
}
.bar i[data-done="1"] { background: linear-gradient(90deg, #ffe37a, #ffb020); box-shadow: 0 0 10px rgba(255,190,60,0.8); }

.moves-pill {
  flex: 0 0 auto;
  display: flex; align-items: baseline; gap: 4px;
  padding: 5px 12px 6px;
  background: rgba(10,4,22,0.46);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 15px;
  backdrop-filter: blur(6px);
}
.moves-pill b { font-size: 24px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.moves-pill b.low { color: #ff7f95; animation: pulseLow 0.8s ease-in-out infinite; }
.moves-pill span { font-size: 9.5px; letter-spacing: 1.2px; opacity: 0.6; text-transform: uppercase; }
@keyframes pulseLow { 50% { transform: scale(1.13); } }

#stage { position: relative; flex: 1 1 auto; min-height: 0; z-index: 0; pointer-events: none; }
#fx { position: absolute; inset: 0; z-index: 4; pointer-events: none; overflow: hidden; }

/* --------------------------------------------------------- chat composer */
#foot {
  position: relative; z-index: 3;
  display: flex; align-items: flex-end; gap: 7px;
  padding: 0 12px calc(10px + var(--safe-b));
  transition: opacity 0.22s;
}
.avatar { position: relative; width: 42px; height: 42px; flex: 0 0 42px; }
.avatar img {
  width: 100%; height: 100%; object-fit: contain;
  filter: drop-shadow(0 4px 7px rgba(0,0,0,0.5));
  animation: mascot 3s ease-in-out infinite;
  transform-origin: 50% 90%;
}
@keyframes mascot {
  0%, 100% { transform: rotate(-3deg) translateY(0); }
  50% { transform: rotate(3deg) translateY(-3px); }
}
.avatar .dot {
  position: absolute; right: 1px; bottom: 3px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #4ade80; border: 2px solid #160a28;
  box-shadow: 0 0 9px rgba(74,222,128,0.9);
}
.msg {
  flex: 1 1 auto; min-width: 0; min-height: 42px;
  display: flex; align-items: center;
  padding: 8px 13px;
  font-size: 12.5px; line-height: 1.3; font-weight: 600;
  color: #2a1240;
  background: linear-gradient(180deg, #ffffff, #eef0f7);
  border-radius: 16px 16px 16px 5px;
  box-shadow: 0 5px 14px rgba(0,0,0,0.3);
}
.msg.pop { animation: sayPop 0.34s cubic-bezier(.2,1.6,.4,1); }
@keyframes sayPop {
  0% { transform: scale(0.96) translateY(3px); }
  60% { transform: scale(1.02) translateY(0); }
  100% { transform: scale(1); }
}

.nudge {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  width: 56px; padding: 6px 4px 7px;
  border: none; border-radius: 14px;
  background: linear-gradient(180deg, #ffdd80, #ffa91f);
  color: #3a1e00;
  font-family: var(--ui); font-size: 8.5px; font-weight: 800; letter-spacing: 0.9px;
  box-shadow: 0 3px 0 #9c6100, 0 6px 14px rgba(255,170,0,0.28);
  cursor: pointer;
}
.nudge span { font-size: 16px; line-height: 1; margin-bottom: 1px; }
.nudge:active { transform: translateY(2px); box-shadow: 0 1px 0 #9c6100; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: block; width: 100%;
  padding: 13px 16px; margin: 0 0 9px;
  border: none; border-radius: 14px;
  font-family: var(--ui); font-weight: 800; font-size: 16px;
  letter-spacing: 1px; text-transform: uppercase;
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff, #e2e6f1);
  box-shadow: 0 4px 0 rgba(0,0,0,0.3), 0 8px 18px rgba(0,0,0,0.26);
  cursor: pointer;
  transition: transform 0.07s ease, box-shadow 0.07s ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.3); }
.btn.primary {
  background: linear-gradient(180deg, #ffe27a, #ffb020);
  box-shadow: 0 4px 0 #a86a00, 0 10px 22px rgba(255,170,0,0.32);
  color: #3a1e00;
}
.btn.ghost {
  background: rgba(255,255,255,0.10); color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
  box-shadow: 0 4px 0 rgba(0,0,0,0.22);
  backdrop-filter: blur(6px);
}
.btn.tiny { width: auto; padding: 8px 13px; font-size: 12px; margin: 0; border-radius: 11px; }

/* --------------------------------------------------------------- title */
#title.bare {
  background: none;
  backdrop-filter: none;
  justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  pointer-events: none;
}
/* a soft vignette keeps the logo legible over the falling pieces */
#title.bare::before {
  content: '';
  position: absolute; inset: 0; z-index: -1;
  background:
    radial-gradient(58% 32% at 50% 30%, rgba(18,7,38,0.92), rgba(18,7,38,0.55) 58%, rgba(18,7,38,0) 82%),
    linear-gradient(to bottom, rgba(13,5,28,0.5), rgba(13,5,28,0) 20%, rgba(13,5,28,0) 58%, rgba(13,5,28,0.9));
}
.title-top { width: 100%; display: flex; justify-content: flex-end; gap: 8px; pointer-events: auto; }
.title-mid { text-align: center; margin-top: 2vh; }
.title-bottom { width: 100%; max-width: 360px; margin: 0 auto; pointer-events: auto; }
.duo { display: flex; gap: 8px; }
.duo .btn { margin-bottom: 0; }

.kicker { font-size: 10px; letter-spacing: 4px; opacity: 0.72; font-weight: 700; margin-bottom: 6px; text-shadow: 0 1px 6px rgba(0,0,0,0.85); }
#title h1 {
  margin: 0; font-size: clamp(46px, 16vw, 76px); line-height: 0.84;
  font-weight: 800; letter-spacing: -1px; color: #fff;
  text-shadow: 0 4px 0 #7a2bb5, 0 8px 0 #47136e, 0 16px 30px rgba(0,0,0,0.75);
}
#title h1 span {
  display: block; color: var(--gold);
  text-shadow: 0 4px 0 #c47b00, 0 8px 0 #7a4a00, 0 16px 30px rgba(0,0,0,0.75);
}
.sub { margin: 9px 0 0; font-size: 12px; letter-spacing: 6px; font-weight: 700; color: #ff86bd; text-shadow: 0 2px 10px rgba(0,0,0,0.95), 0 0 18px rgba(0,0,0,0.8); }
.foot {
  display: flex; justify-content: center; gap: 18px; margin-top: 12px;
  font-size: 11px; letter-spacing: 1px; opacity: 0.8; text-shadow: 0 1px 3px rgba(0,0,0,0.7);
}
.foot b { color: var(--gold); }

/* -------------------------------------------------------------- overlays */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  padding: calc(12px + var(--safe-t)) 16px calc(12px + var(--safe-b));
  background: radial-gradient(120% 80% at 50% 0%, rgba(84,28,124,0.62), rgba(10,4,22,0.95));
  backdrop-filter: blur(8px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.18) transparent;
}
.overlay.show { display: flex; animation: fadeIn 0.22s ease; }
.overlay::-webkit-scrollbar { width: 7px; }
.overlay::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 99px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: 100%; max-width: 380px; margin: auto;
  background: linear-gradient(180deg, rgba(68,30,106,0.97), rgba(28,11,48,0.98));
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 22px;
  padding: 20px 18px 16px;
  box-shadow: 0 22px 60px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.18);
  text-align: center;
}
.panel.wide { max-width: 460px; }
.panel h2 { margin: 0 0 12px; font-size: 22px; letter-spacing: 0.5px; }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.panel-head h2 { margin: 0; flex: 1; font-size: 16px; letter-spacing: 1.6px; text-align: left; }
.panel-head .stars { font-size: 12px; opacity: 0.85; }
.panel-head .stars b { color: var(--gold); }

.map {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 7px; max-height: 62vh; overflow-y: auto; padding: 2px;
  scrollbar-width: thin;
}
.lvl {
  position: relative; aspect-ratio: 1 / 1.08;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.03));
  color: #fff; font-family: var(--ui);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  cursor: pointer; padding: 4px 3px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.28);
}
.lvl:active { transform: translateY(2px); }
.lvl.done { background: linear-gradient(180deg, rgba(255,210,63,0.26), rgba(255,150,30,0.06)); border-color: rgba(255,210,63,0.45); }
.lvl.locked { opacity: 0.38; filter: grayscale(0.8); }
.lvl-n { font-size: 20px; font-weight: 800; line-height: 1; }
.lvl-s { font-size: 9px; letter-spacing: 0.5px; color: rgba(255,255,255,0.2); }
.lvl-s i { font-style: normal; }
.lvl-s i.on { color: var(--gold); text-shadow: 0 0 7px rgba(255,210,63,0.85); }
.lvl-nm { font-size: 8.5px; opacity: 0.75; text-align: center; line-height: 1.1; max-height: 2.2em; overflow: hidden; }

.stars-big { display: flex; justify-content: center; gap: 6px; margin: 4px 0 8px; }
.stars-big span {
  font-size: 44px; line-height: 1; color: rgba(255,255,255,0.13);
  transform: scale(0.75);
}
.stars-big span.on {
  color: var(--gold);
  text-shadow: 0 0 22px rgba(255,200,40,0.85), 0 3px 0 #a86a00;
  animation: starPop 0.5s cubic-bezier(.2,1.6,.4,1) forwards;
}
@keyframes starPop {
  0% { transform: scale(0.3) rotate(-25deg); opacity: 0; }
  70% { transform: scale(1.22) rotate(6deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
#resultTitle[data-win="1"] { color: var(--gold); }
#resultTitle[data-win="0"] { color: #ff7f95; }
.tally { font-size: 38px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.meta {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 10px; letter-spacing: 1px; opacity: 0.72; margin: 8px 0 4px;
}
.blurb { font-size: 12.5px; line-height: 1.45; opacity: 0.82; margin: 8px 2px 14px; min-height: 2.6em; }
.row { display: flex; gap: 9px; }
.row .btn { margin-bottom: 8px; }
.panel > .btn.tiny { margin: 4px auto 0; }

.howto { text-align: left; margin-top: 14px; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 12px; }
.howto h3 { margin: 0 0 8px; font-size: 12px; letter-spacing: 1.4px; opacity: 0.8; text-transform: uppercase; }
.howto ul { margin: 0; padding: 0; list-style: none; font-size: 11.5px; line-height: 1.45; opacity: 0.85; }
.howto li { margin-bottom: 5px; padding-left: 12px; position: relative; }
.howto li::before { content: '·'; position: absolute; left: 2px; color: var(--gold); }

/* ------------------------------------------------------------- floaters */
.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--ui);
  font-weight: 800; font-size: 16px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(16,4,30,0.9), 0 0 12px rgba(0,0,0,0.35);
  pointer-events: none;
  white-space: nowrap;
  animation: floatUp 0.95s cubic-bezier(.2,.8,.3,1) forwards;
}
.float.big { font-size: 22px; color: #ffe45e; }
.float.word {
  font-size: 30px; letter-spacing: 1px; color: #ffe45e;
  animation: wordPop 1s cubic-bezier(.2,1.4,.4,1) forwards;
}
.float.word.c4, .float.word.c5 { color: #ffd0ff; }
.float.word.c6 { color: #9dfbbf; }
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.7); }
  18% { opacity: 1; transform: translate(-50%, -70%) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -180%) scale(0.95); }
}
@keyframes wordPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(-6deg); }
  25% { opacity: 1; transform: translate(-50%, -60%) scale(1.1) rotate(2deg); }
  75% { opacity: 1; transform: translate(-50%, -70%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -110%) scale(0.9); }
}

#toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-b));
  transform: translate(-50%, 10px);
  background: rgba(18,7,32,0.95);
  border: 1px solid rgba(255,255,255,0.15);
  font-size: 12px; font-weight: 600;
  padding: 9px 15px; border-radius: 11px;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  z-index: 40; max-width: 84vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* rotate gate */
#rotate { display: none; }
@media (orientation: landscape) and (max-height: 520px) {
  #rotate {
    position: fixed; inset: 0; z-index: 60;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
    background: radial-gradient(120% 90% at 50% 30%, #3b1663, #140a24 80%);
    text-align: center; padding: 20px;
  }
  #rotate .phone { font-size: 46px; color: var(--gold); animation: rotateHint 2.4s ease-in-out infinite; }
  #rotate p { margin: 0; font-weight: 700; font-size: 14px; letter-spacing: 0.6px; }
  #rotate small { opacity: 0.6; font-weight: 500; font-size: 11px; }
  @keyframes rotateHint { 0%,40% { transform: rotate(90deg); } 60%,100% { transform: rotate(0deg); } }
}

@media (max-width: 360px) {
  .lvl-badge { width: 38px; height: 38px; flex-basis: 38px; font-size: 18px; }
  .icon-btn { width: 36px; height: 36px; font-size: 16px; }
  .moves-pill b { font-size: 21px; }
  .avatar { width: 38px; height: 38px; flex-basis: 38px; }
  .msg { font-size: 11.5px; padding: 7px 10px; }
  .nudge { width: 50px; font-size: 8px; }
}
