.activities-page {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 50% 0, rgba(240, 132, 44, .1), transparent 48rem),
    var(--paper);
}

.activities-heading {
  width: min(1160px, calc(100% - 2rem));
  margin: 0 auto;
  padding: clamp(2.25rem, 6vw, 4.5rem) 0 1.5rem;
  text-align: center;
}

.activities-heading h1,
.life-intro h2 { color: var(--tower); }

.activities-heading > p { margin-inline: auto; }
.activities-heading > .btn { margin-top: .25rem; }

.activity-apps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(1rem, 3vw, 1.75rem);
  width: min(1040px, calc(100% - 2rem));
  margin: 0 auto clamp(3rem, 8vw, 6rem);
}

.activity-app-card {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  grid-template-rows: 1fr auto;
  gap: .9rem 1.1rem;
  min-height: 240px;
  padding: clamp(1.2rem, 3vw, 2rem);
  border: 1px solid rgba(230, 207, 184, .9);
  border-top: 5px solid var(--dragon);
  border-radius: 6px 20px 6px 20px;
  background: rgba(255, 250, 243, .94);
  box-shadow: 7px 8px 0 rgba(83, 54, 36, .11), 0 18px 44px rgba(45, 23, 16, .08);
  color: var(--ink);
  text-decoration: none;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}

.activity-app-card:hover,
.activity-app-card:focus-visible {
  transform: translateY(-4px);
  border-color: var(--flame);
  box-shadow: 9px 12px 0 rgba(83, 54, 36, .13), 0 22px 48px rgba(45, 23, 16, .12);
}

.app-icon {
  grid-column: 1;
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border: 1px solid rgba(143, 42, 29, .2);
  border-radius: 16px 7px 16px 7px;
  background: linear-gradient(145deg, #f8e7cf, #edd0aa);
  color: var(--maroon);
}

.app-icon svg { width: 52px; height: 52px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.app-icon--dice { color: var(--dragon); background: linear-gradient(145deg, #f8e0c8, #e9b5a0); }
.app-copy { display: grid; align-content: start; gap: .45rem; }
.app-type { color: var(--maroon); font-size: .7rem; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.app-copy strong { color: var(--tower); font: 400 clamp(1.25rem, 2.3vw, 1.75rem) var(--font-display); }
.app-copy > span:last-child { color: #55463d; font-size: .95rem; line-height: 1.5; }
.app-open { grid-column: 2; display: flex; justify-content: space-between; align-items: center; padding-top: .7rem; border-top: 1px solid var(--line); color: var(--maroon); font-weight: 700; }

@media (max-width: 700px) {
  .activity-apps { grid-template-columns: 1fr; max-width: 520px; }
  .activity-app-card { min-height: 200px; }
}

@media (max-width: 430px) {
  .activity-app-card { grid-template-columns: 58px minmax(0, 1fr); gap: .65rem .8rem; min-height: 180px; padding: 1rem; }
  .app-icon { width: 58px; height: 58px; }
  .app-icon svg { width: 42px; height: 42px; }
  .app-copy > span:last-child { font-size: .88rem; }
}

.activities-kicker {
  margin: 0 0 .55rem;
  color: var(--maroon);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.life-section {
  width: min(1320px, calc(100% - 2rem));
  margin: 0 auto 3rem;
  padding: clamp(1rem, 3vw, 2rem);
  border: 1px solid var(--line);
  border-top: 5px solid var(--dragon);
  background: rgba(255, 250, 243, .88);
  box-shadow: 8px 8px 0 rgba(230, 207, 184, .55);
}

.life-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1.5rem;
}

.life-intro h2 { margin-bottom: .45rem; }
.life-intro > div > p:last-child { max-width: 68ch; margin-bottom: 0; }

.game-setup {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: .65rem;
  flex: 0 0 auto;
}

.game-setup label { font-weight: 700; }
.game-setup select {
  min-height: 46px;
  padding: .5rem .75rem;
  border: 2px solid var(--line);
  border-radius: 4px 10px 4px 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.game-setup .btn { min-height: 46px; padding-block: .45rem; }

.game-status {
  margin: 1.25rem 0 .8rem;
  color: var(--tower-soft);
  font-size: .92rem;
  font-weight: 700;
}

.player-grid {
  display: contents;
}

.table-scene {
  --seat-count: 4;
  --seat-width: 217px;
  --table-width: 440px;
  --table-height: 340px;
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: auto minmax(var(--table-height), auto) auto;
  align-items: stretch;
  gap: 1rem .55rem;
  padding: 1.25rem;
  border: 10px ridge #65472e;
  background:
    radial-gradient(ellipse at 50% 50%, rgba(233, 181, 160, .12), transparent 58%),
    repeating-linear-gradient(0deg, transparent 0 42px, rgba(255, 250, 243, .025) 43px 44px),
    linear-gradient(135deg, #6e482d, #8a6040 45%, #66432d);
  box-shadow: inset 0 0 0 3px rgba(45, 23, 16, .55), 0 10px 22px rgba(45, 23, 16, .18);
}

.table-center {
  grid-row: 2;
  grid-column: 3 / span 4;
  align-self: center;
  justify-self: center;
  display: grid;
  justify-items: center;
  width: min(var(--table-width), 100%);
  height: var(--table-height);
  padding: .8rem 1.2rem;
  border: 12px ridge #795133;
  border-radius: 28px;
  background: #244a37;
  box-shadow: 0 16px 28px rgba(27, 18, 16, .38), inset 0 0 0 4px rgba(229, 199, 151, .2);
  color: #f8ead5;
  text-align: center;
}

.table-center h3 {
  z-index: 1;
  align-self: end;
  margin: 0 0 .25rem;
  font-size: clamp(1rem, 2vw, 1.35rem);
  text-shadow: 0 2px 3px #14291e;
}

.table-center > p {
  z-index: 1;
  align-self: start;
  margin: .35rem 0 0;
  font-size: .78rem;
  opacity: .88;
}

.table-felt {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 185px;
  margin-top: .25rem;
}

.table-card {
  position: absolute;
  display: grid;
  grid-template-rows: 1fr auto;
  width: 86px;
  height: 124px;
  padding: 6px;
  border: 3px solid #e5d1ad;
  border-radius: 7px;
  background: #c4a77d;
  box-shadow: 0 5px 8px rgba(0, 0, 0, .42);
  color: #30241b;
  text-align: left;
  transform: rotate(-9deg) translate(-60px, 2px);
}

.table-card span {
  display: block;
  border: 1px solid rgba(48, 36, 27, .38);
  border-radius: 3px;
  background: radial-gradient(circle at 50% 45%, #d8c18f, #73844e 48%, #385341);
}

.table-card i {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  height: 70%;
  border-radius: 3px;
  background: linear-gradient(145deg, rgba(240, 219, 163, .72), rgba(127, 75, 47, .5));
}

.table-card b { z-index: 1; padding-top: 3px; font-size: .55rem; }
.table-card--land { transform: rotate(-13deg) translate(-58px, 9px); }
.table-card--land span { background: linear-gradient(145deg, #d7bd82, #69825d 56%, #344d3b); }
.table-card--creature { z-index: 2; transform: rotate(2deg) translate(0, -8px); }
.table-card--creature span { background: linear-gradient(145deg, #c98652, #9a4430 55%, #372b36); }
.table-card--spell { transform: rotate(13deg) translate(58px, 9px); }
.table-card--spell span { background: linear-gradient(145deg, #789dc4, #56678f 52%, #382e52); }
.table-card--back {
  z-index: 3;
  width: 76px;
  height: 110px;
  transform: rotate(27deg) translate(105px, 18px);
  background: repeating-linear-gradient(45deg, #7f3425 0 6px, #bc7746 7px 9px);
}
.table-card--back span {
  display: grid;
  place-items: center;
  border: 2px solid #e5c58e;
  border-radius: 50%;
  background: #7f3425;
  color: #f4dfb8;
  font: 700 1.1rem var(--font-display);
}

.player-seat {
  position: relative;
  align-self: center;
  justify-self: center;
  width: var(--seat-width, 230px);
}

.player-seat::before {
  position: absolute;
  z-index: -1;
  inset: -13px -9px;
  border: 5px solid #4b3020;
  border-radius: 18px 18px 10px 10px;
  background: linear-gradient(180deg, #99704d 0 18%, #755034 18% 80%, #543721 80% 100%);
  box-shadow: 0 10px 12px rgba(27, 18, 16, .35), inset 0 2px 0 rgba(255, 224, 185, .3);
  content: "";
}

.player-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-top: 6px solid var(--player-color);
  background: #fffdf9;
  box-shadow: 3px 4px 0 rgba(45, 23, 16, .12);
}

.life-card-top { padding: .9rem 1rem .8rem; }
.player-heading { display: flex; align-items: center; gap: .55rem; }

.player-swatch {
  width: .8rem;
  height: .8rem;
  flex: 0 0 auto;
  border: 2px solid rgba(27, 18, 16, .5);
  border-radius: 50%;
  background: var(--player-color);
}

.player-name {
  width: 100%;
  min-width: 0;
  padding: .25rem .35rem;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--tower);
  font: 700 1rem var(--font-body);
}

.player-name:hover,
.player-name:focus { border-bottom-color: var(--player-color); }

.life-total {
  margin: -.1rem 0 .1rem;
  color: var(--player-text);
  font-size: clamp(3.5rem, 8vw, 5.2rem);
  font-weight: 700;
  line-height: 1.12;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.life-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .45rem;
}

.counter-button {
  min-width: 2.35rem;
  min-height: 2.35rem;
  padding: .2rem .55rem;
  border: 1px solid rgba(45, 23, 16, .25);
  border-radius: 4px 10px 4px 10px;
  background: #f4e8d7;
  color: var(--tower);
  font: 700 1.05rem var(--font-body);
  cursor: pointer;
  touch-action: manipulation;
}

.counter-button:hover:not(:disabled) { background: #ead1b2; }
.counter-button:disabled { opacity: .42; cursor: not-allowed; }

.player-counters {
  padding: .7rem .85rem .85rem;
  border-top: 1px solid var(--line);
  background: #fbf5ed;
}

.counter-heading,
.damage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
}

.counter-heading { min-height: 2.5rem; }
.counter-title { font-weight: 700; }
.counter-total {
  min-width: 1.7rem;
  color: var(--maroon);
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.mini-controls { display: inline-flex; align-items: center; gap: .3rem; }
.mini-controls .counter-button { min-width: 2rem; min-height: 2rem; padding: 0 .45rem; }
.commander-details { border-top: 1px dashed var(--line); }
.commander-details summary {
  padding: .6rem 0 .25rem;
  color: var(--tower);
  font-weight: 700;
  cursor: pointer;
}

.damage-list { display: grid; gap: .25rem; max-height: 190px; overflow-y: auto; margin: .4rem 0 0; padding: 0; list-style: none; overscroll-behavior: contain; }
.damage-source { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.damage-source::before {
  display: inline-block;
  width: .55rem;
  height: .55rem;
  margin-right: .4rem;
  border-radius: 50%;
  background: var(--player-color);
  content: "";
}
.damage-value { min-width: 1.4rem; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

.player-card.is-defeated {
  background: #f2ece7;
  border-top-color: #6d6260;
}
.player-card.is-defeated .life-total { color: #6d6260; }
.defeated-note { margin: 0; padding: .45rem .85rem; background: #eadbd5; color: #542c26; font-size: .83rem; font-weight: 700; }

.activities-dice {
  margin-top: 2rem;
  border-block: 5px solid var(--maroon);
  background: var(--tower);
  color: var(--parchment);
}

.activities-dice h2 { color: #fff; }
.activities-dice .activities-kicker { color: var(--flame); }
.activities-dice .d20-result { color: var(--ink); }

@media (max-width: 1000px) {
  .table-scene {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 1rem;
    padding: 1rem;
  }
  .table-center {
    width: min(100%, 460px);
    height: var(--table-height);
    min-height: 0;
    grid-row: 1;
    grid-column: 1;
    justify-self: center;
  }
  .player-grid {
    display: grid;
    grid-row: 2;
    grid-column: 1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
  }
  .player-seat {
    position: relative;
    width: 100%;
    grid-row: auto !important;
    grid-column: auto !important;
  }
  .player-seat::before { inset: -7px; }
  .life-intro { align-items: start; flex-direction: column; }
  .game-setup { align-items: end; }
  .activities-dice { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .activities-heading,
  .life-section { width: min(100% - 1rem, 1320px); }
  .game-setup { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .game-setup label { grid-column: 1 / -1; }
  .game-setup select, .game-setup .btn { width: 100%; min-width: 0; }
  .table-scene { padding: .8rem; }
  .player-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
  .life-card-top { padding: .65rem; }
  .player-name { font-size: .9rem; }
  .life-total { font-size: clamp(2.6rem, 13vw, 4.2rem); }
  .life-controls { gap: .25rem; }
  .life-controls .counter-button { min-width: 0; padding-inline: .2rem; }
  .player-counters { padding-inline: .6rem; }
  .damage-row { gap: .2rem; font-size: .82rem; }
  .mini-controls { gap: .15rem; }
  .mini-controls .counter-button { min-width: 1.7rem; min-height: 1.8rem; padding-inline: .3rem; }
  .activities-dice { padding-inline: 1rem; }
  .activities-dice .d20-stage { padding: 1rem; }
}

@media (max-width: 365px) {
  .player-grid { grid-template-columns: 1fr; }
}
