:root {
  color-scheme: light;
  --ink: #2f2a24;
  --muted: #6b6258;
  --paper: #fffaf0;
  --panel: #ffffff;
  --sun: #f8c14a;
  --leaf: #4fb477;
  --sky: #7cc7e8;
  --berry: #e75f7a;
  --border: #eadfcd;
  --shadow: 0 12px 30px rgba(82, 62, 31, 0.14);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(124, 199, 232, 0.38), rgba(255, 250, 240, 0.92)),
    var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  letter-spacing: 0;
  touch-action: manipulation;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
}

.app {
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  gap: 16px;
  min-height: 100svh;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

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

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1;
}

.score {
  display: grid;
  min-width: 92px;
  min-height: 58px;
  place-items: center;
  border: 3px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 1.4rem;
  font-weight: 900;
}

.question-panel {
  display: grid;
  gap: 6px;
  justify-items: center;
  border: 3px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px 16px 16px;
  box-shadow: var(--shadow);
}

.prompt,
.message {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.target-word {
  min-height: 74px;
  font-size: clamp(2.8rem, 8vw, 5.2rem);
  font-weight: 950;
  line-height: 1;
}

.sticker-shelf {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  border: 3px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  padding: 8px 12px;
  box-shadow: 0 8px 18px rgba(82, 62, 31, 0.08);
}

.sticker-title {
  flex: 0 0 auto;
  color: var(--muted);
  font-weight: 900;
}

.stickers {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sticker {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 2px solid var(--sun);
  border-radius: 50%;
  background: #fff4c7;
  box-shadow: 0 5px 12px rgba(82, 62, 31, 0.12);
  font-size: 1.55rem;
}

.sticker.is-empty {
  border-color: var(--border);
  background: #fffdf7;
  color: #c9bda9;
}

.stage {
  display: grid;
  grid-template-columns: repeat(4, minmax(112px, 1fr));
  gap: 14px;
  align-content: center;
}

.item {
  position: relative;
  display: grid;
  min-height: 124px;
  place-items: center;
  border: 3px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.item:active {
  transform: scale(0.97);
}

.item-emoji {
  display: block;
  font-size: clamp(3rem, 8vw, 5.7rem);
  line-height: 1;
}

.item.is-correct {
  border-color: var(--leaf);
  background: #f1fff6;
  animation: pop 420ms ease;
}

.item.is-wrong {
  border-color: var(--berry);
  animation: shake 280ms ease;
}

.item.is-hint {
  border-color: var(--sun);
  animation: glow 900ms ease-in-out infinite alternate;
}

.sparkle {
  position: absolute;
  inset: 8px;
  pointer-events: none;
}

.sparkle::before,
.sparkle::after {
  position: absolute;
  content: "きら";
  color: var(--sun);
  font-weight: 950;
  opacity: 0;
  animation: sparkle 650ms ease forwards;
}

.sparkle::before {
  top: 8px;
  left: 12px;
}

.sparkle::after {
  right: 10px;
  bottom: 8px;
  animation-delay: 120ms;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.control-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.chip,
.reset-button {
  min-height: 54px;
  border: 3px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 0 18px;
  box-shadow: 0 8px 18px rgba(82, 62, 31, 0.1);
  font-weight: 900;
}

.chip.is-active {
  border-color: var(--sky);
  background: #ecf9ff;
}

.reset-button {
  border-color: var(--sun);
  background: #fff4c7;
}

@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

@keyframes glow {
  from { box-shadow: 0 12px 30px rgba(82, 62, 31, 0.14), 0 0 0 rgba(248, 193, 74, 0); }
  to { box-shadow: 0 12px 30px rgba(82, 62, 31, 0.14), 0 0 28px rgba(248, 193, 74, 0.7); }
}

@keyframes sparkle {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.8);
  }
  45% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-18px) scale(1.12);
  }
}

@media (max-width: 760px) {
  .app {
    gap: 12px;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .stage {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    gap: 10px;
  }

  .item {
    min-height: 108px;
  }

  .controls {
    justify-content: stretch;
  }

  .control-group,
  .reset-button {
    flex: 1 1 100%;
  }

  .chip,
  .reset-button {
    flex: 1;
  }
}
