:root {
  --color-sky: #68c8e8;
  --color-grass: #70b83b;
  --color-surface: #fff7e3;
  --color-white: #fffdf8;
  --color-ink: #2d241d;
  --color-muted: #62574e;
  --color-board: #30241d;
  --color-border: #a87335;
  --color-primary: #3b7d2b;
  --color-on-primary: #ffffff;
  --color-danger: #c63e35;
  --color-focus: #135f9b;
  --block-yellow: #f7b824;
  --block-blue: #2e83c5;
  --block-green: #79b82d;
  --block-red: #e9544d;
  --block-purple: #8644a3;
  --block-orange: #ec7135;
  --block-cyan: #2aa8a1;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --radius-board: 8px;
  --radius-panel: 8px;
  --radius-button: 8px;
  --control-size: 64px;
  --utility-size: 44px;
  --board-max-width: 300px;
  --panel-width: 190px;
  --page-max-width: 980px;
  --motion-fast: 120ms;
  --motion-normal: 220ms;
  --motion-celebrate: 300ms;
  --motion-easing: cubic-bezier(0.2, 0.8, 0.2, 1);
  --shadow-low: 0 2px 0 rgba(72, 46, 24, 0.24), 0 6px 16px rgba(72, 46, 24, 0.12);
  --shadow-high: 0 4px 0 rgba(72, 46, 24, 0.28), 0 10px 24px rgba(72, 46, 24, 0.16);
  --font-family: "Arial Rounded MT Bold", "Trebuchet MS", "Apple SD Gothic Neo", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--color-sky);
}

body {
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--color-ink);
  font-family: var(--font-family);
  letter-spacing: 0;
  background-color: var(--color-sky);
  background-image: url("assets/garden-bg.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

button {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}

button:focus-visible {
  outline: 4px solid var(--color-focus);
  outline-offset: var(--space-1);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.game-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: var(--space-3);
  width: min(100%, var(--page-max-width));
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(var(--space-3), env(safe-area-inset-top)) max(var(--space-3), env(safe-area-inset-right)) max(var(--space-3), env(safe-area-inset-bottom)) max(var(--space-3), env(safe-area-inset-left));
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.brand-lockup {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: var(--space-3);
}

.brand-blocks {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(2, var(--space-4));
  grid-template-rows: repeat(2, var(--space-4));
  gap: var(--space-1);
  padding: var(--space-2);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-panel);
  background: var(--color-surface);
  box-shadow: var(--shadow-low);
}

.brand-blocks i {
  display: block;
  border-radius: var(--space-1);
  background: var(--block-yellow);
}

.brand-blocks i:nth-child(2) {
  background: var(--block-blue);
}

.brand-blocks i:nth-child(3) {
  background: var(--block-green);
}

.brand-blocks i:nth-child(4) {
  background: var(--block-red);
}

.brand-kicker {
  margin: 0 0 var(--space-1);
  color: var(--color-muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 38px);
  font-weight: 700;
  line-height: 1.05;
}

.utility-actions {
  display: flex;
  flex: 0 0 auto;
  gap: var(--space-2);
}

.icon-button {
  display: grid;
  width: var(--utility-size);
  height: var(--utility-size);
  padding: 0;
  place-items: center;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-button);
  background: var(--color-surface);
  box-shadow: var(--shadow-low);
  cursor: pointer;
  font-size: 21px;
  font-weight: 700;
  line-height: 1;
  transition: transform var(--motion-fast) var(--motion-easing), filter var(--motion-fast) var(--motion-easing);
}

.icon-button:not(:disabled):hover {
  filter: brightness(1.06);
}

.icon-button:not(:disabled):active {
  transform: translateY(3px);
}

.icon-button.is-muted {
  color: var(--color-muted);
  text-decoration: line-through;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-panel);
  background: var(--color-surface);
  box-shadow: var(--shadow-low);
}

.score-item {
  display: grid;
  min-width: 0;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  text-align: center;
}

.score-item + .score-item {
  border-left: 2px solid var(--color-border);
}

.score-item span {
  color: var(--color-muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
}

.score-item strong {
  overflow: hidden;
  font-size: clamp(20px, 4vw, 30px);
  font-weight: 700;
  line-height: 1;
  text-overflow: ellipsis;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, var(--board-max-width)) minmax(160px, var(--panel-width));
  gap: var(--space-4);
  min-height: 0;
  align-items: center;
  justify-content: center;
}

.board-stage {
  position: relative;
  width: min(var(--board-max-width), calc((100dvh - 260px) / 2), calc(100vw - var(--space-6)));
  min-width: 180px;
  aspect-ratio: 1 / 2;
  overflow: hidden;
  border: var(--space-1) solid var(--color-border);
  border-radius: var(--radius-board);
  background: var(--color-board);
  box-shadow: var(--shadow-high);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--color-board);
}

.game-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  padding: var(--space-4);
  place-items: center;
  background: rgba(48, 36, 29, 0.84);
  color: var(--color-white);
  text-align: center;
  transition: opacity var(--motion-normal) var(--motion-easing);
}

.game-overlay.is-hidden {
  pointer-events: none;
  opacity: 0;
}

.overlay-content {
  display: grid;
  width: 100%;
  max-width: 240px;
  gap: var(--space-3);
  justify-items: center;
}

.overlay-content[hidden] {
  display: none;
}

.overlay-content h2 {
  margin: 0;
  font-size: clamp(24px, 6vw, 34px);
  line-height: 1.08;
}

.overlay-content p {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.45;
}

.seed-mark {
  position: relative;
  width: var(--space-10);
  height: var(--space-10);
  border-radius: 50%;
  background: var(--block-green);
  box-shadow: inset 0 -4px 0 rgba(45, 36, 29, 0.2);
}

.seed-mark::before,
.seed-mark::after {
  position: absolute;
  top: calc(var(--space-3) * -1);
  width: var(--space-5);
  height: var(--space-3);
  border-radius: 50%;
  background: var(--color-grass);
  content: "";
}

.seed-mark::before {
  left: 0;
  transform: rotate(32deg);
}

.seed-mark::after {
  right: 0;
  transform: rotate(-32deg);
}

.primary-button,
.secondary-button {
  min-width: 156px;
  min-height: 56px;
  padding: var(--space-3) var(--space-5);
  border: 2px solid var(--color-white);
  border-radius: var(--radius-button);
  box-shadow: var(--shadow-low);
  cursor: pointer;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  transition: transform var(--motion-fast) var(--motion-easing), filter var(--motion-fast) var(--motion-easing);
}

.primary-button {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.secondary-button {
  background: var(--color-surface);
  color: var(--color-ink);
}

.primary-button:hover,
.secondary-button:hover {
  filter: brightness(1.06);
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(3px);
}

.quick-guide {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2) var(--space-3);
  font-size: 13px;
  line-height: 1.3;
}

.quick-guide span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.quick-guide b {
  font-size: 18px;
}

.garden-panel {
  display: grid;
  gap: var(--space-3);
}

.next-piece,
.friend-card {
  border: 2px solid var(--color-border);
  border-radius: var(--radius-panel);
  background: var(--color-surface);
  box-shadow: var(--shadow-low);
}

.next-piece {
  display: grid;
  justify-items: center;
  padding: var(--space-3);
}

.panel-label {
  color: var(--color-muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
}

#next-canvas {
  display: block;
  width: 120px;
  height: 120px;
}

.friend-card {
  display: grid;
  gap: var(--space-3);
  justify-items: center;
  padding: var(--space-4);
  text-align: center;
}

.friend-face {
  position: relative;
  display: block;
  width: 78px;
  height: 70px;
  border: 3px solid var(--color-primary);
  border-radius: 50% 50% 44% 44%;
  background: var(--block-green);
  box-shadow: inset 0 -6px 0 rgba(45, 36, 29, 0.13);
}

.friend-face::before,
.friend-face::after {
  position: absolute;
  top: -10px;
  width: 26px;
  height: 22px;
  border: 3px solid var(--color-primary);
  border-radius: 80% 20% 70% 30%;
  background: var(--color-grass);
  content: "";
}

.friend-face::before {
  left: 7px;
  transform: rotate(-18deg);
}

.friend-face::after {
  right: 7px;
  transform: rotate(18deg) scaleX(-1);
}

.friend-eye {
  position: absolute;
  top: 27px;
  width: 8px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-ink);
}

.friend-eye:first-of-type {
  left: 21px;
}

.friend-eye:nth-of-type(2) {
  right: 21px;
}

.friend-smile {
  position: absolute;
  bottom: 13px;
  left: 50%;
  width: 22px;
  height: 11px;
  border-bottom: 3px solid var(--color-ink);
  border-radius: 0 0 50% 50%;
  transform: translateX(-50%);
}

.friend-card p {
  margin: 0;
  color: var(--color-muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
}

.friend-card.is-celebrating .friend-face {
  animation: friend-celebrate var(--motion-celebrate) var(--motion-easing) 2 alternate;
}

.touch-controls {
  display: grid;
  grid-template-columns: repeat(5, var(--control-size));
  gap: var(--space-3);
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}

.control-button {
  display: grid;
  width: var(--control-size);
  height: var(--control-size);
  padding: 0;
  place-items: center;
  border: 3px solid var(--color-surface);
  border-radius: 50%;
  box-shadow: var(--shadow-high);
  color: var(--color-white);
  cursor: pointer;
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
  touch-action: none;
  user-select: none;
  transition: transform var(--motion-fast) var(--motion-easing), filter var(--motion-fast) var(--motion-easing);
}

.control-button:hover {
  filter: brightness(1.06);
}

.control-button:active,
.control-button.is-pressed {
  transform: translateY(3px) scale(0.96);
}

.control-left {
  background: var(--block-orange);
}

.control-down {
  background: var(--block-blue);
}

.control-rotate {
  background: var(--color-primary);
}

.control-right {
  background: var(--block-red);
}

.control-drop {
  background: var(--block-purple);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes friend-celebrate {
  from {
    transform: translateY(0) rotate(-3deg);
  }
  to {
    transform: translateY(-8px) rotate(3deg);
  }
}

@media (max-width: 700px) {
  .game-shell {
    gap: var(--space-2);
    padding-top: max(var(--space-2), env(safe-area-inset-top));
  }

  .brand-kicker {
    display: none;
  }

  h1 {
    font-size: clamp(20px, 6vw, 28px);
  }

  .brand-blocks {
    grid-template-columns: repeat(2, var(--space-3));
    grid-template-rows: repeat(2, var(--space-3));
    padding: var(--space-1);
  }

  .utility-actions {
    gap: var(--space-1);
  }

  .icon-button {
    width: 40px;
    height: 40px;
  }

  .score-item {
    padding: var(--space-2) var(--space-1);
  }

  .score-item span {
    font-size: 11px;
  }

  .score-item strong {
    font-size: clamp(18px, 6vw, 24px);
  }

  .play-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-2);
  }

  .board-stage {
    width: min(var(--board-max-width), calc((100dvh - 264px) / 2), calc(100vw - var(--space-6)));
    justify-self: center;
  }

  .garden-panel {
    grid-template-columns: auto minmax(0, 1fr);
    width: min(100%, 360px);
    justify-self: center;
  }

  .next-piece {
    grid-template-columns: auto auto;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
  }

  #next-canvas {
    width: 64px;
    height: 64px;
  }

  .friend-card {
    grid-template-columns: auto minmax(0, 1fr);
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    text-align: left;
  }

  .friend-face {
    width: 48px;
    height: 44px;
    border-width: 2px;
  }

  .friend-face::before,
  .friend-face::after {
    top: -7px;
    width: 17px;
    height: 14px;
    border-width: 2px;
  }

  .friend-eye {
    top: 17px;
    width: 5px;
    height: 7px;
  }

  .friend-eye:first-of-type {
    left: 13px;
  }

  .friend-eye:nth-of-type(2) {
    right: 13px;
  }

  .friend-smile {
    bottom: 7px;
    width: 14px;
    height: 7px;
    border-bottom-width: 2px;
  }

  .touch-controls {
    grid-template-columns: repeat(5, minmax(56px, var(--control-size)));
    gap: var(--space-2);
  }
}

@media (max-width: 380px) {
  .brand-blocks {
    display: none;
  }

  .touch-controls {
    grid-template-columns: repeat(3, var(--control-size));
  }
}

@media (max-height: 700px) and (min-width: 701px) {
  .garden-panel {
    align-self: stretch;
    align-content: center;
  }

  .friend-face {
    width: 58px;
    height: 52px;
  }
}

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