:root {
  --ink: #2b1d14;
  --cream: #fff7e6;
  --cream2: #f6e7c8;
  --wood: #a0673a;
  --wood2: #7a4a26;
  --gold: #f7c22f;
  --blue: #2f7de1;
  --red: #e0443a;
  --green: #4f9a2e;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: #2f5d1c; color: var(--ink); font-family: var(--font); }
img { -webkit-touch-callout: none; -webkit-user-drag: none; user-select: none; pointer-events: none; }
#field { touch-action: none; }
body {
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,0.05) 0 12%, transparent 13%) 0 0 / 46px 46px,
    linear-gradient(#3e7424, #2a5317);
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
button:focus-visible, [tabindex]:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
#app { position: relative; width: 100%; max-width: 560px; height: 100%; height: 100dvh; margin: 0 auto; overflow: hidden; box-shadow: 0 0 60px rgba(0,0,0,0.35); }
#field { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; position: relative;
  min-height: 48px; padding: 10px 22px; border-radius: 16px; border: 3px solid var(--ink);
  background: var(--cream); font-weight: 900; font-size: 17px; letter-spacing: 0.04em;
  box-shadow: 0 5px 0 var(--ink); transition: transform 0.06s, box-shadow 0.06s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: linear-gradient(#ffd84d, #f5b81c); }
.btn.big { min-height: 64px; font-size: 26px; padding: 12px 40px; border-radius: 20px; }
.btn.small { min-height: 42px; font-size: 14px; padding: 8px 14px; border-radius: 13px; box-shadow: 0 4px 0 var(--ink); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 3px solid var(--ink); background: var(--cream);
  font-size: 20px; font-weight: 900; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 3px 0 var(--ink); padding: 0;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.icon-btn.small { width: 36px; height: 36px; font-size: 15px; border-radius: 11px; }
.dot { position: absolute; top: -8px; right: -8px; min-width: 22px; height: 22px; border-radius: 11px; background: var(--red); color: #fff; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; border: 2px solid var(--ink); padding: 0 4px; }

/* ---------- screens ---------- */
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding: calc(12px + var(--safe-t)) 16px calc(14px + var(--safe-b)); z-index: 5; }
.screen.dim { background: rgba(30, 22, 12, 0.55); align-items: center; justify-content: center; }

#home { justify-content: space-between; background: linear-gradient(rgba(30,50,15,0.55), rgba(30,50,15,0.05) 32%, rgba(30,50,15,0.05) 58%, rgba(30,40,12,0.7)); }
.home-top { display: flex; justify-content: space-between; align-items: center; }
.pill { background: var(--cream); border: 3px solid var(--ink); border-radius: 20px; padding: 6px 14px; font-weight: 900; font-size: 18px; box-shadow: 0 3px 0 var(--ink); }
.home-mid { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.logo { margin: 4px 0 0; display: flex; flex-direction: column; align-items: center; line-height: 0.88; font-weight: 1000; letter-spacing: 0.02em; transform: rotate(-3deg); }
.logo span { color: #ffd84d; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--ink); }
.logo .l1 { font-size: clamp(46px, 14.5vw, 76px); }
.logo .l2 { font-size: clamp(50px, 15.5vw, 82px); color: #fff3d6; }
.tag { margin: 6px 0 2px; color: #fff; font-weight: 800; font-size: 16px; text-shadow: 0 2px 0 rgba(0,0,0,0.5); text-align: center; }
.arena-card { width: min(100%, 360px); background: var(--cream); border: 3px solid var(--ink); border-radius: 18px; padding: 10px 14px 12px; box-shadow: 0 5px 0 var(--ink); }
.arena-head { display: flex; align-items: center; gap: 10px; font-weight: 900; font-size: 19px; }
.arena-num { width: 30px; height: 30px; border-radius: 50%; background: var(--wood); color: #fff; display: inline-flex; align-items: center; justify-content: center; border: 2px solid var(--ink); font-size: 16px; }
.arena-bar { height: 14px; border-radius: 7px; background: #e2d2ad; border: 2px solid var(--ink); margin: 9px 0 7px; overflow: hidden; }
#arenaFill { height: 100%; background: linear-gradient(90deg, #f5b81c, #ffd84d); width: 0; transition: width 0.6s; }
.arena-next { display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 14px; color: #5a4030; min-height: 30px; }
.nx-i { width: 34px; height: 30px; object-fit: contain; }
.home-bot { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.deck-row { display: flex; gap: 6px; cursor: pointer; }
.mini { width: 70px; background: var(--cream); border: 2px solid var(--ink); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; align-items: center; box-shadow: 0 3px 0 var(--ink); }
.mini img { width: 100%; height: 50px; object-fit: cover; display: block; }
.mini-n { font-size: 11px; font-weight: 900; padding: 2px 0 3px; white-space: nowrap; }
.home-links { display: flex; gap: 10px; }
.credit { margin: 0; color: rgba(255,255,255,0.75); font-size: 11px; font-weight: 700; }

/* ---------- deck ---------- */
.panel-screen { background: linear-gradient(#f9eccf, #f1dcb2); overflow-y: auto; -webkit-overflow-scrolling: touch; gap: 6px; }
.row-head { display: flex; align-items: center; gap: 12px; }
.row-head h2 { margin: 0; font-size: 26px; font-weight: 1000; }
.sub { margin: 4px 0 6px; font-weight: 700; font-size: 14px; color: #5a4030; }
.panel-screen h3 { margin: 12px 0 4px; font-size: 18px; font-weight: 900; }
.deck-slots, .collection { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.dcard { position: relative; background: var(--cream); border: 3px solid var(--ink); border-radius: 13px; padding: 0 0 5px; overflow: hidden; display: flex; flex-direction: column; align-items: center; box-shadow: 0 3px 0 var(--ink); min-width: 0; }
.dcard img { width: 100%; aspect-ratio: 104 / 84; object-fit: cover; display: block; border-bottom: 2px solid var(--ink); }
.dc-n { font-weight: 900; font-size: 12.5px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 96%; }
.dc-r { font-weight: 700; font-size: 10.5px; color: #7a5a40; }
.dcard.in-deck { border-color: var(--blue); box-shadow: 0 3px 0 #1b4d96; }
.dcard.swap { animation: wiggle 0.5s infinite; }
.dcard.locked img { filter: grayscale(1) brightness(0.45); }
.dcard.locked { background: #d9cbb0; }
.dcard.used { opacity: 0.6; }
.new-tag, .in-tag { position: absolute; top: 4px; right: 4px; font-size: 9.5px; font-weight: 900; border-radius: 6px; padding: 1px 5px; border: 2px solid var(--ink); }
.new-tag { background: var(--red); color: #fff; }
.in-tag { background: var(--blue); color: #fff; }
.swap-hint { cursor: pointer;  margin: 6px 0 0; font-weight: 900; color: var(--blue); text-align: center; }
@keyframes wiggle { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }

.modal { position: absolute; inset: 0; background: rgba(30,22,12,0.6); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 18px; }
.info-card { position: relative; width: min(100%, 340px); background: var(--cream); border: 3px solid var(--ink); border-radius: 20px; padding: 16px; box-shadow: 0 6px 0 var(--ink); display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.info-card.small { gap: 10px; }
.info-card.small p { margin: 0 0 6px; font-weight: 700; }
.info-card .close { position: absolute; top: 10px; right: 10px; width: 38px; height: 38px; font-size: 16px; }
#infoArt { width: 170px; height: 138px; object-fit: cover; border-radius: 14px; border: 3px solid var(--ink); }
.info-card h3 { margin: 4px 0 0; font-size: 24px; font-weight: 1000; }
.role { font-weight: 900; color: #fff; background: var(--wood); border-radius: 8px; padding: 1px 10px; font-size: 13px; }
#infoText { margin: 4px 0; font-weight: 700; font-size: 15px; }
.stats { display: flex; gap: 8px; }
.st { background: #fff; border: 2px solid var(--ink); border-radius: 10px; padding: 4px 8px; display: flex; flex-direction: column; min-width: 74px; }
.st b { font-size: 18px; }
.st span { font-size: 11px; font-weight: 800; color: #7a5a40; }
.perk { margin: 6px 0; font-size: 13.5px; font-weight: 700; background: #fff3c4; border: 2px dashed #c9a03a; border-radius: 10px; padding: 6px 8px; }
.perk b { color: #b07a00; }

/* ---------- VS ---------- */
.vs-box { background: var(--cream); border: 3px solid var(--ink); border-radius: 22px; padding: 16px 18px; width: min(100%, 360px); box-shadow: 0 6px 0 var(--ink); display: flex; flex-direction: column; align-items: center; gap: 8px; animation: pop 0.35s ease-out; }
.vs-arena { font-weight: 900; color: #7a5a40; }
.vs-row { display: flex; align-items: center; gap: 12px; }
.vs-side { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 17px; width: 120px; text-align: center; }
.vs-side img { width: 88px; height: 88px; }
.vs-x { font-size: 32px; font-weight: 1000; color: var(--red); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; }
.vs-deck-t { font-weight: 900; font-size: 13px; color: #7a5a40; margin-top: 4px; }
.vs-deck { display: flex; gap: 6px; }
.vs-deck img { width: 66px; height: 54px; object-fit: cover; border-radius: 10px; border: 2px solid var(--ink); }
.vs-tough { font-weight: 900; font-size: 13px; color: var(--red); }
.vs-tap { font-size: 12px; font-weight: 800; color: #9a7a5a; margin-top: 2px; }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 4; display: flex; flex-direction: column; }
#hud button, #hud .card { pointer-events: auto; }
.hud-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: rgba(255, 247, 230, 0.93); border-color: var(--ink); border-style: solid; border-width: 0; }
.hud-bar.top { padding-top: calc(8px + var(--safe-t)); border-bottom-width: 3px; border-radius: 0 0 18px 18px; }
.hud-bar.bottom { margin-top: auto; padding-bottom: calc(8px + var(--safe-b)); border-top-width: 3px; border-radius: 18px 18px 0 0; }
.pic { width: 46px; height: 46px; flex: none; }
.who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.who-row { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.who-row b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hearts { display: inline-flex; gap: 1px; font-size: 16px; color: #e53935; text-shadow: 0 1px 0 var(--ink); }
.heart.empty { color: #cdbfa6; text-shadow: none; }
.heart.breaking { animation: heartbreak 0.9s ease-out; }
@keyframes heartbreak { 0% { transform: scale(1); color: #e53935; } 30% { transform: scale(1.7) rotate(-12deg); color: #e53935; } 100% { transform: scale(1); } }
.chips { display: flex; gap: 4px; flex-wrap: wrap; min-height: 26px; }
.chip { display: inline-flex; align-items: center; gap: 1px; background: #fff; border: 2px solid var(--ink); border-radius: 9px; padding: 0 5px 0 1px; height: 26px; font-weight: 900; font-size: 12.5px; }
.chip img { width: 26px; height: 22px; object-fit: contain; }
.chip-s { color: #b07a00; font-size: 11px; margin-left: 2px; }
.chip.trick { background: #eaf3ff; }
.chip-empty { font-size: 12px; font-weight: 700; color: #9a7a5a; line-height: 26px; }
.speed { width: 52px; font-size: 18px; flex: none; }
.round-tag { align-self: center; margin-top: 8px; background: rgba(43,29,20,0.72); color: #fff; font-weight: 900; font-size: 13px; padding: 3px 12px; border-radius: 10px; }

#tray { margin-top: auto; padding: 10px 10px 8px; }
#tray:not([hidden]) + .hud-bar.bottom { margin-top: 0; }
.tray-head { display: flex; flex-direction: column; align-items: center; gap: 0; margin-bottom: 8px; }
.tray-head b { font-size: 20px; color: #fff; -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; letter-spacing: 0.02em; }
#pickHint { font-size: 13.5px; font-weight: 900; color: #fff; text-shadow: 0 1px 0 var(--ink), 0 0 6px rgba(0,0,0,0.6); min-height: 18px; text-align: center; }
#tray.comeback .tray-head b { color: var(--gold); }
.offers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.card {
  position: relative; display: flex; flex-direction: column; align-items: center; padding: 0 0 6px; overflow: hidden;
  background: var(--cream); border: 3px solid var(--ink); border-radius: 16px; box-shadow: 0 5px 0 var(--ink);
  animation: deal 0.28s ease-out both; min-width: 0;
}
.card:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.card.gold { background: #fff1c2; border-color: #8a5a00; box-shadow: 0 5px 0 #8a5a00, 0 0 18px rgba(255,200,40,0.7); }
.card-art { width: 100%; aspect-ratio: 104 / 84; object-fit: cover; display: block; border-bottom: 2px solid var(--ink); }
.badge { position: absolute; top: 4px; left: 5px; z-index: 2; font-size: 22px; font-weight: 1000; color: #fff; -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; line-height: 1; }
.card.gold .badge { color: #ffd84d; }
.card-n { font-weight: 1000; font-size: 15px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 96%; }
.card-l { font-weight: 800; font-size: 12px; color: #7a5a40; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 96%; min-height: 15px; }
.card.perk .card-l { color: #b07a00; }
.card.chosen { animation: chosen 0.4s ease-in forwards; }
.card.gone { animation: gone 0.3s ease-in forwards; }
@keyframes deal { from { transform: translateY(40px) scale(0.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes chosen { 30% { transform: scale(1.08); } 100% { transform: translateY(-120px) scale(0.5); opacity: 0; } }
@keyframes gone { to { transform: translateY(30px); opacity: 0; } }
.timer { height: 8px; margin: 10px 4px 0; border-radius: 4px; background: rgba(43,29,20,0.45); overflow: hidden; }
#timerFill { height: 100%; width: 100%; background: #9be15d; transition: width 0.2s linear; }
.timer.low #timerFill { background: #ff6b5e; }

/* ---------- banner + toast ---------- */
.banner { position: absolute; left: 0; right: 0; top: 38%; z-index: 8; display: flex; flex-direction: column; align-items: center; pointer-events: none; opacity: 0; transform: scale(0.6); transition: opacity 0.15s, transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1); }
.banner.in { opacity: 1; transform: none; }
.b-main { font-size: clamp(40px, 13vw, 62px); font-weight: 1000; color: #fff; -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; letter-spacing: 0.02em; text-shadow: 0 6px 0 var(--ink); }
.b-sub { margin-top: 6px; font-size: 16px; font-weight: 900; color: #fff; background: rgba(43,29,20,0.78); padding: 4px 12px; border-radius: 10px; }
.banner.win .b-main { color: #8fd0ff; }
.banner.lose .b-main { color: #ff8a80; }
.banner.gold .b-main { color: #ffd84d; }
.banner.go .b-main { color: #ffd84d; }
.toast { position: absolute; left: 4%; right: 4%; margin: 0 auto; width: fit-content; top: calc(96px + var(--safe-t)); z-index: 9; background: rgba(43,29,20,0.88); color: #fff; font-weight: 800; font-size: 14px; padding: 7px 14px; border-radius: 12px; text-align: center; pointer-events: none; }

/* ---------- result + help ---------- */
.res-box { width: min(100%, 360px); background: var(--cream); border: 3px solid var(--ink); border-radius: 22px; padding: 18px; box-shadow: 0 6px 0 var(--ink); display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; animation: pop 0.35s ease-out; }
.res-box h2 { margin: 0; font-size: 42px; font-weight: 1000; color: #ff8a80; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; }
#result.won .res-box h2 { color: #ffd84d; }
#resSub { margin: 0; font-weight: 800; }
.res-tro { display: flex; align-items: baseline; gap: 6px; font-size: 26px; font-weight: 1000; }
.res-total { font-size: 14px; font-weight: 800; color: #7a5a40; margin-left: 8px; }
.unlock { width: 100%; background: #fff3c4; border: 2px dashed #c9a03a; border-radius: 14px; padding: 8px; }
.unl-t { font-weight: 1000; font-size: 17px; margin-bottom: 6px; }
.unl-row { display: flex; gap: 10px; justify-content: center; }
.unl-card { display: flex; flex-direction: column; align-items: center; font-weight: 900; font-size: 13px; gap: 2px; }
.unl-card img { width: 92px; height: 74px; object-fit: cover; border-radius: 12px; border: 3px solid var(--ink); animation: pop 0.5s 0.6s both; }
.res-box .btn { width: 100%; }
.help-box h2 { color: #ffd84d; font-size: 34px; }
.steps { text-align: left; margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 8px; font-size: 15px; font-weight: 700; }
.steps b { font-weight: 1000; }
.k { display: inline-block; background: var(--ink); color: #ffd84d; border-radius: 6px; padding: 0 5px; font-weight: 1000; }
.tip { margin: 2px 0; font-size: 14px; font-weight: 800; color: #7a5a40; }

.rotate { display: none; }
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .rotate { display: flex; position: fixed; inset: 0; z-index: 50; background: #2f5d1c; color: #fff; align-items: center; justify-content: center; font-weight: 900; font-size: 22px; text-align: center; padding: 20px; }
}
.noscript { color: #fff; text-align: center; padding: 40px; font-weight: 800; }

@media (max-height: 700px) {
  .btn.big { min-height: 54px; font-size: 22px; }
  .logo .l1 { font-size: 44px; }
  .logo .l2 { font-size: 48px; }
  .mini img { height: 40px; }
  .card-l { display: none; }
  .badge { font-size: 19px; }
}
@media (prefers-reduced-motion: reduce) {
  .card, .vs-box, .res-box, .unl-card img { animation: none !important; }
  .dcard.swap { animation: none; outline: 3px dashed var(--blue); }
}

/* 404 page */
.lost { position: fixed; }
