* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: flex;
  justify-content: center;
}

.game-shell {
  min-height: 100vh;
  width: min(100%, 520px);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(10px);
  box-shadow: 0 0 0 1px rgba(61, 92, 72, 0.06);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px 12px;
  background: rgba(245, 248, 241, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(61, 92, 72, 0.08);
}

.topbar-copy {
  min-width: 0;
  flex: 1;
}

.topbar-kicker {
  margin-bottom: 4px;
  color: var(--color-primary-dark);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.primary-action {
  flex: 0 0 auto;
}

.top-resource-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 12px 16px 0;
}

.top-resource-chip {
  min-width: 0;
  border: 1px solid rgba(61, 92, 72, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow-panel);
  padding: 8px 10px;
}

.top-resource-label {
  display: block;
  color: var(--color-muted);
  font-size: 11px;
  font-weight: 700;
}

.top-resource-value {
  display: block;
  margin-top: 3px;
  font-size: 15px;
  font-weight: 900;
}

.village-stage {
  position: relative;
  min-height: 320px;
  margin: 12px 16px 0;
  border: 1px solid rgba(61, 92, 72, 0.12);
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(#b9e5ff 0%, #dff2f0 48%, #9bc077 49%, #6d9d55 100%);
  isolation: isolate;
  transition: background .24s ease;
  box-shadow: var(--shadow-panel);
}

.village-sky,
.village-horizon,
.village-ground,
.village-path {
  position: absolute;
  inset: 0;
}

.village-sky {
  z-index: 0;
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 245, 179, .9) 0 32px, transparent 34px),
    linear-gradient(#a8dff8 0%, #def3f5 72%, transparent 72%);
}

.cloud {
  position: absolute;
  display: block;
  width: clamp(74px, 18vw, 132px);
  height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .86);
  box-shadow: 20px -10px 0 rgba(255, 255, 255, .72), 42px 2px 0 rgba(255, 255, 255, .64);
}

.cloud-a {
  top: 18%;
  right: 18%;
}

.cloud-b {
  top: 30%;
  left: 12%;
  transform: scale(.78);
  opacity: .78;
}

.village-horizon {
  top: auto;
  height: 46%;
  z-index: 1;
  background:
    linear-gradient(160deg, transparent 0 52%, rgba(73, 126, 84, .32) 53% 60%, transparent 61%),
    linear-gradient(24deg, transparent 0 48%, rgba(82, 142, 91, .28) 49% 58%, transparent 59%);
}

.village-ground {
  top: auto;
  height: 42%;
  z-index: 2;
  background:
    radial-gradient(ellipse at 18% 72%, rgba(255, 255, 255, .16) 0 18%, transparent 19%),
    linear-gradient(#8ab965 0%, #6f9f55 100%);
}

.village-path {
  top: auto;
  height: 34%;
  z-index: 3;
  background: linear-gradient(112deg, transparent 0 38%, rgba(216, 177, 112, .88) 39% 61%, transparent 62%);
  opacity: .9;
}

.village-tier-2 .village-sky {
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 233, 141, .95) 0 36px, transparent 38px),
    linear-gradient(#9bd7f4 0%, #dcf0eb 72%, transparent 72%);
}

.village-tier-3 .village-sky {
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 226, 111, .96) 0 40px, transparent 42px),
    linear-gradient(#8fcff0 0%, #d6f0e8 72%, transparent 72%);
}

.village-tier-3 .village-path {
  background:
    linear-gradient(112deg, transparent 0 35%, rgba(196, 141, 82, .9) 36% 64%, transparent 65%),
    repeating-linear-gradient(112deg, transparent 0 22px, rgba(113, 82, 50, .18) 23px 25px);
}

.village-buildings {
  position: absolute;
  inset: auto 0 54px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(12px, 4vw, 32px);
  padding: 0 18px;
  z-index: 5;
}

.building {
  position: relative;
  width: clamp(72px, 24vw, 160px);
  aspect-ratio: 1.2;
  border: 3px solid #67492d;
  border-radius: 8px 8px 4px 4px;
  background: linear-gradient(#e0b06e, #c88448);
  box-shadow: inset 0 0 0 8px rgba(255, 255, 255, .15);
  transition: transform .2s ease, filter .2s ease, box-shadow .2s ease;
}

.building::before {
  content: "";
  position: absolute;
  left: -12%;
  right: -12%;
  top: -30%;
  height: 36%;
  border: 3px solid #67492d;
  border-bottom: 0;
  border-radius: 10px 10px 2px 2px;
  background: linear-gradient(135deg, #a84032, #cf6c3c);
  transform: skewX(-10deg);
}

.building::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 24%;
  height: 42%;
  border: 2px solid #67492d;
  border-bottom: 0;
  border-radius: 5px 5px 0 0;
  background: #744e34;
  transform: translateX(-50%);
}

.building-level-2 {
  filter: saturate(1.08);
  box-shadow: inset 0 0 0 8px rgba(255, 255, 255, .18), 0 8px 0 rgba(92, 67, 43, .18);
}

.building-level-2::after {
  background:
    linear-gradient(#f4d38b 0 35%, transparent 36%),
    #744e34;
}

.building-level-3 {
  transform: translateY(-8px) scale(1.06);
  filter: saturate(1.16);
  box-shadow: inset 0 0 0 8px rgba(255, 255, 255, .2), 0 12px 0 rgba(92, 67, 43, .2);
}

.building-level-3::before {
  background: linear-gradient(135deg, #8f2f2f, #d98538);
}

.building-level-3::after {
  width: 28%;
  background:
    linear-gradient(#f7dc91 0 30%, transparent 31%),
    linear-gradient(90deg, transparent 0 40%, rgba(255, 255, 255, .18) 41% 58%, transparent 59%),
    #62442f;
}

.guild-hall {
  width: clamp(110px, 34vw, 230px);
  background: linear-gradient(#d99d5f, #b96543);
}

.warehouse {
  background: linear-gradient(#c79a72, #9f6f4d);
}

.lumber-yard {
  background: linear-gradient(#d1b15c, #aa8538);
}

.village-props {
  position: absolute;
  inset: auto 18px 34px;
  z-index: 4;
  height: 54px;
  pointer-events: none;
}

.prop {
  position: absolute;
  bottom: 0;
  display: block;
}

.prop.crate {
  left: 22%;
  width: 28px;
  height: 22px;
  border: 2px solid #6b4d31;
  background: #bd8652;
}

.prop.sign {
  right: 22%;
  width: 32px;
  height: 24px;
  border: 2px solid #6b4d31;
  background: #f3d48e;
}

.prop.sign::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 5px;
  height: 24px;
  background: #6b4d31;
  transform: translateX(-50%);
}

.prop.cart {
  display: none;
  left: 58%;
  width: 50px;
  height: 24px;
  border: 3px solid #6b4d31;
  border-top: 0;
  background: #c98d52;
}

.village-tier-2 .prop.cart,
.village-tier-3 .prop.cart {
  display: block;
}

.village-tier-3 .prop.crate {
  box-shadow: 34px 0 0 #bd8652, 34px 0 0 2px #6b4d31;
}

.player-paperdoll {
  position: absolute;
  left: clamp(24px, 10vw, 140px);
  bottom: 42px;
  z-index: 6;
  width: 62px;
  height: 112px;
}

.paperdoll-layer {
  position: absolute;
  inset: 0;
  border-radius: 28px 28px 12px 12px;
}

.paperdoll-layer.body {
  background: transparent;
}

.paperdoll-layer.body::before {
  content: "";
  position: absolute;
  left: 17px;
  top: 0;
  width: 30px;
  height: 30px;
  border: 3px solid #6b4d31;
  border-radius: 50%;
  background: #f0c6a0;
}

.paperdoll-layer.body::after {
  content: "";
  position: absolute;
  left: 15px;
  top: 28px;
  width: 34px;
  height: 70px;
  border: 3px solid #6b4d31;
  border-radius: 18px 18px 9px 9px;
  background: #f0c6a0;
}

.paperdoll-layer.outfit {
  top: 34px;
  left: 12px;
  width: 40px;
  height: 58px;
  border: 3px solid #245245;
  border-radius: 14px 14px 8px 8px;
  background: #2d7f6f;
}

.paperdoll-layer.weapon {
  left: 42px;
  top: 36px;
  width: 8px;
  height: 62px;
  background: #75563b;
  transform: rotate(-18deg);
}

.paperdoll-layer.pack {
  left: 4px;
  top: 48px;
  width: 16px;
  height: 28px;
  border: 2px solid #5e412d;
  border-radius: 6px;
  background: #b77a42;
}

.avatar-carpenter .paperdoll-layer.outfit {
  border-color: #6b4d31;
  background: #b77a42;
}

.avatar-carpenter .paperdoll-layer.weapon {
  width: 14px;
  height: 52px;
  background: linear-gradient(#9ca3af 0 22%, #75563b 23%);
}

.avatar-keeper .paperdoll-layer.outfit {
  border-color: #315e76;
  background: #427f9c;
}

.avatar-keeper .paperdoll-layer.pack {
  background: #d1a45d;
}

.avatar-steward .paperdoll-layer.outfit {
  border-color: #7a2f36;
  background: #c44f3f;
}

.avatar-steward .paperdoll-layer.weapon {
  left: 46px;
  width: 10px;
  height: 70px;
  background: #d6b45f;
  transform: rotate(-8deg);
}

.stage-caption {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 7;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(22, 35, 28, 0.42);
  color: #fff;
}

.stage-caption-kicker {
  display: block;
  font-size: 11px;
  font-weight: 700;
  opacity: 0.82;
}

#stage-tier-label {
  font-size: 18px;
  font-weight: 900;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 14px 16px 0;
}

.feature-tile {
  display: grid;
  gap: 6px;
  min-height: 78px;
  align-content: start;
  justify-items: start;
  padding: 12px;
  border: 1px solid rgba(61, 92, 72, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--color-text);
  box-shadow: var(--shadow-panel);
}

.feature-tile.is-active {
  border-color: rgba(29, 122, 70, 0.36);
  background: rgba(237, 246, 238, 0.96);
}

.feature-tile-kicker {
  color: var(--color-primary-dark);
  font-size: 11px;
  font-weight: 800;
}

.feature-tile-label {
  font-size: 15px;
  font-weight: 850;
}

.screen-stack {
  padding: 16px 16px 92px;
}

.content-screen {
  display: none;
  gap: 16px;
}

.content-screen.screen-active {
  display: grid;
}

.panel-section {
  display: grid;
  gap: 10px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 17px;
}

button,
.card-link {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--color-primary);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
}

.card-grid {
  display: grid;
  gap: 10px;
}

.compact-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.task-card,
.recommendation-card,
.mini-card,
.empty-card {
  border: 1px solid var(--color-line);
  border-radius: 8px;
  background: var(--color-surface);
  box-shadow: var(--shadow-panel);
  padding: 14px;
}

.card-kicker {
  color: var(--color-primary-dark);
  font-size: 12px;
  font-weight: 800;
}

.card-title {
  font-size: 16px;
  font-weight: 850;
}

.card-text {
  margin-top: 4px;
  color: var(--color-muted);
  line-height: 1.5;
}

.card-link {
  margin-top: 10px;
}

.recommendation-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.reward-pill {
  flex: 0 0 auto;
  border: 1px solid rgba(29, 122, 70, .22);
  border-radius: 999px;
  background: #edf6ee;
  color: var(--color-primary-dark);
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
  padding: 6px 8px;
}

.recommendation-spotlight {
  display: grid;
  gap: 3px;
  margin-top: 10px;
  border-left: 4px solid var(--color-accent);
  padding-left: 10px;
}

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

.recommendation-spotlight strong {
  font-size: 16px;
}

.product-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.product-chip {
  border: 1px solid #dbc9ab;
  border-radius: 999px;
  background: #fbf3e2;
  color: #5f4328;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.2;
  padding: 6px 9px;
}

.recommendation-footer {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.mission-note {
  color: var(--color-muted);
  font-size: 12px;
  line-height: 1.45;
}

.recommendation-footer .card-link {
  justify-self: start;
  margin-top: 0;
}

.fragment-card {
  border: 1px solid var(--color-line);
  border-radius: 8px;
  background: var(--color-surface);
  box-shadow: var(--shadow-panel);
  padding: 14px;
  min-width: 0;
}

.fragment-card-main {
  display: grid;
  gap: 12px;
}

.fragment-value {
  font-size: 26px;
  font-weight: 900;
}

.fragment-meter {
  height: 8px;
  margin-top: 12px;
  border-radius: 999px;
  background: #e8ece5;
  overflow: hidden;
}

.fragment-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--color-primary);
}

.fragment-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 10px;
  color: var(--color-muted);
  font-size: 12px;
}

.mini-card {
  min-width: 0;
}

.building-card {
  display: grid;
  gap: 8px;
  align-content: start;
}

.character-card {
  display: grid;
  gap: 10px;
  align-content: start;
}

.crafting-card,
.crafting-job-card {
  display: grid;
  gap: 10px;
  align-content: start;
}

.card-meta {
  color: var(--color-muted);
  font-size: 12px;
  font-weight: 750;
}

.cost-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cost-chip {
  border: 1px solid #cfe2d1;
  border-radius: 999px;
  background: #eef7ef;
  color: #205239;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.2;
  padding: 6px 8px;
}

.cost-chip-missing {
  border-color: #e4c8c8;
  background: #fbefef;
  color: #8d3840;
}

.output-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.output-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(94, 191, 166, 0.28);
  background: rgba(94, 191, 166, 0.12);
  color: var(--color-text);
  font-size: 12px;
}

.card-meta-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid rgba(84, 97, 127, 0.16);
  background: rgba(84, 97, 127, 0.08);
  color: var(--color-text);
  font-size: 12px;
}

.attribute-list,
.job-switch-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attribute-chip,
.job-switch {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(44, 95, 72, 0.16);
  background: rgba(44, 95, 72, 0.06);
  color: var(--color-text);
  font-size: 12px;
}

.job-switch {
  cursor: pointer;
}

.job-switch:disabled {
  cursor: default;
  opacity: 0.55;
}

.job-switch-active {
  border-color: rgba(44, 95, 72, 0.32);
  background: rgba(44, 95, 72, 0.14);
  font-weight: 700;
}

.exploration-card,
.exploration-run-card,
.combat-stage-card,
.codex-card {
  display: grid;
  gap: 10px;
  align-content: start;
}

.combat-stage-grid {
  display: grid;
  gap: 10px;
}

.combat-unit-list {
  display: grid;
  gap: 8px;
}

.combat-unit {
  border: 1px solid rgba(84, 97, 127, 0.14);
  border-radius: 8px;
  background: rgba(84, 97, 127, 0.04);
  padding: 10px;
}

.bottom-nav {
  position: sticky;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(245, 248, 241, 0.96);
  border-top: 1px solid rgba(61, 92, 72, 0.08);
  backdrop-filter: blur(12px);
}

.bottom-nav-item {
  min-width: 0;
  min-height: 52px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--color-muted);
  border: 1px solid rgba(61, 92, 72, 0.1);
  font-size: 13px;
  font-weight: 800;
}

.bottom-nav-item.is-active {
  background: var(--color-primary);
  color: #fff;
  border-color: transparent;
}

@media (min-width: 768px) {
  body {
    padding: 24px 0;
  }

  .game-shell {
    min-height: calc(100vh - 48px);
    border-radius: 18px;
    overflow: clip;
  }

  .village-stage {
    min-height: 360px;
  }

  .compact-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .fragment-card-main {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .recommendation-footer {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }

  .combat-stage-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
