:root {
  --lav: #d9ccff;
  --lemon: #fff3a3;
  --mint: #c5f0dc;
  --ink: #111;
  --r: 28px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #fff;
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

header {
  flex: none;
  text-align: center;
  padding: max(8px, var(--safe-t)) 16px 2px;
}
h1 { font-size: 1.05rem; margin: 0; }
h2 { margin: 0 0 12px; font-size: 1.15rem; }
p { margin: 0 0 10px; }

/* bottom tab bar, reachable with a thumb */
nav {
  flex: none;
  display: flex;
  gap: 6px;
  padding: 8px 12px calc(8px + var(--safe-b));
  background: #fff;
  border-top: 2px solid var(--ink);
}
nav a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 999px;
  background: #f3f0fa;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  touch-action: manipulation;
  transition: transform .1s;
}
nav a:active { transform: scale(.95); }
nav a.active { background: var(--ink); color: #fff; }

/* main fills the screen; only Results and Admin scroll, inside it */
main {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 6px 14px 14px;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  -webkit-user-select: auto;
  user-select: auto;
}
main > * { flex: none; }
main > .survey { flex: 1; min-height: 0; overflow: hidden; }

/* buttons and links */
button, .btn {
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  padding: 12px 22px;
  min-height: 48px;
  touch-action: manipulation;
  transition: transform .1s, opacity .1s;
}
button:active, .btn:active { transform: scale(.94); }
button:disabled { opacity: .3; cursor: default; }
button:disabled:active { transform: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
button.ghost { background: #fff; color: var(--ink); border: 2px solid var(--ink); }
button.small { padding: 8px 16px; font-size: .9rem; min-height: 40px; }

input, textarea, select {
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 10px 14px;
  width: 100%;
  min-height: 48px;
}

/* pastel blocks */
.block { border-radius: var(--r); padding: 18px; margin-bottom: 14px; }
.lav { background: var(--lav); }
.lemon { background: var(--lemon); }
.mint { background: var(--mint); }

.err { color: #c0172b; font-weight: 700; }
.sub { font-size: .85rem; opacity: .7; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  transform: translate(-50%, 20px);
  max-width: 90vw;
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* hide global header when survey is shown */
body.survey-active header { display: none; }

/* survey: Tinder-style full screen, nothing scrolls */
.survey {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

/* single-line top row: title left, ring+name+switch right */
.survey-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  width: 100%;
  padding-bottom: 2px;
}
.survey-title {
  flex: 1;
  font-size: .98rem;
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.survey-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.who {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 0;
  max-width: 130px;
}
/* respondent name chip — prominent, pastel lav background */
.who-name {
  font-weight: 900;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.2;
  background: var(--lav);
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  border: 2px solid var(--ink);
}
/* "To nie ja" → subtle text-only link */
.switch-link {
  all: unset;
  display: block;
  font-size: .72rem;
  font-weight: 400;
  color: #aaa;
  cursor: pointer;
  padding: 4px 0 2px;
  min-height: 28px;
  touch-action: manipulation;
  transition: color .1s;
  white-space: nowrap;
}
.switch-link:hover { color: #555; }

/* compact ring variant used in survey top bar */
.ring { position: relative; width: 42px; height: 42px; flex: none; }
.ring svg { display: block; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: #eee; }
.ring .bar { stroke: var(--ink); transition: stroke-dasharray .3s; }
.ring span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .62rem;
  font-weight: 700;
}

.stack {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 420px;
}
.card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: var(--r);
  transform-origin: 50% 90%;
  backface-visibility: hidden;
  transition: transform .25s ease-out;
}
.card.front {
  z-index: 2;
  touch-action: none;
  cursor: grab;
  will-change: transform;
}
.card.next {
  z-index: 1;
  transform: scale(.95) translateY(10px);
  pointer-events: none;
}
.photo {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--lav);
}
.photo img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
}
.name {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 6px 14px;
  border-radius: 999px;
  background: #fff;
  border: 2px solid var(--ink);
  font-weight: 800;
  max-width: calc(100% - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stamp {
  position: absolute;
  top: 18px;
  padding: 4px 14px;
  border: 4px solid;
  border-radius: 14px;
  background: rgba(255, 255, 255, .85);
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 1px;
  opacity: 0;
  pointer-events: none;
}
.stamp.yes { left: 16px; color: #0a8f55; transform: rotate(-14deg); }
.stamp.no { right: 16px; color: #d6234a; transform: rotate(14deg); }
.q {
  flex: none;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.25;
  background: var(--lemon);
  border-top: 2px solid var(--ink);
  overflow: hidden;
}
/* icon buttons row inside card (replaces external .actions row) */
.card-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 10px 16px 12px;
  background: var(--lemon);
  flex: none;
}
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  min-height: 0;
  cursor: pointer;
  font-style: normal;
  line-height: 1;
  padding: 0;
  transition: transform .1s, opacity .1s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.icon-btn:active { transform: scale(.88); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn:disabled:active { transform: none; }
.no-btn  { width: 58px; height: 58px; background: #ffd3dc; font-size: 1.45rem; }
.yes-btn { width: 58px; height: 58px; background: var(--mint); font-size: 1.45rem; }
.undo-btn { width: 44px; height: 44px; font-size: 1.1rem; }
/* external actions kept for done screen */
.actions { display: flex; align-items: center; justify-content: center; gap: 10px; flex: none; }
.actions { width: 100%; max-width: 420px; }
.actions button { flex: 1; min-width: 0; padding: 12px 8px; white-space: nowrap; }
.actions .btn { flex: 1; white-space: nowrap; }
.hint { flex: none; margin: 0; font-size: .75rem; opacity: .6; text-align: center; }
.done { text-align: center; margin: auto 0; width: 100%; max-width: 420px; }

/* small phones: tighter */
@media (max-height: 620px) {
  .q { min-height: 56px; font-size: .95rem; }
  .no-btn, .yes-btn { width: 52px; height: 52px; font-size: 1.25rem; }
  .undo-btn { width: 40px; height: 40px; font-size: 1rem; }
  .card-actions { padding: 8px 16px 10px; gap: 14px; }
  .hint { display: none; }
  .ring { width: 38px; height: 38px; }
  .ring span { font-size: .58rem; }
  main { padding-top: 2px; padding-bottom: 8px; }
}
/* touch devices have no arrow keys */
@media (hover: none) { .hint { display: none; } }

/* results */
.chips, .tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.chip {
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--ink);
  padding: 8px 16px;
  min-height: 40px;
}
.chip.on { background: var(--ink); color: #fff; }
.qrow { margin-bottom: 14px; }
.qrow .t, .resp .row { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; margin-bottom: 4px; }
.meter { height: 12px; border-radius: 999px; background: rgba(255, 255, 255, .8); border: 2px solid var(--ink); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--ink); border-radius: 999px; }
.resp { padding: 10px 0; border-bottom: 2px dashed rgba(0, 0, 0, .2); cursor: pointer; touch-action: manipulation; }
.resp:last-child { border-bottom: 0; }
.detail { margin-top: 8px; cursor: default; }
.ans { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; font-size: .92rem; }
.pill { flex: none; padding: 2px 12px; border-radius: 999px; border: 2px solid var(--ink); font-weight: 700; font-size: .85rem; }
.pill.y { background: var(--mint); }
.pill.n { background: #ffd3dc; }

/* admin */
.item { border: 2px solid var(--ink); border-radius: 20px; padding: 12px; margin-bottom: 12px; background: #fff; }
.item.lav { background: var(--lav); }
.line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.line:last-child { margin-bottom: 0; }
.line input { flex: 1; min-width: 140px; width: auto; }
.line input.num { flex: none; width: 76px; min-width: 0; }
.thumb { width: 48px; height: 64px; object-fit: cover; border-radius: 12px; border: 2px solid var(--ink); flex: none; }

/* tap the thumbnail to pick or replace a photo */
.pick {
  position: relative; flex: none; width: 66px; height: 88px; border-radius: 14px; border: 2px solid var(--ink);
  background: var(--lemon); overflow: hidden; cursor: pointer; display: grid; place-items: center;
  touch-action: manipulation;
}
.pick img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pick img[src=""] { display: none; }
.pick span {
  position: absolute; left: 0; right: 0; bottom: 0; text-align: center; font-size: .7rem; font-weight: 800;
  background: rgba(255, 255, 255, .85); padding: 2px 0;
}
.pick input { display: none; }
.pick.busy { opacity: .5; pointer-events: none; }

/* desktop */
@media (min-width: 700px) {
  .stack { max-width: 400px; }
}
