:root {
  color-scheme: light;
  --bg: #f6efe7;
  --ink: #241915;
  --muted: #766a61;
  --panel: #fffaf4;
  --line: #d8c6b5;
  --accent: #d84b30;
  --accent-dark: #9f2e22;
  --button: #2e2520;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% 0%, rgba(216, 75, 48, 0.11), transparent 28rem),
    linear-gradient(180deg, #fff8ef 0%, var(--bg) 100%);
  color: var(--ink);
  font-family:
    ui-rounded, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select {
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--line);
  touch-action: manipulation;
}

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

.app {
  width: min(100vw, 520px);
  height: 100svh;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: 6px;
}

.topbar,
.player-panel,
.controls,
.cat-preview {
  border: 1px solid rgba(216, 198, 181, 0.9);
  border-radius: 8px;
  background: rgba(255, 250, 244, 0.84);
  backdrop-filter: blur(14px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: 0;
}

.scorebox {
  min-width: 82px;
  padding: 6px 9px;
  border-radius: 8px;
  background: #2e2520;
  color: #fff8ef;
  text-align: right;
}

.scorebox span {
  display: block;
  font-size: 11px;
  color: #e6c8b6;
}

.scorebox strong {
  display: block;
  font-size: 22px;
  line-height: 1;
}

.player-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 100px;
  gap: 8px;
  padding: 6px;
}

.skin-field,
.best-score {
  min-width: 0;
  border-radius: 8px;
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--line);
}

.skin-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 0 10px;
}

.skin-field span,
.best-score span,
.board-title span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.skin-field select {
  width: 100%;
  min-height: 40px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
}

.best-score {
  display: grid;
  place-items: center;
  padding: 5px;
  text-align: center;
}

.best-score strong {
  font-size: 20px;
  line-height: 1;
}

.game-wrap {
  position: relative;
  min-height: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid #2e2520;
  background: linear-gradient(180deg, #fff6ec, #f1dcc8);
  box-shadow: 0 14px 32px rgba(74, 42, 29, 0.16);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  aspect-ratio: 720 / 900;
  touch-action: none;
}

.drop-guide {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(216, 75, 48, 0.45);
  pointer-events: none;
  transform: translateX(-1px);
}

.game-over {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  background: rgba(36, 25, 21, 0.72);
  color: #fffaf4;
  text-align: center;
  font-size: 24px;
}

.game-over[hidden] {
  display: none;
}

.game-over button {
  background: var(--accent);
  color: #fff;
  box-shadow: none;
}

.controls {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 7px;
  padding: 7px;
}

.next-card {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 68px;
  border-radius: 8px;
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--line);
}

.next-card span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
}

#nextCat {
  width: 48px;
  height: 48px;
}

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

.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

.cat-preview {
  padding: 5px;
}

#catGallery {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}

.cat-tile {
  min-width: 0;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(216, 198, 181, 0.8);
}

.cat-tile img {
  max-width: 92%;
  max-height: 37px;
  object-fit: contain;
  display: block;
}

@media (max-height: 720px) {
  .app {
    gap: 5px;
  }

  #game {
    min-height: 0;
  }

  h1 {
    font-size: 18px;
  }

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

  .next-card {
    min-height: 60px;
  }

  .cat-preview {
    padding: 4px;
  }

  .cat-tile {
    height: 35px;
  }

  .cat-tile img {
    max-height: 31px;
  }
}
