:root {
  color-scheme: light;
  --paper: #fffaf1;
  --ink: #23343a;
  --muted: #667878;
  --line: rgba(39, 57, 55, 0.18);
  --wood: #b77947;
  --mint: #dff1d3;
  --blue: #3a8fda;
  --violet: #8b5cf6;
  --red: #e75c54;
  --yellow: #f2bd3f;
  --green: #75b94a;
  --shadow: 0 18px 48px rgba(37, 50, 47, 0.22);
  font-family:
    "Hiragino Sans",
    "Yu Gothic",
    "Meiryo",
    system-ui,
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  min-height: 100svh;
  place-items: center;
  overflow-x: hidden;
  background:
    linear-gradient(135deg, rgba(255, 250, 241, 0.92), rgba(223, 241, 211, 0.86)),
    url("./assets/studio-board.png") center / cover;
  color: var(--ink);
}

button,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

button:focus-visible {
  outline: 3px solid rgba(58, 143, 218, 0.45);
  outline-offset: 3px;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.45);
  opacity: 0.52;
}

.game-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  width: min(1180px, calc(100vw - 28px));
  min-height: min(720px, calc(100svh - 28px));
  padding: 18px;
}

.play-section,
.hud,
.screen-card {
  border: 1px solid rgba(255, 255, 255, 0.52);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.play-section {
  display: grid;
  min-width: 0;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.74);
}

.canvas-frame {
  position: relative;
  width: min(100%, 960px);
  aspect-ratio: 48 / 31;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: #f7ead7;
  box-shadow: inset 0 0 0 1px rgba(63, 44, 31, 0.16);
}

.toast {
  position: absolute;
  left: 18px;
  bottom: 16px;
  max-width: min(520px, calc(100% - 36px));
  margin: 0;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 8px;
  background: rgba(35, 52, 58, 0.86);
  color: #fffdf5;
  font-size: 14px;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}

.toast.is-visible {
  animation: toast-in 2200ms ease both;
}

.hud {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.88);
}

.eyebrow {
  margin: 0 0 6px;
  color: #5d735b;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.14;
}

h2 {
  margin-bottom: 10px;
  font-size: clamp(24px, 5vw, 38px);
  line-height: 1.14;
}

.lead,
.help,
#screen-text,
#screen-meta {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.lead {
  margin-bottom: 0;
}

.art-strip {
  position: relative;
  overflow: hidden;
  height: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e9f4dc;
}

.art-strip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 52%;
}

.difficulty {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.difficulty button {
  padding: 0 6px;
  font-size: 14px;
  font-weight: 750;
  white-space: nowrap;
  word-break: keep-all;
}

.difficulty button,
.secondary,
.ghost {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
}

.difficulty button[aria-pressed="true"] {
  background: #273a35;
  color: #fffaf1;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 0;
}

.stats div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.64);
}

.stats dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.stats dd {
  margin: 4px 0 0;
  color: var(--ink);
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.palette {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.swatch {
  display: grid;
  place-items: center;
  min-height: 54px;
  border: 1px solid rgba(35, 52, 58, 0.16);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.44), rgba(255, 255, 255, 0.1)), var(--swatch);
  box-shadow:
    inset 0 -6px 0 rgba(0, 0, 0, 0.12),
    0 8px 16px rgba(45, 52, 43, 0.12);
  color: rgba(24, 30, 31, 0.78);
  font-weight: 900;
}

.swatch[aria-current="true"] {
  box-shadow:
    inset 0 -6px 0 rgba(0, 0, 0, 0.14),
    0 0 0 4px rgba(255, 255, 255, 0.92),
    0 0 0 7px var(--swatch),
    0 12px 22px rgba(45, 52, 43, 0.18);
}

.swatch.is-hint {
  animation: pulse-hint 900ms ease-in-out infinite alternate;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary {
  background: #273a35;
  color: #fffaf1;
  font-weight: 800;
  box-shadow: 0 10px 18px rgba(39, 58, 53, 0.2);
}

.secondary {
  font-weight: 750;
}

.ghost {
  grid-column: 1 / -1;
  color: #4c6060;
}

.help {
  margin-bottom: 0;
}

.screen {
  position: fixed;
  inset: 18px;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  border-radius: 8px;
  background: rgba(23, 34, 36, 0.46);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.screen.is-open {
  opacity: 1;
  pointer-events: auto;
}

.screen-card {
  width: min(520px, 100%);
  max-height: calc(100svh - 40px);
  overflow: auto;
  padding: clamp(22px, 5vw, 34px);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 250, 241, 0.99), rgba(255, 250, 241, 0.96)),
    url("./assets/studio-board.png") center / cover;
}

.screen-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.screen-actions button {
  flex: 1 1 160px;
}

@keyframes toast-in {
  0%,
  100% {
    opacity: 0;
    transform: translateY(8px);
  }
  12%,
  86% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse-hint {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-3px);
  }
}

@media (hover: hover) {
  button:not(:disabled):hover {
    transform: translateY(-1px);
  }
}

@media (max-width: 900px) {
  body {
    place-items: start center;
  }

  .game-shell {
    grid-template-columns: 1fr;
    width: min(100vw, 720px);
    min-height: auto;
    padding: 10px;
  }

  .art-strip {
    display: none;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .ghost {
    grid-column: auto;
  }

  .screen {
    inset: 10px;
  }
}

@media (max-width: 520px) {
  .hud {
    padding: 14px;
  }

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

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .swatch {
    min-height: 46px;
  }
}

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