/* «Курятник»: ванильные матовые панели поверх 3D-фермы. */
:root {
  --cream: #f4ecd8;
  --cream2: #ebe1c7;
  --ink: #3b3328;
  --muted: #7a6f5d;
  --line: #d9cdae;
  --red: #c9503c;
  --gold: #d9a23a;
  --green: #5f8f55;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #efe6d2; color: var(--ink); font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; user-select: none; }
[hidden] { display: none !important; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#flash { position: fixed; inset: 0; background: #fffbe8; opacity: 0; pointer-events: none; z-index: 3; }

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(244, 236, 216, 0.3); backdrop-filter: blur(1.5px); z-index: 6; }
.overlay.soft { background: rgba(244, 236, 216, 0.15); backdrop-filter: none; }
.card { width: min(720px, 100%); max-height: 100%; overflow: auto; background: rgba(244, 236, 216, 0.96); border: 2px solid var(--line); border-radius: 22px; padding: 22px 26px; box-shadow: 0 18px 50px rgba(59, 51, 40, 0.18); }
h1 { margin: 2px 0 12px; font-size: 28px; line-height: 1.15; }
.step, .kicker { font-size: 13px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }
.hint, .muted { margin-top: 10px; text-align: center; font-size: 13px; color: var(--muted); }
.btn { font: inherit; font-weight: 650; color: #fbf6e8; background: var(--ink); border: 2px solid var(--ink); border-radius: 12px; padding: 10px 18px; cursor: pointer; text-decoration: none; display: inline-block; }
.btn.ghost { background: transparent; color: var(--ink); border-color: #b9ab88; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:hover:not(:disabled) { filter: brightness(1.15); }

/* правила */
#ruleArt { width: 100%; aspect-ratio: 560 / 220; border-radius: 16px; background: #e9dfc4; display: block; }
.rule-text { margin-top: 14px; min-height: 120px; }
.rule-text p { margin: 6px 0; }
.rule-text table { width: 100%; border-collapse: collapse; font-size: 15px; }
.rule-text td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.rule-text td:first-child { font-weight: 700; white-space: nowrap; padding-right: 14px; }
.dots { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: #d4c7a6; }
.dots i.on { background: var(--red); }

/* лобби: компактная панель сверху — загон с курицами виден */
#screen-lobby { align-items: flex-start; background: none; backdrop-filter: none; padding-top: 10px; }
.lobby { width: min(980px, 100%); padding: 14px 18px; background: rgba(244, 236, 216, 0.93); }
.lobby h1 { font-size: 22px; margin: 0 0 8px; }
.lobby .row { margin-top: 10px; }
.join-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.join { background: var(--cream2); border-radius: 12px; padding: 8px 10px; font-size: 13px; color: var(--muted); }
.join b { display: block; color: var(--ink); font-size: 15px; }
.join-short { font-size: 14px; color: var(--muted); }
.join-short b { color: var(--ink); }
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 6px; }
.slot { background: var(--cream2); border: 2px solid var(--line); border-radius: 14px; padding: 6px 10px; min-height: 56px; position: relative; display: flex; gap: 10px; align-items: center; }
.slot.empty { border-style: dashed; color: var(--muted); justify-content: center; font-size: 14px; }
.slot.ready { border-color: var(--green); background: #e3e6c8; }
.slot canvas { width: 44px; height: 44px; flex: none; }
.slot .nm { font-weight: 800; display: flex; align-items: center; gap: 7px; }
.slot .dev { font-size: 12.5px; color: var(--muted); }
.slot .rd { font-size: 12.5px; font-weight: 700; color: var(--green); }
.slot .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.slot .x { position: absolute; top: 4px; right: 8px; background: none; border: 0; font-size: 18px; color: var(--muted); cursor: pointer; }
.ready-hint { font-size: 14px; color: var(--muted); text-align: center; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
.hud-tl { position: absolute; left: 14px; top: 12px; background: rgba(244, 236, 216, 0.92); border-radius: 16px; padding: 8px 16px; text-align: center; border: 2px solid var(--line); }
.hud-tl .round { font-size: 12px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.hud-tl .timer { font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.1; }
.hud-tl .timer.low { color: var(--red); }
.hud-weather { position: absolute; right: 14px; top: 12px; background: rgba(244, 236, 216, 0.92); border-radius: 16px; padding: 8px 14px; display: flex; gap: 10px; align-items: center; border: 2px solid var(--line); max-width: 300px; transition: transform 0.25s; }
.hud-weather.pop { transform: scale(1.12); }
.hud-weather b { display: block; font-size: 17px; }
.hud-weather small { display: block; font-size: 12.5px; color: var(--muted); line-height: 1.2; }
.wicon { width: 38px; height: 38px; flex: none; }
.wicon svg { width: 100%; height: 100%; }
.alerts { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.alert { background: rgba(59, 51, 40, 0.86); color: #fbf6e8; border-radius: 14px; padding: 6px 16px; font-weight: 750; font-size: 16px; white-space: nowrap; animation: pop 0.25s ease-out; }
.alert.red { background: rgba(176, 62, 44, 0.92); }
.alert.gold { background: rgba(196, 140, 40, 0.94); }
.alert.green { background: rgba(70, 120, 70, 0.92); }
.alert.fade { opacity: 0; transition: opacity 0.4s; }
@keyframes pop { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.chips { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; gap: 8px; flex-wrap: nowrap; justify-content: center; width: calc(100% - 24px); }
.chip { background: rgba(244, 236, 216, 0.94); border: 2px solid var(--line); border-radius: 14px; padding: 5px 12px 5px 8px; display: flex; align-items: center; gap: 8px; font-size: 14px; flex: 0 1 170px; min-width: 0; }
.chip > div { min-width: 0; }
.chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.chip .nm { font-weight: 750; }
.chip .hp { color: var(--red); letter-spacing: 1px; font-size: 15px; }
.chip .hp i { font-style: normal; color: #cdbf9f; }
.chip .sc { margin-left: auto; font-weight: 900; font-size: 18px; font-variant-numeric: tabular-nums; }
.chip .st { font-size: 12px; color: var(--muted); }
.chip.out { opacity: 0.6; }
.chip.bump .sc { animation: bump 0.3s; }
@keyframes bump { 50% { transform: scale(1.35); color: var(--gold); } }
.big { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); font-size: clamp(48px, 10vw, 130px); font-weight: 900; color: #fbf6e8; text-shadow: 0 5px 0 rgba(59, 51, 40, 0.55), 0 0 40px rgba(59, 51, 40, 0.3); white-space: nowrap; text-align: center; }
.big small { display: block; font-size: 0.28em; }

/* бирки над курицами */
#tags { position: fixed; inset: 0; pointer-events: none; z-index: 1; overflow: hidden; }
.tag { position: absolute; transform: translate(-50%, -100%); background: rgba(244, 236, 216, 0.9); border: 2px solid; border-radius: 10px; padding: 0 7px; font-size: 12.5px; font-weight: 800; white-space: nowrap; line-height: 1.5; }
.tag .h { color: var(--red); font-weight: 700; margin-left: 4px; letter-spacing: 0.5px; }
.tag .pts { position: absolute; left: 50%; top: -6px; transform: translateX(-50%); color: var(--gold); font-weight: 900; font-size: 15px; text-shadow: 0 1px 0 #fff; animation: rise 0.9s ease-out forwards; }
.tag .pts.minus { color: var(--red); }
@keyframes rise { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, -26px); } }

/* итоги */
.round-card { width: min(640px, 100%); }
table { width: 100%; border-collapse: collapse; margin: 6px 0 10px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
th { font-size: 12.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.win td { font-weight: 800; background: #f7edcf; }
.results { width: min(820px, 100%); }
.awards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.award { background: var(--cream2); border-radius: 12px; padding: 8px 12px; font-size: 13px; color: var(--muted); }
.award b { display: block; color: var(--ink); font-size: 15px; }
.pause { width: min(440px, 100%); text-align: center; }

@media (max-width: 1000px) {
  .chip { font-size: 12.5px; padding: 4px 8px 4px 6px; gap: 6px; }
  .chip .sc { font-size: 16px; }
}
@media (max-width: 760px) {
  .join-grid, .slots { grid-template-columns: repeat(2, 1fr); }
  .hud-weather { top: auto; bottom: 86px; }
}

/* всплывающие надписи «БАМ!», «КО-КО!» */
#pops { position: fixed; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
.pop { position: absolute; left: 0; top: 0; will-change: transform; white-space: nowrap; }
.pop { font: 900 calc(30px * var(--big, 1)) / 1 'Arial Black', 'Segoe UI Black', system-ui, sans-serif; letter-spacing: 0.5px; color: #fff4c9;
  -webkit-text-stroke: calc(2px * var(--big, 1)) #3b2414; paint-order: stroke fill; text-shadow: 0 4px 0 rgba(59, 36, 20, 0.55), 0 0 18px rgba(255, 200, 80, 0.35); }
.pop { animation: popIn 1.1s cubic-bezier(0.2, 0.9, 0.3, 1.2) forwards; }
.pop.hit { color: #ffe066; }
.pop.faint { color: #ff9b8a; }
.pop.gold { color: #ffd34d; }
.pop.dodge { color: #b8f0ff; font-size: calc(24px * var(--big, 1)); }
.pop.combo { color: #ffffff; background: linear-gradient(90deg, #ffde59, #ff7a59); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
@keyframes popIn {
  0% { scale: 0.2; rotate: calc(var(--rot) * 3); opacity: 0; translate: -50% -50%; }
  14% { scale: 1.35; rotate: var(--rot); opacity: 1; translate: -50% -50%; }
  28% { scale: 0.95; translate: -50% -50%; }
  40% { scale: 1.05; translate: -50% -50%; }
  75% { opacity: 1; translate: -50% -50%; }
  100% { scale: 0.85; opacity: 0; translate: -50% -70%; }
}
.tag .pts { animation: ptsUp 0.9s cubic-bezier(0.2, 0.9, 0.3, 1.2) forwards; }
@keyframes ptsUp { 0% { translate: 0 6px; scale: 0.4; opacity: 0; } 20% { translate: 0 -4px; scale: 1.35; opacity: 1; } 100% { translate: 0 -34px; scale: 1; opacity: 0; } }

/* рекорд */
.record { margin-top: 8px; text-align: center; font-size: 14px; color: var(--muted); }
.record b { color: var(--ink); }
.record.lg { font-size: 17px; margin: 6px 0 4px; }
.record.new { color: var(--gold); font-weight: 900; animation: recPop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.3); }
@keyframes recPop { 0% { scale: 0.6; opacity: 0; } 100% { scale: 1; opacity: 1; } }

/* настройки */
#screen-settings { z-index: 8; }
.settings { width: min(560px, 100%); }
.set-row { display: flex; align-items: center; gap: 12px; margin: 12px 0; flex-wrap: wrap; }
.set-row > b { min-width: 150px; }
.set-row input[type=range] { flex: 1; min-width: 140px; accent-color: var(--red); }
.set-row.check { gap: 8px; }
.set-note { font-size: 13px; color: var(--muted); }
.seg { display: inline-flex; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; flex-wrap: wrap; }
.seg button { font: inherit; font-weight: 650; background: transparent; border: 0; padding: 8px 12px; cursor: pointer; color: var(--ink); }
.seg button.on { background: var(--ink); color: #fbf6e8; }
.link { background: none; border: 0; color: var(--red); text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }

/* FPS */
#fps { position: fixed; left: 50%; bottom: 6px; transform: translateX(-50%); z-index: 9; font: 700 12px/1 ui-monospace, monospace; background: rgba(59, 51, 40, 0.75); color: #fbf6e8; padding: 4px 8px; border-radius: 8px; pointer-events: none; }

/* касание: кнопка взмаха */
.touch-flap { position: fixed; right: 18px; bottom: 18px; z-index: 5; width: 92px; height: 92px; border-radius: 50%; border: 3px solid var(--ink); background: rgba(244, 236, 216, 0.92); font-size: 34px; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 8px 24px rgba(59, 51, 40, 0.25); touch-action: none; user-select: none; -webkit-user-select: none; }
.touch-flap span { font-size: 12px; font-weight: 800; color: var(--ink); }
.touch-flap:active, .touch-flap.on { transform: scale(0.94); background: #f2d98a; }
#view { touch-action: none; }

/* телефоны и узкие экраны */
@media (max-width: 760px) {
  h1 { font-size: 22px; }
  .card { padding: 14px 14px; border-radius: 16px; }
  .join-grid { grid-template-columns: repeat(2, 1fr); }
  .slots { grid-template-columns: repeat(2, 1fr); }
  .lobby h1 { font-size: 18px; }
  .hud-tl { left: 8px; top: 8px; padding: 4px 10px; border-radius: 12px; }
  .hud-tl .timer { font-size: 22px; }
  .hud-weather { right: 8px; padding: 4px 8px; max-width: 160px; }
  .hud-weather small { display: none; }
  .wicon { width: 28px; height: 28px; }
  .alerts { top: 58px; width: 92%; }
  .alert { font-size: 13px; white-space: normal; text-align: center; padding: 5px 10px; }
  .pop { font-size: calc(22px * var(--big, 1)); }
  .rule-text { min-height: 0; font-size: 14px; }
  .btn { padding: 9px 13px; }
}
@media (max-height: 480px) {
  .card { max-height: 96vh; }
  #ruleArt { max-height: 120px; object-fit: contain; }
}
body.touch .chips { width: calc(100% - 132px); left: 12px; transform: none; justify-content: flex-start; flex-wrap: wrap; }
@media (max-width: 760px) {
  .chips { flex-wrap: wrap; gap: 4px; bottom: 6px; }
  .chip { flex: 0 1 31%; padding: 3px 8px 3px 6px; font-size: 12px; gap: 5px; border-radius: 10px; }
  .chip .sc { font-size: 15px; }
  .chip .hp { font-size: 12px; }
  .touch-flap { width: 80px; height: 80px; right: 12px; bottom: 12px; }
}
@media (max-width: 760px) { body.touch .hud-weather { bottom: 108px; } }
