:root {
  --ink: #22252f;
  --muted: #667085;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-strong: #ffffff;
  --sky: #9fd7f5;
  --sky-deep: #6bb9e6;
  --grass: #4f9f65;
  --grass-dark: #27724b;
  --sun: #ffc857;
  --coral: #ff6b5f;
  --mint: #42c6a4;
  --grape: #7b5dd6;
  --shadow: rgba(32, 36, 48, 0.22);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  background: #d9f3ff;
}

button {
  border: 0;
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  width: 100vw;
  height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.32), rgba(255, 255, 255, 0) 34%),
    var(--sky);
}

.topbar {
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.74);
  border-bottom: 2px solid rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 24px rgba(69, 93, 110, 0.15);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 220px;
  gap: 12px;
}

.cat-mark {
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  height: 40px;
}

.cat-mark::before,
.cat-mark::after {
  position: absolute;
  top: 2px;
  width: 0;
  height: 0;
  content: "";
  border-right: 9px solid transparent;
  border-bottom: 16px solid #ffb15c;
  border-left: 9px solid transparent;
}

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

.cat-mark::after {
  right: 7px;
  transform: rotate(18deg);
}

.cat-mark span {
  position: absolute;
  bottom: 0;
  left: 4px;
  width: 38px;
  height: 30px;
  background: #ffb15c;
  border: 3px solid #5c3f2f;
  border-radius: 18px 18px 15px 15px;
  box-shadow: inset 0 -5px 0 rgba(209, 98, 61, 0.22);
}

.cat-mark span::before,
.cat-mark span::after {
  position: absolute;
  top: 10px;
  width: 5px;
  height: 5px;
  content: "";
  background: #33291f;
  border-radius: 50%;
}

.cat-mark span::before {
  left: 10px;
}

.cat-mark span::after {
  right: 10px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1rem, 2.3vw, 1.38rem);
  line-height: 1.05;
}

.brand p,
.kicker,
.best-row span,
.hud span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hud {
  display: grid;
  grid-template-columns: repeat(7, minmax(62px, 1fr));
  gap: 8px;
  min-width: min(720px, 58vw);
}

.hud div {
  min-width: 0;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(64, 92, 116, 0.11);
  border-radius: 8px;
}

.hud strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.screen-panel {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 22px;
  pointer-events: auto;
}

.screen-panel.hidden {
  display: none;
}

.level-card {
  width: min(440px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 116px));
  overflow: auto;
  padding: 22px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  box-shadow: 0 22px 55px var(--shadow);
  backdrop-filter: blur(10px);
}

.level-card h2 {
  margin-top: 4px;
  color: #26313d;
  font-size: clamp(1.6rem, 5vw, 2.35rem);
  line-height: 1;
}

.level-card p:not(.kicker) {
  margin-top: 10px;
  color: #435161;
  font-size: 1rem;
  line-height: 1.45;
}

.best-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  padding: 10px 12px;
  background: #f6fbff;
  border: 1px solid rgba(64, 92, 116, 0.12);
  border-radius: 8px;
}

.modifier-row,
.calendar-strip,
.closet-grid,
.goal-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.modifier-row {
  margin-top: 14px;
}

.modifier-chip,
.goal-chip,
.calendar-day,
.closet-item,
.reward-banner {
  border: 1px solid rgba(64, 92, 116, 0.14);
  border-radius: 8px;
}

.modifier-chip,
.goal-chip {
  padding: 7px 9px;
  color: #293746;
  background: #eef9ff;
  font-size: 0.8rem;
  font-weight: 800;
}

.goal-list {
  margin-top: 12px;
}

.goal-chip.done {
  color: #195d4f;
  background: #dff9ed;
}

.goal-chip.missed {
  color: #7c3731;
  background: #ffe7df;
}

.calendar-strip {
  margin-top: 14px;
}

.calendar-day,
.closet-item {
  min-height: 42px;
  padding: 7px 9px;
  color: #243442;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 4px 0 rgba(94, 114, 130, 0.18);
  cursor: pointer;
  font-weight: 800;
}

.calendar-day.active,
.closet-item.active {
  color: #ffffff;
  background: #4d73d9;
  box-shadow: 0 4px 0 #314b94;
}

.calendar-day span,
.closet-item span {
  display: block;
  color: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  opacity: 0.78;
}

.closet-panel {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(64, 92, 116, 0.12);
}

.home-base-panel,
.shop-panel {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(64, 92, 116, 0.12);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
  color: #435161;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

.home-stats div {
  min-width: 0;
  padding: 8px 9px;
  background: #f6fbff;
  border: 1px solid rgba(64, 92, 116, 0.12);
  border-radius: 8px;
}

.home-stats span,
.shop-item span {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.home-stats strong {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: #243442;
  font-size: 1.04rem;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mystery-note {
  margin-top: 8px;
  padding: 9px 10px;
  color: #394457;
  background: #fff8d8;
  border: 1px solid rgba(227, 180, 63, 0.32);
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1.25;
}

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

.shop-item {
  min-height: 64px;
  padding: 9px;
  color: #243442;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(64, 92, 116, 0.14);
  border-radius: 8px;
  box-shadow: 0 4px 0 rgba(94, 114, 130, 0.18);
  cursor: pointer;
  text-align: left;
}

.shop-item strong {
  display: block;
  margin-bottom: 3px;
  font-size: 0.9rem;
  line-height: 1.1;
}

.shop-item span + span {
  margin-top: 5px;
  color: #243442;
}

.shop-item.owned {
  color: #195d4f;
  background: #dff9ed;
  cursor: default;
}

.shop-item.locked {
  color: #6f7781;
  background: #eef1f5;
}

.closet-item.locked {
  color: #6f7781;
  background: #eef1f5;
  cursor: default;
}

.reward-banner {
  display: none;
  margin-top: 12px;
  padding: 10px 12px;
  color: #273244;
  background: #fff2b8;
  font-weight: 800;
}

.reward-banner.visible {
  display: block;
}

.best-row strong {
  font-size: 1rem;
}

.finish-grade {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  margin-top: 10px;
  padding: 0 12px;
  color: #ffffff;
  background: #4d73d9;
  border-radius: 8px;
  box-shadow: 0 4px 0 #314b94;
  font-weight: 900;
}

.clear-best-button {
  min-height: 30px;
  padding: 0 9px;
  color: #435161;
  background: #e9f1f6;
  border: 1px solid rgba(64, 92, 116, 0.14);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 800;
}

.clear-best-button:hover {
  background: #dcebf4;
}

.menu-actions,
.game-actions,
.touch-pad {
  display: flex;
  align-items: center;
  gap: 10px;
}

.menu-actions {
  margin-top: 18px;
}

.primary-action,
.secondary-action,
.game-actions button,
.touch-button {
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.primary-action,
.secondary-action {
  flex: 1;
  padding: 0 16px;
}

.primary-action {
  color: #ffffff;
  background: #e95348;
  box-shadow: 0 8px 0 #b9342f;
}

.secondary-action {
  color: #243442;
  background: #ffe18d;
  box-shadow: 0 8px 0 #d79b2f;
}

.game-actions button {
  padding: 0 12px;
  color: #233041;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(64, 92, 116, 0.14);
  box-shadow: 0 6px 0 rgba(94, 114, 130, 0.2);
}

.primary-action:hover,
.secondary-action:hover,
.game-actions button:hover,
.touch-button:hover {
  transform: translateY(-1px);
}

.primary-action:active,
.secondary-action:active,
.game-actions button:active,
.touch-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(67, 75, 89, 0.32);
}

.game-actions {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 3;
}

.feedback-stack {
  position: absolute;
  top: 74px;
  left: 18px;
  z-index: 3;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 36px));
  pointer-events: none;
}

.feedback-pop {
  padding: 9px 12px;
  color: #26313d;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(64, 92, 116, 0.12);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(32, 36, 48, 0.16);
  font-weight: 850;
  animation: feedback-pop 1.5s ease forwards;
}

@keyframes feedback-pop {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  12%,
  78% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-12px) scale(0.98);
  }
}

.touch-pad {
  position: absolute;
  right: 14px;
  bottom: 14px;
  left: 14px;
  z-index: 3;
  display: none;
  justify-content: space-between;
  pointer-events: none;
}

body.touch-device .touch-pad {
  display: flex;
}

@media (hover: none), (pointer: coarse) {
  .touch-pad {
    display: flex;
  }
}

.touch-button {
  width: min(30vw, 132px);
  color: #213244;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(64, 92, 116, 0.14);
  box-shadow: 0 7px 0 rgba(72, 91, 108, 0.24);
  pointer-events: auto;
  user-select: none;
}

.touch-button.jump {
  color: #ffffff;
  background: var(--mint);
  box-shadow: 0 7px 0 #238a76;
}

@media (max-width: 780px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100vh;
    height: auto;
    grid-template-rows: auto minmax(540px, 1fr);
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 10px;
  }

  .brand {
    width: 100%;
  }

  .hud {
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(4, 1fr);
  }

  .hud div {
    padding: 7px 8px;
  }

  .hud strong {
    font-size: 0.9rem;
  }

  .touch-pad {
    display: flex;
  }

  .game-actions {
    top: 10px;
    right: 10px;
  }
}

@media (max-width: 480px) {
  .topbar {
    gap: 8px;
  }

  .cat-mark {
    width: 38px;
    height: 34px;
  }

  .cat-mark span {
    width: 32px;
    height: 26px;
  }

  .hud {
    gap: 6px;
  }

  .hud div {
    padding: 6px;
  }

  .hud span {
    font-size: 0.64rem;
  }

  .level-card {
    padding: 18px;
  }

  .menu-actions {
    flex-direction: column;
  }

  .primary-action,
  .secondary-action {
    width: 100%;
  }

  .home-stats,
  .shop-grid {
    grid-template-columns: 1fr;
  }
}
