/* Dragon Parade Snake — woodblock-print UI: cream paper, cinnabar red, festival gold, jade, charcoal ink. */
* { box-sizing: border-box; }
:root { --paper: #f3e6c4; --red: #b23a2e; --red2: #c8322a; --gold: #e3b23c; --jade: #2f5d50; --ink: #1b1b1b; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #2a1810; color: var(--ink);
  font-family: 'Baloo 2', 'Nunito', system-ui, 'Noto Sans', sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
#viewport { position: fixed; inset: 0; }
#stage { position: absolute; left: 0; top: 0; width: 1280px; height: 720px; transform-origin: 0 0; overflow: hidden; }
#game { position: absolute; inset: 0; width: 1280px; height: 720px; display: block; touch-action: none; }

.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(42, 24, 16, .55); animation: fade .2s ease; }
.overlay.hidden, .hidden { display: none !important; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { transform: scale(.85) rotate(-1.5deg); opacity: 0 } to { transform: scale(1) rotate(0); opacity: 1 } }
@keyframes wob { 0%,100% { transform: rotate(-2deg) } 50% { transform: rotate(1deg) } }
@keyframes bounce { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-5px) } }
@keyframes shake { 0%,100% { transform: rotate(-2deg) translateX(0) } 25% { transform: rotate(-2deg) translateX(-4px) } 75% { transform: rotate(-2deg) translateX(4px) } }
@keyframes rot { to { transform: rotate(360deg) } }

#loading { background: var(--paper) url(assets/menu_bg.webp) center/cover; }
.loader { text-align: center; font-size: 24px; font-weight: 800; background: var(--paper); padding: 22px 40px; border: 4px solid var(--ink); border-radius: 10px; box-shadow: 7px 7px 0 var(--ink); }
.spin { width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 50%; border: 7px solid #e9d9ae; border-top-color: var(--red2); animation: rot .8s linear infinite; }
.bar { width: 260px; height: 14px; border: 3px solid var(--ink); background: #fff; overflow: hidden; margin-top: 8px; border-radius: 7px; }
.bar i { display: block; height: 100%; width: 0; background: var(--red2); transition: width .2s; }

/* ---------------- menu (attract-mode parade runs behind it) */
#menu { display: block; background: linear-gradient(90deg, rgba(243,230,196,.95) 0%, rgba(243,230,196,.86) 38%, rgba(243,230,196,0) 60%); }
.menu-left { position: absolute; left: 36px; top: 38px; width: 600px; }
.menu-right { position: absolute; right: 24px; top: 84px; width: 420px; display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.logo { display: flex; flex-direction: column; line-height: .84; margin-bottom: 18px; transform-origin: left center; animation: wob 4s ease-in-out infinite; }
.logo .l1, .logo .l2 { font-weight: 900; letter-spacing: 2px; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 5px 5px 0 var(--ink); }
.logo .l1 { font-size: 74px; color: var(--gold); }
.logo .l2 { font-size: 96px; color: var(--red2); margin-left: 24px; }
.logo .l3 { align-self: flex-start; margin-top: 12px; font-size: 21px; font-weight: 800; background: var(--paper); border: 3px solid var(--ink); padding: 2px 14px; transform: rotate(-2deg); box-shadow: 4px 4px 0 var(--ink); border-radius: 6px; }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 8px; }
.mode { font: inherit; text-align: left; cursor: pointer; border: 4px solid var(--ink); border-radius: 12px; padding: 10px 12px 8px; box-shadow: 5px 5px 0 var(--ink); color: #fff; display: flex; flex-direction: column; gap: 2px; min-height: 118px; position: relative; transition: transform .08s, box-shadow .08s; }
.mode:hover { transform: translate(-1px, -3px) rotate(-1deg); box-shadow: 7px 8px 0 var(--ink); }
.mode:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.mode b { font-size: 30px; line-height: 1; -webkit-text-stroke: 1.2px var(--ink); paint-order: stroke fill; }
.mode small { font-size: 14px; font-weight: 700; line-height: 1.15; opacity: .95; overflow-wrap: anywhere; }
.mode i { font-style: normal; font-size: 13px; font-weight: 900; margin-top: auto; background: rgba(0,0,0,.25); border-radius: 8px; padding: 0 8px; align-self: flex-start; }
.mode i:empty { display: none; }
.mode.red { background: var(--red2); }
#mode-classic { animation: bounce 1.4s ease-in-out infinite; }
.mode.gold { background: #d99a1c; }
.mode.jade { background: var(--jade); }
.btn.daily { margin-top: 14px; display: flex; flex-direction: column; align-items: flex-start; line-height: 1.05; background: var(--paper); padding: 8px 18px 10px; max-width: 600px; width: 100%; background-image: repeating-linear-gradient(135deg, rgba(178,58,46,.08) 0 8px, transparent 8px 16px); }
.daily b { font-size: 22px; color: var(--red2); }
.daily small { font-size: 15px; font-weight: 700; }
.bestline { margin-top: 12px; font-size: 20px; font-weight: 800; }
.goal { font-size: 16px; font-weight: 800; background: var(--paper); border: 3px solid var(--ink); padding: 6px 12px; box-shadow: 4px 4px 0 var(--ink); border-radius: 8px; line-height: 1.2; }
.menu-nav { position: absolute; left: 36px; bottom: 22px; display: flex; gap: 10px; flex-wrap: wrap; max-width: 1200px; }

.card { background: var(--paper); border: 4px solid var(--ink); border-radius: 10px; box-shadow: 6px 6px 0 var(--ink); padding: 10px 14px; }
.coinsbox { align-self: flex-end; font-size: 26px; font-weight: 900; padding: 4px 18px; }
.coinsbox b { color: var(--red2); }
.mcard { padding: 8px 14px 10px; }
.mhead { display: flex; justify-content: space-between; font-size: 18px; font-weight: 900; text-transform: uppercase; letter-spacing: 1px; gap: 8px; }
.streak { color: var(--red2); font-size: 16px; text-transform: none; letter-spacing: 0; }
.mmini { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.mm { font-size: 15px; font-weight: 700; line-height: 1.1; display: flex; gap: 8px; align-items: center; }
.mm .t { flex: 1; }
.mm .pb, .tunlock .pb { width: 90px; height: 10px; border: 2px solid var(--ink); background: #fff; flex: none; border-radius: 5px; overflow: hidden; display: inline-block; vertical-align: middle; }
.mm .pb i, .tunlock .pb i { display: block; height: 100%; background: var(--red2); }

.btn { font: inherit; font-weight: 900; font-size: 20px; color: var(--ink); border: 3.5px solid var(--ink); cursor: pointer; padding: 7px 18px 9px; border-radius: 10px; position: relative;
  box-shadow: 5px 5px 0 var(--ink); transition: transform .08s, box-shadow .08s, filter .15s; }
.btn:hover { transform: translate(-1px, -2px) rotate(-1deg); box-shadow: 7px 7px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled { filter: grayscale(.8); opacity: .6; cursor: not-allowed; transform: none; }
.btn.big { font-size: 36px; padding: 4px 36px 8px; letter-spacing: 1px; }
.btn.red { background: var(--red2); color: #fff; -webkit-text-stroke: .8px var(--ink); }
.btn.gold { background: var(--gold); }
.btn.jade { background: var(--jade); color: #fff; }
.btn.paper { background: var(--paper); }
.btn.white { background: #fff; }
.btn small { display: block; font-size: 13px; font-weight: 700; }
.badge { background: var(--red2); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 14px; margin-left: 2px; }

.modal { background: var(--paper); border: 5px solid var(--ink); border-radius: 14px; padding: 16px 26px; min-width: 440px; max-width: 900px; max-height: 700px; text-align: center; box-shadow: 10px 10px 0 var(--ink); animation: pop .22s ease both; display: flex; flex-direction: column;
  background-image: radial-gradient(rgba(178,58,46,.06) 1.5px, transparent 1.6px); background-size: 10px 10px; }
.modal.wide { width: 860px; }
.modal.xwide { width: 1160px; max-width: 1160px; }
.modal h2 { margin: 0 0 6px; font-size: 40px; line-height: 1; color: var(--gold); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 4px 4px 0 var(--ink); letter-spacing: 1px; }
.sub { margin: 0 0 8px; color: #3b2d20; font-size: 16px; font-weight: 700; }
.actions { display: flex; gap: 14px; justify-content: center; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.coins { font-size: 22px; font-weight: 900; margin-right: auto; } .coins b { color: var(--red2); }
.stack { display: flex; flex-direction: column; gap: 12px; min-width: 280px; margin: 8px auto; }

.maps { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.mapcard { font: inherit; background: #fff; border: 3.5px solid var(--ink); border-radius: 10px; padding: 6px; cursor: pointer; box-shadow: 4px 4px 0 var(--ink); display: flex; flex-direction: column; gap: 2px; text-align: left; transition: transform .1s; }
.mapcard:hover { transform: translateY(-2px) rotate(-1deg); }
.mapcard canvas { width: 100%; height: auto; border: 2px solid var(--ink); border-radius: 4px; display: block; }
.mapcard b { font-size: 15px; line-height: 1.05; }
.mapcard small { font-size: 12px; font-weight: 700; color: #5a4a3a; line-height: 1.1; }
.mapcard.on { background: var(--gold); }
.mapcard.locked canvas { filter: grayscale(1) opacity(.5); }
.speeds { display: flex; gap: 12px; justify-content: center; margin-top: 12px; }
.speeds .btn { min-width: 170px; }

.tribe { display: flex; gap: 18px; text-align: left; min-height: 0; }
.tprev { width: 360px; flex: none; display: flex; flex-direction: column; gap: 6px; }
.tprev canvas { width: 100%; height: auto; display: block; border: 4px solid var(--ink); border-radius: 10px; background: #e8cf95;
  background-image: repeating-linear-gradient(0deg, rgba(178,58,46,.12) 0 2px, transparent 2px 22px); }
.tname { font-size: 28px; font-weight: 900; line-height: 1; }
.tdesc { font-size: 16px; font-weight: 700; color: #3b2d20; min-height: 40px; line-height: 1.2; }
.tunlock { font-size: 15px; font-weight: 800; line-height: 1.3; }
.tgrid { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; align-content: start; max-height: 520px; overflow-y: auto; padding: 4px 8px 8px 4px; }
.tgrid.three { grid-template-columns: repeat(3, 1fr); }
.titem { background: #fff; border: 3.5px solid var(--ink); border-radius: 10px; padding: 6px; cursor: pointer; text-align: center; font: inherit; position: relative; box-shadow: 4px 4px 0 var(--ink); transition: transform .1s; }
.titem:hover { transform: translateY(-2px) rotate(-1deg); }
.titem.on { background: var(--gold); }
.titem canvas { width: 100%; height: auto; display: block; }
.titem .tn { font-size: 15px; font-weight: 900; line-height: 1.05; min-height: 32px; overflow-wrap: anywhere; display: flex; align-items: center; justify-content: center; }
.titem .tc { font-size: 15px; font-weight: 900; color: var(--red2); min-height: 18px; }
.titem .sel { position: absolute; top: -10px; right: -8px; background: var(--red2); color: #fff; border: 2.5px solid var(--ink); border-radius: 12px; font-size: 12px; padding: 0 7px; font-weight: 900; }

.list { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.qrow { display: flex; align-items: center; gap: 12px; background: #fff8e3; border: 3px solid var(--ink); border-radius: 10px; padding: 8px 12px; }
.qrow .ic { font-size: 30px; width: 44px; text-align: center; flex: none; }
.qrow .qt { flex: 1; font-weight: 800; font-size: 17px; line-height: 1.15; }
.qrow .qt small { display: block; font-weight: 700; font-size: 14px; color: #5a4a3a; }
.qrow .qp { width: 170px; flex: none; }
.qrow .pb { height: 14px; border: 2.5px solid var(--ink); background: #fff; border-radius: 7px; overflow: hidden; }
.qrow .pb i { display: block; height: 100%; background: var(--jade); }
.qrow .qp small { display: block; font-size: 13px; font-weight: 800; text-align: center; }
.qrow .qr { width: 80px; text-align: right; font-weight: 900; color: var(--red2); font-size: 18px; flex: none; }

.howto { text-align: left; font-size: 17px; margin: 4px 0; padding-left: 26px; line-height: 1.3; font-weight: 600; }
.hitems { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; text-align: left; margin: 8px 0; }
.hitem { display: flex; flex-direction: column; gap: 4px; align-items: center; text-align: center; background: #fff8e3; border: 2.5px solid var(--ink); border-radius: 10px; padding: 6px; font-size: 13px; line-height: 1.15; font-weight: 600; }
.hitem canvas { width: 48px; height: 48px; flex: none; }
.hitem b { display: block; font-size: 14px; }
.keys { margin: 4px 0; color: #3b2d20; font-size: 15px; font-weight: 700; }

.setrow { display: flex; justify-content: space-between; align-items: center; gap: 30px; margin: 6px 0; font-size: 20px; font-weight: 800; }
.setrow select { font: inherit; font-size: 17px; padding: 4px 10px; border-radius: 8px; background: #fff; border: 3px solid var(--ink); }
.toggle { min-width: 120px; font-size: 17px; }

.result .rtitle { display: flex; justify-content: center; }
.result h2 { font-size: 64px; color: var(--red2); transform: rotate(-2deg); animation: shake .3s ease 2; }
.quip { font-size: 19px; font-style: italic; }
.rbody { display: flex; gap: 18px; align-items: stretch; text-align: left; }
#r-dancer { width: 150px; height: auto; align-self: center; flex: none; }
.rstats { width: 400px; flex: none; display: grid; grid-template-columns: 1fr auto; gap: 3px 14px; font-size: 19px; font-weight: 800; align-content: start; background: #fff8e3; border: 3px solid var(--ink); border-radius: 10px; padding: 10px 16px; }
.rstats .v { text-align: right; }
.rstats .big { font-size: 30px; color: var(--red2); }
.rstats .nb { display: inline-block; background: var(--gold); border: 2.5px solid var(--ink); font-size: 13px; padding: 0 6px; margin-left: 6px; transform: rotate(-4deg); animation: pop .3s ease both; border-radius: 6px; }
.rright { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.rewards { background: var(--red); color: #fff; border: 3px solid var(--ink); border-radius: 10px; padding: 10px 16px; font-size: 18px; font-weight: 800; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.rewards .tot { font-size: 28px; color: #ffd24a; -webkit-text-stroke: 1px var(--ink); }
.rextra { display: flex; flex-direction: column; gap: 5px; font-size: 16px; font-weight: 800; max-height: 190px; overflow-y: auto; }
.rextra .ms { background: var(--jade); color: #fff; border: 2.5px solid var(--ink); border-radius: 8px; padding: 3px 10px; animation: pop .3s ease both; }
.rextra .ms.new { background: var(--gold); color: var(--ink); }
.rextra .nx { background: #fff8e3; border: 2.5px solid var(--ink); border-radius: 8px; padding: 3px 10px; }

.toast { position: absolute; top: 120px; left: 50%; transform: translateX(-50%); background: var(--paper); border: 4px solid var(--ink); box-shadow: 6px 6px 0 var(--ink); padding: 8px 22px; border-radius: 10px; font-size: 20px; font-weight: 900; z-index: 20; animation: pop .2s ease; max-width: 900px; text-align: center; pointer-events: none; }
.pausebtn { position: absolute; top: 14px; right: 16px; width: 54px; height: 54px; border-radius: 10px; border: 3.5px solid var(--ink); background: var(--paper); color: var(--ink); font-size: 18px; font-weight: 900; cursor: pointer; z-index: 5; box-shadow: 4px 4px 0 var(--ink); }
#rotate { display: none; position: fixed; inset: 0; background: var(--paper); color: var(--ink); font-size: 26px; font-weight: 900; align-items: center; justify-content: center; text-align: center; padding: 30px; z-index: 50; }
@media (orientation: portrait) and (max-width: 820px) and (pointer: coarse) { #rotate { display: flex; } }
@media (prefers-reduced-motion: reduce) { .logo, #mode-classic, .result h2 { animation: none; } }
.btn.red small { -webkit-text-stroke: 0; }
/* phones: the 1280×720 stage is scaled ~0.55×, so give the menu buttons finger-sized heights (≈44 real px) */
@media (pointer: coarse) {
  .menu-nav .btn { min-height: 80px; }
}
@media (pointer: coarse) { .pausebtn { width: 80px; height: 80px; font-size: 24px; } }
