:root {
  --wood: #6b3a22; --wood-d: #3d1f10; --ink: #1d1208; --cream: #fff3d6;
  --gold: #fbbf24; --gold-d: #b7790d; --gold-l: #ffe39a; --green: #22a33a; --green-d: #136b24; --red: #e23b3b; --blue: #2f6fd6;
  --font: "Baloo 2", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: #2a160b; color: var(--ink); font-family: var(--font); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }
button, input { font-family: inherit; }
button { touch-action: manipulation; cursor: pointer; }

/* najpierw 100% — zapas dla iOS < 15.4 i Chrome < 108, które nie znają dvh i pominęłyby całą deklarację */
.app { position: relative; max-width: 480px; height: 100%; height: 100dvh; margin: 0 auto; overflow: hidden; touch-action: none; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.sound { position: absolute; z-index: 6; top: max(8px, env(safe-area-inset-top)); right: 10px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,243,214,.85); box-shadow: 0 2px 0 rgba(0,0,0,.25); font-size: 17px; }
.stage { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.screen { position: absolute; top: max(8px, env(safe-area-inset-top)); bottom: max(10px, env(safe-area-inset-bottom)); left: 12px; right: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; opacity: 0; visibility: hidden; transition: opacity .25s, visibility 0s .25s; }
.screen.active { opacity: 1; visibility: visible; transition: opacity .25s; }
.screen button, .screen input, .screen label, .panel, .over { pointer-events: auto; }

/* ---------------------------------------------------------------- wspólne */
.btn { display: inline-flex; align-items: center; justify-content: center; width: 100%; max-width: 330px; min-height: 50px; padding: 0 18px; border-radius: 99px; border: 0; font: 800 18px var(--font); color: #fff; }
.btn-green { background: var(--green); box-shadow: inset 0 0 0 3px var(--green-d), 0 4px 0 var(--green-d); text-shadow: 0 1px 0 rgba(0,0,0,.3); }
.btn-green:active { transform: translateY(3px); box-shadow: inset 0 0 0 3px var(--green-d), 0 1px 0 var(--green-d); }
.pill { display: inline-flex; align-items: center; gap: 5px; height: 38px; padding: 0 16px; border-radius: 99px; font: 800 20px var(--font); white-space: nowrap; }
.pill-score { background: var(--gold); box-shadow: inset 0 0 0 3px var(--gold-d); }
.pill.bump { animation: bump .3s cubic-bezier(.3,1.8,.5,1); }
@keyframes bump { 40% { transform: scale(1.16); } }

/* ---------------------------------------------------------------- powitanie i menu */
.hero-title { margin: -26vh 0 0; font: 800 54px/1 var(--font); color: var(--gold); -webkit-text-stroke: 2px var(--wood-d); text-shadow: 0 5px 0 var(--wood-d); }
.hero-sub { margin: 8px 0 0; font: 700 19px var(--font); color: var(--cream); text-shadow: 0 2px 3px rgba(0,0,0,.4); }
#s-menu { justify-content: flex-start; overflow-y: auto; overflow-x: hidden; padding: 56px 0 14px; pointer-events: auto; }
#s-menu::before, #s-menu::after { content: ''; flex: 1 1 0; }
.panel { width: 100%; max-width: 380px; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 16px 14px; border-radius: 26px; background: var(--cream); box-shadow: 0 10px 30px rgba(0,0,0,.45), inset 0 0 0 3px var(--gold); flex: none; }
.title { margin: 0; font: 800 34px/1 var(--font); color: var(--ink); }
.lead { margin: 0; text-align: center; font: 600 15px/1.35 var(--font); color: #6b4a2c; }
.lead b { color: var(--ink); }
.mode { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 66px; padding: 8px 16px; border-radius: 20px; border: 0; text-align: left; color: var(--ink);
  background: var(--gold-l); box-shadow: inset 0 0 0 3px var(--gold), 0 5px 0 var(--gold-d); }
.mode:active { transform: translateY(3px); box-shadow: inset 0 0 0 3px var(--gold), 0 2px 0 var(--gold-d); }
.m-ico { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 14px; background: rgba(255,255,255,.8); font-size: 24px; }
.m-txt { display: flex; flex-direction: column; min-width: 0; }
.m-txt b { font: 800 21px/1.1 var(--font); }
.m-txt small { font: 600 13px/1.3 var(--font); color: #6b4a2c; }
.best { margin: 0; font: 700 15px var(--font); color: #6b4a2c; }
.name-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 10px; border-radius: 14px; background: #fff; box-shadow: inset 0 0 0 2px #ecd9b0; font: 700 13px var(--font); color: #6b4a2c; }
.name-row span { flex: none; max-width: 48%; }
.name-row input { flex: 1; min-width: 0; height: 34px; padding: 0 10px; border-radius: 10px; border: 2px solid #ecd9b0; font: 700 15px var(--font); color: var(--ink); outline: none; user-select: text; -webkit-user-select: text; }
.name-row input:focus { border-color: var(--gold-d); }
.rules { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.rules span { padding: 3px 10px; border-radius: 99px; background: #fff; box-shadow: inset 0 0 0 2px #ecd9b0; font: 700 12px var(--font); color: #6b4a2c; }
.duel-invite { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px; border-radius: 18px; background: #d9f5dd; box-shadow: inset 0 0 0 3px var(--green); text-align: center; }
.duel-invite b { font: 800 17px/1.2 var(--font); }
.duel-invite span { font: 600 13px/1.3 var(--font); color: #2d5a35; }

/* ---------------------------------------------------------------- gra */
#s-play { justify-content: flex-start; }
.hud { display: flex; align-items: center; gap: 10px; width: 100%; padding-right: 50px; }
.lives { margin-left: auto; display: flex; gap: 2px; font: 900 26px/1 var(--font); }
.lives i { font-style: normal; color: rgba(255,243,214,.35); -webkit-text-stroke: 1px rgba(0,0,0,.25); }
.lives i.lost { color: var(--red); -webkit-text-stroke: 1px #7a1414; animation: bump .4s ease; }
.cat { margin-top: 10px; padding: 7px 18px; border-radius: 99px; background: var(--gold-l); box-shadow: inset 0 0 0 3px var(--gold), 0 3px 0 rgba(0,0,0,.3); font: 700 17px var(--font); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.cat b { font-weight: 800; letter-spacing: .02em; }
.cat.flash { animation: bump .4s cubic-bezier(.3,1.8,.5,1); }
.banner { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; padding: 14px 26px; border-radius: 24px; background: var(--cream); box-shadow: inset 0 0 0 4px var(--gold), 0 10px 30px rgba(0,0,0,.4); white-space: nowrap; animation: pop .4s cubic-bezier(.2,1.5,.4,1) both; }
.banner small { font: 700 16px var(--font); color: #6b4a2c; }
.banner b { font: 800 28px var(--font); }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } }
.feedback { position: absolute; left: 0; right: 0; bottom: 56px; margin: 0 auto; width: max-content; max-width: 100%; padding: 9px 16px; border-radius: 18px; background: var(--gold); box-shadow: inset 0 0 0 3px #c2410c, 0 6px 16px rgba(0,0,0,.35); font: 700 16px/1.25 var(--font); text-align: center; animation: pop2 .3s cubic-bezier(.2,1.5,.4,1) both; }
.feedback b { font-weight: 800; }
.feedback .ok { color: #0f5d1f; }
.feedback .bad { color: #9b1c1c; text-decoration: line-through; }
.feedback.miss { background: var(--cream); box-shadow: inset 0 0 0 3px var(--gold-d), 0 6px 16px rgba(0,0,0,.35); }
@keyframes pop2 { from { transform: scale(.7); opacity: 0; } }
.hint { position: absolute; left: 0; right: 0; bottom: 14px; text-align: center; font: 700 16px var(--font); color: var(--cream); text-shadow: 0 2px 2px rgba(0,0,0,.5); }

/* koniec gry */
.over { position: absolute; inset: 52px 0 10px; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 14px 12px; border-radius: 28px; background: rgba(61,31,16,.88); box-shadow: inset 0 0 0 3px var(--gold-d); text-align: center; animation: pop2 .4s cubic-bezier(.2,1.4,.4,1) both; }
.o-title { font: 800 32px var(--font); color: var(--gold); }
.o-score { font: 800 46px/1 var(--font); color: var(--cream); }
.o-combo { padding: 3px 14px; border-radius: 99px; background: var(--gold); font: 800 16px var(--font); }
.o-rank { padding: 5px 18px; border-radius: 99px; background: var(--blue); color: #fff; box-shadow: inset 0 0 0 3px #1c4fa8; font: 800 18px var(--font); }
.o-mist { width: 100%; max-width: 340px; padding: 10px 12px; border-radius: 20px; background: var(--gold); box-shadow: inset 0 0 0 3px #c2410c; }
.o-mist b { font: 800 16px var(--font); }
.o-mist ul { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 3px; max-height: 26vh; overflow-y: auto; }
.o-mist li { display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; font: 700 15px/1.25 var(--font); }
.o-mist li .bad { text-decoration: line-through; color: #9b1c1c; }
.o-mist li small { font: 600 13px var(--font); color: #5b3612; }
.o-mist li button { border: 0; background: rgba(255,255,255,.55); border-radius: 99px; width: 30px; height: 26px; font-size: 14px; padding: 0; }
.duel { display: flex; flex-direction: column; gap: 2px; padding: 6px 14px; border-radius: 16px; background: var(--cream); font: 700 15px var(--font); }
.duel b { font-size: 16px; }

.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; background: rgba(29,18,8,.55); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.modal-card { width: 100%; max-width: 330px; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 22px 20px 16px; border-radius: 24px; background: var(--cream); text-align: center; }
.modal-title { font: 800 26px var(--font); }
.modal-card p { margin: 0 0 6px; font: 600 16px/1.4 var(--font); color: #6b4a2c; }

@media (max-height: 640px) {
  .o-score { font-size: 38px; }
  .o-title { font-size: 27px; }
  .title { font-size: 30px; }
  .mode { min-height: 58px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
