:root {
  --ink: #36473a;
  --ink-soft: #5d7060;
  --paper: #f8f3e4;
  --paper-2: #efe8d2;
  --moss: #567f4d;
  --moss-d: #456a3e;
  --clay: #c9744d;
  --mist: #dbe9e1;
  --line: rgba(54, 71, 58, 0.14);
  --shadow: 0 10px 30px rgba(60, 84, 62, 0.2);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  background: linear-gradient(180deg, #c9dccf, #e7e6cd);
  font-family: 'Nunito', ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  -webkit-user-select: none; user-select: none;
  touch-action: none;
}

#app {
  position: relative;
  width: 100%; max-width: 480px;
  height: 100vh; height: 100dvh;
  margin: 0 auto; overflow: hidden;
  box-shadow: 0 0 60px rgba(60, 84, 62, 0.25);
}
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---------- экраны и карточки ---------- */
.screen {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-t) + 20px) 20px calc(var(--safe-b) + 20px);
}
.card {
  width: 100%;
  background: rgba(250, 246, 233, 0.93);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 24px 22px;
  text-align: center;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: rise .45s cubic-bezier(.2, .9, .3, 1.1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.97); } }

.mark { width: 74px; height: 74px; margin-bottom: 2px; }
.logo { margin: 0; font-size: 44px; line-height: 1; font-weight: 900; letter-spacing: -0.5px; color: var(--ink); }
.tag { margin: 10px 0 18px; color: var(--ink-soft); font-weight: 700; font-size: 15px; line-height: 1.35; }
.eyebrow { margin: 0; font-size: 13px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
h2 { margin: 6px 0 14px; font-size: 28px; font-weight: 900; }

input {
  width: 100%; height: 52px; padding: 0 16px;
  border: 2px solid var(--line); border-radius: 16px;
  background: #fffdf6; color: var(--ink);
  font-family: inherit; font-weight: 800; font-size: 18px; text-align: center;
  outline: none; -webkit-user-select: text; user-select: text;
}
input:focus { border-color: var(--moss); }
input::placeholder { color: #a3ae9f; font-weight: 700; }
#code { text-transform: uppercase; letter-spacing: .25em; }

.btn {
  display: block; width: 100%; height: 52px; margin-top: 10px;
  border: 0; border-radius: 16px;
  background: var(--paper-2); color: var(--ink);
  font-family: inherit; font-weight: 800; font-size: 17px; cursor: pointer;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--moss); color: #fffdf4; box-shadow: 0 4px 0 var(--moss-d); }
.btn.primary:active { transform: translateY(3px) scale(.99); box-shadow: 0 1px 0 var(--moss-d); }
.btn.ghost { background: transparent; color: var(--ink-soft); height: 44px; }
.btn:disabled { filter: grayscale(.6) opacity(.55); pointer-events: none; }

.or { display: flex; align-items: center; gap: 10px; margin: 16px 0 6px; color: var(--ink-soft); font-size: 13px; font-weight: 800; }
.or::before, .or::after { content: ''; flex: 1; height: 2px; background: var(--line); border-radius: 2px; }
.row { display: flex; gap: 10px; }
.row input { flex: 1.2; }
.row .btn { flex: 1; margin-top: 0; }
.err { min-height: 20px; margin: 10px 0 0; color: var(--clay); font-weight: 800; font-size: 14px; }
.hint { margin: 10px 0 0; color: var(--ink-soft); font-weight: 700; font-size: 14px; min-height: 18px; }

/* ---------- лобби ---------- */
.roomcode { font-size: 56px; font-weight: 900; letter-spacing: .12em; padding-left: .12em; margin: 2px 0 6px; color: var(--ink); }
.plist { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.plist li {
  display: flex; align-items: center; gap: 12px;
  height: 50px; padding: 0 14px; border-radius: 14px;
  background: #fffdf6; border: 2px solid var(--line);
  font-weight: 800; font-size: 17px; text-align: left;
}
.plist li.empty { color: #a3ae9f; background: transparent; border-style: dashed; font-weight: 700; }
.plist .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .tagx { font-size: 12px; color: var(--ink-soft); font-weight: 800; }
.dot { width: 20px; height: 20px; border-radius: 7px; flex: none; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .15); }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
#hud > * { pointer-events: auto; }
#hudTop { position: absolute; top: 0; left: 0; right: 0; padding: calc(var(--safe-t) + 10px) 12px 0; pointer-events: none; }
#chips { display: flex; gap: 6px; }
.chip {
  flex: 1; min-width: 0; padding: 7px 8px 8px; border-radius: 14px;
  background: rgba(250, 246, 233, .86); border: 2px solid transparent;
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
  transition: transform .2s, border-color .2s, background .2s;
  box-shadow: 0 3px 10px rgba(60, 84, 62, .12);
}
.chip.turn { border-color: var(--moss); transform: translateY(2px) scale(1.03); background: #fffdf4; }
.chip.out { opacity: .45; }
.chip .who { display: flex; align-items: center; gap: 6px; width: 100%; }
.chip .dot { width: 12px; height: 12px; border-radius: 4px; }
.chip .nm { font-weight: 800; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaves { display: flex; gap: 2px; }
.leaves svg { width: 15px; height: 15px; fill: #6f9e63; }
.leaves svg.lost { fill: #c9c3ae; opacity: .7; }

#banner {
  position: relative; overflow: hidden; margin-top: 10px; padding: 10px 14px;
  border-radius: 14px; background: rgba(250, 246, 233, .92);
  text-align: center; font-weight: 800; font-size: 15px; line-height: 1.2;
  box-shadow: 0 3px 10px rgba(60, 84, 62, .12);
}
#banner.mine { background: var(--moss); color: #fffdf4; }
#bar { position: absolute; left: 0; bottom: 0; height: 4px; width: 0; background: rgba(86, 127, 77, .55); border-radius: 0 4px 4px 0; }
#banner.mine #bar { background: rgba(255, 253, 244, .6); }
#meta { margin-top: 8px; text-align: left; padding-left: 4px; font-size: 13px; font-weight: 800; color: rgba(54, 71, 58, .75); text-shadow: 0 1px 0 rgba(255, 255, 255, .5); }

/* выбор фигуры */
#choosePanel {
  position: absolute; left: 12px; right: 12px; bottom: calc(var(--safe-b) + 14px);
  width: auto; padding: 16px 14px 14px;
}
#chooseTitle { margin: 0 0 12px; font-weight: 800; font-size: 16px; }
#chooseCards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
#chooseCards button {
  aspect-ratio: 1; border: 2px solid var(--line); border-radius: 18px;
  background: #fffdf6; cursor: pointer; padding: 6px;
  transition: transform .1s, border-color .15s;
}
#chooseCards button:active { transform: scale(.94); border-color: var(--moss); }
#chooseCards canvas { width: 100%; height: 100%; display: block; }

/* кнопки управления */
#controls {
  position: absolute; left: 12px; right: 12px; bottom: calc(var(--safe-b) + 14px);
  display: flex; align-items: center; gap: 12px;
}
#controls .drop { margin: 0; height: 64px; font-size: 20px; flex: 1; }
.round {
  width: 60px; height: 60px; flex: none; border: 0; border-radius: 50%;
  background: rgba(250, 246, 233, .95); box-shadow: 0 4px 0 rgba(54, 71, 58, .14), var(--shadow);
  display: grid; place-items: center; cursor: pointer;
}
.round:active { transform: translateY(2px); }
.round svg { width: 28px; height: 28px; fill: none; stroke: var(--ink); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

/* всплывашка */
.toast {
  position: absolute; left: 24px; right: 24px; top: 38%;
  padding: 18px 16px; border-radius: 22px; text-align: center;
  background: rgba(250, 246, 233, .96); box-shadow: var(--shadow);
  font-weight: 900; font-size: 22px; line-height: 1.2;
  animation: pop .4s cubic-bezier(.2, .9, .3, 1.3) both;
}
.toast small { display: block; margin-top: 6px; font-size: 15px; font-weight: 800; color: var(--ink-soft); }
@keyframes pop { from { opacity: 0; transform: scale(.8); } }

#over { background: rgba(219, 233, 225, .35); }

/* звук и связь */
.iconbtn {
  position: absolute; z-index: 9; right: 10px; bottom: calc(var(--safe-b) + 10px);
  width: 38px; height: 38px; border: 0; border-radius: 50%;
  background: rgba(250, 246, 233, .8); color: var(--ink-soft);
  font-size: 18px; cursor: pointer; display: grid; place-items: center;
}
.iconbtn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
body.playing .iconbtn { bottom: auto; top: calc(var(--safe-t) + 112px); right: 12px; width: 30px; height: 30px; opacity: .7; }
.conn { position: absolute; z-index: 20; top: calc(var(--safe-t) + 8px); left: 50%; transform: translateX(-50%); padding: 8px 14px; border-radius: 12px; background: var(--clay); color: #fff; font-weight: 800; font-size: 14px; }

@media (max-height: 640px) {
  .logo { font-size: 36px; }
  .mark { width: 56px; height: 56px; }
  .card { padding: 18px 18px; }
}

/* ---------- режим разработчика ---------- */
#devLobby { margin-top: 12px; }
.devpill {
  position: absolute; z-index: 29; right: 56px; bottom: calc(var(--safe-b) + 16px);
  height: 26px; padding: 0 10px; border: 0; border-radius: 13px;
  background: #36473a; color: #f8f3e4; font: 800 12px/26px inherit; font-family: inherit; letter-spacing: .08em; cursor: pointer; opacity: .85;
}
body.playing .devpill { bottom: auto; top: calc(var(--safe-t) + 150px); right: 12px; }
#dbg {
  position: absolute; z-index: 28; margin: 0; pointer-events: none; text-align: right;
  top: calc(var(--safe-t) + 184px); right: 12px;
  font: 700 11px/1.35 ui-monospace, Menlo, Consolas, monospace; color: #36473a;
  background: rgba(250, 246, 233, .78); padding: 5px 8px; border-radius: 8px; white-space: pre;
}
body:not(.playing) #dbg { top: calc(var(--safe-t) + 10px); }
#devPanel { position: absolute; inset: 0; z-index: 30; background: rgba(40, 56, 44, .38); display: flex; align-items: flex-end; }
.sheet {
  width: 100%; max-height: 86%; overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch;
  background: var(--paper); border-radius: 26px 26px 0 0; padding: 18px 18px calc(var(--safe-b) + 14px);
  box-shadow: 0 -10px 40px rgba(40, 56, 44, .3); animation: rise .3s ease both;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; font-size: 18px; }
.x { width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--paper-2); font-size: 24px; line-height: 1; color: var(--ink); cursor: pointer; }
.dstats { margin: 8px 0 4px; font-size: 13px; font-weight: 800; color: var(--ink-soft); }
.drow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 0; border-top: 2px solid var(--line); }
.drow .lbl { flex: 1; min-width: 0; font-weight: 800; font-size: 15px; line-height: 1.2; }
.drow .lbl small { display: block; margin-top: 3px; font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.sw { position: relative; width: 54px; height: 32px; flex: none; border: 0; border-radius: 16px; background: #c9c3ae; cursor: pointer; transition: background .15s; }
.sw::after { content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fffdf4; box-shadow: 0 2px 4px rgba(0, 0, 0, .2); transition: transform .15s; }
.sw.on { background: var(--moss); }
.sw.on::after { transform: translateX(22px); }
.step { display: flex; align-items: center; gap: 10px; flex: none; }
.step button { width: 38px; height: 38px; border: 0; border-radius: 12px; background: var(--paper-2); font: 800 20px/1 inherit; font-family: inherit; color: var(--ink); cursor: pointer; }
.step button:active { transform: scale(.92); }
.step b { min-width: 28px; text-align: center; font-size: 18px; }
.seg { display: flex; flex: none; background: var(--paper-2); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 8px 9px; border-radius: 9px; font-family: inherit; font-weight: 800; font-size: 13px; color: var(--ink-soft); cursor: pointer; }
.seg button.on { background: var(--moss); color: #fffdf4; }

/* ---------- сдаться ---------- */
#metaRow { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; padding-right: 42px; }
#metaRow #meta { margin-top: 0; }
.pill {
  pointer-events: auto; height: 30px; padding: 0 12px; border: 0; border-radius: 15px;
  background: rgba(250, 246, 233, .9); color: #9a4a2e; font-family: inherit; font-weight: 800; font-size: 13px;
  box-shadow: 0 2px 8px rgba(60, 84, 62, .15); cursor: pointer;
}
.pill:active { transform: scale(.95); }
.btn.danger { background: var(--clay); color: #fffdf4; box-shadow: 0 4px 0 #a9573a; }
.btn.danger:active { transform: translateY(3px); box-shadow: 0 1px 0 #a9573a; }
.notice {
  margin: 8px auto 0; width: fit-content; max-width: 100%; padding: 8px 14px; border-radius: 12px;
  background: rgba(54, 71, 58, .88); color: #fffdf4; font-weight: 800; font-size: 14px; text-align: center;
  animation: pop .3s ease both;
}

/* ---------- поддержка разработчика ---------- */
.btn.support { display: flex; align-items: center; justify-content: center; gap: 8px; background: transparent; color: #9a4a2e; border: 2px solid rgba(201, 116, 77, .35); height: 46px; font-size: 15px; }
.btn.support svg { width: 18px; height: 18px; fill: #c9744d; flex: none; }
.btn.support.hidden { display: none !important; }
.dsec { margin: 14px 0 0; font-size: 12px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.durl { padding: 12px 0 6px; border-top: 2px solid var(--line); }
.durl .lbl { font-weight: 800; font-size: 15px; }
.durl .lbl small { display: block; margin: 3px 0 8px; font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.durl .urlrow { display: flex; gap: 8px; }
.durl input { height: 44px; font-size: 14px; text-align: left; padding: 0 12px; }
.durl button { flex: none; height: 44px; padding: 0 14px; border: 0; border-radius: 12px; background: var(--moss); color: #fffdf4; font-family: inherit; font-weight: 800; cursor: pointer; }
.durl .derr { min-height: 16px; margin: 6px 0 0; font-size: 12.5px; font-weight: 800; color: var(--clay); }
