* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --card: #F6F1E7; --ink: #2B2F36; --orange: #E8803A; --orange-d: #c9652a; --teal: #2E9A9A; --red: #C8463C;
  --navy: #22304a; --gold: #e2b84a; --bg: #3a2c22;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
html, body { margin: 0; height: 100%; background: #1c1a18; color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif; overscroll-behavior: none;
  word-break: auto-phrase; text-wrap: pretty; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:disabled { cursor: default; }
#app { position: relative; max-width: 480px; height: 100dvh; margin: 0 auto; display: flex; flex-direction: column; overflow: hidden;
  background: radial-gradient(120% 60% at 50% 0%, #6b4a30 0%, #3a2a1f 55%, #2a201a 100%); }

/* ---------- resource bar ---------- */
#resbar { flex: none; padding: calc(var(--sat) + 8px) 12px 6px; background: linear-gradient(#2a201a, rgba(42,32,26,0.85)); }
.res { display: flex; justify-content: space-around; align-items: center; background: var(--card); border-radius: 14px; padding: 6px 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.3); font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; }
.res > span { display: flex; align-items: center; min-width: 0; white-space: nowrap; }
.ic { display: inline-block; width: 1.05em; height: 1.05em; vertical-align: -0.17em; flex: none; }
.ic svg { width: 100%; height: 100%; display: block; }

/* ---------- screens ---------- */
#screen { flex: 1; overflow-y: auto; padding: 12px 14px 20px; -webkit-overflow-scrolling: touch; }
.title-plate { display: inline-block; margin: 2px auto 10px; padding: 6px 22px; background: #efe4cc; border: 3px solid #8a6a45; border-radius: 10px;
  font-size: 22px; font-weight: 900; letter-spacing: .08em; box-shadow: 0 3px 0 rgba(0,0,0,.25); }
.center { text-align: center; }
.card { background: var(--card); border-radius: 16px; padding: 12px 14px; margin: 10px 0; box-shadow: 0 3px 10px rgba(0,0,0,.25); }
.card h3 { margin: 0 0 6px; font-size: 17px; }
.muted { color: #6c6a66; font-size: 15px; }
.small { font-size: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.btn { display: block; width: 100%; min-height: 52px; border-radius: 16px; background: var(--orange); color: #fff; font-size: 20px; font-weight: 900;
  box-shadow: 0 4px 0 var(--orange-d); margin: 10px 0 4px; letter-spacing: .05em; }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--orange-d); }
.btn:disabled { background: #b9b2a6; box-shadow: 0 4px 0 #948d82; }
.btn.sub { background: var(--card); color: var(--ink); border: 3px solid var(--teal); box-shadow: none; font-size: 17px; min-height: 48px; }
.btn.mini { display: inline-block; width: auto; min-height: 40px; padding: 4px 14px; font-size: 15px; margin: 0; border-radius: 12px; box-shadow: 0 3px 0 var(--orange-d); }
.btn.mini.sub { box-shadow: none; border-width: 2px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.tag { display: inline-block; padding: 1px 9px; border-radius: 8px; font-size: 13px; font-weight: 800; color: #fff; background: var(--teal); white-space: nowrap; }
.tag.red { background: var(--red); } .tag.gold { background: var(--gold); color: #3a2a10; } .tag.gray { background: #8c8780; }
.pips { display: inline-flex; gap: 4px; }
.pips i { width: 11px; height: 11px; border-radius: 50%; background: #ddd5c6; border: 1px solid #c9bfae; }
.pips i.on { background: var(--teal); border-color: var(--teal); }
.pips i.gold { background: var(--gold); border-color: #b48a1e; box-shadow: 0 0 6px #ffd76a; }
.bar { height: 12px; border-radius: 6px; background: #ddd5c6; overflow: hidden; }
.bar > b { display: block; height: 100%; background: var(--teal); border-radius: 6px; transition: width .2s; }
.bar.over > b { background: var(--red); }

/* robot stage */
.stage { position: relative; height: 210px; margin: 0 -14px; border-radius: 0 0 18px 18px; overflow: hidden;
  background: linear-gradient(#5b3f2a 0%, #7a5434 58%, #8f6440 58%, #6d4a2f 100%); }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.weight { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.weight .bar { flex: 1; }

/* part rows */
.prow { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--card); border-radius: 14px; padding: 8px 10px; margin: 8px 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.2); min-height: 64px; }
.prow canvas { width: 52px; height: 52px; flex: none; }
.prow .slot { font-size: 13px; }
.prow .pname { font-weight: 800; font-size: 17px; }
.prow .chev { font-size: 22px; color: #8c8780; }
.prow.sel { outline: 3px solid var(--orange); }
.prow.dis { opacity: .55; background: #e3ddd2; }
.prow .desc { font-size: 14px; color: #555; }

/* tournament */
.round { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px solid #e3dccf; }
.round:last-child { border-bottom: 0; }
.round.now { background: #fff1e3; border-radius: 12px; outline: 2px solid #f3b27d; }
.round .lbl { width: 62px; flex: none; font-weight: 900; font-size: 15px; color: var(--teal); }
.face { width: 46px; height: 46px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 900; color: #fff; font-size: 18px;
  border: 3px solid rgba(0,0,0,.15); text-shadow: 0 1px 2px rgba(0,0,0,.4); }

/* shop */
.shelves { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.shelf { background: var(--card); border-radius: 16px; padding: 10px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,.25); font-weight: 900; }
.shelf.sel { outline: 4px solid var(--orange); }

/* tabs */
#tabs { flex: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 6px 8px calc(var(--sab) + 6px); background: #2a201a; }
#tabs button { background: var(--card); border-radius: 12px; min-height: 56px; font-weight: 800; font-size: 15px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#tabs .ti { font-size: 20px; line-height: 1.1; }
#tabs button.on { background: var(--teal); color: #fff; }

/* overlay (pre-battle, battle, result) */
#overlay { position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; overflow: hidden;
  background: radial-gradient(120% 60% at 50% 0%, #6b4a30 0%, #3a2a1f 55%, #2a201a 100%); }
#overlay[hidden] { display: none; }
.ov-scroll { flex: 1; overflow-y: auto; padding: calc(var(--sat) + 10px) 14px calc(var(--sab) + 14px); }
.ov-head { display: flex; align-items: center; justify-content: space-between; background: #efe4cc; border-radius: 14px; padding: 6px 14px; font-weight: 900; font-size: 22px; }
.timer-chip { background: var(--teal); color: #fff; border-radius: 12px; padding: 2px 12px; font-size: 20px; font-variant-numeric: tabular-nums; }
.mapcard { position: relative; background: var(--card); border-radius: 16px; overflow: hidden; margin: 10px 0; }
.mapcard canvas { display: block; width: 100%; height: 190px; }
.mapcard .maplabel { position: absolute; left: 0; top: 0; background: var(--teal); color: #fff; font-weight: 900; padding: 3px 14px; border-radius: 0 0 12px 0; }
.mapcard .mapnote { padding: 6px 12px 10px; font-size: 14px; }
.versus { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.versus .side { background: rgba(246,241,231,.12); border-radius: 14px; padding: 6px; text-align: center; color: #fff; }
.versus canvas { width: 100%; height: 130px; }
.versus .nm { font-weight: 900; }
.hint-band { background: #22262c; color: #fff; font-weight: 900; border-radius: 10px; padding: 6px 10px; margin-top: 4px; font-size: 15px; }
.icons5 { display: flex; justify-content: center; gap: 2px; margin-top: 4px; }
.icons5 canvas { width: 30px; height: 30px; background: var(--card); border-radius: 6px; }
.swapbar { display: flex; justify-content: space-between; gap: 6px; }
.swapbar button { flex: 1; background: #fff; border-radius: 12px; padding: 4px 0 2px; border: 2px solid #e3dccf; }
.swapbar button.changed { border-color: var(--orange); background: #fff1e3; box-shadow: 0 0 10px rgba(232,128,58,.6); }
.swapbar canvas { width: 44px; height: 44px; display: block; margin: 0 auto; }
.swapbar .sl { font-size: 13px; font-weight: 800; }
.advice { background: var(--navy); color: #fff; border: 2px solid var(--gold); }
.advice h3 { color: var(--gold); }
.advice li { margin: 4px 0; font-size: 15px; }

/* battle */
.battle { position: absolute; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
.battle canvas.field, .battle canvas.field3d, .battle canvas.fieldfx { position: absolute; inset: 0; width: 100%; height: 100%; }
.battle canvas.fieldfx { pointer-events: none; }
.hud { position: absolute; left: 0; right: 0; top: 0; padding: calc(var(--sat) + 8px) 10px 0; display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: start; pointer-events: none; }
.hp { color: #fff; font-weight: 800; font-size: 13px; }
.hp .nm { text-shadow: 0 1px 2px #000; }
.hp .hb { height: 16px; border-radius: 8px; background: rgba(0,0,0,.5); overflow: hidden; border: 2px solid rgba(255,255,255,.7); position: relative; }
.hp .hb b { position: absolute; left: 0; top: 0; bottom: 0; background: var(--orange); transition: width .15s; }
.hp.enemy .hb b { left: auto; right: 0; background: var(--teal); }
.hp .hb span { position: absolute; inset: 0; text-align: center; font-size: 12px; line-height: 12px; text-shadow: 0 1px 2px #000; }
.hp .sb { height: 6px; border-radius: 3px; background: rgba(0,0,0,.45); margin-top: 3px; overflow: hidden; }
.hp .sb b { display: block; height: 100%; background: #ffd36b; }
.hp.enemy { text-align: right; } .hp.enemy .sb b { margin-left: auto; }
.clock { background: rgba(20,22,26,.8); color: #fff; font-weight: 900; font-size: 24px; padding: 2px 12px; border-radius: 12px; font-variant-numeric: tabular-nums; }
.stick { position: absolute; left: 14px; bottom: calc(var(--sab) + 18px); width: 150px; height: 150px; border-radius: 50%;
  background: rgba(246,241,231,.18); border: 3px solid rgba(246,241,231,.45); touch-action: none; }
.stick .knob { position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%; background: rgba(246,241,231,.75); box-shadow: 0 3px 8px rgba(0,0,0,.4); }
.stick .dashlbl { position: absolute; bottom: -2px; left: 0; right: 0; text-align: center; color: rgba(255,255,255,.75); font-size: 12px; font-weight: 800; }
.acts { position: absolute; right: 10px; bottom: calc(var(--sab) + 18px); width: 214px; height: 150px; }
.act { position: absolute; width: 76px; height: 76px; border-radius: 50%; background: var(--card); box-shadow: 0 4px 0 #b9ad98, 0 6px 14px rgba(0,0,0,.4);
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 900; font-size: 17px; touch-action: none; }
.act canvas { width: 34px; height: 34px; }
.act.cool::after { content: ''; position: absolute; inset: -5px; border-radius: 50%;
  background: conic-gradient(rgba(46,154,154,.0) calc(var(--cd) * 360deg), rgba(20,22,26,.55) 0); pointer-events: none; }
.act.none { opacity: .35; }
.act:active { transform: translateY(3px); }
.act.a1 { left: 0; bottom: 0; } .act.a2 { left: 69px; bottom: 50px; } .act.a3 { right: 0; bottom: 0; }
.jumpchip { position: absolute; right: 22px; bottom: calc(var(--sab) + 178px); background: rgba(246,241,231,.92); border-radius: 14px; padding: 6px 12px; font-weight: 800; font-size: 14px; }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; font-size: 64px; font-weight: 900; color: #fff;
  text-shadow: 0 4px 0 rgba(0,0,0,.4), 0 0 20px rgba(232,128,58,.9); }
.howto { position: absolute; inset: 0; background: rgba(20,22,26,.72); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; }
.howto .card { max-width: 360px; }
.howto ul { padding-left: 1.2em; margin: 6px 0; }

/* result */
.banner { margin: 6px auto 0; width: 82%; text-align: center; background: var(--orange); color: #fff; font-size: 44px; font-weight: 900; border-radius: 14px;
  padding: 2px 0; box-shadow: 0 4px 0 var(--orange-d); letter-spacing: .1em; }
.banner.lose { background: #5d6470; box-shadow: 0 4px 0 #3d434c; }
.reward-card { background: var(--navy); color: #fff; border: 3px solid var(--gold); }
.reward-card h3 { color: var(--gold); text-align: center; }
.reward-card .inner { background: var(--card); color: var(--ink); border-radius: 12px; padding: 8px 10px; margin: 6px 0; }
.gains { display: flex; justify-content: center; gap: 26px; font-size: 24px; font-weight: 900; font-variant-numeric: tabular-nums; }
.pop { animation: pop .45s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* sheets / popups: dark blurred backdrop */
#sheet-layer { position: absolute; inset: 0; z-index: 40; display: flex; flex-direction: column; justify-content: flex-end; }
#sheet-layer[hidden] { display: none; }
#sheet-layer .backdrop { position: absolute; inset: 0; background: rgba(15,14,13,.55); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); animation: fade .2s both; }
#sheet { position: relative; background: #f3ede2; border-radius: 22px 22px 0 0; padding: 8px 14px calc(var(--sab) + 14px); max-height: 86%; overflow-y: auto; animation: up .22s ease-out both; }
#sheet.center-pop { margin: auto 16px; border-radius: 22px; padding-bottom: 14px; animation: fade .2s both, pop .3s both; }
#sheet-layer.centered { justify-content: center; }
#sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: #c9bfae; margin: 2px auto 8px; }
#sheet h2 { margin: 2px 0 8px; text-align: center; font-size: 22px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
#toast { position: absolute; left: 50%; top: calc(var(--sat) + 64px); transform: translateX(-50%); z-index: 60; background: rgba(20,22,26,.92); color: #fff;
  padding: 8px 16px; border-radius: 12px; font-weight: 800; max-width: 90%; text-align: center; }
canvas[data-robot] { display: block; width: 100%; height: 100%; }
.versus canvas[data-robot] { height: 130px; }
.sticky-foot { position: sticky; bottom: calc(-14px - var(--sab)); margin: 0 -14px; padding: 4px 14px calc(var(--sab) + 10px);
  background: linear-gradient(rgba(42,32,26,0), rgba(42,32,26,.95) 30%); }
#screen .sticky-foot { bottom: -20px; padding-bottom: 14px; }
.shelf canvas { margin: 0 auto; display: block; }
