/* G17 · Ланцюжок слів — YAPOO Arcade */
:root {
  --bg: #F3F4F8;
  --card: #FFFFFF;
  --card-2: #ECEEF5;
  --text: #1B1E2B;
  --muted: #565C72;
  --line: #D9DCE8;
  --accent: #D9691F;
  --accent-strong: #B9500C;
  --accent-soft: #FCE9DA;
  --teal: #0F7E76;
  --teal-strong: #0B655E;
  --teal-soft: #D8F0ED;
  --danger: #C62E2E;
  --good: #1E8A4C;
  --on-accent: #FFFFFF;
  --shadow: 0 6px 24px rgba(27, 30, 43, .10);
  --ring-track: #E1E4EF;
  --font-head: "Unbounded", system-ui, sans-serif;
  --font-body: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
:root[data-theme="dark"] {
  --bg: #11131D;
  --card: #1B1E2C;
  --card-2: #252940;
  --text: #EEF0F8;
  --muted: #A8AEC4;
  --line: #333852;
  --accent: #F39A55;
  --accent-strong: #F39A55;
  --accent-soft: #3A2A1D;
  --teal: #45C3B5;
  --teal-strong: #45C3B5;
  --teal-soft: #17353A;
  --danger: #FF7B7B;
  --good: #5FD08A;
  --on-accent: #1A1208;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  --ring-track: #2A2F47;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #11131D; --card: #1B1E2C; --card-2: #252940; --text: #EEF0F8; --muted: #A8AEC4;
    --line: #333852; --accent: #F39A55; --accent-strong: #F39A55; --accent-soft: #3A2A1D;
    --teal: #45C3B5; --teal-strong: #45C3B5; --teal-soft: #17353A; --danger: #FF7B7B; --good: #5FD08A;
    --on-accent: #1A1208; --shadow: 0 6px 24px rgba(0, 0, 0, .45); --ring-track: #2A2F47;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; overscroll-behavior: none; }
body { font-family: var(--font-body); font-size: 16px; line-height: 1.4; -webkit-text-size-adjust: 100%; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

/* Каркас: фіксований блок рівно у видимій області (visualViewport виставляє --vh / --vtop з JS) */
#app {
  position: fixed; left: 0; right: 0;
  top: var(--vtop, 0px);
  height: var(--vh, 100dvh);
  display: flex; flex-direction: column;
  max-width: 1280px; margin: 0 auto;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
.topbar {
  flex: none; display: flex; align-items: center; gap: 8px;
  min-height: 52px; padding: 6px 12px;
}
.brand { font-family: var(--font-head); font-weight: 700; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-g { color: var(--accent); }
@media (max-width: 479px) { .brand-t { display: none; } }
.topbar-actions { margin-left: auto; display: flex; gap: 6px; }
.icon-btn {
  width: 44px; height: 44px; min-width: 44px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); font-size: 18px; font-weight: 800; display: grid; place-items: center; padding: 0;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }

.screen { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 4px 16px calc(24px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
h1, h2, h3 { font-family: var(--font-head); margin: 0; letter-spacing: -.02em; }
h1 { font-size: clamp(26px, 7vw, 40px); line-height: 1.1; }
h2 { font-size: 22px; margin: 6px 0 14px; }
.lead { margin: 8px 0 0; color: var(--muted); font-size: 16px; }
.hint { color: var(--muted); font-size: 14px; margin: 10px 0 0; }
.center { text-align: center; }
.field-label { font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 8px; }
.field-label:first-child { margin-top: 0; }

/* Головна */
.home-hero { display: flex; gap: 14px; align-items: center; margin: 6px 0 18px; }
.loop-canvas { width: 88px; height: 88px; image-rendering: pixelated; flex: none; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.mode-grid { display: grid; gap: 12px; grid-template-columns: 1fr; margin-bottom: 16px; }
.mode-card {
  display: grid; grid-template-columns: 56px 1fr; grid-template-rows: auto auto; column-gap: 12px; row-gap: 2px;
  text-align: left; padding: 16px; border-radius: 20px; border: 2px solid var(--line); background: var(--card);
  box-shadow: var(--shadow); transition: transform .12s, border-color .12s;
}
.mode-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.mode-card:active { transform: scale(.98); }
.mode-ico { grid-row: 1 / 3; font-size: 38px; display: grid; place-items: center; }
.mode-title { font-family: var(--font-head); font-weight: 700; font-size: 17px; align-self: end; }
.mode-desc { color: var(--muted); font-size: 14px; }
.rules-inline summary { font-weight: 800; cursor: pointer; font-size: 17px; min-height: 28px; }
.rules-body { font-size: 15.5px; }
.rules-body ol { margin: 10px 0 0; padding-left: 22px; }
.rules-body li { margin-bottom: 8px; }
.rules-body b { color: var(--accent-strong); }
:root[data-theme="dark"] .rules-body b { color: var(--accent); }
.kbd { display: inline-block; padding: 0 7px; border-radius: 7px; background: var(--card-2); font-family: var(--font-mono); font-weight: 800; }

/* Налаштування */
.seg { display: flex; gap: 6px; background: var(--card-2); padding: 5px; border-radius: 16px; }
.seg button { flex: 1; min-height: 46px; border: 0; border-radius: 12px; background: transparent; font-weight: 800; font-size: 15px; padding: 6px 8px; }
.seg button[aria-pressed="true"] { background: var(--accent-strong); color: var(--on-accent); box-shadow: 0 2px 8px rgba(0,0,0,.18); }
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.names:has(> label:only-child) { grid-template-columns: 1fr; }
.names label { font-size: 13px; font-weight: 700; color: var(--muted); display: grid; gap: 4px; }
.names input, #word {
  height: 48px; border-radius: 14px; border: 2px solid var(--line); background: var(--bg); padding: 0 14px; font-size: 17px; font-weight: 700; width: 100%; min-width: 0;
}
.names input:focus, #word:focus { border-color: var(--teal); outline: none; }
.topic-chips { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-top: 12px; }
.topic-chip { min-height: 56px; border-radius: 16px; border: 2px solid var(--line); background: var(--card); text-align: left; padding: 8px 12px; display: grid; grid-template-columns: 34px 1fr; align-items: center; column-gap: 8px; font-weight: 800; }
.topic-chip small { grid-column: 2; color: var(--muted); font-weight: 600; font-size: 12.5px; margin-top: -2px; }
.topic-chip .te { grid-row: 1 / 3; font-size: 26px; }
.topic-chip[aria-pressed="true"] { border-color: var(--teal); background: var(--teal-soft); }
.check { display: flex; gap: 10px; align-items: center; margin-top: 12px; font-weight: 600; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--teal); }
.stepper { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.step-btn { width: 52px; height: 52px; border-radius: 16px; border: 2px solid var(--line); background: var(--card); font-size: 28px; font-weight: 800; line-height: 1; }
.step-val { font-family: var(--font-mono); font-weight: 800; font-size: 30px; min-width: 76px; text-align: center; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { min-width: 48px; min-height: 48px; border-radius: 14px; border: 2px solid var(--line); background: var(--card); font-family: var(--font-mono); font-weight: 800; font-size: 17px; }
.chips button[aria-pressed="true"] { border-color: var(--teal); background: var(--teal-soft); color: var(--text); }
#timerChips { margin-left: auto; }

.btn-primary, .btn-cta {
  display: block; width: 100%; min-height: 58px; border: 0; border-radius: 18px; background: var(--accent-strong); color: var(--on-accent);
  font-family: var(--font-head); font-weight: 700; font-size: 18px; padding: 12px 18px; text-align: center; text-decoration: none;
  box-shadow: 0 8px 20px rgba(185, 80, 12, .28);
}
.btn-primary:active, .btn-cta:active { transform: translateY(1px) scale(.99); }
.btn-primary:disabled { opacity: .6; }
.btn-ghost { display: block; width: 100%; min-height: 50px; border-radius: 16px; border: 2px solid var(--line); background: var(--card); font-weight: 800; font-size: 16px; padding: 10px 14px; }

/* Гра */
.screen.game { display: flex; flex-direction: column; padding: 0 14px calc(8px + env(safe-area-inset-bottom)); overflow: hidden; gap: 6px; }
.players { flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pcard {
  position: relative; border-radius: 18px; padding: 8px 12px; background: var(--card); border: 3px solid var(--line);
  display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; align-items: center; column-gap: 8px; transition: border-color .15s, background .15s, transform .15s, box-shadow .15s;
  min-width: 0;
}
.pcard.p0 { --pc: var(--accent); --pc-soft: var(--accent-soft); --pc-text: var(--accent-strong); }
.pcard.p1 { --pc: var(--teal); --pc-soft: var(--teal-soft); --pc-text: var(--teal-strong); }
:root[data-theme="dark"] .pcard { --pc-text: var(--pc); }
.pcard.active { border-color: var(--pc); background: var(--pc-soft); transform: scale(1.02); box-shadow: 0 0 0 4px color-mix(in srgb, var(--pc) 22%, transparent); }
.pcard.dim { opacity: .72; }
.pname { font-family: var(--font-head); font-weight: 700; font-size: 15px; color: var(--pc-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pscore { grid-row: 1 / 3; grid-column: 2; font-family: var(--font-mono); font-weight: 800; font-size: 26px; line-height: 1; text-align: right; }
.hearts { font-size: 18px; letter-spacing: 2px; line-height: 1.2; }
.hearts .lost { opacity: .25; filter: grayscale(1); }
.pcard.hit { animation: shake .4s; }
.float-pts { position: absolute; right: 10px; top: -6px; font-family: var(--font-mono); font-weight: 800; font-size: 20px; color: var(--good); pointer-events: none; animation: floatup 1.1s ease-out forwards; }
@keyframes floatup { 0% { opacity: 0; transform: translateY(8px); } 15% { opacity: 1; } 100% { opacity: 0; transform: translateY(-26px); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }

.stage { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.turnlabel { font-family: var(--font-head); font-weight: 800; font-size: clamp(18px, 4.6vw, 34px); text-transform: uppercase; letter-spacing: .02em; text-align: center; line-height: 1.1; }
.turnlabel .who { color: var(--tl, var(--accent-strong)); }
:root[data-theme="dark"] .turnlabel .who { color: var(--tl, var(--accent)); }
.ringwrap { position: relative; width: var(--ring, 240px); height: var(--ring, 240px); flex: none; }
#app { --ring: clamp(132px, min(72vw, calc(var(--vh, 700px) * .38)), 400px); }
.ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: var(--card); stroke: var(--ring-track); stroke-width: 10; }
.ring-fg { fill: none; stroke: var(--rc, var(--accent)); stroke-width: 10; stroke-linecap: round; stroke-dasharray: 578.05; stroke-dashoffset: 0; transition: stroke .2s; }
.ringwrap.danger .ring-fg { stroke: var(--danger); }
.ringwrap.danger { animation: pulse .5s infinite alternate; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.03); } }
.ring-in { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.hintlabel { font-weight: 800; text-transform: uppercase; letter-spacing: .08em; font-size: calc(var(--ring) * .058); letter-spacing: .04em; white-space: nowrap; color: var(--muted); }
.bigletter { font-family: var(--font-head); font-weight: 800; font-size: calc(var(--ring) * .50); line-height: 1; color: var(--rc, var(--accent)); text-transform: uppercase; }
.bigletter.pop { animation: pop .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { 0% { transform: scale(.3) rotate(-10deg); opacity: .2; } 100% { transform: scale(1) rotate(0); opacity: 1; } }
.ringwrap.danger .bigletter { color: var(--danger); }
.timernum { font-family: var(--font-mono); font-weight: 800; font-size: calc(var(--ring) * .13); color: var(--text); }
.rulenote { font-size: 14px; font-weight: 700; text-align: center; color: var(--text); background: var(--teal-soft); border-radius: 12px; padding: 6px 12px; max-width: 520px; }
.prevword { font-family: var(--font-head); font-weight: 700; font-size: clamp(20px, 5vw, 34px); letter-spacing: .04em; min-height: 1.3em; text-align: center; word-break: break-all; }
.prevword .hl { color: var(--rc, var(--accent)); text-decoration: underline; text-decoration-thickness: 4px; text-underline-offset: 5px; }
.prevword .skip { opacity: .45; }
.loopbox { position: absolute; left: 0; bottom: 0; display: flex; align-items: flex-end; gap: 6px; pointer-events: none; }
.loopbox .loop-canvas { width: 66px; height: 66px; animation-duration: 1.2s; }
.bubble { max-width: 150px; background: var(--card); border: 2px solid var(--line); border-radius: 14px 14px 14px 4px; padding: 5px 9px; font-size: 13px; font-weight: 700; opacity: 0; transition: opacity .2s; margin-bottom: 36px; }
.bubble.show { opacity: 1; }
.pause-overlay { position: absolute; inset: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; border-radius: 20px; z-index: 5; }
.pause-title { font-family: var(--font-head); font-size: 40px; font-weight: 800; }
.pause-overlay .btn-primary { width: auto; min-width: 220px; }

.chainstrip { flex: none; display: flex; gap: 6px; align-items: center; overflow-x: auto; padding: 4px 2px 6px; scroll-behavior: smooth; min-height: 44px; scrollbar-width: none; }
.chainstrip::-webkit-scrollbar { display: none; }
.bead { flex: none; padding: 5px 12px; border-radius: 999px; font-weight: 800; font-size: 15px; background: var(--card); border: 2px solid var(--bc, var(--line)); color: var(--text); animation: pop .35s cubic-bezier(.2, 1.6, .4, 1); white-space: nowrap; }
.bead.b0 { --bc: var(--accent); background: var(--accent-soft); }
.bead.b1 { --bc: var(--teal); background: var(--teal-soft); }
.bead b { text-decoration: underline; text-underline-offset: 3px; }
.link { flex: none; color: var(--muted); font-weight: 800; }

.msg { flex: none; min-height: 24px; text-align: center; font-weight: 800; font-size: 15px; }
.msg.bad { color: var(--danger); }
.msg.good { color: var(--good); }

.inputbar { flex: none; display: flex; gap: 8px; align-items: center; }
#word { flex: 1; height: 56px; font-size: 20px; }
#word::placeholder { font-size: 16px; color: var(--muted); opacity: .9; }
#word.shake { animation: shake .35s; border-color: var(--danger); }
#word.good { border-color: var(--good); }
.tool { width: 46px; min-width: 46px; height: 56px; }
.btn-send { height: 56px; padding: 0 20px; border: 0; border-radius: 16px; background: var(--accent-strong); color: var(--on-accent); font-family: var(--font-head); font-weight: 700; font-size: 17px; flex: none; }
.btn-finish { align-self: center; flex: none; background: none; border: 0; color: var(--muted); font-weight: 700; font-size: 14px; min-height: 34px; text-decoration: underline; }

/* Підсумок */
.result-hero { text-align: center; margin: 4px 0 16px; }
.result-hero .rh-title { font-family: var(--font-head); font-weight: 800; font-size: clamp(26px, 7vw, 42px); line-height: 1.1; }
.result-hero .rh-sub { color: var(--muted); margin-top: 6px; font-weight: 600; }
.beads { display: flex; flex-wrap: wrap; gap: 6px 4px; align-items: center; }
.beads .bead { animation: none; font-size: 16px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px 14px; box-shadow: var(--shadow); }
.stat .sv { font-family: var(--font-mono); font-weight: 800; font-size: 28px; line-height: 1.1; }
.stat .sv.word { font-family: var(--font-head); font-size: 20px; overflow-wrap: anywhere; }
.stat.wide { grid-column: span 2; }
.stat .sl { color: var(--muted); font-size: 13px; font-weight: 700; margin-top: 2px; }
.stat.p0 .sv { color: var(--accent-strong); }
.stat.p1 .sv { color: var(--teal-strong); }
:root[data-theme="dark"] .stat.p0 .sv { color: var(--accent); }
:root[data-theme="dark"] .stat.p1 .sv { color: var(--teal); }
.tr-list { list-style: none; padding: 0; margin: 0 0 6px; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 14px; }
.tr-list li { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dashed var(--line); padding: 4px 0; font-size: 15px; }
.tr-list li b { font-weight: 800; }
.tr-list li span { color: var(--muted); text-align: right; }
.tr-list.left li b { color: var(--muted); font-weight: 700; }
.result-actions { display: grid; gap: 10px; margin-bottom: 14px; }
.cta { text-align: center; background: linear-gradient(135deg, var(--accent-soft), var(--teal-soft)); }
.cta-text { font-family: var(--font-head); font-weight: 700; font-size: 17px; margin-bottom: 12px; line-height: 1.3; }
.btn-cta { background: var(--teal-strong); box-shadow: 0 8px 20px rgba(11, 101, 94, .28); }
:root[data-theme="dark"] .btn-cta { background: var(--teal); color: #08211E; }

/* Діалоги */
dialog { border: 0; border-radius: 22px; background: var(--card); color: var(--text); padding: 16px; width: min(560px, calc(100vw - 24px)); max-height: calc(var(--vh, 90vh) - 24px); box-shadow: 0 20px 60px rgba(0,0,0,.4); }
dialog::backdrop { background: rgba(10, 12, 20, .6); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; position: sticky; top: 0; background: var(--card); }
.list-body { display: grid; gap: 10px; }
.lg { display: grid; grid-template-columns: 34px 1fr; gap: 8px; align-items: start; }
.lg-l { font-family: var(--font-head); font-weight: 800; font-size: 20px; color: var(--accent-strong); }
.lg-w { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 14.5px; }
.lg-w span { color: var(--muted); }
.lg-w i { font-style: normal; font-weight: 800; color: var(--text); }
.lg-w .used { text-decoration: line-through; opacity: .5; }
.lg.cur .lg-l { color: var(--teal-strong); }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

/* Адаптив */
@media (min-width: 720px) {
  .mode-grid { grid-template-columns: repeat(3, 1fr); }
  .mode-card { grid-template-columns: 1fr; grid-template-rows: auto auto auto; text-align: center; }
  .mode-ico { grid-row: auto; font-size: 52px; }
  .screen:not(.game) { padding-left: 28px; padding-right: 28px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .pname { font-size: 20px; } .pscore { font-size: 40px; } .hearts { font-size: 26px; }
  .pcard { padding: 12px 18px; }
  #screen-setup, #screen-result { max-width: 760px; width: 100%; margin: 0 auto; }
  .loopbox .loop-canvas { width: 110px; height: 110px; }
  .bubble { font-size: 16px; max-width: 220px; margin-bottom: 60px; }
  .bead { font-size: 18px; }
  #word { font-size: 24px; height: 64px; }
  .btn-send, .tool { height: 64px; }
  .msg { font-size: 18px; }
}
/* Низький екран (телефон з клавіатурою): лишаємо тільки найважливіше — гравці, літера, таймер, поле */
.compact .loopbox, .compact .chainstrip, .compact .btn-finish, .compact .rulenote { display: none; }
.compact .prevword { font-size: 18px; min-height: 1.2em; }
.compact .topbar { min-height: 44px; padding-top: 2px; padding-bottom: 2px; }
.compact .icon-btn { height: 38px; width: 38px; min-width: 38px; }
.compact .pcard { padding: 4px 10px; }
.compact .pscore { font-size: 20px; }
.compact .hearts { font-size: 15px; }
.tiny .brand, .tiny .turnlabel, .tiny .prevword { display: none; }
.tiny .stage { gap: 2px; }
#app.tiny { --ring: clamp(96px, min(46vw, calc(var(--vh, 700px) * .40)), 400px); }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* підтвердження (замість системного confirm) */
#confirmDialog { width: min(420px, calc(100vw - 32px)); padding: 22px; }
.confirm-text { font-family: var(--font-head); font-weight: 700; font-size: 20px; line-height: 1.3; margin: 4px 0 18px; text-align: center; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.confirm-actions > button { margin: 0; width: 100%; }
