* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background-color: var(--outer-bg, #e8c98a);
  overscroll-behavior: none;
  touch-action: none;
  background-image: repeating-linear-gradient(
    45deg,
    var(--body-pattern, rgba(160, 100, 30, 0.08)) 0px,
    var(--body-pattern, rgba(160, 100, 30, 0.08)) 1px,
    transparent 1px,
    transparent 28px
  );
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

#mainCanvas {
  position: fixed;
  top: 0;
  left: 0;
  display: block;
  width: 100vw;
  height: 100dvh;
  z-index: 100;
  cursor: pointer;
  background-color: transparent;
}

.game-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  overflow: hidden;
}

.game-inner {
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  width: min(100%, 560px);
  flex: 0 1 auto;
  min-height: 0;
  background: transparent;
  border-radius: 22px;
  padding: 12px;
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.20);
}

#gameCanvas {
  cursor: crosshair;
  display: block;
  flex-shrink: 0;
  touch-action: none;
  border-radius: 14px;
}

#gameCanvas.dragging {
  cursor: grabbing;
}

.shapes-panel-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 75%;
  align-self: center;
}

.shapes-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 10px;
  background: var(--panel-bg, #d4a055);
  border: 2px solid var(--interactive-border, #7a3a10);
  border-radius: 16px;
  width: 100%;
  box-sizing: border-box;
  overflow: visible;
}

.shape-item {
  cursor: grab;
  touch-action: none;
  transform-origin: center center;
}

@keyframes shape-idle-wiggle {
  0%, 80%, 100% { transform: rotate(0deg); }
  84%            { transform: rotate(-9deg); }
  91%            { transform: rotate(9deg); }
  97%            { transform: rotate(-4deg); }
}

.shape-item:active {
  cursor: grabbing;
}

.shapes-count {
  text-align: center;
  font-family: Georgia, serif;
  color: var(--ui-text, #3d1505);
  font-size: 15px;
  font-weight: bold;
  opacity: 0.7;
  pointer-events: none;
  padding: 4px 0 0;
}

.edit-seed-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding-top: 2px;
}

.edit-seed-row .shapes-count {
  padding: 0;
}

.edit-seed-row .ctrl-btn {
  font-size: 12px;
  padding: 2px 10px;
  min-width: 0;
}

.preview-rules-panel {
  display: flex;
  flex-direction: row;
  align-items: center;
  background: var(--panel-bg, #d4a055);
  border: 2px solid var(--interactive-border, #7a3a10);
  border-radius: 16px;
  padding: 10px 16px;
  width: 75%;
  box-sizing: border-box;
  align-self: center;
  opacity: 0.9;
}

.preview-col {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

#previewCanvas {
  flex: 0 0 auto;
}

.xor-rules-col {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

#rulesCanvas {
  display: block;
}

.game-controls {
  display: flex;
  flex-direction: row;
  gap: 30px;
  width: min(100%, 560px);
  margin-top: auto;
  flex-shrink: 0;
  padding: 0 12px;
}

.ctrl-btn {
  flex: 1;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--interactive-bg, #7a3a10);
  color: var(--button-text, #e8c98a);
  border: none;
  border-radius: 22px;
  font-family: Georgia, serif;
  font-size: 18px;
  font-weight: bold;
  text-transform: uppercase;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.36);
  touch-action: manipulation;
}

.ctrl-btn:active {
  opacity: 0.75;
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.34);
}
