* { box-sizing: border-box; }

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

body {
  display: grid;
  place-items: center;
  padding: 16px;
  background:
    radial-gradient(circle at 50% 0%, #3d6ea8 0%, #14213d 62%);
  color: #243047;
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Chalkboard SE", "Comic Sans MS", sans-serif;
}

#stage {
  width: min(1080px, 100%);
  position: relative;
  background: #fff8ea;
  border: 8px solid #f4d35e;
  border-radius: 28px;
  box-shadow: 0 14px 0 #c9842a, 0 28px 40px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  user-select: none;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #ffe8a3;
  border-bottom: 4px solid #243047;
}

.brand {
  font-size: 26px;
  font-weight: 800;
  color: #0a7a72;
  letter-spacing: 0.5px;
}

#level-label {
  flex: 1;
  font-weight: 700;
  font-size: 18px;
}

#stars {
  font-weight: 800;
  font-size: 20px;
  color: #e09f3e;
}

#flood {
  display: flex;
  gap: 1px;
  padding: 2px 6px 2px 4px;
  background: rgba(255, 255, 255, 0.55);
  border: 2px solid #243047;
  border-radius: 999px;
}

.drop {
  font-size: 16px;
  line-height: 1;
  opacity: 0.28;
  filter: grayscale(1);
}

.drop.full {
  opacity: 1;
  filter: none;
}

#playfield {
  background: #8fd9cf;
}
#view {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 960 / 540;
  background: #8fd9cf;
  cursor: pointer;
  touch-action: manipulation;
}

#toast {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 74px;
  transform: translateX(-50%);
  margin: 0;
  max-width: min(640px, calc(100% - 24px));
  padding: 8px 14px;
  border: 3px solid #243047;
  border-radius: 999px;
  background: #fffdf8;
  font-weight: 800;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 4px 0 #243047;
}

#toast:empty { display: none; }

#dock {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 12px;
  background: #fff3d6;
  border-top: 4px solid #243047;
}

#goal-row {
  flex: 1 1 100%;
  display: grid;
  gap: 2px;
}

#goals, #status, #item-hint, #keys {
  margin: 0;
}

#goals { font-weight: 800; font-size: 18px; }
#status { min-height: 1.2em; color: #0a7a72; font-weight: 700; }
#item-hint, #keys { color: #5c6b73; font-size: 14px; }

#slots, #actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  font: inherit;
  font-weight: 800;
  color: #243047;
  background: #fff;
  border: 3px solid #243047;
  border-radius: 14px;
  min-height: 52px;
  padding: 8px 12px;
  cursor: pointer;
  box-shadow: 0 4px 0 #243047;
  touch-action: manipulation;
}

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

button:focus-visible {
  outline: 3px solid #4895ef;
  outline-offset: 2px;
}

#btn-fix { background: #b6f2a0; }
#btn-use { background: #9ad7ff; }
#btn-snap { background: #e3c7ff; }
#btn-left, #btn-right { min-width: 56px; font-size: 22px; }

.slot {
  width: 92px;
  height: 84px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.slot svg { width: 36px; height: 36px; }
.slot span { font-size: 12px; line-height: 1.1; text-align: center; }
.slot .plus { font-size: 28px; color: #8d99ae; }
.slot.selected { background: #fff3bf; border-color: #e09f3e; }
.slot.can-snap { background: #f3e8ff; }

#overlay {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(20, 33, 61, 0.38);
}

#overlay[hidden] { display: none; }

.card {
  width: min(560px, 100%);
  max-height: calc(100% - 8px);
  overflow: auto;
  background: #fffdf8;
  border: 4px solid #243047;
  border-radius: 24px;
  padding: 20px 22px 18px;
  box-shadow: 0 8px 0 #243047;
}

.card h1, .card h2 { margin: 0 0 6px; }
.card h1 { font-size: 40px; color: #0a7a72; line-height: 1.05; }
.card h2 { font-size: 32px; color: #0a7a72; }
.sub, .tag-boss, .tag-bonus { margin: 0 0 8px; font-weight: 800; }
.sub { color: #e09f3e; }
.tag-boss { color: #e85d4c; }
.tag-bonus { color: #d97706; }
.card p, .card li { font-size: 18px; line-height: 1.35; }
.card ul { margin: 8px 0; padding-left: 1.2em; }
.recipes {
  display: grid;
  gap: 8px;
  margin: 8px 0 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #fff3d6;
  font-weight: 700;
}
.recipe { display: grid; gap: 1px; }
.recipe span { font-weight: 650; color: #3d4c54; font-size: 15px; }
.recipe-label {
  margin: 2px 0 0;
  font-size: 14px;
  color: #0a7a72;
}
.mode-hint { margin: 0 0 8px; font-weight: 800; color: #0a7a72; }

#cover {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 22px 20px;
  overflow: auto;
  background:
    linear-gradient(#9fe0d6 0 46%, #fff 46% 47%, #f6e2c4 47% 78%, #e7c79a 78% 100%);
}

#cover[hidden] { display: none; }

.cover-top { display: flex; justify-content: flex-end; gap: 8px; }
.cover-hero, .cover-pick { display: grid; justify-items: center; text-align: center; }
.cover-hero { flex: 1; align-content: center; gap: 4px; }
.cover-pick { align-content: start; gap: 8px; }
.cover-kicker { margin: 0; font-weight: 800; color: #e09f3e; letter-spacing: 0.4px; }
#cover-title { margin: 0; font-size: clamp(42px, 7vw, 68px); line-height: 1; color: #0a7a72; }
#cover-blurb { margin: 0 0 4px; font-size: 18px; font-weight: 700; }
.cover-label { margin: 0; font-weight: 800; }
.cover-stars { margin: 0; font-weight: 800; color: #e09f3e; font-size: 18px; }

.cover-scene { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 8px; }
.mini-toilet {
  width: 58px;
  height: 70px;
  position: relative;
  background: #f7fbff;
  border: 3px solid #243047;
  border-radius: 14px 14px 20px 20px;
  box-shadow: 0 4px 0 #243047;
}
.mini-toilet span {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 12px;
  height: 18px;
  border: 5px solid #3ec6b6;
  border-radius: 50%;
}
.mini-toilet.shaky span { border-color: #ff8fab; }
.mini-toilet i {
  position: absolute;
  top: -16px;
  left: 50%;
  width: 26px;
  height: 26px;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  background: #ffd23f;
  border: 3px solid #243047;
  border-radius: 50%;
  font-style: normal;
  font-weight: 800;
}
.mini-mop {
  width: 46px;
  height: 86px;
  position: relative;
}
.mini-mop::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 0;
  width: 22px;
  height: 22px;
  background: #ffd7ba;
  border: 3px solid #243047;
  border-radius: 50%;
  box-shadow: 0 -8px 0 0 #ffd23f;
}
.mini-mop::after {
  content: "";
  position: absolute;
  left: 8px;
  bottom: 0;
  width: 30px;
  height: 40px;
  background: #3a7bd5;
  border: 3px solid #243047;
  border-radius: 10px;
}

.cover-modes {
  width: min(680px, 100%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.cover-mode {
  min-height: 104px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
}
.cover-mode strong { font-size: 24px; }
.cover-mode span { font-size: 14px; line-height: 1.25; font-weight: 700; color: #3d4c54; }
.cover-mode.selected { background: #b6f2a0; }
#cover-play { min-width: 220px; font-size: 28px; margin-top: 4px; }

.shop-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.shop-head p { margin: 0; font-weight: 800; }
.ape-face { width: 76px; height: 68px; flex: none; }
.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.shop-item { min-height: 108px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px; }
.shop-item svg { width: 36px; height: 36px; }
.shop-item strong { font-size: 15px; }
.shop-price { color: #e09f3e; font-size: 14px; font-weight: 800; }

@media (max-width: 680px) {
  .cover-modes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cover-mode { min-height: 72px; padding: 6px; }
  .cover-mode strong { font-size: 16px; }
  .cover-mode span { font-size: 11px; }
}

@media (max-width: 820px) {
  html, body {
    height: 100%;
    overflow: hidden;
  }
  body {
    padding: 0;
    place-items: stretch;
  }
  #stage {
    width: 100%;
    height: 100dvh;
    height: 100svh;
    border-width: 0;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
  }
  #topbar {
    flex-wrap: wrap;
    gap: 6px;
    padding: max(6px, env(safe-area-inset-top)) 8px 6px;
  }
  .brand { font-size: 16px; }
  #level-label {
    order: 8;
    flex: 1 1 100%;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #stars { font-size: 16px; }
  #topbar button {
    min-height: 40px;
    min-width: 40px;
    padding: 4px 8px;
    font-size: 14px;
    box-shadow: 0 2px 0 #243047;
  }
  #playfield {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    place-items: center;
    overflow: hidden;
  }
  #view {
    flex: none;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 960 / 540;
  }
  #toast {
    top: auto;
    bottom: 12px;
    font-size: 14px;
    max-width: calc(100% - 16px);
  }
  #dock {
    gap: 6px;
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
  }
  #keys, #item-hint, #status { display: none; }
  #goals { font-size: 15px; }
  #slots { flex: 1 1 auto; }
  .slot {
    width: 62px;
    height: 56px;
    border-radius: 12px;
  }
  .slot svg { width: 26px; height: 26px; }
  .slot span { font-size: 10px; }
  #actions { flex: 1 1 100%; }
  #actions button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 52px;
    padding: 8px 4px;
    font-size: 16px;
  }
  #overlay { padding: 8px; }
  .card {
    width: 100%;
    max-height: 100%;
    padding: 14px 12px;
    border-radius: 18px;
  }
  .card h1 { font-size: 30px; }
  .card h2 { font-size: 24px; }
  .card p, .card li { font-size: 16px; }
  #cover {
    padding: max(8px, env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
    gap: 4px;
  }
  .cover-scene { gap: 8px; margin-bottom: 0; }
  .mini-toilet { width: 42px; height: 52px; }
  .mini-mop { width: 34px; height: 64px; }
  #cover-blurb { font-size: 14px; }
  #cover-play { width: min(100%, 280px); min-width: 0; font-size: 22px; }
  .shop-head { align-items: flex-start; }
  .shop-item { min-height: 86px; }
  .row button { flex: 1 1 40%; min-width: 0; }
}

@media (max-height: 520px) and (orientation: landscape) {
  #goal-row { display: none; }
  .slot { width: 52px; height: 44px; }
  .slot span { display: none; }
  #actions button { min-height: 44px; }
  .cover-hero { display: none; }
}
.row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
button.primary { background: #b6f2a0; min-width: 140px; font-size: 22px; }

@keyframes bob {
  50% { transform: translateY(-3px); }
}

.can-snap { animation: bob 0.8s ease-in-out infinite; }
.fresh { animation: bob 0.35s ease; }

@media (prefers-reduced-motion: reduce) {
  .can-snap, .fresh { animation: none; }
}
