:root {
  --bg: #15b8e5;
  --sky: #1496e7;
  --sea: #19d3d7;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: #ffffff;
  --line: rgba(10, 37, 64, 0.18);
  --text: #102033;
  --muted: #5f7085;
  --green: #65d34e;
  --blue: #2479ef;
  --orange: #ffae20;
  --red: #f15d52;
  --ink: #0d1728;
  --shadow: 0 14px 28px rgba(4, 35, 68, 0.24);
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky) 0%, var(--sea) 100%);
  color: var(--text);
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: not-allowed;
  filter: saturate(0.55);
  opacity: 0.58;
}

.app-shell {
  width: min(100%, 480px);
  height: 100dvh;
  min-height: 640px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
}

.topbar,
.stats-strip,
.game-panel,
.mission-grid article,
.leaderboard-card,
.bottom-nav {
  min-width: 0;
  border: 2px solid rgba(9, 40, 68, 0.2);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.topbar {
  min-height: 58px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 10px;
  border-radius: 8px;
  text-align: center;
}

.eyebrow,
.mode-label {
  margin: 0 0 4px;
  color: #1370b3;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  overflow: hidden;
  font-size: 22px;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f8fcff;
  color: #1675b6;
  box-shadow:
    inset 0 -4px 0 rgba(0, 0, 0, 0.09),
    0 2px 0 rgba(13, 47, 78, 0.2);
  font-size: 20px;
  font-weight: 900;
}

.stats-strip {
  border-radius: 8px;
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stats-strip div {
  min-width: 0;
  padding: 7px;
  border-radius: 6px;
  background: #f4fbff;
}

.stats-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stats-strip strong {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  font-size: clamp(18px, 5.4vw, 25px);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-panel {
  position: relative;
  min-height: 0;
  padding: 10px;
  border-radius: 8px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  background:
    linear-gradient(180deg, rgba(27, 141, 233, 0.08), rgba(28, 213, 215, 0.1)),
    rgba(255, 255, 255, 0.2);
  overflow: hidden;
}

.level-row,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.level-row h2,
.section-head h2 {
  font-size: 20px;
  line-height: 1.1;
}

.tray-count {
  min-width: 62px;
  min-height: 36px;
  padding: 7px 10px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: inset 0 -4px 0 rgba(20, 110, 170, 0.12);
  color: #1675b6;
  text-align: center;
  font-size: 16px;
  font-weight: 900;
}

.mini-button {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 7px;
  background: #e6f5ff;
  color: #116fae;
  font-size: 13px;
  font-weight: 850;
}

.shelf {
  position: relative;
  width: 100%;
  height: auto;
  min-height: 0;
  border-radius: 8px;
  border: 3px solid rgba(9, 45, 80, 0.2);
  background:
    linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, #188ddd 0%, #20d4d4 100%);
  background-size: 34px 34px, 34px 34px, auto;
  overflow: hidden;
}

.card {
  position: absolute;
  width: clamp(48px, 13vw, 68px);
  height: clamp(52px, 14vw, 74px);
  display: grid;
  place-items: center;
  border: 3px solid #17344d;
  border-radius: 8px;
  background: #effbff;
  box-shadow:
    inset 0 -8px 0 rgba(39, 124, 167, 0.2),
    0 5px 0 rgba(12, 45, 72, 0.28),
    0 10px 16px rgba(5, 38, 65, 0.16);
  font-size: clamp(28px, 8vw, 42px);
  transition:
    transform 150ms ease,
    opacity 150ms ease,
    filter 150ms ease;
  user-select: none;
}

.card::after {
  content: "";
  position: absolute;
  inset: auto 8px 7px;
  height: 4px;
  border-radius: 999px;
  background: rgba(26, 116, 170, 0.2);
}

.card.blocked {
  filter: brightness(0.62) saturate(0.7);
}

.card.blocked::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 5px;
  background: rgba(16, 32, 51, 0.3);
}

.card.selected {
  transform: translateY(-12px) scale(0.9);
  opacity: 0;
}

.tray-wrap {
  margin-top: 8px;
  padding: 7px;
  border: 3px solid #112e45;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: inset 0 -7px 0 rgba(11, 91, 136, 0.2);
}

.tray {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  min-height: 52px;
}

.tray-slot {
  min-width: 0;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #ecf7fe;
  box-shadow: inset 0 -5px 0 rgba(28, 116, 166, 0.14);
  font-size: clamp(24px, 7vw, 36px);
}

.tray-slot.empty {
  background: #f8fcff;
}

.tray-slot.clearing {
  transform: scale(0.32) rotate(8deg);
  opacity: 0;
  transition:
    transform 160ms ease,
    opacity 160ms ease;
}

.ad-tool-row,
.result-actions {
  display: grid;
  gap: 8px;
}

.ad-tool-row {
  grid-template-columns: repeat(3, 1fr);
  margin-top: 9px;
}

.ad-tool {
  position: relative;
  min-width: 0;
  min-height: 60px;
  padding: 7px 6px 6px;
  border: 3px solid rgba(13, 47, 78, 0.55);
  border-radius: 8px;
  box-shadow:
    inset 0 -6px 0 rgba(0, 0, 0, 0.2),
    0 4px 0 rgba(9, 45, 80, 0.25);
  color: #ffffff;
  text-align: center;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.22);
}

.ad-tool b {
  position: absolute;
  right: 7px;
  top: 6px;
  min-width: 24px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #174166;
  font-size: 12px;
  line-height: 1;
  text-shadow: none;
}

.ad-tool.green {
  background: linear-gradient(180deg, #84ed61, #39b72d);
}

.ad-tool.blue {
  background: linear-gradient(180deg, #4a9dff, #1464d3);
}

.ad-tool.orange {
  background: linear-gradient(180deg, #ffc653, #f49b12);
}

.ad-tool strong,
.ad-tool em {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ad-tool strong {
  font-size: clamp(14px, 4vw, 17px);
  line-height: 1.1;
  font-weight: 950;
}

.ad-tool em {
  margin-top: 2px;
  font-size: 12px;
  font-style: normal;
  font-weight: 850;
}

.video-badge {
  position: absolute;
  top: -8px;
  left: -7px;
  width: 28px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: #ffffff;
  color: #35a8f5;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.18);
  font-size: 12px;
  text-shadow: none;
}

.primary-button,
.ghost-button,
.danger-button {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  font-weight: 850;
}

.primary-button {
  background: linear-gradient(135deg, var(--green), #28c4e3);
  color: var(--ink);
}

.ghost-button {
  border: 1px solid rgba(19, 112, 179, 0.32);
  background: #eef8ff;
  color: #126fad;
}

.danger-button {
  background: #ffe7e4;
  color: #bf3028;
}

.result-panel {
  position: absolute;
  inset: auto 16px 106px;
  padding: 16px;
  border: 2px solid rgba(13, 47, 78, 0.18);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.result-panel h2 {
  margin-bottom: 8px;
  font-size: 22px;
}

.result-panel p,
.mission-grid p,
.leaderboard-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.result-actions {
  grid-template-columns: 1fr 1fr;
  margin-top: 14px;
}

.hidden {
  display: none !important;
}

.mission-grid {
  display: none;
  gap: 8px;
}

.mission-grid article {
  min-height: 64px;
  padding: 10px 12px;
  border-radius: 8px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.mission-grid strong {
  display: block;
  margin-bottom: 2px;
  font-size: 14px;
}

.mission-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--orange);
  box-shadow: 0 0 0 5px rgba(255, 174, 32, 0.18);
}

.mission-dot.done {
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(101, 211, 78, 0.18);
}

.leaderboard-card {
  display: none;
  padding: 12px;
  border-radius: 8px;
}

.leaderboard-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-list li {
  min-height: 38px;
  padding: 7px 8px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border-radius: 6px;
  background: #f3f9ff;
}

.leaderboard-list span {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 50%;
  background: #fff1c7;
  color: #a96d00;
  font-size: 12px;
  font-weight: 850;
}

.leaderboard-list strong {
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-list em {
  color: #149447;
  font-style: normal;
  font-size: 13px;
  font-weight: 850;
}

.bottom-nav {
  min-height: 56px;
  padding: 7px;
  border-radius: 8px;
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.bottom-nav button {
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.bottom-nav button.active {
  background: #e3f5ff;
  color: #126fad;
}

.ad-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 16, 28, 0.58);
  backdrop-filter: blur(10px);
}

.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 11;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 16, 28, 0.46);
  backdrop-filter: blur(8px);
}

.ad-card {
  width: min(100%, 320px);
  padding: 18px;
  border: 2px solid rgba(13, 47, 78, 0.18);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  text-align: center;
}

.settings-card {
  width: min(100%, 360px);
  padding: 14px;
  border: 2px solid rgba(13, 47, 78, 0.18);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.settings-card .section-head {
  margin-bottom: 12px;
}

.settings-actions {
  display: grid;
  gap: 8px;
}

.ad-card strong {
  display: block;
  font-size: 20px;
}

.ad-card span {
  display: grid;
  width: 58px;
  height: 58px;
  margin: 16px auto 0;
  place-items: center;
  border-radius: 50%;
  background: #e8fff1;
  color: #16964a;
  font-size: 28px;
  font-weight: 900;
}

@media (max-width: 380px) {
  .app-shell {
    padding-left: 8px;
    padding-right: 8px;
  }

  .shelf {
    min-height: 0;
  }

  .ad-tool {
    min-height: 60px;
  }
}

@media (min-width: 760px) {
  .app-shell {
    width: min(100%, 520px);
    height: 100dvh;
    min-height: 720px;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
    align-items: stretch;
    padding: 24px;
  }

  .topbar,
  .stats-strip,
  .mission-grid,
  .leaderboard-card,
  .bottom-nav {
    grid-column: auto;
  }

  .game-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .shelf {
    height: auto;
    min-height: 0;
  }
}
