:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #657089;
  --paper: #fff9ec;
  --panel: rgba(255, 255, 255, 0.92);
  --line: rgba(23, 32, 51, 0.12);
  --gold: #f8b935;
  --mint: #1fcf9f;
  --rose: #f45f84;
  --violet: #7658ff;
  --sky: #32a9ff;
  --lime: #a7df34;
  --bad: #d74e46;
  --good: #138c69;
  --shadow: 0 18px 40px rgba(25, 35, 65, 0.18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family:
    Inter, ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 10%, rgba(255, 255, 255, 0.9), transparent 18rem),
    linear-gradient(160deg, #78d9ff 0%, #fedc70 42%, #ff8c8f 100%);
  overflow-x: hidden;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  width: min(100vw, 520px);
  min-height: 100svh;
  margin: 0 auto;
  padding: calc(10px + var(--safe-top)) 12px calc(12px + var(--safe-bottom));
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  position: relative;
}

.top-bar,
.status-panel,
.event-ribbon,
.bottom-dock,
.modal {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.top-bar {
  min-height: 68px;
  border-radius: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 38px;
  gap: 8px;
  align-items: center;
  padding: 8px;
}

.profile-chip {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--violet), var(--sky));
  color: white;
  font-weight: 950;
  letter-spacing: 0;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.15);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.profile-chip strong,
.event-ribbon strong,
.status-panel strong {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}

.resource-strip {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  min-width: 0;
}

.resource {
  min-width: 48px;
  height: 34px;
  border-radius: 8px;
  padding: 4px 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: #f4f7ff;
  border: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 950;
}

.resource span {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: white;
  font-size: 0.67rem;
  background: var(--gold);
}

.resource b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resource:nth-child(2) span {
  background: var(--sky);
}

.resource:nth-child(3) span {
  background: var(--mint);
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #edf2ff;
  border: 1px solid var(--line);
  font-size: 1.15rem;
  font-weight: 900;
  transition: transform 0.16s ease, filter 0.16s ease;
}

.icon-btn:active,
.roll-btn:active,
.quick-nav button:active,
.small-action:active,
.primary-action:active,
.mult-btn:active {
  transform: scale(0.96);
  filter: brightness(0.96);
}

.game-stage {
  display: grid;
  align-content: center;
  gap: 10px;
  min-height: 0;
}

.event-ribbon {
  border-radius: 8px;
  padding: 9px 10px;
  display: grid;
  grid-template-columns: 118px 1fr 62px;
  align-items: center;
  gap: 9px;
}

.progress {
  height: 11px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(23, 32, 51, 0.1);
}

.progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--rose), var(--gold), var(--mint));
  transition: width 0.35s ease;
}

.event-ribbon small {
  font-weight: 950;
  text-align: right;
  color: var(--violet);
}

.board-wrap {
  display: grid;
  place-items: center;
}

.board {
  position: relative;
  width: min(94vw, 440px);
  aspect-ratio: 1;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.74), rgba(255, 255, 255, 0.45)),
    radial-gradient(circle at 50% 48%, var(--district-a, #ffe2aa), var(--district-b, #a7f0ff));
  border: 2px solid rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow), inset 0 0 0 8px rgba(255, 255, 255, 0.23);
  overflow: hidden;
}

.board::before {
  content: "";
  position: absolute;
  inset: 15%;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.2), transparent),
    repeating-linear-gradient(0deg, transparent 0 23px, rgba(23, 32, 51, 0.05) 24px),
    repeating-linear-gradient(90deg, transparent 0 23px, rgba(23, 32, 51, 0.05) 24px);
}

.tile {
  position: absolute;
  width: 12.4%;
  height: 12.4%;
  border-radius: 8px;
  display: grid;
  place-items: center;
  padding: 2px;
  background: #ffffff;
  color: var(--ink);
  border: 1px solid rgba(23, 32, 51, 0.12);
  box-shadow: 0 8px 16px rgba(20, 30, 55, 0.12), inset 0 -4px 0 rgba(0, 0, 0, 0.07);
  transform: translate(-50%, -50%);
  transition: filter 0.22s ease, transform 0.22s ease;
}

.tile.active {
  filter: saturate(1.25) brightness(1.08);
  transform: translate(-50%, -50%) scale(1.08);
}

.tile-icon {
  font-size: clamp(1rem, 4vw, 1.55rem);
  line-height: 1;
}

.tile-label {
  max-width: 100%;
  font-size: clamp(0.42rem, 1.8vw, 0.58rem);
  font-weight: 950;
  line-height: 1;
  text-transform: uppercase;
}

.tile.coin,
.tile.bigCoin {
  background: linear-gradient(145deg, #ffe27a, #ffad32);
}

.tile.raid,
.tile.attack {
  background: linear-gradient(145deg, #ff8c8c, #f74978);
  color: white;
}

.tile.shield,
.tile.dice,
.tile.gift {
  background: linear-gradient(145deg, #90f0d1, #28b8ff);
  color: white;
}

.tile.card,
.tile.event,
.tile.mini {
  background: linear-gradient(145deg, #b9a7ff, #6f5cff);
  color: white;
}

.tile.tax,
.tile.discount {
  background: linear-gradient(145deg, #ecf3ff, #ffffff);
}

.district-core {
  position: absolute;
  inset: 26%;
  border-radius: 8px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  padding: 12px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(255, 255, 255, 0.62)),
    linear-gradient(145deg, var(--district-a, #ffe2aa), var(--district-b, #a7f0ff));
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: inset 0 -7px 0 rgba(23, 32, 51, 0.08), 0 14px 32px rgba(23, 32, 51, 0.14);
  text-align: center;
}

.district-core strong {
  font-size: clamp(1rem, 5vw, 1.5rem);
  font-weight: 1000;
}

.building-skyline {
  width: 100%;
  min-height: 62px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 5px;
}

.mini-building {
  width: 18%;
  min-width: 20px;
  border-radius: 5px 5px 2px 2px;
  background: linear-gradient(180deg, var(--sky), var(--violet));
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.13);
  position: relative;
  transition: height 0.25s ease;
}

.mini-building::before {
  content: "";
  position: absolute;
  inset: 7px 5px auto;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 10px 0 rgba(255, 255, 255, 0.45), 0 20px 0 rgba(255, 255, 255, 0.35);
}

.mini-building.damaged {
  filter: grayscale(0.45) brightness(0.8);
}

.small-action,
.primary-action,
.secondary-action {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 950;
  background: var(--ink);
  color: white;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2);
}

.secondary-action {
  background: #eef2ff;
  color: var(--ink);
  box-shadow: none;
  border: 1px solid var(--line);
}

.token {
  position: absolute;
  left: 50%;
  top: 93%;
  width: 39px;
  height: 39px;
  border-radius: 50% 50% 50% 14%;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #ffffff, #d8efff);
  color: var(--rose);
  border: 3px solid white;
  box-shadow: 0 10px 22px rgba(23, 32, 51, 0.28), inset 0 -5px 0 rgba(0, 0, 0, 0.12);
  transform: translate(-50%, -50%) rotate(-45deg);
  transition: left 0.18s ease, top 0.18s ease, transform 0.18s ease;
  z-index: 5;
}

.token span {
  transform: rotate(45deg);
  font-size: 1.25rem;
}

.token.hop {
  transform: translate(-50%, -62%) rotate(-45deg) scale(1.08);
}

.status-panel {
  min-height: 68px;
  border-radius: 8px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
}

.dice-display {
  display: flex;
  gap: 6px;
}

.dice-display span {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--violet);
  font-weight: 1000;
  font-size: 1.25rem;
  box-shadow: inset 0 -4px 0 rgba(23, 32, 51, 0.09);
}

.dice-display.rolling span {
  animation: dice-bounce 0.24s ease infinite alternate;
}

.dice-display.rolling span:nth-child(2) {
  animation-delay: 0.08s;
}

.bottom-dock {
  border-radius: 8px;
  padding: 10px;
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 8px 10px;
  align-items: center;
}

.multiplier {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  border-radius: 8px;
  background: #eef2ff;
  border: 1px solid var(--line);
}

.mult-btn {
  min-height: 34px;
  border-radius: 6px;
  background: transparent;
  font-size: 0.72rem;
  font-weight: 950;
}

.mult-btn.active {
  color: white;
  background: linear-gradient(145deg, var(--violet), var(--rose));
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.17);
}

.roll-btn {
  min-height: 62px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #ffec75, #ff9f2f);
  box-shadow: 0 13px 22px rgba(220, 105, 22, 0.28), inset 0 -7px 0 rgba(128, 65, 0, 0.2);
  color: #472200;
  font-weight: 1000;
}

.roll-btn span {
  font-size: 1.35rem;
  line-height: 1;
}

.roll-btn small {
  font-size: 0.7rem;
  font-weight: 950;
}

.quick-nav {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.quick-nav button {
  min-height: 52px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  gap: 2px;
  background: #f8fbff;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 900;
}

.quick-nav span {
  font-size: 1.1rem;
}

.home-link {
  grid-column: 1 / -1;
  min-height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--violet), var(--sky));
  color: white;
  font-size: 0.78rem;
  font-weight: 950;
  text-decoration: none;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.16);
}

.home-link:active {
  transform: scale(0.98);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  padding: 12px;
  background: rgba(11, 15, 28, 0.4);
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  width: min(100%, 520px);
  max-height: calc(100svh - 24px);
  border-radius: 8px;
  overflow: hidden;
  animation: modal-up 0.22s ease both;
}

.modal-header {
  min-height: 62px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.12rem;
}

.modal-content {
  max-height: min(68svh, 620px);
  overflow: auto;
  padding: 12px;
}

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

.building-card,
.reward-card,
.friend-row,
.card-item,
.milestone,
.daily-row,
.feed-row,
.vault {
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.building-card {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 9px;
  align-items: center;
  padding: 10px;
}

.building-icon {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--district-a), var(--district-b));
  font-size: 1.35rem;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.1);
}

.building-card h3,
.reward-card h3,
.friend-row h3,
.card-item h3,
.milestone h3 {
  margin: 0 0 4px;
  font-size: 0.92rem;
}

.building-card p,
.reward-card p,
.friend-row p,
.card-item p,
.milestone p,
.daily-row p,
.feed-row p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.28;
}

.building-meter {
  display: flex;
  gap: 4px;
  margin-top: 7px;
}

.building-meter span {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: #e8edf7;
}

.building-meter .filled {
  background: linear-gradient(90deg, var(--mint), var(--sky));
}

.price-btn {
  min-width: 84px;
  min-height: 40px;
  border-radius: 8px;
  padding: 0 10px;
  background: linear-gradient(145deg, var(--mint), var(--sky));
  color: white;
  font-size: 0.78rem;
  font-weight: 950;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.15);
}

.modal-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.modal-actions button {
  flex: 1;
}

.reward-card {
  padding: 12px;
  display: grid;
  gap: 9px;
}

.reward-card.big {
  background: linear-gradient(145deg, #fff8df, #fff);
}

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

.vault {
  min-height: 92px;
  display: grid;
  place-items: center;
  padding: 8px;
  text-align: center;
  font-weight: 950;
  background: linear-gradient(145deg, #42526f, #1b2334);
  color: white;
  box-shadow: inset 0 -7px 0 rgba(0, 0, 0, 0.22);
}

.vault.revealed {
  background: linear-gradient(145deg, #ffe27a, #ff9f2f);
  color: #4a2700;
  animation: pop 0.28s ease both;
}

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

.card-item {
  min-height: 118px;
  padding: 9px;
  display: grid;
  align-content: space-between;
  background: linear-gradient(145deg, #ffffff, #eef7ff);
}

.card-art {
  width: 100%;
  aspect-ratio: 1.25;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--card-a, #ffbd6b), var(--card-b, #7ddcff));
  color: white;
  font-size: 1.6rem;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.12);
}

.card-item.missing {
  opacity: 0.55;
  filter: grayscale(0.9);
}

.friend-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 9px;
  align-items: center;
  padding: 10px;
}

.friend-avatar {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 950;
  background: linear-gradient(145deg, var(--rose), var(--violet));
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  background: #eef2ff;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 950;
}

.milestone {
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

.milestone.claimed {
  background: #f3fff9;
}

.daily-row {
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

.feed-row {
  padding: 9px 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(156px + var(--safe-bottom));
  z-index: 35;
  transform: translateX(-50%);
  max-width: min(92vw, 430px);
  border-radius: 8px;
  padding: 10px 12px;
  color: white;
  background: rgba(23, 32, 51, 0.94);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  font-weight: 850;
  animation: toast-in 2.45s ease both;
}

.burst {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  color: #ffe36a;
  font-weight: 1000;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.16);
  animation: burst 0.9s ease forwards;
}

.confetti {
  position: fixed;
  z-index: 40;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  pointer-events: none;
  animation: confetti 1s ease forwards;
}

@keyframes dice-bounce {
  from {
    transform: translateY(0) rotate(-8deg);
  }
  to {
    transform: translateY(-8px) rotate(8deg);
  }
}

@keyframes modal-up {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes pop {
  0% {
    transform: scale(0.86);
  }
  70% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes toast-in {
  0%,
  100% {
    opacity: 0;
    transform: translate(-50%, 14px);
  }
  12%,
  86% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes burst {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.8);
  }
  18% {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translateY(-70px) scale(1.25);
  }
}

@keyframes confetti {
  to {
    opacity: 0;
    transform: translate(var(--x), 120px) rotate(360deg);
  }
}

@media (max-width: 430px) {
  .app-shell {
    width: 100vw;
    max-width: 430px;
  }

  .top-bar {
    grid-template-columns: minmax(0, 1fr) 34px;
  }

  .profile-chip strong {
    max-width: 170px;
  }

  .resource-strip {
    grid-column: 1 / -1;
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: stretch;
    width: 100%;
  }

  .resource {
    width: 100%;
    min-width: 0;
    height: 32px;
    padding: 3px 5px;
    font-size: 0.74rem;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
  }

  .status-panel strong {
    display: -webkit-box;
    overflow: hidden;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
}

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

  .event-ribbon {
    grid-template-columns: 102px 1fr 54px;
    gap: 6px;
  }

  .board {
    width: min(96vw, 350px);
  }

  .bottom-dock {
    grid-template-columns: 78px 1fr;
    padding: 8px;
  }

  .quick-nav {
    gap: 5px;
  }

  .quick-nav button {
    min-height: 48px;
    font-size: 0.64rem;
  }

  .modal-content {
    max-height: 64svh;
  }
}

@media (max-width: 759px) {
  .app-shell {
    width: 100vw;
  }

  .top-bar {
    grid-template-columns: minmax(0, 1fr) 38px;
    grid-template-rows: auto auto;
  }

  .resource-strip {
    grid-column: 1 / -1;
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    justify-content: stretch;
  }

  .resource {
    width: 100%;
    min-width: 0;
  }

  .status-panel strong {
    display: -webkit-box;
    overflow: hidden;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .board {
    width: min(calc(100vw - 24px), 430px);
  }

  .modal-backdrop {
    place-items: center;
    padding: 10px;
  }

  .modal {
    max-height: calc(100svh - 20px);
  }

  .modal-content {
    max-height: calc(100svh - 102px);
  }
}

@media (min-width: 760px) {
  body {
    min-height: 100vh;
  }

  .app-shell {
    width: min(100vw, 980px);
    grid-template-columns: minmax(360px, 520px) minmax(280px, 360px);
    grid-template-rows: auto 1fr;
    align-items: start;
  }

  .top-bar {
    grid-column: 1 / -1;
  }

  .game-stage {
    grid-column: 1;
  }

  .bottom-dock {
    grid-column: 2;
    grid-row: 2;
    align-self: start;
    grid-template-columns: 1fr;
    align-content: start;
  }

  .quick-nav {
    grid-column: auto;
    grid-template-columns: 1fr 1fr;
  }

  .modal-backdrop {
    place-items: center;
  }
}
