:root {
  --ink: #23160f;
  --parchment: #f3e2c2;
  --parchment-dark: #e4cc9a;
  --wood: #3b2416;
  --wood-light: #5a3824;
  --gold: #e4b84a;
  --gold-deep: #b8872a;
  --castle: #6d7d8c;
  --village: #8a5a28;
  --felt: #1b3a2f;
  --danger: #a33b2b;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(228, 184, 74, 0.16), transparent 55%),
    linear-gradient(180deg, #2a1a12 0%, #140c08 100%);
  color: var(--parchment);
  font-family: "Source Serif 4", Georgia, serif;
}

#app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 8px 12px 12px;
  min-width: 0;
}

button,
.card {
  font-family: inherit;
}

h1,
h2,
h3,
.brand {
  font-family: Cinzel, serif;
  letter-spacing: 0.04em;
}

.menu {
  min-height: 80vh;
  display: grid;
  place-items: center;
}

.menu-card {
  width: min(560px, 100%);
  background: linear-gradient(180deg, #f7e7c8, #e8d0a0);
  color: var(--ink);
  border: 4px solid #6b4a24;
  box-shadow: var(--shadow);
  padding: 36px 32px;
  text-align: center;
}

.menu-card h1 {
  margin: 0 0 8px;
  font-size: 2.4rem;
}

.menu-card p.lead {
  margin: 0 0 24px;
  font-size: 1.05rem;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  appearance: none;
  border: 2px solid #5c3b1d;
  background: #6f4324;
  color: #f8ead0;
  padding: 12px 16px;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.btn:hover {
  background: #82512c;
}

.btn.gold {
  background: linear-gradient(180deg, #efc65a, #c4922a);
  color: #2a1a0c;
  font-weight: 700;
}

.btn.ghost {
  background: transparent;
  color: var(--ink);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.fine {
  margin-top: 22px;
  font-size: 0.82rem;
  opacity: 0.75;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 6px;
  min-width: 0;
}

.topbar .actions {
  margin: 0;
  flex-shrink: 0;
}

.brand small {
  display: block;
  font-family: "Source Serif 4", serif;
  opacity: 0.7;
  letter-spacing: 0;
  font-size: 0.8rem;
}

.topbar .btn.ghost {
  color: var(--parchment);
  border-color: rgba(243, 226, 194, 0.35);
}

.legend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-width: 0;
  justify-content: center;
}

.shield {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 22px;
  clip-path: polygon(50% 0, 100% 22%, 82% 100%, 18% 100%, 0 22%);
  color: #fff8e8;
  vertical-align: middle;
}

.shield.inline {
  width: 16px;
  height: 20px;
  margin: 0 1px;
}

.shield .glyph {
  font-size: 10px;
  line-height: 1;
  font-weight: 700;
  transform: translateY(1px);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}

.legend .shield {
  width: 20px;
  height: 24px;
}

.legend .shield .glyph {
  font-size: 12px;
}

.banner {
  display: inline-block;
  width: 16px;
  height: 11px;
  margin: 0 2px;
  vertical-align: 0;
  clip-path: polygon(0 0, 82% 0, 100% 50%, 82% 100%, 0 100%);
}

.banner.castle {
  background: #8a9aaa;
}

.banner.village {
  background: #b57a3a;
}

.ico-gold,
.ico-key {
  display: inline-block;
  vertical-align: -2px;
  margin: 0 2px;
}

.ico-gold {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #fff4c4, #e8bc3a 42%, #b07812 78%);
  box-shadow: inset 0 0 0 1.5px rgba(255, 232, 160, 0.55), 0 0 0 1px #5a3408;
}

.ico-key {
  width: 18px;
  height: 13px;
}

.ico-key svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.card-body .ico-gold,
.scroll .ico-gold,
.choice-list .ico-gold {
  width: 11px;
  height: 11px;
}

.card-body .ico-key,
.scroll .ico-key,
.choice-list .ico-key {
  width: 16px;
  height: 11px;
}

.pill {
  background: rgba(243, 226, 194, 0.1);
  border: 1px solid rgba(243, 226, 194, 0.2);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.92rem;
}

.chrome {
  grid-area: chrome;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

.chrome .btn {
  padding: 8px 10px;
  font-size: 0.85rem;
  width: 100%;
}

.chrome .btn.ghost {
  color: var(--parchment);
  border-color: rgba(243, 226, 194, 0.35);
}

.playfield {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-x: hidden;
}

.markets {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) 88px;
  grid-template-areas:
    "loc-c cards-c chrome"
    "loc-v cards-v chrome";
  gap: 8px;
  background: rgba(20, 12, 8, 0.45);
  border: 1px solid rgba(228, 184, 74, 0.18);
  padding: 8px;
  min-width: 0;
}

.loc-label.castle {
  grid-area: loc-c;
  color: #c9d6e2;
}

.loc-label.village {
  grid-area: loc-v;
  color: #e8c48a;
}

.castle-market {
  grid-area: cards-c;
}

.village-market {
  grid-area: cards-v;
}

.loc-label {
  text-align: center;
  font-family: Cinzel, serif;
  padding: 8px 6px;
  border: 1px dashed rgba(243, 226, 194, 0.25);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}

.loc-name {
  font-size: 0.82rem;
}

.msg-here {
  font-size: 1.15rem;
  line-height: 1;
}

.btn.tiny {
  padding: 6px 5px;
  font-size: 0.7rem;
  line-height: 1.2;
}

.btn.tiny.gold {
  background: linear-gradient(180deg, #efc65a, #c4922a);
  color: #2a1a0c;
  font-weight: 700;
}

.market-card {
  min-width: 0;
}

.pick-actions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.pick-actions .btn {
  flex: 1;
}

.loc-label.active {
  outline: 2px solid var(--gold);
  background: rgba(228, 184, 74, 0.08);
}

.cards-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.cards-3 .card {
  min-height: 122px;
}

.card-art {
  font-size: 1.55rem;
  text-align: center;
  line-height: 1.1;
  margin: 2px 0;
}

.card-name {
  font-family: Cinzel, serif;
  font-size: 0.74rem;
  font-weight: 700;
  text-align: center;
  min-height: auto;
}

.card {
  position: relative;
  min-height: 0;
  background: linear-gradient(180deg, #f8eccf, #ead4a6);
  color: var(--ink);
  border: 2px solid #6a4b2b;
  padding: 6px 7px 8px;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

.card.castle {
  border-color: #4e5d6b;
  background: linear-gradient(180deg, #eef3f6, #d5dde4);
}

.card.village {
  border-color: #6b4a24;
}

.card.selected {
  outline: 3px solid var(--gold);
  transform: translateY(-4px);
}

.card.disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.cost {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gold);
  color: #3a250c;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-family: Cinzel, serif;
}

.cost.free {
  background: #d9d1c3;
}

.shields {
  display: flex;
  gap: 3px;
  align-items: center;
}

.card-body {
  font-size: 0.72rem;
  line-height: 1.25;
  flex: 1;
  overflow-wrap: anywhere;
}

.scroll {
  margin-top: 6px;
  background: #fbf1d6;
  border: 1px solid #c9ae7a;
  padding: 4px 6px;
  font-size: 0.7rem;
}

.msg-icon {
  position: absolute;
  right: 8px;
  bottom: 8px;
  font-size: 0.85rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.hint {
  min-height: 1.2em;
  opacity: 0.9;
  margin: 0 0 6px;
}

.boards {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
}

.board {
  background: var(--felt);
  border: 6px solid #2b1810;
  padding: 8px;
  min-width: 0;
}

.board h3 {
  margin: 0 0 6px;
  font-size: 0.88rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.board.is-winner {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(228, 184, 74, 0.4);
}

.res {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(243, 226, 194, 0.18);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
}

.res.pts {
  color: var(--gold);
  margin-left: auto;
}

.end-bar {
  margin: 8px 0 0;
  padding: 8px 12px;
  background: var(--parchment);
  color: var(--ink);
  border: 2px solid #6b4a24;
  text-align: center;
  font-family: Cinzel, serif;
  font-size: 0.95rem;
}

.shift-pad {
  position: absolute;
  inset: 0;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.12s ease;
  pointer-events: none;
}

.slot.filled:hover .shift-pad,
.slot.filled:focus-within .shift-pad {
  opacity: 1;
}

.shift-arrow {
  pointer-events: auto;
  position: absolute;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: rgba(42, 26, 12, 0.82);
  color: var(--gold);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.shift-arrow:hover {
  background: var(--gold);
  color: #2a1a0c;
}

.shift-arrow.n {
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
}

.shift-arrow.s {
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
}

.shift-arrow.w {
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
}

.shift-arrow.e {
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
}

.grid {
  display: grid;
  gap: 4px;
  justify-content: center;
  min-width: 0;
}

.grid.tableau {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: 100%;
}

.slot {
  position: relative;
  min-height: 168px;
  min-width: 0;
  border: 1px dashed rgba(243, 226, 194, 0.25);
  background: rgba(0, 0, 0, 0.12);
}

.slot.last-played {
  outline: 3px solid var(--gold);
  outline-offset: -2px;
  z-index: 2;
  box-shadow: 0 0 16px rgba(228, 184, 74, 0.45);
}

.gold-on {
  position: absolute;
  left: 4px;
  bottom: 4px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: #3a250c;
  color: var(--gold);
  font-size: 0.68rem;
  padding: 1px 5px;
  z-index: 1;
}

.live-pts {
  position: absolute;
  right: 4px;
  bottom: 4px;
  min-width: 1.35em;
  text-align: center;
  background: var(--gold);
  color: #2a1a0c;
  font-family: Cinzel, serif;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 1px 6px;
  border-radius: 3px;
  z-index: 3;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.slot.legal {
  border-color: var(--gold);
  background: rgba(228, 184, 74, 0.16);
  cursor: pointer;
  animation: pulse 1.4s ease-in-out infinite;
}

.slot .card {
  min-height: 168px;
  height: 100%;
  cursor: default;
  box-shadow: none;
}

.slot .card .card-art {
  font-size: 1.15rem;
  margin: 0;
}

.slot .card .card-name {
  font-size: 0.66rem;
  min-height: auto;
}

.slot .card .card-body {
  font-size: 0.62rem;
}

.slot .card .scroll {
  font-size: 0.58rem;
  margin-top: 3px;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}

.log {
  background: rgba(20, 12, 8, 0.5);
  border: 1px solid rgba(243, 226, 194, 0.12);
  padding: 8px 10px;
  max-height: calc(100vh - 80px);
  overflow-x: hidden;
  overflow-y: auto;
  font-size: 0.82rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.log div {
  padding: 3px 0;
  border-bottom: 1px solid rgba(243, 226, 194, 0.08);
}

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(8, 4, 2, 0.62);
  display: grid;
  place-items: center;
  padding: 12px;
  z-index: 20;
  overflow: auto;
}

.modal {
  width: min(520px, 100%);
  background: var(--parchment);
  color: var(--ink);
  padding: 22px;
  border: 4px solid #6b4a24;
}

.modal.score-modal {
  width: min(860px, 96vw);
  max-height: 92vh;
  overflow: auto;
  padding: 14px 16px 12px;
}

.modal h2 {
  margin-top: 0;
}

.score-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 22px;
}

.score-col h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
}

.choice-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.choice-list .btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.score-table td {
  padding: 1px 4px;
  border-bottom: 1px solid rgba(35, 22, 15, 0.1);
  vertical-align: top;
}

.score-table td:last-child {
  text-align: right;
  font-weight: 700;
  white-space: nowrap;
  width: 2.2em;
}

.score-modal .actions {
  margin: 10px 0 0;
  justify-content: center;
}

.winner {
  font-size: 1.15rem;
  margin-bottom: 10px;
  text-align: center;
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 3px rgba(228, 184, 74, 0.25);
  }
}

@media (max-width: 980px) {
  .boards,
  .score-grid {
    grid-template-columns: 1fr;
  }
  .markets {
    grid-template-columns: 1fr;
    grid-template-areas:
      "chrome"
      "loc-c"
      "cards-c"
      "loc-v"
      "cards-v";
  }
  .chrome {
    flex-direction: row;
  }
  .cards-3 {
    grid-template-columns: 1fr;
  }
}
