:root {
  --bg: #fff7ef;
  --card: #ffffff;
  --ink: #2a1d17;
  --muted: #8a776c;
  --line: #f0e2d6;
  --accent: #e8553d;
  --accent-ink: #ffffff;
  --good: #2f9e62;
  --warn: #d98a00;
  --shadow: 0 6px 20px rgba(120, 60, 30, .08);
  --t0: #e8553d; --t1: #2f7fd9; --t2: #2f9e62; --t3: #9a4fd1;
  --t4: #d98a00; --t5: #d1478f; --t6: #19a3a3; --t7: #6b7a2a;
  --t8: #7a5230; --t9: #4d5bd1; --t10: #c23b3b; --t11: #3f8f3f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1411; --card: #261c18; --ink: #f6ebe3; --muted: #b19d91;
    --line: #3a2c25; --shadow: 0 6px 20px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: "Noto Sans Georgian", system-ui, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  overscroll-behavior: none;
}
#app { max-width: 520px; margin: 0 auto; padding: 16px 16px 32px; }
h1 { font-size: 40px; margin: 24px 0 4px; text-align: center; letter-spacing: .5px; }
h2 { font-size: 20px; margin: 0 0 12px; }
.sub { text-align: center; color: var(--muted); margin: 0 0 24px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.card {
  background: var(--card); border-radius: 18px; padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 6px; }
input, select {
  width: 100%; font: inherit; font-size: 17px; padding: 13px 14px;
  border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--bg); color: var(--ink); outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
button {
  font: inherit; font-weight: 600; font-size: 17px; border: 0; cursor: pointer;
  border-radius: 14px; padding: 14px 16px; width: 100%;
  background: var(--accent); color: var(--accent-ink);
  transition: transform .06s, opacity .2s;
  touch-action: manipulation;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .45; }
button.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
button.link { background: none; color: var(--muted); width: auto; padding: 8px; font-weight: 400; font-size: 15px; }
button.good { background: var(--good); }
button.mini { width: auto; padding: 6px 10px; font-size: 14px; border-radius: 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.stack > * + * { margin-top: 10px; }
.or { text-align: center; color: var(--muted); margin: 14px 0; font-size: 14px; }

.code {
  font-size: 44px; font-weight: 800; letter-spacing: 8px; text-align: center;
  margin: 4px 0 2px; font-variant-numeric: tabular-nums;
}
.plist { list-style: none; margin: 0; padding: 0; }
.plist li {
  display: flex; align-items: center; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.plist li:last-child { border-bottom: 0; }
.plist .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist select { width: auto; padding: 8px 10px; font-size: 15px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--good); flex: none; }
.dot.off { background: var(--muted); opacity: .5; }
.tag {
  font-size: 12px; padding: 3px 8px; border-radius: 99px; color: #fff;
  font-weight: 600; white-space: nowrap;
}
.tag.host { background: var(--ink); color: var(--bg); }

.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.team {
  border-radius: 14px; padding: 12px; border: 2px solid var(--line); min-height: 88px;
}
.team h3 { margin: 0 0 6px; font-size: 15px; }
.team .m { font-size: 15px; }
.team button { margin-top: 8px; padding: 8px; font-size: 14px; }

.words input { margin-bottom: 8px; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.round-pill {
  background: var(--accent); color: #fff; font-weight: 800; border-radius: 99px;
  padding: 6px 12px; font-size: 14px;
}
.rule { font-size: 15px; font-weight: 600; text-align: center; margin: 4px 0 14px; }
.scores { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.score {
  flex: 1 0 auto; min-width: 96px; background: var(--card); border-radius: 14px;
  padding: 8px 10px; box-shadow: var(--shadow); border-top: 4px solid var(--c);
}
.score .n { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.score .who { font-size: 12px; color: var(--muted); white-space: nowrap; }
.score.active { outline: 2px solid var(--c); }

.big-turn { text-align: center; padding: 24px 16px; }
.big-turn .who { font-size: 26px; font-weight: 800; margin: 6px 0; }
.arrow { font-size: 22px; color: var(--muted); }

.timer-wrap { display: flex; justify-content: center; margin: 4px 0 14px; }
.timer {
  width: 132px; height: 132px; border-radius: 50%;
  display: grid; place-items: center; font-size: 44px; font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0);
  position: relative;
}
.timer::before { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--bg); }
.timer span { position: relative; }
.timer.low { --accent: #d63b3b; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.04); } }

.word {
  font-size: clamp(30px, 10vw, 48px); font-weight: 800; text-align: center;
  padding: 36px 12px; word-break: break-word; line-height: 1.15;
  user-select: none; -webkit-user-select: none;
}
.guess { font-size: 26px; padding: 26px; border-radius: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--line); border-radius: 99px; padding: 4px 10px; font-size: 14px; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 4px; text-align: center; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
.winner { font-size: 30px; font-weight: 800; text-align: center; margin: 12px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 12px 18px; border-radius: 12px; max-width: 90vw; z-index: 20; font-size: 15px;
}
.conn {
  position: fixed; top: 0; left: 0; right: 0; background: var(--warn); color: #fff;
  text-align: center; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; font-size: 14px; z-index: 20;
}
input.bad { border-color: #d63b3b; background: rgba(214,59,59,.08); }

.tabs { display: flex; gap: 6px; background: var(--card); padding: 5px; border-radius: 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.tabs button { background: transparent; color: var(--muted); padding: 10px 6px; font-size: 15px; border-radius: 10px; }
.tabs button.on { background: var(--accent); color: var(--accent-ink); }
.small-tabs button { padding: 7px 4px; font-size: 14px; }
ol.lb { list-style: none; margin: 0; padding: 0; }
ol.lb li { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
ol.lb li:last-child { border-bottom: 0; }
ol.lb .rk { width: 30px; text-align: center; font-weight: 800; color: var(--muted); font-size: 18px; }
ol.lb .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ol.lb b { font-size: 20px; }
ol.lb li.me { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 10px; }
ol.lb + ol.lb { margin-top: 8px; border-top: 2px dashed var(--line); padding-top: 8px; }


/* ---------- ფურცელი ქუდიდან ---------- */
.slip-stage { perspective: 900px; padding: 18px 8px 26px; display: flex; justify-content: center; }
.slip {
  position: relative; width: min(100%, 340px); aspect-ratio: 1.45;
  transform: rotate(var(--tilt, 0deg));
  filter: drop-shadow(0 10px 14px rgba(60, 30, 10, .22)) drop-shadow(0 2px 2px rgba(60, 30, 10, .18));
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.slip.fresh { animation: slip-pull .55s cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes slip-pull {
  from { transform: translateY(70px) scale(.55) rotate(calc(var(--tilt, 0deg) - 14deg)); opacity: 0; }
  60%  { opacity: 1; }
  to   { transform: rotate(var(--tilt, 0deg)); opacity: 1; }
}
.slip-inner {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transition: transform .18s ease-out;
}
.slip.hidden-mode .slip-inner { transform: rotateY(0deg); }
.slip.hidden-mode.open .slip-inner { transform: rotateY(180deg); }
.slip-face {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  backface-visibility: hidden; -webkit-backface-visibility: hidden; padding: 18px; text-align: center;
  clip-path: polygon(2% 7%, 17% 1%, 36% 4%, 54% 0%, 73% 3%, 97% 1%, 99% 22%, 96% 44%, 100% 67%, 97% 95%,
                     77% 99%, 53% 96%, 31% 100%, 9% 97%, 1% 79%, 3% 53%, 0% 31%);
}
/* დაკუჭული ქაღალდი: ნაკეცები + ჩრდილები */
.slip-front {
  color: #2a1d17;
  background:
    linear-gradient(112deg, transparent 37%, rgba(90,60,30,.10) 38.5%, rgba(255,255,255,.65) 40%, transparent 42.5%),
    linear-gradient(61deg, transparent 56%, rgba(90,60,30,.09) 57.5%, rgba(255,255,255,.55) 59%, transparent 61%),
    linear-gradient(168deg, transparent 18%, rgba(90,60,30,.07) 19.5%, rgba(255,255,255,.4) 21%, transparent 23%),
    linear-gradient(28deg, transparent 72%, rgba(90,60,30,.06) 73.5%, transparent 75.5%),
    radial-gradient(ellipse at 18% 28%, rgba(255,255,255,.8), transparent 42%),
    radial-gradient(ellipse at 82% 78%, rgba(120,85,45,.16), transparent 48%),
    radial-gradient(ellipse at 66% 12%, rgba(120,85,45,.10), transparent 38%),
    radial-gradient(ellipse at 30% 90%, rgba(120,85,45,.10), transparent 40%),
    #f8f1e1;
}
.slip:not(.hidden-mode) .slip-front { transform: none; }
.slip.hidden-mode .slip-front { transform: rotateY(180deg); }
.slip-word {
  font-size: clamp(28px, 9vw, 44px); font-weight: 800; line-height: 1.15; word-break: break-word;
  transform: rotate(calc(var(--tilt, 0deg) * -0.6));
}
/* ამობრუნებული ფურცლის ზურგი — ოთხად დაკეცილი */
.slip-back {
  color: #6b5238; gap: 4px;
  background:
    linear-gradient(90deg, transparent 49.2%, rgba(90,60,30,.22) 50%, rgba(255,255,255,.35) 50.8%, transparent 52%),
    linear-gradient(0deg, transparent 48.5%, rgba(90,60,30,.2) 49.5%, rgba(255,255,255,.3) 50.5%, transparent 51.5%),
    linear-gradient(125deg, transparent 30%, rgba(90,60,30,.08) 31.5%, transparent 33.5%),
    radial-gradient(ellipse at 25% 25%, rgba(255,255,255,.5), transparent 45%),
    radial-gradient(ellipse at 75% 80%, rgba(100,70,35,.2), transparent 50%),
    #e9dcc0;
}
.slip-hat { font-size: 40px; line-height: 1; margin-bottom: 4px; }
.slip-back b { font-size: 18px; }
.slip-back small { font-size: 13px; opacity: .8; }
@media (prefers-reduced-motion: reduce) {
  .slip.fresh { animation: none; }
  .slip-inner { transition: none; }
}

/* ---------- ქულები ---------- */
.pts { font-weight: 700; color: var(--ink); }
.pts-tag { background: var(--line); color: var(--ink); }
.pts-tag.low { background: #ffe0dc; color: #b3261e; }
.points-note { line-height: 1.5; }
.points-note.low { background: #fff0ec; border: 2px solid #f3b6a8; }
.points-note a { color: var(--accent); font-weight: 700; }
.award { font-size: 44px; font-weight: 900; color: var(--good); margin: 10px 0 0; animation: slip-pull .6s both; }

/* ---------- წესების ფანჯარა ---------- */
.rules-btn { width: 100%; }
body.sheet-open { overflow: hidden; }
.sheet {
  position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column;
  animation: sheet-in .2s ease-out;
}
.sheet[hidden] { display: none; }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 18px 12px; border-bottom: 1px solid var(--line);
  max-width: 720px; width: 100%; margin: 0 auto;
}
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-close { font-size: 22px; padding: 6px 10px; }
.sheet-body {
  overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1;
  padding: 16px 18px calc(32px + env(safe-area-inset-bottom, 0px)); max-width: 720px; width: 100%; margin: 0 auto;
}
.rules { line-height: 1.6; font-size: 16px; }
.rules h3 { font-size: 18px; margin: 26px 0 8px; }
.rules p, .rules li { margin: 0 0 8px; }
.rules ul, .rules ol { padding-left: 22px; margin: 0 0 8px; }
.rules-lead { font-size: 17px; }
.rules-tip { background: var(--card); border-radius: 12px; padding: 10px 14px; }
.rules-rounds { display: grid; gap: 10px; margin: 10px 0 12px; }
.rules-round { background: var(--card); border-radius: 14px; padding: 12px 14px; border-left: 5px solid var(--accent); }
.rules-round b { display: block; margin-bottom: 4px; font-size: 16px; }
.rules-round p { margin: 0 0 6px; }
.rules-no { color: var(--muted); font-size: 14px; }

/* მობილური: iOS-ზე ორმაგი დაჭერით ზუმი და ტექსტის გადიდება არ მოხდეს */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, a, input, select, [role="button"] { touch-action: manipulation; }
input, select, textarea { font-size: max(16px, 1em); }

/* qeqe.app-ზე დაბრუნება */
.home-back { display: inline-block; margin: 2px 0 6px; font-weight: 700; font-size: 14px; text-decoration: none; color: inherit; opacity: .75; padding: 6px 2px; }
.home-back:hover { opacity: 1; }
.home-mini { font-weight: 800; text-decoration: none; color: inherit; letter-spacing: -.02em; }
.home-mini:hover { text-decoration: underline; }

.testcard { border: 2px dashed #d9a441; }
.testbar { text-align: center; font-size: 13px; font-weight: 800; color: #2b1a05; background: repeating-linear-gradient(45deg, #ffd66e 0 10px, #f2c14e 10px 20px); border-radius: 10px; padding: 6px 10px; margin-bottom: 8px; }

/* კომპიუტერი */
@media (min-width: 980px) {
  #app, main { max-width: 640px; }
  body { background: radial-gradient(ellipse at 50% 0%, #fff, var(--bg) 60%); }
  .card { padding: 22px 24px; }
  button { transition: transform .12s, filter .12s; } button:hover:not(:disabled) { filter: brightness(1.05); }
  .chatsheet, .sheet .sheet-body { max-width: 760px; }
}

.guestcard { border: 2px dashed #e8b4a8; }
