* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --ink: #18212f;
  --paper: rgba(255, 252, 238, 0.96);
  --mint: #40c5a5;
  --sky: #49a8e8;
  --coral: #f46f65;
  --sun: #ffd667;
  --berry: #8a62c4;
  --shadow: rgba(27, 53, 72, 0.18);
}

html,
body {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 14px;
  color: var(--ink);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  background:
    radial-gradient(circle at 12% 10%, rgba(255, 214, 103, 0.74), transparent 12rem),
    radial-gradient(circle at 86% 18%, rgba(64, 197, 165, 0.34), transparent 13rem),
    linear-gradient(90deg, rgba(255, 255, 255, 0.22) 0 2px, transparent 2px 58px),
    linear-gradient(180deg, #8fe0ef 0%, #ffe59a 46%, #ffaaa0 100%);
}

button {
  font: inherit;
}

.game-shell {
  width: min(100%, 1040px);
  display: grid;
  gap: 12px;
}

.game-top,
.score-row,
.tool-tray {
  border: 2px solid rgba(24, 33, 47, 0.12);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 12px 28px var(--shadow);
}

.game-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #9b3f34;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 1.9rem;
  line-height: 1.08;
}

.sound-toggle,
.scene-buttons button,
.result-actions button,
.tool-tray button {
  min-height: 58px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  background: linear-gradient(180deg, #fff08f, #ffb14d);
  box-shadow: 0 5px 0 #b75d1b;
  font-weight: 900;
}

.sound-toggle {
  min-width: 128px;
  padding: 0 14px;
}

.score-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 9px;
}

.score-card {
  display: grid;
  min-width: 0;
  min-height: 62px;
  align-content: center;
  gap: 3px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.score-card span {
  color: #52606d;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.score-card strong {
  min-width: 0;
  font-size: 1.35rem;
  overflow-wrap: anywhere;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  border: 3px solid #fff;
  border-radius: 8px;
  background: #fff8df;
  box-shadow: 0 18px 35px rgba(27, 53, 72, 0.2);
  touch-action: none;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: 66vh;
}

canvas:focus {
  outline: 4px solid #224f7a;
  outline-offset: 3px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  overflow-y: auto;
  background: rgba(255, 248, 223, 0.86);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(100%, 480px);
  padding: 22px;
  border: 3px solid #fff;
  border-radius: 8px;
  background: #fffdf4;
  box-shadow: 0 16px 30px rgba(27, 53, 72, 0.22);
  text-align: center;
}

.overlay-card h2 {
  margin: 0 0 8px;
  font-size: 1.75rem;
  line-height: 1.08;
}

.overlay-card p {
  margin: 0 0 16px;
  color: #465566;
  line-height: 1.45;
}

.scene-buttons,
.result-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.result-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.scene-buttons button,
.result-actions button {
  width: 100%;
  min-width: 0;
  padding: 0 8px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.tool-tray {
  display: grid;
  gap: 8px;
  padding: 9px;
}

.primary-tools,
.item-tray {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.item-tray {
  padding-top: 8px;
  border-top: 2px dashed rgba(24, 33, 47, 0.18);
}

.tool-tray button {
  width: 100%;
  min-width: 0;
  padding: 0 8px;
  overflow-wrap: anywhere;
}

.tool-button.active,
.tray-choice.active {
  background: linear-gradient(180deg, #a9f3d8, #40c5a5);
  box-shadow: 0 5px 0 #247c68;
}

#stickerTool {
  background: linear-gradient(180deg, #d7f0ff, var(--sky));
  box-shadow: 0 5px 0 #236692;
}

#stampTool {
  background: linear-gradient(180deg, #ffccc7, var(--coral));
  box-shadow: 0 5px 0 #a83f38;
}

#eraserTool {
  background: linear-gradient(180deg, #eadcff, var(--berry));
  box-shadow: 0 5px 0 #584183;
}

.status-text {
  min-height: 28px;
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 246, 0.82);
  font-weight: 800;
  text-align: center;
}

button:focus-visible {
  outline: 4px solid var(--berry);
  outline-offset: 3px;
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #8f4a18;
}

@media (max-width: 720px) {
  body {
    align-items: start;
    padding: 8px;
  }

  .game-shell {
    gap: 9px;
  }

  .game-top {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
  }

  h1 {
    font-size: 1.35rem;
  }

  .sound-toggle {
    width: 100%;
  }

  .score-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 6px;
  }

  .score-card {
    min-height: 58px;
    padding: 8px;
  }

  .score-card strong {
    font-size: 1.12rem;
  }

  .overlay {
    align-items: start;
    padding: 10px;
  }

  .overlay-card {
    padding: 16px;
  }

  .overlay-card h2 {
    font-size: 1.35rem;
  }

  .tool-tray {
    gap: 7px;
    padding: 7px;
  }

  .primary-tools,
  .item-tray {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .scene-buttons {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 360px) {
  .eyebrow,
  .score-card span {
    font-size: 0.68rem;
  }

  .overlay {
    padding: 6px;
  }

  .overlay-card {
    padding: 10px;
  }

  .overlay-card h2 {
    margin-bottom: 6px;
    font-size: 1.08rem;
  }

  #overlayText {
    display: none;
  }

  .scene-buttons,
  .result-actions {
    gap: 6px;
  }

  .tool-tray {
    gap: 6px;
  }

  .primary-tools,
  .item-tray {
    gap: 6px;
  }

  .tool-tray button,
  .scene-buttons button,
  .result-actions button {
    padding: 0 5px;
    font-size: 0.88rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }

  button:active {
    transform: none;
  }
}
