/* Poszukiwacz Diamentów — interfejs gry (nie strony) */
:root {
  --bg: #07060a;
  --ink: #f4efe6;
  --ink-dim: #a69e92;
  --ink-faint: #6d665d;
  --gold: #ffc94a;
  --gold-deep: #e08a1e;
  --cyan: #5ff3ff;
  --cyan-deep: #1aa7c4;
  --red: #ff4d3d;
  --panel: rgba(10, 9, 14, 0.72);
  --edge: rgba(255, 220, 160, 0.16);
  --font: 'Chakra Petch', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#app { position: fixed; inset: 0; overflow: hidden; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font-family: inherit; color: inherit; }

/* ───────────── HUD ───────────── */
#hud {
  position: absolute;
  left: 0; right: 0; top: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  pointer-events: none;
  z-index: 10;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.65), 0 0 12px rgba(0, 0, 0, 0.6);
}
.hud-left, .hud-right, .hud-center { display: flex; align-items: center; gap: 18px; }
.hud-center { position: absolute; left: 50%; transform: translateX(-50%); top: max(12px, env(safe-area-inset-top)); }
.hud-label { font-size: 11px; color: var(--ink-dim); margin-right: 7px; letter-spacing: 0.18em; }
.hud-level, .hud-score { font-size: 20px; display: flex; align-items: baseline; }
#hud-level-num { color: var(--gold); }
#hud-score-num { font-variant-numeric: tabular-nums; min-width: 6ch; }
.hud-gems { display: flex; align-items: center; gap: 5px; font-size: 20px; font-variant-numeric: tabular-nums; }
.hud-gems .gem-icon { width: 22px; height: 22px; filter: drop-shadow(0 0 6px rgba(95, 243, 255, 0.7)); transition: transform 0.12s; }
.hud-gems.pulse .gem-icon { transform: scale(1.35) rotate(-8deg); }
.hud-gems.ready #hud-gems-num, .hud-gems.ready #hud-gems-need { color: var(--cyan); text-shadow: 0 0 10px rgba(95, 243, 255, 0.8), 0 2px 0 #000; }
.hud-gems.burst { animation: gemBurst 0.6s ease-out; }
@keyframes gemBurst { 0% { transform: scale(1); } 30% { transform: scale(1.25); } 100% { transform: scale(1); } }
.hud-sep { color: var(--ink-faint); margin: 0 1px; }
#hud-gems-need { color: var(--ink-dim); }
.hud-time { font-size: 15px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.hud-lives { display: flex; gap: 4px; }
.heart { width: 20px; height: 18px; display: block; filter: drop-shadow(0 0 5px rgba(255, 77, 61, 0.55)); transition: transform 0.2s, opacity 0.2s; }
.heart.lost { animation: heartLost 0.55s ease-in forwards; }
@keyframes heartLost {
  0% { transform: scale(1); opacity: 1; }
  30% { transform: scale(1.5); opacity: 1; filter: drop-shadow(0 0 12px #ff4d3d) brightness(2); }
  100% { transform: scale(0.2) translateY(14px); opacity: 0; }
}
.heart.gain { animation: heartGain 0.5s ease-out; }
@keyframes heartGain { 0% { transform: scale(0); } 70% { transform: scale(1.4); } 100% { transform: scale(1); } }
.hud-pause {
  pointer-events: auto;
  width: 34px; height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.35);
  display: grid; place-items: center;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s, transform 0.1s;
}
.hud-pause:hover { opacity: 1; }
.hud-pause:active { transform: scale(0.92); }
.hud-pause svg { width: 16px; height: 16px; fill: var(--ink); }
.hud-score.bump #hud-score-num { color: var(--gold); }

/* ───────────── Banery i podpowiedzi w grze ───────────── */
.banner {
  position: absolute;
  left: 50%; top: 22%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  z-index: 12;
  opacity: 0;
  white-space: nowrap;
}
.banner .b-main {
  font-size: clamp(30px, 6vw, 64px);
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--gold);
  text-shadow: 0 0 24px rgba(255, 180, 60, 0.55), 0 4px 0 #3a1d00, 0 0 2px #000;
}
.banner .b-sub { margin-top: 6px; font-size: clamp(13px, 2vw, 18px); letter-spacing: 0.32em; color: var(--ink-dim); font-weight: 600; }
.banner.cyan .b-main { color: var(--cyan); text-shadow: 0 0 24px rgba(95, 243, 255, 0.7), 0 3px 0 #003340; }
.banner.red .b-main { color: #ff6a4d; text-shadow: 0 0 24px rgba(255, 80, 50, 0.7), 0 3px 0 #300; }
.banner.small .b-main { font-size: clamp(20px, 3.4vw, 34px); }
.banner.show { animation: bannerIn 1.5s ease-out forwards; }
.banner.show-long { animation: bannerIn 2.4s ease-out forwards; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -38%) scale(1.15); filter: blur(6px); }
  14% { opacity: 1; transform: translate(-50%, -50%) scale(1); filter: blur(0); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -56%) scale(0.98); }
}
.hint {
  position: absolute;
  left: 50%; bottom: max(28px, calc(env(safe-area-inset-bottom) + 18px));
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(8, 7, 12, 0.62);
  border: 1px solid rgba(255, 220, 160, 0.18);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.14em;
  white-space: nowrap;
  pointer-events: none;
  z-index: 12;
  opacity: 0;
  transition: opacity 0.35s, transform 0.35s;
}
.hint.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.hint .k { display: inline-block; min-width: 24px; padding: 1px 6px; margin: 0 2px; border-radius: 5px; background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.2); text-align: center; }
.hint .gold { color: var(--gold); }
.hint .cyan { color: var(--cyan); }
.hint .red { color: #ff7a5c; }

/* ───────────── Ekrany ───────────── */
#ui { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  padding: 24px 16px;
  animation: screenIn 0.35s ease-out;
}
@keyframes screenIn { from { opacity: 0; transform: scale(1.03); } to { opacity: 1; transform: none; } }
.screen.dim { background: radial-gradient(ellipse at center, rgba(5, 4, 8, 0.45) 0%, rgba(5, 4, 8, 0.86) 75%); }
.screen.dimmer { background: rgba(5, 4, 8, 0.6); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }

.title {
  text-align: center;
  margin-bottom: 4vh;
}
.title h1 {
  margin: 0;
  font-size: clamp(38px, 8.4vw, 104px);
  line-height: 0.92;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gold);
  text-shadow: 0 0 38px rgba(255, 170, 50, 0.45), 0 6px 0 #4a2300, 0 10px 24px rgba(0, 0, 0, 0.8);
}
.title h1 .l2 { display: block; color: var(--cyan); text-shadow: 0 0 38px rgba(95, 243, 255, 0.55), 0 6px 0 #00303d, 0 10px 24px rgba(0, 0, 0, 0.8); }
.title .tagline { margin-top: 16px; font-size: clamp(13px, 1.8vw, 18px); letter-spacing: 0.5em; color: var(--ink-dim); font-weight: 600; }

.menu { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.mbtn {
  position: relative;
  background: none;
  border: none;
  padding: 7px 34px;
  font-size: clamp(20px, 3vw, 30px);
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--ink-dim);
  cursor: pointer;
  transition: color 0.12s, transform 0.12s, text-shadow 0.12s;
  outline: none;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.6);
}
.mbtn .sub { display: block; font-size: 12px; letter-spacing: 0.3em; color: var(--ink-faint); margin-top: -2px; }
.mbtn::before, .mbtn::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 12px; height: 12px;
  margin-top: -6px;
  background: var(--cyan);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  opacity: 0;
  transform: scale(0.3);
  transition: opacity 0.12s, transform 0.12s;
  filter: drop-shadow(0 0 6px var(--cyan));
}
.mbtn::before { left: 6px; }
.mbtn::after { right: 6px; }
.mbtn.focus, .mbtn:focus-visible { color: var(--ink); transform: scale(1.08); text-shadow: 0 0 18px rgba(255, 200, 100, 0.45), 0 3px 0 rgba(0, 0, 0, 0.6); }
.mbtn.focus::before, .mbtn.focus::after { opacity: 1; transform: scale(1); }
.mbtn.focus .sub { color: var(--gold); }
.mbtn.small { font-size: clamp(16px, 2.2vw, 22px); }
.mbtn[disabled] { opacity: 0.35; cursor: default; }

.panel {
  position: relative;
  min-width: min(440px, 92vw);
  max-width: 92vw;
  padding: 26px 30px 22px;
  background: linear-gradient(180deg, rgba(22, 18, 26, 0.92), rgba(10, 9, 14, 0.94));
  border-radius: 16px;
  border: 1px solid var(--edge);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 24px 70px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  text-align: center;
  animation: panelIn 0.32s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes panelIn { from { opacity: 0; transform: translateY(18px) scale(0.94); } to { opacity: 1; transform: none; } }
.panel::before {
  content: '';
  position: absolute; left: 18px; right: 18px; top: -1px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: 0.7;
}
.panel h2 {
  margin: 0 0 16px;
  font-size: clamp(26px, 4.4vw, 42px);
  letter-spacing: 0.14em;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(255, 170, 50, 0.4), 0 3px 0 #3a1d00;
}
.panel h2.cyan { color: var(--cyan); text-shadow: 0 0 20px rgba(95, 243, 255, 0.5), 0 3px 0 #00303d; }
.panel h2.red { color: #ff5a43; text-shadow: 0 0 22px rgba(255, 70, 40, 0.55), 0 3px 0 #300; }
.panel .menu { margin-top: 14px; }

.screen-title {
  font-size: clamp(30px, 5vw, 54px);
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--gold);
  text-shadow: 0 0 26px rgba(255, 170, 50, 0.45), 0 4px 0 #3a1d00;
  margin: 0 0 3vh;
  text-align: center;
}

/* Tabela wyników w panelu ukończenia */
.tally { display: grid; grid-template-columns: 1fr auto; gap: 7px 30px; margin: 4px auto 6px; max-width: 360px; font-size: 17px; font-weight: 600; letter-spacing: 0.08em; text-align: left; }
.tally .k { color: var(--ink-dim); }
.tally .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }
.tally .v.gold { color: var(--gold); }
.tally .v.cyan { color: var(--cyan); }
.tally .total { border-top: 1px solid rgba(255, 255, 255, 0.12); padding-top: 9px; margin-top: 3px; font-size: 21px; }
.stars { display: flex; justify-content: center; gap: 12px; margin: 2px 0 14px; }
.star { width: 34px; height: 34px; opacity: 0.18; transform: scale(0.7); transition: all 0.3s cubic-bezier(0.2, 1.6, 0.4, 1); }
.star.on { opacity: 1; transform: scale(1); filter: drop-shadow(0 0 10px rgba(255, 200, 60, 0.8)); }
.record { color: var(--cyan); letter-spacing: 0.2em; font-weight: 700; font-size: 14px; margin-top: 2px; animation: pulseTxt 1s ease-in-out infinite; }
@keyframes pulseTxt { 50% { opacity: 0.5; } }

/* Wybór poziomu */
.lvl-grid { display: flex; flex-direction: column; gap: 10px; }
.lvl-row { display: flex; align-items: center; gap: 10px; }
.lvl-chapter { width: 150px; text-align: right; font-size: 11px; letter-spacing: 0.2em; color: var(--ink-faint); font-weight: 700; line-height: 1.2; }
.lvl {
  position: relative;
  width: clamp(54px, 7.6vw, 78px);
  height: clamp(54px, 7.6vw, 78px);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(160deg, rgba(40, 34, 46, 0.85), rgba(14, 12, 18, 0.9));
  font-size: clamp(18px, 2.6vw, 26px);
  font-weight: 700;
  cursor: pointer;
  outline: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.lvl .mini-stars { display: flex; gap: 1px; margin-top: 2px; height: 11px; }
.lvl .mini-stars i { width: 10px; height: 10px; background: #554c3d; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.lvl .mini-stars i.on { background: var(--gold); }
.lvl.done { border-color: rgba(255, 201, 74, 0.35); }
.lvl.locked { opacity: 0.38; cursor: default; }
.lvl.locked .n { display: none; }
.lvl.locked::after { content: ''; width: 16px; height: 18px; background: var(--ink-dim); clip-path: polygon(20% 45%, 20% 30%, 30% 12%, 50% 4%, 70% 12%, 80% 30%, 80% 45%, 100% 45%, 100% 100%, 0 100%, 0 45%, 32% 45%, 32% 30%, 40% 18%, 50% 15%, 60% 18%, 68% 30%, 68% 45%); }
.lvl.focus { transform: scale(1.1); border-color: var(--cyan); box-shadow: 0 0 22px rgba(95, 243, 255, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.1); z-index: 2; }
.lvl-info { height: 22px; margin-top: 14px; font-size: 14px; letter-spacing: 0.16em; color: var(--ink-dim); text-align: center; font-weight: 600; }
.lvl-info b { color: var(--ink); }

/* Najlepsze wyniki */
.scores { min-width: min(520px, 92vw); font-size: clamp(16px, 2.4vw, 22px); font-weight: 700; letter-spacing: 0.1em; }
.score-row { display: grid; grid-template-columns: 3ch 1fr auto auto; gap: 18px; padding: 6px 14px; border-radius: 8px; align-items: baseline; }
.score-row:nth-child(1) { color: var(--gold); font-size: 1.15em; }
.score-row:nth-child(2) { color: #e8e2d6; }
.score-row:nth-child(3) { color: #e0a96d; }
.score-row .pos { color: var(--ink-faint); }
.score-row .lv { font-size: 0.65em; color: var(--ink-faint); letter-spacing: 0.15em; }
.score-row .pts { font-variant-numeric: tabular-nums; text-align: right; }
.score-row.me { background: rgba(95, 243, 255, 0.1); color: var(--cyan); }
.score-empty { color: var(--ink-faint); text-align: center; padding: 20px; letter-spacing: 0.2em; }

/* Wpisywanie inicjałów */
.initials { display: flex; gap: 14px; justify-content: center; margin: 10px 0 6px; }
.ini {
  width: 58px; height: 74px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.35);
  font-size: 42px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  color: var(--ink-dim);
}
.ini.focus { border-color: var(--cyan); color: var(--cyan); box-shadow: 0 0 20px rgba(95, 243, 255, 0.3); }
.ini.focus::before, .ini.focus::after { content: ''; position: absolute; left: 50%; width: 12px; height: 8px; margin-left: -6px; background: var(--cyan); }
.ini.focus::before { top: -12px; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.ini.focus::after { bottom: -12px; clip-path: polygon(0 0, 100% 0, 50% 100%); }
.ini-help { font-size: 12px; letter-spacing: 0.22em; color: var(--ink-faint); margin-top: 12px; }

/* Ustawienia */
.settings { display: flex; flex-direction: column; gap: 6px; min-width: min(460px, 92vw); }
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: clamp(16px, 2.2vw, 21px); font-weight: 700; letter-spacing: 0.14em;
  color: var(--ink-dim);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border: none; background: none; text-align: left;
}
.set-row.focus { color: var(--ink); background: rgba(255, 255, 255, 0.06); }
.bar { display: flex; gap: 4px; }
.bar i { width: 12px; height: 20px; border-radius: 2px; background: rgba(255, 255, 255, 0.1); transition: background 0.1s; }
.bar i.on { background: linear-gradient(180deg, var(--gold), var(--gold-deep)); box-shadow: 0 0 8px rgba(255, 180, 60, 0.4); }
.set-row.focus .bar i.on { background: linear-gradient(180deg, #fff2c4, var(--gold)); }
.toggle { font-size: 0.9em; min-width: 5ch; text-align: right; }
.toggle.on { color: var(--cyan); text-shadow: 0 0 10px rgba(95, 243, 255, 0.6); }
.toggle.off { color: var(--ink-faint); }

/* Jak grać */
.howto { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; max-width: 900px; width: 100%; margin-bottom: 18px; }
.howto-item {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px 10px 14px;
  border-radius: 14px;
  background: rgba(14, 12, 18, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.07);
  text-align: center;
}
.howto-item canvas { width: 96px; height: 72px; }
.howto-item h3 { margin: 0; font-size: 15px; letter-spacing: 0.18em; color: var(--gold); }
.howto-item p { margin: 0; font-size: 13px; line-height: 1.35; color: var(--ink-dim); letter-spacing: 0.04em; }
.keys { display: inline-flex; gap: 4px; }

/* Ekran końcowy */
.victory h1 { font-size: clamp(40px, 8vw, 96px); margin: 0; color: var(--gold); letter-spacing: 0.08em; text-shadow: 0 0 50px rgba(255, 180, 60, 0.6), 0 6px 0 #4a2300; text-align: center; }
.victory h3 { margin: 6px 0 22px; font-size: clamp(15px, 2.6vw, 26px); letter-spacing: 0.24em; color: var(--cyan); text-shadow: 0 0 20px rgba(95, 243, 255, 0.6); text-align: center; }
.gameover h1 { font-size: clamp(48px, 10vw, 120px); margin: 0 0 10px; color: #ff4d3d; letter-spacing: 0.12em; text-shadow: 0 0 50px rgba(255, 60, 40, 0.55), 0 7px 0 #2a0000; text-align: center; animation: goIn 0.9s cubic-bezier(0.2, 1.2, 0.3, 1); }
@keyframes goIn { from { transform: scale(2.2); opacity: 0; filter: blur(10px); } to { transform: none; opacity: 1; filter: none; } }

.footer-hint { position: absolute; bottom: max(16px, env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; font-size: 11px; letter-spacing: 0.3em; color: var(--ink-faint); font-weight: 600; pointer-events: none; }

/* ───────────── Sterowanie dotykowe ───────────── */
#touch { position: absolute; inset: 0; pointer-events: none; z-index: 15; }
.dpad {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 172px; height: 172px;
  pointer-events: auto;
  opacity: 0.82;
}
.dpad-btn {
  position: absolute;
  width: 62px; height: 62px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(10, 9, 14, 0.42);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: grid; place-items: center;
  touch-action: none;
  transition: transform 0.06s, background 0.06s;
}
.dpad-btn svg { width: 26px; height: 26px; fill: rgba(255, 240, 220, 0.85); }
.dpad-btn.up { left: 55px; top: 0; }
.dpad-btn.down { left: 55px; bottom: 0; }
.dpad-btn.left { left: 0; top: 55px; }
.dpad-btn.right { right: 0; top: 55px; }
.dpad-btn.active { transform: scale(0.9); background: rgba(95, 243, 255, 0.28); border-color: rgba(95, 243, 255, 0.7); box-shadow: 0 0 18px rgba(95, 243, 255, 0.45); }
.dpad-core { position: absolute; left: 66px; top: 66px; width: 40px; height: 40px; border-radius: 50%; background: rgba(255, 255, 255, 0.05); pointer-events: none; }

/* ───────────── Przejścia ───────────── */
.fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 40; transition: opacity 0.3s; }
.fade.on { opacity: 1; }

@media (max-width: 720px) {
  .hud-label { display: none; }
  .hud-level, .hud-score, .hud-gems { font-size: 17px; }
  .hud-left, .hud-right { gap: 10px; }
  .hud-center { top: max(48px, calc(env(safe-area-inset-top) + 36px)); }
  .lvl-chapter { display: none; }
  .hint { font-size: 12px; white-space: normal; text-align: center; width: max-content; max-width: calc(100vw - 32px); border-radius: 14px; bottom: auto; top: max(84px, calc(env(safe-area-inset-top) + 72px)); }
  .banner { top: 30%; }
}
@media (max-height: 520px) {
  .title { margin-bottom: 2vh; }
  .mbtn { padding: 3px 26px; }
}
@media (prefers-reduced-motion: reduce) {
  .screen, .panel, .banner.show, .banner.show-long, .gameover h1 { animation-duration: 0.01s !important; }
}
.reduced .screen, .reduced .panel, .reduced .gameover h1 { animation-duration: 0.01s !important; }
