* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%; overflow: hidden; background: #111; font-family: 'Segoe UI', Tahoma, sans-serif; color: #eee;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: none; touch-action: none; -webkit-user-drag: none; }

.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(20, 30, 15, 0.55), rgba(0, 0, 0, 0.88));
  z-index: 10; cursor: default; padding: 12px; overflow: auto;
}
.overlay.dim { background: rgba(0, 0, 0, 0.55); z-index: 12; }
.hidden { display: none !important; }

.panel {
  width: min(460px, calc(100vw - 24px)); padding: 26px 28px 22px; border-radius: 14px; margin: auto;
  background: rgba(22, 26, 20, 0.95); border: 2px solid #3d4a2c; box-shadow: 0 12px 50px rgba(0, 0, 0, 0.6);
  text-align: center;
}
.panel h2 { font-family: Impact, 'Arial Black', sans-serif; font-size: 34px; letter-spacing: 2px; color: #9fd14a; margin-bottom: 12px; }
.title {
  font-family: Impact, 'Arial Black', sans-serif; font-size: 64px; letter-spacing: 3px; color: #9fd14a;
  text-shadow: 0 4px 0 #3a5418, 0 0 30px rgba(140, 200, 60, 0.35); line-height: 1;
}
.title span { color: #d9d9d9; font-size: 40px; text-shadow: 0 3px 0 #444; }
.subtitle { color: #a9b39a; margin: 8px 0 18px; font-size: 15px; }
.note { color: #8e9882; font-size: 13px; margin: 6px 0 14px; }

#nick, #room, .set-row select {
  width: 100%; padding: 12px 14px; font-size: 18px; border-radius: 8px; border: 2px solid #46523a;
  background: #12150f; color: #eee; outline: none; margin-bottom: 10px; font-family: inherit;
}
#nick:focus, #room:focus { border-color: #9fd14a; }
#room { font-size: 15px; cursor: pointer; }

.btn-play {
  width: 100%; padding: 14px; font-size: 24px; font-family: Impact, 'Arial Black', sans-serif; letter-spacing: 2px;
  background: linear-gradient(#8fc23c, #5f8a22); color: #fff; border: none; border-radius: 8px; cursor: pointer;
  box-shadow: 0 4px 0 #3a5418; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); transition: transform 0.08s;
}
.btn-play.small { font-size: 18px; padding: 10px; }
.btn-play:hover { filter: brightness(1.1); }
.btn-play:active { transform: translateY(3px); box-shadow: 0 1px 0 #3a5418; }
.btn-play:disabled { filter: grayscale(1); cursor: wait; }
.btn-sec { flex: 1; padding: 10px; font-size: 15px; background: #2a2f25; color: #ccc; border: 1px solid #46523a; border-radius: 8px; cursor: pointer; font-family: inherit; }
.btn-sec.wide { width: 100%; margin-top: 10px; }
.btn-sec.danger { color: #ff9a8a; border-color: #6a3a32; }
.btn-sec:disabled { opacity: 0.45; cursor: not-allowed; }
.note.warn { color: #ffb070; margin: 8px 0 0; }
.btn-sec:hover { background: #343a2e; }
.btn-x { background: #2a2f25; color: #ccc; border: 1px solid #46523a; border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 16px; }
.menu-row { display: flex; gap: 10px; margin-top: 12px; }

.status { min-height: 20px; margin: 8px 0 4px; color: #e0a040; font-size: 14px; }
.tips { margin-top: 14px; font-size: 13px; color: #8e9882; line-height: 1.5; }

.death-panel h2 { font-size: 52px; color: #c43a2e; text-shadow: 0 4px 0 #4a120d; }
#deathBy { color: #c9c9c9; margin: 6px 0 18px; }
.stats { display: flex; justify-content: space-around; margin-bottom: 20px; }
.stats div { display: flex; flex-direction: column; }
.stats span { font-size: 30px; font-weight: bold; color: #fff; }
.stats small { color: #9aa38e; font-size: 12px; }

/* menu w grze i ustawienia */
.esc-panel { width: min(360px, calc(100vw - 24px)); }
.settings-panel { width: min(440px, calc(100vw - 24px)); text-align: left; }
.settings-panel h2 { text-align: center; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px solid #2e3628; }
.set-row label { color: #c9d0bd; font-size: 15px; }
.set-row select { width: 150px; margin: 0; padding: 6px 8px; font-size: 14px; }
.set-row input[type=range] { width: 150px; accent-color: #9fd14a; }
.set-row input[type=checkbox] { width: 22px; height: 22px; accent-color: #9fd14a; }

/* pomoc */
.help-panel { width: min(760px, calc(100vw - 24px)); text-align: left; }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 { margin: 0; }
#helpBody { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 22px; margin-top: 14px; }
.help-cat h4 { color: #9fd14a; font-size: 15px; margin-bottom: 6px; border-bottom: 1px solid #3d4a2c; padding-bottom: 3px; }
.help-cat div { display: flex; gap: 10px; font-size: 13px; color: #c9d0bd; padding: 2px 0; }
.help-cat b { color: #fff; min-width: 108px; flex-shrink: 0; }
.help-cat.help-tips { grid-column: 1 / -1; }
.help-cat ul { margin-left: 18px; color: #aab39c; font-size: 13px; line-height: 1.55; }
@media (max-width: 640px) { #helpBody { grid-template-columns: 1fr; } }

/* umiejętności */
#skills {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(980px, calc(100vw - 24px));
  max-height: calc(100vh - 24px); overflow: auto; padding: 16px 20px; border-radius: 12px; z-index: 11; cursor: default;
  background: rgba(14, 17, 12, 0.95); border: 1px solid #5a4a7a; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
#skills h3 { font-family: Impact, 'Arial Black', sans-serif; letter-spacing: 2px; color: #9fd14a; font-size: 24px; }
.skills-head { display: flex; align-items: center; gap: 16px; margin-bottom: 10px; }
#skillInfo { color: #e0c8ff; font-weight: bold; flex: 1; }
#skillTrees { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.tree h4 { font-size: 16px; margin-bottom: 8px; padding-bottom: 4px; border-bottom: 2px solid currentColor; }
.tier { display: flex; gap: 6px; margin-bottom: 8px; align-items: stretch; }
.tier .or { align-self: center; font-size: 11px; color: #888; }
.skill {
  flex: 1; padding: 8px; border-radius: 8px; background: #1d2219; border: 2px solid #333a2c; cursor: pointer;
  font-size: 12px; color: #b9c2ab; transition: transform 0.06s, border-color 0.1s;
}
.skill b { display: block; font-size: 13px; color: #fff; margin-bottom: 3px; }
.skill .cost { float: right; color: #e0c8ff; font-weight: bold; }
.skill.owned { border-color: #9fd14a; background: #253019; }
.skill.owned b::after { content: ' ✓'; color: #9fd14a; }
.skill.avail { border-color: #a070e0; }
.skill.avail:hover { transform: translateY(-2px); background: #2a2436; }
.skill.locked { opacity: 0.45; cursor: not-allowed; }
.skill.excluded { opacity: 0.25; cursor: not-allowed; text-decoration: line-through; }
.skills-foot { margin-top: 8px; font-size: 12px; color: #8e9882; }
@media (max-width: 760px) { #skillTrees { grid-template-columns: 1fr; } }

#chatInput {
  position: fixed; left: 16px; bottom: 180px; width: min(420px, calc(100vw - 32px)); padding: 8px 12px;
  background: rgba(0, 0, 0, 0.7); color: #fff; border: 1px solid #9fd14a; border-radius: 6px; font-size: 15px; outline: none; z-index: 5;
}

#rotate {
  position: fixed; inset: 0; z-index: 30; background: #10140d; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; color: #d8f090; font-size: 20px; text-align: center; padding: 20px;
}
#rotate div { font-size: 64px; animation: spin 2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-height: 640px) {
  .title { font-size: 44px; }
  .title span { font-size: 28px; }
  .panel { padding: 16px 18px; }
  .tips { display: none; }
}

/* pola tekstowe muszą dać się zaznaczać (iOS) */
input, textarea { user-select: text; -webkit-user-select: text; }

/* niskie ekrany (telefon poziomo) – ciaśniejsze panele */
@media (max-height: 500px) {
  .panel h2 { font-size: 24px; margin-bottom: 6px; }
  #helpBody { gap: 6px 18px; margin-top: 6px; }
  .help-cat h4 { font-size: 13px; margin-bottom: 3px; }
  .help-cat div { font-size: 12px; padding: 1px 0; }
  .help-cat b { min-width: 96px; }
  .help-cat ul { font-size: 12px; line-height: 1.4; }
  .set-row { padding: 5px 0; }
}

/* ================================================= Zombie Defense */
.title span { display: block; font-size: 34px; letter-spacing: 8px; margin-top: 4px; }
.records { margin-top: 14px; text-align: left; }
.records h4 { color: #9fd14a; font-size: 13px; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 4px; }
#records div { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: #c9d0bd; padding: 2px 0; border-bottom: 1px solid #262d21; }
#records div b { color: #ffd23a; white-space: nowrap; }
#records div span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#records p { font-size: 13px; color: #8e9882; }

.over-panel { width: min(560px, calc(100vw - 24px)); }
.over-panel h2 { font-size: 46px; color: #c43a2e; text-shadow: 0 4px 0 #4a120d; }
#oTable { width: 100%; border-collapse: collapse; margin: 4px 0 10px; font-size: 14px; }
#oTable th { color: #9aa38e; font-weight: normal; font-size: 12px; text-align: right; padding: 3px 6px; }
#oTable td { text-align: right; padding: 4px 6px; border-top: 1px solid #2e3628; color: #ddd; }
#oTable th:first-child, #oTable td:first-child { text-align: left; }
#oTable tr.me td { color: #ffe070; font-weight: bold; }

/* pasek budowy i rzemiosło */
#buildBar {
  position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 4; cursor: default;
  display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: calc(100vw - 16px);
}
#buildInfo { background: rgba(10, 12, 8, 0.78); border-radius: 8px; padding: 6px 12px; font-size: 13px; color: #c9d0bd; text-align: center; max-width: 520px; }
#buildInfo b { color: #fff; }
#buildInfo .cost { color: #ffd890; }
#buildInfo .bad { color: #ff7a6a; }
#buildSlots { display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; max-width: calc(100vw - 16px); padding: 4px; }
.bslot {
  position: relative; width: 64px; height: 70px; flex: 0 0 auto; border-radius: 8px; background: rgba(10, 12, 8, 0.75);
  border: 2px solid rgba(255, 255, 255, 0.15); color: #ddd; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start; padding-top: 3px; font-family: inherit; touch-action: manipulation;
}
.bslot canvas { width: 40px; height: 40px; }
.bslot small { font-size: 10px; line-height: 1.1; color: #c9d0bd; }
.bslot i { position: absolute; left: 4px; top: 2px; font-style: normal; font-size: 10px; color: #999; }
.bslot.sel { border-color: #b8e060; background: rgba(60, 70, 40, 0.9); }
.bslot.poor { opacity: 0.55; }
.bslot .tool { font-size: 26px; line-height: 40px; }

#craft {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(720px, calc(100vw - 24px));
  max-height: calc(100vh - 24px); overflow: auto; padding: 16px 20px; border-radius: 12px; z-index: 11; cursor: default;
  background: rgba(14, 17, 12, 0.95); border: 1px solid #6a5a2a; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
#craft h3 { font-family: Impact, 'Arial Black', sans-serif; letter-spacing: 2px; color: #e0b050; font-size: 24px; }
#craftStock { flex: 1; color: #ffd890; font-weight: bold; font-size: 14px; }
#craftList { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.citem {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: #1d2219; border: 2px solid #333a2c;
  cursor: pointer; color: #ddd; font-family: inherit; text-align: left; touch-action: manipulation;
}
.citem canvas { width: 40px; height: 40px; flex: 0 0 auto; }
.citem b { display: block; font-size: 13px; color: #fff; }
.citem small { font-size: 11px; color: #ffd890; }
.citem:hover { border-color: #e0b050; }
.citem.poor { opacity: 0.45; cursor: not-allowed; }
.citem.poor small { color: #ff8a7a; }
@media (max-height: 500px) {
  .bslot { width: 54px; height: 60px; }
  .bslot canvas { width: 32px; height: 32px; }
  #buildInfo { font-size: 11px; padding: 4px 8px; }
}
.rcost { display: inline-flex; gap: 8px; align-items: center; }
.rcost span { display: inline-flex; align-items: center; gap: 2px; color: #ffd890; font-weight: bold; }
.rcost span.bad { color: #ff7a6a; }
.rcost img { width: 16px; height: 16px; }
.citem .rcost { font-size: 11px; gap: 6px; }
.citem .rcost img { width: 13px; height: 13px; }
#craftStock .rcost { gap: 14px; font-size: 15px; }
