* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1d6fa3; font-family: 'Trebuchet MS', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
canvas#game { position: fixed; left: 0; top: 0; width: 100vw; height: 100vh; touch-action: none; display: block; }
button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
.hide { display: none !important; }

/* HUD */
#hud { position: fixed; top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; pointer-events: none; }
#hud > * { pointer-events: auto; }
.pill { background: rgba(255,255,255,0.92); border: 3px solid #253041; border-radius: 999px; padding: 6px 14px; font-weight: 800; font-size: 20px; color: #253041; box-shadow: 0 3px 0 rgba(0,0,0,0.25); white-space: nowrap; }
.pill.coins { color: #8a5a00; background: #fff4c2; }
.pill.area { font-size: 16px; }
.spacer { flex: 1; }
.hbtn { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 58px; height: 58px; border-radius: 16px; border: 3px solid #253041; background: #ffd23f; font-size: 24px; line-height: 1; box-shadow: 0 4px 0 #b8860b; padding: 2px 6px; }
.hbtn span { font-size: 12px; font-weight: 800; color: #253041; margin-top: 2px; }
.hbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 #b8860b; }
#soundBtn { background: #e8f4ff; box-shadow: 0 4px 0 #7aa0c0; }
#minimap { flex-basis: 100%; height: 14px; display: flex; position: relative; border: 2px solid #253041; border-radius: 8px; overflow: hidden; max-width: 520px; margin: 0 auto; }
.mm-seg { flex: 1; font-size: 9px; text-align: center; line-height: 10px; border-right: 1px solid rgba(0,0,0,0.3); }
.mm-seg.locked { filter: grayscale(0.8) brightness(0.6); }
#mmBoat { position: absolute; top: 1px; width: 10px; height: 8px; margin-left: -5px; background: #e8463c; border: 1.5px solid #fff; border-radius: 3px; }

#hint { position: fixed; left: 50%; top: 44%; transform: translateX(-50%); color: #fff; font-weight: 900; font-size: 26px; text-shadow: 0 3px 0 #253041, 0 0 12px rgba(0,0,0,0.4); pointer-events: none; opacity: 0; transition: opacity 0.3s; white-space: nowrap; animation: bob 1.6s ease-in-out infinite; }
#hint.show { opacity: 1; }
@keyframes bob { 50% { transform: translateX(-50%) translateY(-6px); } }
#toast { position: fixed; left: 50%; top: 110px; transform: translate(-50%, -20px); background: #253041; color: #fff; padding: 10px 18px; border-radius: 14px; font-weight: 700; font-size: 17px; opacity: 0; transition: all 0.3s; pointer-events: none; max-width: 92vw; text-align: center; border: 3px solid #fff; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Drive joystick */
#stick { position: fixed; left: max(18px, env(safe-area-inset-left)); bottom: max(18px, env(safe-area-inset-bottom)); width: 140px; height: 140px; border-radius: 50%; background: rgba(255,255,255,0.22); border: 4px solid rgba(255,255,255,0.75); box-shadow: 0 4px 14px rgba(0,0,0,0.25); touch-action: none; display: flex; align-items: center; justify-content: center; }
#stick::before { content: '▲'; position: absolute; top: 6px; color: rgba(255,255,255,0.9); font-size: 14px; }
#stick::after { content: '▼'; position: absolute; bottom: 6px; color: rgba(255,255,255,0.9); font-size: 14px; }
#stickKnob { width: 66px; height: 66px; border-radius: 50%; background: #ffd23f; border: 4px solid #253041; display: flex; align-items: center; justify-content: center; font-size: 28px; box-shadow: 0 4px 0 #b8860b; pointer-events: none; }
.loadTrack { width: 260px; height: 12px; margin: 14px auto 0; border-radius: 8px; background: rgba(255,255,255,0.25); overflow: hidden; }
#loadBar { width: 0; height: 100%; background: #ffd23f; transition: width 0.3s; }
#loading { z-index: 50; position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 22px; font-weight: 800; background: #1d6fa3; text-align: center; padding: 20px; }

/* Reel UI */
#reelUI { position: fixed; left: 0; right: 0; bottom: max(12px, env(safe-area-inset-bottom)); display: none; align-items: flex-end; justify-content: center; gap: 16px; padding: 0 12px; pointer-events: none; }
#reelUI.show { display: flex; }
.reelPanel { flex: 1; max-width: 560px; background: rgba(255,255,255,0.92); border: 4px solid #253041; border-radius: 20px; padding: 10px 14px; pointer-events: none; }
.progressWrap { display: flex; align-items: center; gap: 8px; font-size: 22px; }
.progress { flex: 1; height: 14px; border-radius: 8px; background: #d8e2ea; overflow: hidden; border: 2px solid #253041; }
#progressFill { height: 100%; width: 0; background: linear-gradient(90deg, #4cc3e0, #2f8fe0); }
#meter { position: relative; height: 40px; margin-top: 10px; border-radius: 12px; border: 3px solid #253041; background: linear-gradient(90deg, #ffe08a 0%, #ffe08a 8%, #fff 8%, #fff 92%, #ff6a5a 92%); overflow: hidden; }
#meter.danger { animation: flash 0.25s infinite alternate; }
#meter.slack { animation: flash2 0.35s infinite alternate; }
@keyframes flash { to { box-shadow: 0 0 0 4px #ff3a3a; } }
@keyframes flash2 { to { box-shadow: 0 0 0 4px #ffb03a; } }
#meterZone { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(45deg, #4fd46a, #4fd46a 10px, #3fc45a 10px, #3fc45a 20px); border-left: 3px solid #1f7a35; border-right: 3px solid #1f7a35; }
#meterNeedle { position: absolute; top: -2px; bottom: -2px; width: 10px; margin-left: -5px; background: #253041; border-radius: 4px; box-shadow: 0 0 0 2px #fff; }
#warnText { text-align: center; font-weight: 800; color: #253041; font-size: 16px; height: 20px; margin-top: 4px; }
#reelBtn { pointer-events: auto; width: 130px; height: 130px; flex: none; border-radius: 50%; border: 5px solid #253041; background: radial-gradient(circle at 40% 35%, #ff8a7a, #e8463c); color: #fff; font-weight: 900; font-size: 20px; text-shadow: 0 2px 0 #7a1a10; box-shadow: 0 7px 0 #8a2018; touch-action: none; }
#reelBtn.down { transform: translateY(6px); box-shadow: 0 1px 0 #8a2018; background: radial-gradient(circle at 40% 35%, #ffb0a0, #ff5a4a); }

/* Catch card */
#card { position: fixed; left: 0; right: 0; bottom: 0; display: none; align-items: flex-end; justify-content: center; padding-bottom: max(10px, env(safe-area-inset-bottom)); pointer-events: none; }
#card .cardInner { pointer-events: auto; }
#card.show { display: flex; animation: pop 0.35s ease-out; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }
.cardInner { position: relative; width: min(92vw, 420px); max-height: 52vh; overflow: auto; background: #fff; border: 5px solid #253041; border-radius: 26px; padding: 14px 16px 18px; text-align: center; box-shadow: 0 10px 0 rgba(0,0,0,0.25); }
#card.golden .cardInner { background: linear-gradient(160deg, #fff6c8, #ffd23f); border-color: #8a5a00; animation: glow 0.8s infinite alternate; }
@keyframes glow { to { box-shadow: 0 0 40px 10px #ffe066; } }
.caughtTitle { font-weight: 800; color: #5a6a7a; font-size: 16px; }
#cardName { font-size: 24px; font-weight: 900; color: #253041; }
#cardRarity { display: inline-block; color: #fff; font-weight: 900; padding: 3px 14px; border-radius: 999px; margin: 4px 0; text-shadow: 0 1px 0 rgba(0,0,0,0.3); }
#cardInfo { color: #5a6a7a; font-weight: 700; }
#cardCoins { font-size: 26px; font-weight: 900; color: #b8860b; margin: 6px 0 10px; }
#cardNew { position: absolute; top: 10px; right: 10px; background: #e8463c; color: #fff; font-weight: 900; padding: 4px 10px; border-radius: 10px; transform: rotate(8deg); }
#cardBtn, #playBtn { font-size: 22px; font-weight: 900; padding: 12px 36px; border-radius: 18px; border: 4px solid #253041; background: #4fd46a; color: #fff; text-shadow: 0 2px 0 #1f7a35; box-shadow: 0 6px 0 #1f7a35; }
#cardBtn:active, #playBtn:active { transform: translateY(4px); box-shadow: 0 2px 0 #1f7a35; }

/* Modal: shop & book */
#modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(10,30,50,0.55); padding: 10px; }
#modal.show { display: flex; }
.modalInner { width: min(96vw, 760px); height: min(92vh, 720px); background: #f4faff; border: 5px solid #253041; border-radius: 24px; display: flex; flex-direction: column; overflow: hidden; }
.modalHead { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: #2f8fe0; color: #fff; font-weight: 900; font-size: 22px; }
#modalClose { width: 46px; height: 46px; border-radius: 50%; border: 3px solid #253041; background: #fff; font-size: 22px; font-weight: 900; }
#modalBody { flex: 1; overflow-y: auto; padding: 10px 12px 16px; -webkit-overflow-scrolling: touch; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.tabs button { flex: 1; min-width: 110px; padding: 8px 6px; border-radius: 12px; border: 3px solid #253041; background: #fff; font-weight: 800; font-size: 15px; color: #253041; }
.tabs button.on { background: #ffd23f; }
.tabs small { font-weight: 700; opacity: 0.7; }
.coinline { font-size: 18px; margin: 4px 2px 10px; color: #253041; }
.shoplist { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 10px; background: #fff; border: 3px solid #c8d8e8; border-radius: 16px; padding: 8px; }
.item.current { border-color: #4fd46a; background: #effff2; }
.item .icon { width: 96px; height: 64px; flex: none; background: #d8f0ff; border-radius: 10px; }
.item .info { flex: 1; min-width: 0; }
.item .name { font-weight: 900; font-size: 18px; color: #253041; }
.item .desc { font-size: 13px; color: #4a5a6a; line-height: 1.4; }
.bar { color: #2f8fe0; letter-spacing: -1px; }
.buy { padding: 10px 14px; border-radius: 14px; border: 3px solid #253041; background: #ffd23f; font-weight: 900; font-size: 16px; box-shadow: 0 4px 0 #b8860b; white-space: nowrap; }
.buy.cant { background: #e0e4e8; box-shadow: 0 4px 0 #a0a8b0; color: #7a8a9a; }
.owned { font-weight: 800; color: #1f7a35; white-space: nowrap; padding: 0 6px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.fcard { background: #fff; border: 3px solid; border-radius: 14px; padding: 4px; text-align: center; }
.fcard img { width: 100%; aspect-ratio: 3 / 2; display: block; background: linear-gradient(#bfe3f5, #7fb8d8); border-radius: 8px; }
.fcard.unknown img { filter: brightness(0) opacity(0.4); background: none; }
.fcard.golden { background: linear-gradient(160deg, #fff6c8, #ffd23f); }
.fname { font-weight: 800; font-size: 13px; color: #253041; min-height: 32px; display: flex; align-items: center; justify-content: center; }
.fmeta { font-size: 11px; font-weight: 700; color: #6a7a8a; }

/* Title */
#title { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(10,40,60,0.25); }
.titleBox { text-align: center; background: rgba(255,255,255,0.86); border: 5px solid #253041; border-radius: 28px; padding: 18px 30px 24px; max-width: 92vw; box-shadow: 0 10px 0 rgba(0,0,0,0.25); }
.titleBox h1 { margin: 0; font-size: clamp(36px, 8vw, 64px); line-height: 1; color: #2f8fe0; text-shadow: 0 4px 0 #253041; -webkit-text-stroke: 2px #253041; font-weight: 900; }
.titleBox p { font-size: 18px; color: #253041; font-weight: 700; }

/* Small screens */
@media (max-height: 480px) {
  .hbtn { min-width: 48px; height: 48px; font-size: 20px; }
  .pill { font-size: 16px; padding: 4px 10px; }
  #stick { width: 112px; height: 112px; }
  #stickKnob { width: 54px; height: 54px; font-size: 22px; }
  .cardInner { padding: 8px 12px 10px; }
  #cardName { font-size: 20px; }
  #cardCoins { font-size: 20px; margin: 2px 0 6px; }
  #reelBtn { width: 108px; height: 108px; font-size: 17px; }
  #meter { height: 30px; }
  #toast { top: 84px; }
  #hint { top: 40%; font-size: 22px; }
}
@media (max-width: 520px) {
  .hbtn span { display: none; }
  .pill.area { font-size: 13px; }
  #reelBtn { width: 110px; height: 110px; }
  #toast { top: 170px; }
}
