html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: #0b5a3c;
  font-family: system-ui, Segoe UI, Arial;
  overflow: hidden;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

img, svg {
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

#app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px;
  box-sizing: border-box;
  visibility: hidden;
}

#app.ready {
  visibility: visible;
}

#boardWrap {
  position: relative;
  flex: 0 0 auto;
}

#board {
  position: absolute;
  left: 0;
  top: 0;
  width: 1024px;
  height: 768px;
  background: #0b5a3c;
  user-select: none;
  transform-origin: top left;
}

/* Settings button */
.settings-toggle {
  display: none;
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.2);
  color: white;
  font-size: 24px;
  cursor: pointer;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.settings-toggle:hover {
  background: rgba(0,0,0,0.3);
}

/* Fullscreen button */
.fullscreen-toggle {
  display: none;
  position: fixed;
  bottom: 16px;
  right: 72px;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.2);
  color: white;
  font-size: 24px;
  cursor: pointer;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.fullscreen-toggle:hover {
  background: rgba(0,0,0,0.3);
}

@media (orientation: landscape) and (max-width: 900px) {
  .fullscreen-toggle:not(.is-fullscreen) {
    background: rgba(0,0,0,0.4);
    animation: pulse-glow 2s ease-in-out infinite;
  }
}

/* Debug-панель тестов анимации. Раскомментировать вместе с разметкой в
   index.html и обработчиком в main.js.
.anim-test-panel {
  position: fixed;
  bottom: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 1000;
}

.anim-test-panel button {
  height: 30px;
  padding: 0 14px;
  border: none;
  border-radius: 15px;
  background: rgba(0,0,0,0.35);
  color: white;
  font: 13px/1 system-ui, Segoe UI, Arial;
  cursor: pointer;
  text-align: left;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.anim-test-panel button:hover {
  background: rgba(0,0,0,0.5);
}
*/

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
  50% { box-shadow: 0 2px 16px rgba(255,255,255,0.3); }
}

/* Game number badge — visible always */
.game-badge {
  position: fixed;
  top: 10px;
  left: 10px;
  padding: 4px 10px;
  background: rgba(0,0,0,0.35);
  color: rgba(255,255,255,0.85);
  font: 13px/1 system-ui, Segoe UI, Arial;
  border-radius: 12px;
  cursor: pointer;
  z-index: 1000;
  user-select: none;
  -webkit-user-select: none;
}
.game-badge:hover {
  background: rgba(0,0,0,0.55);
}

/* Settings overlay */
.settings-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1001;
  opacity: 0;
  transition: opacity 0.2s;
}

.settings-overlay.visible {
  opacity: 1;
}

/* Settings panel */
.settings {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 16px 32px;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  background: rgba(0,0,0,0.2);
  border-radius: 8px;
  color: rgba(255,255,255,0.9);
  font: 14px/1.4 system-ui, Segoe UI, Arial;
}

.settings-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-label {
  font-weight: 600;
  margin-right: 4px;
}

.settings label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.settings input[type="radio"] {
  margin: 0;
  cursor: pointer;
  width: 18px;
  height: 18px;
}

.settings button {
  padding: 6px 16px;
  border: none;
  border-radius: 6px;
  background: rgba(255,255,255,0.2);
  color: white;
  font: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.settings button:hover {
  background: rgba(255,255,255,0.3);
}

.settings button:disabled {
  opacity: 0.35;
  cursor: default;
}

.score-display {
  font-weight: 600;
  min-width: 100px;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

#scoreValue, #statsValue {
  font-variant-numeric: tabular-nums;
}

/* Mobile styles: phones always, portrait tablets up to 1024px */
@media (max-width: 767px), (max-width: 1024px) and (orientation: portrait) {
  #app {
    gap: 8px;
    padding: 8px;
    justify-content: flex-start;
    padding-top: 12px;
  }

  .settings-toggle {
    display: flex;
  }

  .fullscreen-toggle {
    display: flex;
  }

  .settings-overlay {
    display: block;
    pointer-events: none;
  }

  .settings-overlay.visible {
    pointer-events: auto;
  }

  .settings {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    width: 100%;
    max-width: 560px;
    flex-direction: column;
    gap: 16px;
    padding: 20px 20px 40px;
    border-radius: 16px 16px 0 0;
    background: rgba(0,0,0,0.75);
    z-index: 1002;
    transition: transform 0.3s ease-out;
    overflow-y: auto;
    max-height: 80vh;
  }

  .settings.open {
    transform: translateX(-50%) translateY(0);
  }

  .settings-group {
    width: 100%;
    justify-content: space-between;
  }

  .settings-row {
    width: 100%;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 8px;
  }

  .settings-row .settings-group {
    width: auto;
    flex: 1;
    justify-content: center;
  }

  .settings button {
    padding: 12px 16px;
    font-size: 16px;
    width: 100%;
  }

  .settings input[type="radio"] {
    width: 22px;
    height: 22px;
  }

  .settings label {
    gap: 6px;
    font-size: 16px;
  }

  .settings-label {
    font-size: 16px;
  }
}

.slot {
  position: absolute;
  width: var(--cw);
  height: var(--ch);
  border-radius: 10px;
}

.slot.foundation {
  outline: 2px dashed rgba(255,255,255,0.22);
  outline-offset: -2px;
}

.slot.stock-empty {
  outline: 3px solid rgba(255,255,255,0.35);
  outline-offset: -3px;
  cursor: pointer;
}

.slot.stock-empty::after {
  content: '⟳';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 52px;
  color: rgba(255,255,255,0.5);
  line-height: 1;
}

.card {
  position: absolute;
  width: var(--cw);
  height: var(--ch);
  touch-action: none;
  cursor: grab;
  background: #ffffff;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.35);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.22) inset;
  filter: drop-shadow(2px 3px 2px rgba(0,0,0,0.28));
}

.card.dragging {
  cursor: grabbing;
  z-index: 9999;
}

.card .frame {
  position: absolute;
  left: 0px;
  right: 0px;
  top: 3px;
  bottom: 3px;
  overflow: hidden;
  border-radius: 10px;
}

.card .frame svg {
  width: 100%;
  height: 100%;
  display: block;
}

#spriteHost {
  position: absolute;
  left: -100000px;
  top: -100000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

#err {
  color: #fff;
  padding: 14px;
  max-width: 900px;
  white-space: pre-wrap;
}
