:root {
  --water: #0F2A3D;
  --water-2: #1D4560;
  --canvas: #F6F7F3;
  --canvas-2: #E6E9E2;
  --buoy: #F5B800;
  --reed: #5E7330;
  --alert: #B3261E;
  --mist: #8E979C;
  --ink-soft: #4A5B66;

  /* Grafika tła: podmień plik public/img/background.jpg. Bez pliku zostaje szare tło. */
  --bg-image: url("/img/background.jpg");

  --font: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius-tag: 18px;
  --gutter: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  color: var(--water);
  background: var(--mist);
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.scene {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--mist) var(--bg-image) center / cover no-repeat;
}
/* Przyciemnienie u góry, żeby tytuł był czytelny na każdej grafice. */
.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(15, 42, 61, .72) 0, rgba(15, 42, 61, .25) 240px, rgba(15, 42, 61, 0) 420px);
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 28px) var(--gutter) calc(var(--safe-bottom) + 28px);
}

.loading { color: var(--canvas); text-align: center; margin-top: 30vh; }

/* ---------- ekran główny ---------- */

.home-head { color: var(--canvas); margin-bottom: 22px; }

.title {
  margin: 0;
  font-size: clamp(40px, 12vw, 56px);
  line-height: .95;
  font-weight: 900;
  font-stretch: 125%;
  letter-spacing: -.01em;
}

.subtitle {
  margin: 10px 0 0;
  font-size: 18px;
  font-stretch: 100%;
  max-width: 28ch;
  opacity: .92;
}

.tags { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }

/* Każde wyzwanie to „zawieszka” z okienkiem na cyfrę. */
.tag {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 76px;
  align-items: stretch;
  gap: 14px;
  padding: 14px 14px 14px 18px;
  border: 0;
  border-radius: var(--radius-tag);
  background: var(--canvas);
  color: var(--water);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(15, 42, 61, .18), 0 8px 24px rgba(15, 42, 61, .22);
  transition: transform .12s ease;
}
.tag:active { transform: scale(.985); }
.tag:focus-visible { outline: 3px solid var(--buoy); outline-offset: 3px; }

.tag-text { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.tag-number { font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.tag-name { font-size: clamp(16px, 5.2vw, 21px); font-weight: 800; font-stretch: 112%; line-height: 1.15; margin-top: 2px; overflow-wrap: break-word; hyphens: auto; }
.tag-status { font-size: 15px; margin-top: 6px; color: var(--ink-soft); }
.tag-status.is-pending { color: var(--water-2); font-weight: 600; }
.tag-status.is-rejected { color: var(--alert); font-weight: 600; }
.tag-status.is-done { color: var(--reed); font-weight: 700; }

.slot {
  display: grid;
  place-items: center;
  min-height: 84px;
  border-radius: 12px;
  border: 2px dashed rgba(15, 42, 61, .28);
  background: var(--canvas-2);
}
.slot-digit {
  font-size: 54px;
  font-weight: 900;
  font-stretch: 125%;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.tag.is-done .slot { border: 0; background: var(--water); color: var(--buoy); }
.tag.is-pending .slot { border-style: solid; border-color: var(--water-2); }
.slot-wait {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--water-2); border-right-color: transparent;
  animation: spin 1.1s linear infinite;
}

.done-banner {
  margin-top: 16px;
  padding: 18px;
  border-radius: var(--radius-tag);
  background: var(--buoy);
  color: var(--water);
}
.done-lead { margin: 0; font-size: 22px; font-weight: 900; font-stretch: 112%; line-height: 1.15; }
.done-text { margin: 6px 0 0; font-size: 17px; }

.player-no {
  margin: 18px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--canvas);
  text-shadow: 0 1px 2px rgba(15, 42, 61, .6);
}

/* ---------- ekran wyzwania ---------- */

.sheet {
  background: var(--canvas);
  border-radius: 22px;
  padding: 18px 20px 24px;
  box-shadow: 0 10px 40px rgba(15, 42, 61, .3);
  animation: rise .22s ease-out;
}

.back {
  appearance: none;
  border: 0;
  background: none;
  padding: 8px 0;
  margin: 0 0 6px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--water-2);
  cursor: pointer;
}
.back::before { content: "‹ "; font-size: 20px; }

.ch-number { margin: 6px 0 0; font-size: 15px; font-weight: 600; color: var(--ink-soft); }
.ch-name { margin: 2px 0 12px; font-size: clamp(21px, 6.4vw, 30px); line-height: 1.05; font-weight: 900; font-stretch: 118%; overflow-wrap: break-word; hyphens: auto; }
.ch-prompt { margin: 0 0 20px; font-size: 19px; line-height: 1.5; max-width: 60ch; }

.ch-body { display: grid; gap: 14px; }

.illusion {
  display: block;
  width: 100%;
  border-radius: 14px;
  background: var(--canvas-2);
  cursor: zoom-in;
}
.illusion-hint { margin: -6px 0 0; font-size: 14px; color: var(--ink-soft); }

.field-label { font-size: 15px; font-weight: 700; }

.input, .textarea {
  width: 100%;
  font: inherit;
  font-size: 20px;
  color: var(--water);
  background: #fff;
  border: 2px solid rgba(15, 42, 61, .3);
  border-radius: 12px;
  padding: 14px 16px;
}
.input { font-size: 30px; font-weight: 800; font-stretch: 115%; letter-spacing: .04em; }
.textarea { min-height: 128px; resize: vertical; line-height: 1.4; font-size: 18px; }
.input:focus, .textarea:focus { outline: none; border-color: var(--water); box-shadow: 0 0 0 3px rgba(245, 184, 0, .6); }

.counter { margin: -8px 0 0; text-align: right; font-size: 14px; color: var(--ink-soft); }

.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  min-height: 58px;
  padding: 14px 18px;
  font: inherit;
  font-size: 19px;
  font-weight: 800;
  font-stretch: 110%;
  cursor: pointer;
  width: 100%;
}
.btn:focus-visible { outline: 3px solid var(--buoy); outline-offset: 3px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--water); color: var(--canvas); }
.btn-secondary { background: var(--canvas-2); color: var(--water); border: 2px solid rgba(15, 42, 61, .2); }

.msg { margin: 0; padding: 12px 14px; border-radius: 12px; font-size: 16px; font-weight: 600; }
.msg-error { background: #FBE4E2; color: var(--alert); }
.msg-info { background: #E3ECF2; color: var(--water); }

.photo-preview { width: 100%; max-height: 52vh; object-fit: contain; border-radius: 14px; background: var(--water); }

.progress { height: 8px; border-radius: 4px; background: var(--canvas-2); overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--water); transition: width .15s; }

/* Stan po wysłaniu / zaliczeniu w ekranie wyzwania */
.state-box {
  padding: 18px;
  border-radius: 14px;
  background: var(--canvas-2);
}
.state-box h3 { margin: 0 0 6px; font-size: 21px; font-weight: 800; font-stretch: 112%; }
.state-box p { margin: 0; }
.state-box.is-done { background: var(--water); color: var(--canvas); }
.state-box.is-done .big-digit {
  display: block;
  margin-top: 8px;
  font-size: 84px;
  line-height: 1;
  font-weight: 900;
  font-stretch: 125%;
  color: var(--buoy);
}
.state-box.is-rejected { background: #FBE4E2; }
.state-box.is-rejected h3 { color: var(--alert); }

/* ---------- odsłonięcie cyfry ---------- */

.reveal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: var(--gutter);
  background: rgba(15, 42, 61, .82);
  animation: fade .2s ease-out;
}
.reveal-card {
  width: min(100%, 380px);
  background: var(--canvas);
  border-radius: 24px;
  padding: 26px 22px 22px;
  text-align: center;
}
.reveal-title { margin: 0; font-size: 22px; font-weight: 900; font-stretch: 112%; line-height: 1.2; }
.reveal-slot {
  margin: 18px auto;
  width: 150px;
  height: 180px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: var(--water);
  overflow: hidden;
  perspective: 400px;
}
.reveal-digit {
  font-size: 140px;
  line-height: 1;
  font-weight: 900;
  font-stretch: 125%;
  color: var(--buoy);
  animation: tumble .7s cubic-bezier(.2, 1.4, .4, 1) both .15s;
}
.reveal-text { margin: 0 0 18px; font-size: 16px; color: var(--ink-soft); }

/* ---------- komunikat ---------- */

.toast {
  position: fixed;
  left: var(--gutter);
  right: var(--gutter);
  bottom: calc(var(--safe-bottom) + 16px);
  z-index: 20;
  max-width: 488px;
  margin: 0 auto;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--water);
  color: var(--canvas);
  font-weight: 600;
  box-shadow: 0 8px 30px rgba(15, 42, 61, .4);
}

/* ---------- powiększenie złudzenia ---------- */

.zoom {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: #000;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.zoom img { display: block; width: 220%; max-width: none; }
.zoom-close {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 12px;
  width: auto;
  min-height: 48px;
  z-index: 16;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes tumble {
  from { transform: translateY(-110%) rotateX(70deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* Wąskie telefony: zwężony krój zamiast łamania długich słów („spostrzegawczości”). */
@media (max-width: 380px) {
  .tag { grid-template-columns: 1fr 64px; gap: 10px; padding-left: 16px; }
  .slot { min-height: 76px; }
  .slot-digit { font-size: 46px; }
  .tag-name, .ch-name { font-stretch: 86%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition: none !important; }
}
