:root {
  --ink: #1a1410;
  --paper: #f3e6c4;
  --wood: #6a4424;
  --wood2: #4a2e16;
  --rust: #c8502a;
  --gold: #ffcf4a;
  --green: #6ad04a;
  --red: #e04a3a;
  --panel: rgba(26, 18, 10, .82);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0a0705; overflow: hidden; color: var(--paper); font-family: 'Oswald', 'Arial Narrow', sans-serif; user-select: none; -webkit-user-select: none; touch-action: none; }
#wrap { position: absolute; left: 50%; top: 50%; width: 1280px; height: 720px; transform-origin: center center; overflow: hidden; background: #000; box-shadow: 0 0 60px #000; }
canvas#game { position: absolute; inset: 0; display: block; }
.hidden { display: none !important; }
button { font-family: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

/* ---- panels ---- */
.panel { background: var(--panel); border: 2px solid #3a2a18; border-radius: 10px; box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 3px 8px rgba(0,0,0,.4); }
#topbar { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 10px; align-items: stretch; pointer-events: none; }
#topbar > * { pointer-events: auto; }
.lbl { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; opacity: .75; }
.big { font-family: 'Rye', serif; font-size: 26px; color: var(--gold); line-height: 1.05; text-shadow: 0 2px 0 #000; }
.small { font-size: 13px; opacity: .85; }
.cashbox { padding: 6px 14px; min-width: 130px; }
.brew { display: flex; gap: 8px; align-items: center; padding: 6px 12px 6px 8px; text-align: left; transition: transform .1s, border-color .2s; }
.brew:hover { border-color: var(--gold); transform: translateY(-1px); }
.brew.off { opacity: .55; }
.brew .ico { width: 36px; height: 36px; }
.meterbox { padding: 6px 12px; width: 230px; }
.meter { position: relative; height: 22px; border-radius: 11px; background: #1a0e06; border: 2px solid #000; overflow: hidden; margin-top: 3px; }
#meterFill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #c8302a, #ff9a2a, #ffd84a); transition: width .15s; }
#meterFill.full { animation: pulse 0.7s infinite alternate; }
#meterTxt { position: absolute; inset: 0; text-align: center; font-weight: 700; font-size: 13px; line-height: 18px; text-shadow: 0 1px 2px #000; }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.5); } }
.bases { flex: 1; padding: 6px 12px; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.baserow { display: flex; align-items: center; gap: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.baserow span { width: 82px; opacity: .8; }
.bar { flex: 1; height: 12px; background: #1a0e06; border: 2px solid #000; border-radius: 6px; overflow: hidden; }
.fill { height: 100%; width: 100%; transition: width .2s; }
.fill.green { background: linear-gradient(#8ae05a, #3a9a2a); }
.fill.red { background: linear-gradient(#ff6a4a, #a82a1a); }
.tbtns { display: flex; gap: 6px; }
.ibtn { width: 46px; display: grid; place-items: center; font-weight: 700; font-size: 16px; }
.ibtn svg { width: 22px; height: 22px; }
.ibtn:hover { border-color: var(--gold); }
.ibtn.off { opacity: .45; }

/* ---- bottom bar ---- */
#bottombar { position: absolute; left: 0; right: 0; bottom: 0; height: 112px; display: flex; align-items: flex-end; gap: 10px; padding: 0 10px 10px; background: linear-gradient(transparent, rgba(0,0,0,.6) 40%); }
#cards { display: flex; gap: 6px; }
.card { position: relative; width: 84px; height: 96px; border-radius: 10px; background: linear-gradient(#7a5230, #4a2e16); border: 2px solid #2a1a0c; box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 4px 0 #1a0e06; overflow: hidden; transition: transform .08s; padding: 0; }
.card:hover { transform: translateY(-3px); }
.card:active { transform: translateY(1px); box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 1px 0 #1a0e06; }
.card img { position: absolute; left: 50%; top: 2px; width: 64px; height: 58px; transform: translateX(-50%); pointer-events: none; }
.card .nm { position: absolute; left: 0; right: 0; top: 58px; font-size: 11px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 3px; }
.card .cost { position: absolute; left: 0; right: 0; bottom: 3px; text-align: center; font-family: 'Rye', serif; color: var(--gold); font-size: 15px; text-shadow: 0 1px 0 #000; }
.card .key { position: absolute; top: 3px; left: 5px; font-size: 11px; font-weight: 700; background: rgba(0,0,0,.5); border-radius: 4px; padding: 0 4px; }
.card .cdov { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgba(0,0,0,.55); pointer-events: none; }
.card.poor { filter: grayscale(.85) brightness(.7); }
.card.flashok { animation: cardflash .25s; }
@keyframes cardflash { 50% { box-shadow: 0 0 0 3px var(--gold); } }
#minimap { flex: none; width: 300px; height: 46px; border-radius: 8px; border: 2px solid #3a2a18; background: rgba(0,0,0,.6); cursor: pointer; margin-bottom: 2px; margin-left: auto; }
#abils { display: flex; gap: 6px; }
.abil { position: relative; width: 74px; height: 96px; border-radius: 10px; background: linear-gradient(#5a2a1e, #3a160e); border: 2px solid #1a0a06; box-shadow: inset 0 1px 0 rgba(255,255,255,.15), 0 4px 0 #120604; overflow: hidden; padding: 0; transition: transform .08s; }
.abil:hover { transform: translateY(-3px); }
.abil svg { position: absolute; left: 50%; top: 8px; width: 46px; height: 46px; transform: translateX(-50%); }
.abil .nm { position: absolute; left: 0; right: 0; top: 54px; font-size: 10.5px; text-align: center; line-height: 1.1; padding: 0 2px; }
.abil .cost { position: absolute; left: 0; right: 0; bottom: 3px; text-align: center; font-weight: 700; color: #ffb04a; font-size: 13px; }
.abil .key { position: absolute; top: 3px; left: 5px; font-size: 11px; font-weight: 700; background: rgba(0,0,0,.5); border-radius: 4px; padding: 0 4px; }
.abil .cdov { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgba(0,0,0,.6); pointer-events: none; }
.abil.poor { filter: grayscale(.9) brightness(.65); }
.abil.ready { box-shadow: 0 0 12px 2px rgba(255,160,60,.6), 0 4px 0 #120604; }
.abil.active { outline: 3px solid var(--gold); }

#banner { position: absolute; top: 130px; left: 0; right: 0; text-align: center; font-family: 'Rye', serif; font-size: 52px; pointer-events: none; text-shadow: 0 4px 0 #000, 0 0 30px rgba(0,0,0,.8); opacity: 0; transition: opacity .3s; }
#banner.show { opacity: 1; animation: bannerIn .5s; }
@keyframes bannerIn { from { transform: scale(1.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#toast { position: absolute; top: 90px; left: 50%; transform: translateX(-50%); padding: 8px 18px; border-radius: 8px; background: rgba(0,0,0,.75); border: 2px solid var(--gold); font-size: 16px; opacity: 0; transition: opacity .3s; pointer-events: none; white-space: nowrap; }
#toast.show { opacity: 1; }
#tip { position: absolute; bottom: 120px; padding: 6px 10px; border-radius: 6px; background: rgba(0,0,0,.88); border: 1px solid #6a4424; font-size: 13px; max-width: 240px; pointer-events: none; opacity: 0; transition: opacity .15s; }
#tip.show { opacity: 1; }
#tip b { color: var(--gold); font-weight: 600; }

/* ---- screens ---- */
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; background: radial-gradient(ellipse at center, rgba(0,0,0,.15), rgba(0,0,0,.75)); }
.screen h2, .overlay h2 { font-family: 'Rye', serif; font-size: 48px; margin: 0; color: var(--gold); text-shadow: 0 4px 0 #000; }
.logo { text-align: center; transform: rotate(-3deg); margin-top: -40px; }
.logo1 { font-family: 'Rye', serif; font-size: 92px; line-height: .9; color: #ffd24a; text-shadow: 0 6px 0 #6a2a0a, 0 10px 0 #000, 0 0 40px rgba(255,160,40,.4); }
.logo2 { font-family: 'Rye', serif; font-size: 120px; line-height: .9; color: #8ae04a; text-shadow: 0 6px 0 #1a4a0a, 0 10px 0 #000, 0 0 40px rgba(120,255,60,.35); animation: wobble 3s ease-in-out infinite; }
@keyframes wobble { 0%,100% { transform: rotate(-1deg); } 50% { transform: rotate(1.5deg) scale(1.02); } }
.sub { font-size: 22px; letter-spacing: 3px; text-transform: uppercase; margin-top: 10px; text-shadow: 0 2px 0 #000; }
.menu { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.mbtn { font-family: 'Rye', serif; font-size: 28px; min-width: 280px; padding: 10px 26px; border-radius: 12px; color: #2a1406;
  background: linear-gradient(#ffe28a, #e8a83a); border: 3px solid #2a1406; box-shadow: 0 5px 0 #2a1406, inset 0 2px 0 rgba(255,255,255,.6); transition: transform .08s; }
.mbtn:hover { transform: translateY(-2px); filter: brightness(1.08); }
.mbtn:active { transform: translateY(3px); box-shadow: 0 2px 0 #2a1406; }
.mbtn.small { font-size: 18px; min-width: 180px; padding: 7px 18px; }
.mbtn.danger { background: linear-gradient(#ff8a6a, #c8402a); }
.mbtn:disabled { filter: grayscale(1) brightness(.6); cursor: default; transform: none; }
.credit { position: absolute; bottom: 12px; font-size: 12px; opacity: .5; }
.row { display: flex; gap: 12px; align-items: center; justify-content: center; }
.capsline { font-size: 18px; display: flex; align-items: center; gap: 6px; }
.capsline b { font-family: 'Rye', serif; color: var(--gold); font-size: 24px; }
.cap { display: inline-block; width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle, #e8e8e0 30%, #a8a8a0 32%, #d8d8d0 60%); border: 2px dashed #6a6a62; }

#levelGrid { display: grid; grid-template-columns: repeat(5, 200px); gap: 14px; }
.lvl { position: relative; height: 130px; border-radius: 12px; border: 3px solid #2a1406; overflow: hidden; text-align: left; padding: 10px 12px; box-shadow: 0 5px 0 #000; transition: transform .1s; }
.lvl:hover:not(:disabled) { transform: translateY(-3px) rotate(-1deg); }
.lvl .n { font-family: 'Rye', serif; font-size: 34px; color: #fff; text-shadow: 0 3px 0 #000; }
.lvl .t { font-size: 17px; font-weight: 600; text-shadow: 0 2px 0 #000; }
.lvl .st { position: absolute; bottom: 8px; left: 12px; font-size: 22px; letter-spacing: 2px; }
.lvl .st i { font-style: normal; color: rgba(0,0,0,.5); }
.lvl .st i.on { color: var(--gold); text-shadow: 0 0 6px rgba(255,200,60,.7), 0 2px 0 #000; }
.lvl:disabled { filter: grayscale(1) brightness(.4); cursor: default; }
.lvl .lock { position: absolute; right: 12px; bottom: 8px; font-size: 14px; }

#shopList { display: grid; grid-template-columns: repeat(2, 520px); gap: 10px; max-height: 470px; overflow-y: auto; padding: 4px; }
.sitem { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 10px; background: var(--panel); border: 2px solid #3a2a18; }
.sitem img, .sitem .sico { width: 56px; height: 56px; flex: none; }
.sitem .info { flex: 1; }
.sitem .info b { font-size: 17px; }
.sitem .info div { font-size: 13px; opacity: .8; }
.pips { display: flex; gap: 3px; margin-top: 4px; }
.pips i { width: 16px; height: 8px; border-radius: 3px; background: #2a1a0c; border: 1px solid #000; }
.pips i.on { background: var(--gold); }
.sbuy { font-family: 'Rye', serif; font-size: 16px; padding: 6px 12px; border-radius: 8px; background: linear-gradient(#ffe28a, #e8a83a); color: #2a1406; border: 2px solid #2a1406; min-width: 82px; }
.sbuy:disabled { filter: grayscale(1) brightness(.6); cursor: default; }
.sitem.locked { opacity: .45; }

#howtoList { max-width: 760px; font-size: 19px; line-height: 1.45; background: var(--panel); padding: 20px 20px 20px 50px; border-radius: 12px; border: 2px solid #3a2a18; }
#howtoList li { margin: 6px 0; }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.6); }
.overlay .box { display: flex; flex-direction: column; gap: 14px; align-items: center; padding: 30px 50px; border-radius: 16px; background: linear-gradient(#3a2414, #22140a); border: 3px solid #000; box-shadow: 0 10px 40px #000, inset 0 1px 0 rgba(255,255,255,.1); min-width: 440px; }
.stars { font-size: 64px; letter-spacing: 8px; }
.stars i { font-style: normal; color: #2a1a0c; display: inline-block; text-shadow: 0 3px 0 #000; }
.stars i.on { color: var(--gold); animation: starPop .5s backwards; text-shadow: 0 0 20px rgba(255,200,50,.8), 0 3px 0 #000; }
@keyframes starPop { from { transform: scale(0) rotate(-90deg); } 70% { transform: scale(1.4); } }
#resInfo { font-size: 19px; text-align: center; line-height: 1.6; }
#resInfo b { color: var(--gold); }

#rotate { display: none; position: fixed; inset: 0; background: #0a0705; color: var(--paper); font-size: 24px; place-items: center; z-index: 9; font-family: 'Rye', serif; }
@media (orientation: portrait) and (max-width: 800px) { #rotate { display: grid; } }
