* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg1: #1a1230; --bg2: #2d1b4e; --panel: rgba(30, 20, 55, .92);
  --accent: #ffb84d; --accent2: #ff8fab; --text: #f3ecff;
}
html, body { height: 100%; }
body {
  font-family: "Comic Sans MS", "Segoe UI", sans-serif;
  background: radial-gradient(1200px 800px at 20% 10%, var(--bg2), var(--bg1) 70%);
  color: var(--text);
  overflow: hidden;
}
/* --- плавающие клубки на фоне --- */
#bg-yarn { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.yarn {
  position: absolute; border-radius: 50%;
  opacity: .12; animation: floaty linear infinite;
}
@keyframes floaty {
  from { transform: translateY(110vh) rotate(0deg); }
  to { transform: translateY(-20vh) rotate(720deg); }
}

/* --- экраны --- */
.screen {
  position: fixed; inset: 0; display: none;
  align-items: center; justify-content: center; z-index: 2;
}
.screen.active { display: flex; }
.panel {
  background: var(--panel); border: 3px solid #ffffff22;
  border-radius: 22px; padding: 28px 36px; text-align: center;
  max-width: min(92vw, 560px); box-shadow: 0 20px 60px #0009;
  animation: pop .35s ease;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
h1.logo {
  font-size: 52px; letter-spacing: 2px;
  text-shadow: 3px 3px 0 #ff8fab55;
}
h1.logo span { color: var(--accent2); }
.tagline { color: #cbb8f0; margin-bottom: 14px; }
h2 { margin-bottom: 14px; color: var(--accent); }
.btn {
  display: block; width: 100%; margin: 8px auto; padding: 12px;
  font-size: 18px; font-family: inherit; font-weight: bold;
  color: #241436; background: linear-gradient(180deg, #ffd27a, var(--accent));
  border: none; border-radius: 14px; cursor: pointer;
  box-shadow: 0 4px 0 #b87a1e; transition: transform .08s;
}
.btn:hover { transform: translateY(-2px) rotate(-1deg); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #b87a1e; }
.btn.danger { background: linear-gradient(180deg, #ff9db8, #f76a8f); box-shadow: 0 4px 0 #b04a63; }
.hint { font-size: 13px; color: #a793cc; margin-top: 12px; line-height: 1.5; }
.menu-cats { display: flex; justify-content: center; gap: 6px; margin: 10px 0 16px; }
.menu-cats canvas { width: 56px; height: 56px; }

/* --- игровой экран --- */
.game-layout {
  display: flex; gap: 16px; align-items: flex-start; justify-content: center;
  padding: 12px;
}
.side { display: flex; flex-direction: column; gap: 10px; width: 150px; }
.hud-card {
  background: var(--panel); border: 2px solid #ffffff1c;
  border-radius: 14px; padding: 10px; text-align: center;
}
.hud-card h3 { font-size: 13px; color: #cbb8f0; margin-bottom: 4px; }
.big { font-size: 26px; color: var(--accent); font-weight: bold; }
#board-wrap { position: relative; touch-action: none; }
#board {
  background: #120b26; border: 4px solid #ffffff26; border-radius: 10px;
  display: block; max-width: 100%; height: auto;
}
.fx-layer {
  position: absolute; inset: 4px; width: calc(100% - 8px); height: calc(100% - 8px);
  pointer-events: none; z-index: 4;
}
.side canvas { background: #120b26; border-radius: 8px; max-width: 100%; }

/* --- реплики котиков --- */
.speech {
  position: absolute; top: 12%; left: 50%; transform: translateX(-50%);
  background: #fff; color: #3a2450; padding: 6px 16px; border-radius: 16px;
  font-weight: bold; font-size: 16px; opacity: 0; pointer-events: none;
  transition: opacity .2s; white-space: nowrap; z-index: 5;
  box-shadow: 0 4px 12px #0006;
}
.speech.show { opacity: 1; animation: wob .4s ease; }
@keyframes wob { 0%,100% { transform: translateX(-50%) rotate(0); } 25% { transform: translateX(-50%) rotate(-4deg); } 75% { transform: translateX(-50%) rotate(4deg); } }

/* --- оверлеи --- */
.overlay {
  position: absolute; inset: 0; z-index: 6;
  background: #0d0720dd; border-radius: 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; text-align: center; padding: 20px;
}
.overlay.hidden { display: none; }
.go-entry { display: flex; gap: 8px; margin: 8px 0; }
.go-entry input {
  font-family: inherit; font-size: 16px; padding: 10px; border-radius: 10px;
  border: 2px solid var(--accent2); background: #fff; color: #3a2450; width: 160px;
}

/* --- таблица рекордов --- */
#scores-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
#scores-table th, #scores-table td { padding: 7px 6px; border-bottom: 1px solid #ffffff18; }
#scores-table th { color: var(--accent2); font-size: 13px; }
#scores-table tr:nth-child(1) td { color: gold; }
#scores-table tr:nth-child(2) td { color: #d7e2f7; }
#scores-table tr:nth-child(3) td { color: #e8a06c; }

/* --- титры --- */
.credits { max-height: 86vh; overflow: hidden; display: flex; flex-direction: column; }
.credits-roll { height: 300px; overflow: hidden; position: relative; margin-bottom: 14px; }
.credits-roll p { animation: roll 22s linear infinite; position: relative; }
@keyframes roll { from { top: 300px; } to { top: -560px; } }
.c-role { color: var(--accent2); font-size: 13px; margin-top: 14px; }
.c-name { font-size: 17px; font-weight: bold; }

/* --- мобильная раскладка (В КОНЦЕ файла: cascade должен перекрывать базу) --- */
@media (max-width: 700px) {
  body { overflow: hidden; }
  .game-layout {
    flex-direction: column; align-items: stretch; gap: 6px;
    /* высота без браузерных шторок: JS-переменная → dvh → vh (фолбэки) */
    height: 100vh;
    height: 100dvh;
    height: var(--app-h, 100dvh);
    padding:
      calc(8px + env(safe-area-inset-top, 0px))
      calc(8px + env(safe-area-inset-right, 0px))
      calc(8px + env(safe-area-inset-bottom, 0px))
      calc(8px + env(safe-area-inset-left, 0px));
    max-width: 480px; margin: 0 auto;
    overflow: hidden;
  }
  /* верхняя строка счёта */
  .side { flex-direction: row; width: 100%; gap: 6px; }
  .side.left { order: 1; }
  .side .hud-card { flex: 1; padding: 4px 6px; }
  .hud-card h3 { font-size: 10px; margin: 0; }
  .big { font-size: 16px; }
  /* строка: следующий · придержать · пауза · музыка (всё в один ряд даже на 320px) */
  .side.right { order: 2; align-items: center; gap: 4px; }
  .side.right .hud-card { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; padding: 2px 6px; }
  .side.right .hud-card h3 { display: none; }
  .side.right canvas { display: block; }
  .side.right .btn { width: auto; margin: 0; padding: 9px 10px; font-size: 15px; flex: 0 0 auto; }
  .side.right .btn .lbl { display: none; } /* на телефоне — только иконки */
  /* поле занимает всё оставшееся место, вписывается по высоте и ширине */
  #board-wrap { order: 3; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
  #board {
    max-width: min(100%, 440px); max-height: 100%;
    width: auto; height: auto;
  }
  .fx-layer { border-radius: 6px; }
  h1.logo { font-size: 40px; }
  .menu-cats canvas { width: 40px; height: 40px; }
  .panel { padding: 18px 20px; max-height: 94dvh; overflow-y: auto; }
  .speech { font-size: 13px; }
}
