:root {
  --parchment: #f6e7c1;
  --parchment-deep: #e7d2a1;
  --ink: #4a2e16;
  --gold: #e0a23a;
  --gold-deep: #b7791f;
  --green: #2f8f45;
  --frame: #3a2412;
  --btn-pad-y: 4px;
  --btn-pad-x: 9px;
  --btn-font-size: 13px;
  --btn-gap: 4px;
  /* Minimum tap height on mobile (still within ~36–40px guidance). */
  --touch-target: 38px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Tahoma, "Segoe UI", sans-serif;
  background: #140c07;
}

#shell {
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  margin: 0;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: linear-gradient(180deg, #6a4328 0, #3a2414 28px, #2a180e 100%);
  border-radius: 0;
  box-shadow: inset 0 0 0 6px #140c07, inset 0 0 0 10px #d7b56a;
}

.client-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  gap: 8px;
}

#play {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#side {
  background: linear-gradient(#4a2e18, #2c1a0e);
  border: 3px solid #d7b56a;
  border-radius: 0;
  padding: 10px;
  color: #f6e7c1;
  overflow: auto;
}
#side .brand { margin-bottom: 12px; }
.side-player {
  margin: 0 0 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  color: #f3d48a;
}
.side-race {
  margin: 0 0 8px;
  font-size: 13px;
  color: #f6e7c1;
}
.side-race span {
  display: block;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #c9a56a;
}
.side-block { margin-top: 12px; }
.side-block h2 {
  margin: 0 0 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  color: #f3d48a;
}
.side-block button {
  display: block;
  width: 100%;
  margin-bottom: var(--btn-gap);
  text-align: left;
}
.leaderboard-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}
.leaderboard-tabs button {
  width: auto;
  flex: 1 1 calc(50% - 4px);
  margin: 0;
  padding: 5px 6px;
  text-align: center;
  font-size: 11px;
  line-height: 1.2;
  background: #efe0c0;
  color: #3a2412;
  border: 1px solid #6b4320;
}
.leaderboard-tabs button.on {
  background: linear-gradient(#ffe7a8, #e0a23a);
  color: #3a2412;
  border-color: #d7b56a;
}
.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: min(420px, calc(100vh - 180px));
  overflow: auto;
}
.leaderboard-row {
  display: grid;
  grid-template-columns: 2.2em 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 4px 6px;
  font-size: 12px;
  background: rgba(90, 58, 24, 0.12);
}
.leaderboard-row.you {
  background: rgba(224, 162, 58, 0.28);
  outline: 1px solid #d7b56a;
}
.leaderboard-rank {
  color: #6b4320;
  font-variant-numeric: tabular-nums;
}
.leaderboard-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #3a2614;
}
.leaderboard-value {
  font-variant-numeric: tabular-nums;
  color: #5a3a18;
}
.leaderboard-empty {
  margin: 0;
  font-size: 12px;
  color: #5a4a38;
}
.castle-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}
.castle-row .castle-arrow {
  width: 22px;
  min-width: 22px;
  height: 36px;
  margin: 0;
  padding: 0;
  flex: 0 0 auto;
  text-align: center;
  font-size: 20px;
  line-height: 1;
}
.castle-scroll {
  display: flex;
  flex-direction: row;
  gap: 6px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.castle-scroll::-webkit-scrollbar { display: none; }
.castle-scroll button {
  position: relative;
  width: 70px;
  min-width: 70px;
  height: 60px;
  margin: 0;
  padding: 2px;
  flex: 0 0 auto;
}
.castle-queue-dot {
  position: absolute;
  top: 1px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 2;
}
.castle-queue-dot.has-slot {
  background: #2ecc40;
}
.castle-queue-dot.both-busy {
  background: #e74c3c;
}
.castle-scroll canvas {
  display: block;
  width: 64px;
  height: 54px;
  pointer-events: none;
}
.side-empty {
  margin: 0;
  font-size: 13px;
  color: #e7c98a;
}

.client-top {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 6px;
  background: #140e0a;
  border: 1px solid #6b4320;
  color: #f4efe4;
}

/* Invisible on desktop so resources and status stay direct header items. */
.top-cluster { display: contents; }
#castle-dock,
.mobile-nav,
.mobile-sheet-head { display: none; }

.brand { display: flex; align-items: center; min-width: 0; }
.mark {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 14px;
  line-height: 1;
  letter-spacing: 0.5px;
  color: #f3d48a;
}

.status-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.client-top #logout {
  margin: 0;
  padding: 0 8px;
  height: 20px;
  font-size: 12px;
  line-height: 18px;
}
.gold-amt, .tax-amt {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  white-space: nowrap;
}
.gold-amt { color: #f0c14a; }
.tax-amt { color: #f6e7c1; min-width: 28px; }
.mood {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  width: 36px;
  height: 16px;
  padding: 2px;
  background: #2a2118;
  border: 1px solid #6b4320;
}
.mood i {
  display: block;
  height: 4px;
  width: 0;
}
.mood-loyal { background: #3d9a4a; }
.mood-resent { background: #c4473a; }

button {
  font: inherit;
  font-size: var(--btn-font-size);
  line-height: 1.25;
  color: #3a2412;
  background: linear-gradient(#f3c56a, var(--gold));
  border: 2px solid #6b4320;
  border-radius: 0;
  padding: var(--btn-pad-y) var(--btn-pad-x);
  cursor: pointer;
  box-shadow: inset 0 1px 0 #fff1cc;
}
nav button {
  min-width: 58px;
  background: linear-gradient(#efe0c0, #c9b48a);
}
button.on, nav button.on {
  background: linear-gradient(#ffe7a8, #e0a23a);
  box-shadow: inset 0 0 0 2px #fff4d4;
}
button:disabled { opacity: 0.5; cursor: default; }
#new-game { background: #f4e2bf; }

#resources {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.res-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: #f4efe4;
}
.res-chip::before {
  content: "";
  width: 10px;
  height: 10px;
  border: 1px solid #3a2412;
}
.res-chip.lumber::before { background: linear-gradient(#6aaa48, #2f6a28); }
.res-chip.stone::before { background: linear-gradient(#d0c8b8, #7a7468); }
.res-chip.iron::before { background: linear-gradient(#b0b6c0, #4e545c); }
.res-chip.food::before { background: linear-gradient(#f0d060, #c49a28); }
.res-chip.full { color: #ffb4a8; }

.play-hud-top {
  position: absolute;
  top: 6px;
  left: 0;
  right: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}

#queues {
  position: static;
  align-self: flex-start;
  margin-left: 6px;
  width: max-content;
  max-width: min(300px, calc(100% - 120px));
  margin-top: 0;
  margin-bottom: 0;
  margin-right: 0;
  padding: 0;
  pointer-events: none;
}

.play-hud-actions {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  max-width: min(520px, calc(100% - 24px));
  pointer-events: auto;
}
.hud-action-btn {
  margin: 0;
  padding: 3px 12px;
  min-height: 22px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
  background: linear-gradient(#efe0c0, #c9b48a);
  border: 2px solid #6b4320;
  box-shadow: 0 0 0 1px #e2b45a;
  border-radius: 0;
  color: #4a2e16;
  cursor: pointer;
}

.view-mode-toggle {
  display: inline-flex;
  flex: 0 0 auto;
  width: max-content;
  max-width: min(320px, calc(100% - 24px));
  pointer-events: auto;
  border: 2px solid #6b4320;
  box-shadow: 0 0 0 1px #e2b45a, 0 3px 8px rgba(0, 0, 0, 0.22);
  background: #2a2118;
}

.view-mode-toggle button {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  padding: 3px 10px;
  min-height: 22px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
  background: linear-gradient(#efe0c0, #c9b48a);
  border: 0;
  border-right: 1px solid #6b4320;
  border-radius: 0;
  color: #4a2e16;
  box-shadow: none;
}
.view-mode-toggle button:last-child {
  border-right: 0;
}
.view-mode-toggle button.on {
  background: linear-gradient(#ffe7a8, #e0a23a);
  box-shadow: inset 0 0 0 2px #fff4d4;
  color: #3a2412;
}
.queue-dock {
  display: flex;
  flex-direction: column;
  gap: 2px;
  pointer-events: auto;
}
.queue-active {
  position: relative;
  min-height: 22px;
  overflow: hidden;
  border: 1px solid #3a2414;
  background: #2a2118;
  color: #f6e7c1;
  font-size: 11px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
}
.queue-active-idle {
  display: flex;
  align-items: center;
  padding: 2px 8px;
  background: linear-gradient(#f7e4bf, #e8c98a);
  color: #6a4014;
  border-color: #6b4320;
}
.queue-active-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: linear-gradient(#4a9a52, #2d6b34);
  z-index: 0;
}
.queue-active-body {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px 2px 8px;
  min-height: 22px;
}
.queue-active-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;
}
.queue-active-time {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}
.queue-cancel {
  width: 18px;
  min-width: 18px;
  height: 18px;
  padding: 0;
  margin: 0;
  line-height: 1;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff8ee;
  box-shadow: none;
}
.queue-march {
  padding: 1px 6px;
  font-size: 10px;
  color: #f6e7c1;
  background: rgba(20, 12, 8, 0.75);
  border: 1px solid #6b4320;
}
.queue-tabs {
  display: flex;
  flex-direction: row;
  gap: 2px;
}
.queue-tab {
  flex: 1 1 0;
  min-width: 0;
  padding: 3px 4px;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: linear-gradient(#f7e4bf, #e8c98a);
  border: 1px solid #6b4320;
  color: #6a4014;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}
.queue-tab.busy {
  background: linear-gradient(#f08a32, #d65a16);
  border-color: #a84310;
  color: #fff8ee;
}
.queue-tab.on {
  box-shadow: inset 0 0 0 2px #fff4d4;
}
#map-home {
  position: absolute;
  top: auto;
  left: 6px;
  bottom: 6px;
  z-index: 6;
  padding: 2px 7px;
  font-size: 11px;
}
#map-home[hidden] { display: none; }

#map-bar {
  position: absolute;
  top: 8px;
  right: 8px;
  left: auto;
  z-index: 7;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px 10px;
  max-width: min(420px, calc(100% - 16px));
  padding: 5px 10px;
  background: linear-gradient(#f8e7c0, #f0d3a2);
  border: 2px solid #6b4320;
  box-shadow: 0 0 0 1px #e2b45a, 0 6px 16px rgba(0, 0, 0, 0.28);
  font-size: 12px;
  pointer-events: auto;
}
#map-bar[hidden] { display: none; }
#map-bar .role {
  display: none;
}
.map-bar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}
#map-bar label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
#map-bar input[type="number"] {
  width: 4.2em;
  padding: 2px 4px;
  font-size: 12px;
}
#map-bar button {
  padding: 2px 10px;
  font-size: 12px;
}
.map-bar-marches {
  color: #6a4014;
  font-weight: 700;
  white-space: nowrap;
}

body[data-game-view="map"] #panel.map-detail {
  top: 48px;
  max-height: min(300px, calc(100% - 100px));
}
body[data-game-view="map"] #panel.map-detail h2 {
  display: none;
}

main {
  position: relative;
  flex: 1;
  display: block;
  min-height: 0;
}
#panel[hidden] { display: none; }

#view {
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: 0;
  border: 2px solid #6b4320;
  background: #62ae48;
  display: block;
  touch-action: none;
}

#panel {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  pointer-events: auto;
  width: min(300px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  background: linear-gradient(#f8e7c0, #f0d3a2);
  border: 4px solid #6b4320;
  border-radius: 0;
  padding: 0 12px 12px;
  overflow: auto;
  box-shadow: 0 0 0 2px #e2b45a, 0 12px 28px rgba(0, 0, 0, 0.4);
}
#panel ul { margin: 8px 0; padding-left: 18px; }
.govern { margin-top: 12px; padding-top: 8px; border-top: 1px solid #ddc48f; }
.tax-row { display: flex; align-items: center; gap: 8px; }
.tax-row input[type="range"] { flex: 1; }

#academy-window {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(28, 18, 8, 0.35);
  pointer-events: auto;
}
#academy-window[hidden] { display: none; }

#store-window,
#leaderboard-window {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(28, 18, 8, 0.35);
  pointer-events: auto;
}
#store-window[hidden],
#leaderboard-window[hidden] { display: none; }
.store-card,
.leaderboard-card {
  width: min(520px, calc(100vw - 32px));
  max-height: min(640px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  background: linear-gradient(#f8e7c0, #f0d3a2);
  border: 4px solid #c4963e;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  color: #3a2614;
}
.store-title,
.leaderboard-title {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin: 0;
  padding: 10px 36px;
  background: linear-gradient(#f3d48a, #e2b45a);
  border-bottom: 2px solid #b8883a;
  border-radius: 8px 8px 0 0;
}
.store-title h2,
.leaderboard-title h2 { margin: 0; font-size: 22px; }
.store-title button,
.leaderboard-title button {
  position: absolute;
  right: 10px;
  top: 8px;
  z-index: 2;
  border: 0;
  background: #a33b2a;
  color: #fff8e8;
  width: 26px;
  height: 26px;
  border-radius: 4px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  pointer-events: auto;
}
.store-body,
.leaderboard-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 14px 16px 16px;
  -webkit-overflow-scrolling: touch;
}
#store-window #items-root {
  color: #3a2614;
  font-size: 13px;
}
#store-window #items-root h3 {
  margin: 12px 0 6px;
  font-size: 14px;
  color: #5a3a18;
}
#store-window #items-root .shop-copy p { color: #5a4a38; }
#store-window #items-root .shop-row,
#store-window #items-root .bag-row {
  border-bottom-color: rgba(90, 58, 24, 0.2);
}
#store-window #items-root .item-prompt {
  background: rgba(255, 248, 230, 0.65);
  border-color: #b8883a;
}
#store-window #items-root .side-empty { color: #5a4a38; }

.academy-card {
  width: min(860px, calc(100vw - 32px));
  max-height: min(640px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  background: linear-gradient(#f8e7c0, #f0d3a2);
  border: 4px solid #c4963e;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  color: #3a2614;
}
.academy-title {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin: 0;
  padding: 10px 36px;
  background: linear-gradient(#f3d48a, #e2b45a);
  border-bottom: 2px solid #b8883a;
  border-radius: 8px 8px 0 0;
}
.academy-title h2 { margin: 0; font-size: 22px; }
.academy-title button, .academy-x {
  border: 0;
  background: #a33b2a;
  color: #fff8e8;
  width: 26px;
  height: 26px;
  border-radius: 4px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.academy-title button {
  position: absolute;
  right: 10px;
  top: 8px;
  z-index: 2;
  touch-action: manipulation;
  pointer-events: auto;
}
.academy-top {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 16px;
  padding: 14px 16px 8px;
}
.academy-tools { display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
.academy-thumb {
  height: 72px;
  border: 2px solid #c9a56a;
  border-radius: 6px;
  background:
    linear-gradient(#3d6ea8, #3d6ea8) 50% 18% / 70% 16px no-repeat,
    linear-gradient(#d7c4a4, #b7a48c) 50% 70% / 78% 36px no-repeat,
    #6ea24a;
}
.academy-tools button, .academy-tech button, .academy-offer button {
  background: linear-gradient(#f6e2b0, #e7c98a);
  border: 1px solid #b8883a;
  border-radius: 6px;
  padding: var(--btn-pad-y) var(--btn-pad-x);
  font: inherit;
  font-size: var(--btn-font-size);
  cursor: pointer;
}
.academy-blurb { margin: 0; line-height: 1.45; }
.academy-split {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 12px;
  min-height: 0;
  padding: 0 16px 16px;
}
.academy-queue {
  background: #fff6e4;
  border: 1px solid #e0c48a;
  border-radius: 8px;
  padding: 8px;
  min-height: 220px;
}
.academy-queue h3 {
  margin: 0 0 8px;
  padding: 6px 8px;
  background: linear-gradient(#f0b34a, #e09a2e);
  border-radius: 4px;
  font-size: 15px;
}
.academy-study {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #ead7b0;
}
.academy-study span { grid-column: 1; font-size: 13px; }
.academy-list {
  overflow: auto;
  max-height: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.academy-tech {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 8px;
  padding: 8px;
  background: #fff8ea;
  border: 1px solid #e4c98e;
  border-radius: 8px;
}
.academy-tech b { margin-right: 6px; }
.academy-tech p, .academy-tools p { margin: 4px 0; font-size: 13px; }
.academy-tech button { float: right; }
.tech-mark {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  background: #6a5344;
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.2);
}
.tech-mark.lumber { background: #2f7a3a; }
.tech-mark.training { background: #8a3030; }
.tech-mark.logistics { background: #c47a2a; }
.tech-mark.fortification { background: #8d6a32; }
.tech-mark.attack { background: #a33b2a; }
.tech-mark.defense { background: #3d5f8a; }
.tech-mark.quarry { background: #7a7368; }
.tech-mark.construction { background: #b08958; }
.tech-mark.smelt { background: #9a4a28; }
.tech-mark.harvest { background: #c2a24a; }
.tech-mark.sorcery { background: #5a3d78; }
.tech-mark.magical { background: #3d4a88; }
.tech-mark.medicine { background: #3f8a72; }
.tech-mark.load { background: #6a6248; }

#panel h2, #panel h3 {
  font-family: Georgia, "Times New Roman", serif;
  margin: 0 0 8px;
}
#panel h2 {
  margin: 0 -12px 10px;
  padding: 8px 12px;
  text-align: center;
  background: linear-gradient(#f3d48a, #e2b45a);
  border-bottom: 2px solid #b8883a;
  font-size: 18px;
}
#panel h3 { margin-top: 14px; font-size: 16px; }
#panel p { margin: 8px 0; line-height: 1.4; }
#panel ul { margin: 8px 0; padding-left: 18px; }
.role { color: #6a4a28; }
.warn { color: #8d2b1f; }
.gem { font-size: 13px; }

.pill {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.04em;
  border-radius: 999px;
  padding: 2px 6px;
  vertical-align: middle;
}
.pill.locked { background: #d9efe0; color: #1d5c38; }
.pill.estimated { background: #fde7c2; color: #7a4b08; }
.pill.placeholder { background: #f6d4d0; color: #7a261c; }

.build-list { display: flex; flex-direction: column; gap: var(--btn-gap); }
.build-list button { text-align: left; }
.tech-list { display: flex; flex-direction: column; gap: 8px; }
.tech {
  border: 1px solid #ddc48f;
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 248, 230, 0.7);
}
.tech b { font-size: 14px; }
.tech p, .tech ul { margin: 4px 0; font-size: 13px; }

.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#auth[hidden],
#shell[hidden] {
  display: none !important;
}
.auth-card {
  width: min(100%, 360px);
  padding: 0 22px 22px;
  background: linear-gradient(#f8e7c0, #f0d3a2);
  border: 4px solid #6b4320;
  border-radius: 0;
  box-shadow: 0 0 0 3px #e2b45a, 0 18px 40px rgba(0, 0, 0, 0.45);
}
.auth-card h1 {
  margin: 0 -22px 16px;
  padding: 10px 22px;
  text-align: center;
  font-family: Georgia, "Times New Roman", serif;
  color: #3a2412;
  background: linear-gradient(#f3d48a, #e2b45a);
  border-bottom: 2px solid #b8883a;
}
.auth-lead { margin: 0 0 16px; font-size: 14px; }
.auth-card label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
}
.auth-card input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--gold-deep);
  border-radius: 0;
  font: inherit;
}
.auth-actions { display: flex; flex-direction: column; gap: var(--btn-gap); margin-top: 8px; }
.auth-actions button.secondary { background: #f4e2bf; }
.auth-error { color: #7a261c; font-size: 13px; margin: 0 0 8px; }
#chat { display: flex; flex-direction: column; gap: 8px; align-items: stretch; margin-top: 8px; }
#chat label { font-size: 13px; color: #f6e7c1; }
#chat input { display: block; width: 100%; margin-top: 4px; padding: 6px 8px; font: inherit; border: 1px solid #c9a15a; border-radius: 0; }
#chat-log { width: 100%; margin: 0; font-size: 13px; color: #f0d7a4; }
#reports .report { margin: 0 0 8px; padding-bottom: 8px; border-bottom: 1px solid rgba(215, 181, 106, 0.35); color: #f6e7c1; }
#reports .report b { margin-right: 6px; }

#items-root { color: #3a2614; font-size: 13px; }
#items-root h3 { margin: 12px 0 6px; font-size: 14px; color: #5a3a18; }
#items-root .shop-row,
#items-root .bag-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 6px 8px;
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(90, 58, 24, 0.2);
}
#items-root .shop-copy { flex: 1 1 140px; }
#items-root .shop-copy p { margin: 2px 0 0; font-size: 12px; color: #5a4a38; }
#items-root .shop-gold { color: #8a6410; font-weight: 700; }
#items-root .item-prompt {
  margin: 8px 0;
  padding: 8px;
  background: rgba(255, 248, 230, 0.65);
  border: 1px solid #b8883a;
}
#items-root .item-prompt input { width: 5em; margin: 0 6px 0 0; }
#items-root .side-empty { color: #5a4a38; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 40;
  transform: translateX(-50%);
  background: #2a2118;
  color: #f6e7c1;
  padding: 10px 16px;
  border-radius: 0;
  border: 2px solid #e0a23a;
}

/* Narrow desktop windows (not the phone shell): same stack as pre–mobile PR. */
@media (max-width: 860px) {
  html:not(.is-mobile) .client-body { grid-template-columns: 1fr; }
  html:not(.is-mobile) #side { max-height: 420px; }
  html:not(.is-mobile) #view { height: auto; min-height: 420px; }
}

/* Phone and narrow windows. html.is-mobile is set in js/mobile.js.
   Wide desktop layouts above do not use these rules. */
html.is-mobile {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
  --mobile-nav-height: calc(48px + env(safe-area-inset-bottom));
  --castle-dock-height: 64px;
  --mobile-bottom-stack: calc(var(--mobile-nav-height) + var(--castle-dock-height));
}

html.is-mobile body {
  height: 100%;
  overflow: hidden;
}

html.is-mobile #shell {
  height: 100vh;
  height: 100dvh;
  padding: 0;
  gap: 0;
  box-shadow: none;
  background: #140c07;
}

html.is-mobile .client-top {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  height: auto;
  gap: 4px 6px;
  padding: max(4px, env(safe-area-inset-top)) 6px 4px;
  border: 0;
  border-bottom: 2px solid #d7b56a;
}

html.is-mobile .brand {
  grid-column: 1;
  grid-row: 1;
  flex: 0 0 auto;
  z-index: 1;
  align-self: center;
}
html.is-mobile .mark { font-size: 15px; }

html.is-mobile .top-cluster {
  grid-column: 1 / -1;
  grid-row: 1 / 3;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 4px 6px;
  align-items: center;
  min-width: 0;
}

html.is-mobile #logout {
  height: 28px;
  min-width: 0;
  padding: 0 8px;
  font-size: 12px;
  line-height: 24px;
}

html.is-mobile #resources {
  grid-column: 1 / -1;
  grid-row: 2;
  position: static;
  left: auto;
  transform: none;
  z-index: auto;
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: clamp(2px, 1vw, 6px);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 0 2px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  pointer-events: auto;
}
html.is-mobile #resources::-webkit-scrollbar {
  display: none;
}
html.is-mobile .status-right {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex: 0 0 auto;
  justify-content: flex-end;
  gap: 8px;
  margin: 0;
  margin-left: auto;
  position: static;
  z-index: auto;
  padding-left: 0;
  background: transparent;
}
html.is-mobile .res-chip {
  flex: 1 1 0;
  min-width: 0;
  justify-content: center;
  font-size: clamp(8px, 2.35vw, 11px);
  gap: 2px;
  pointer-events: auto;
}
html.is-mobile .gold-amt,
html.is-mobile .tax-amt { font-size: 11px; }
html.is-mobile .res-chip::before { width: 8px; height: 8px; flex-shrink: 0; }
html.is-mobile .mood { width: 40px; height: 14px; }

@media (min-width: 700px) {
  html.is-mobile #resources {
    gap: clamp(4px, 1vw, 8px);
  }
  html.is-mobile .res-chip { font-size: 12px; }
}

html.is-mobile .client-body {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
}

html.is-mobile #play {
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
  gap: 0;
}

html.is-mobile main {
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
}

html.is-mobile #view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  touch-action: none;
}

html.is-mobile .play-hud-top {
  top: max(8px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  padding: 0 8px;
  box-sizing: border-box;
}
html.is-mobile .play-hud-top #queues {
  margin-left: 0;
  width: 100%;
  max-width: none;
}
html.is-mobile .view-mode-toggle {
  max-width: min(320px, 100%);
  border-width: 1px;
  box-shadow: 0 0 0 1px #e2b45a, 0 2px 4px rgba(0, 0, 0, 0.2);
}
html.is-mobile .view-mode-toggle button {
  min-height: 18px;
  min-width: 58px;
  padding: 2px 8px;
  font-size: 7px;
}
html.is-mobile .view-mode-toggle button.on {
  box-shadow: inset 0 0 0 1px #fff4d4;
}
html.is-mobile .queue-dock {
  gap: 1px;
}
html.is-mobile .queue-active {
  min-height: 18px;
  font-size: 7px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
}
html.is-mobile .queue-active-idle {
  padding: 1px 4px;
}
html.is-mobile .queue-active-body {
  gap: 3px;
  padding: 1px 2px 1px 4px;
  min-height: 18px;
}
html.is-mobile .queue-cancel {
  width: 18px;
  min-width: 18px;
  height: 18px;
  font-size: 9px;
}
html.is-mobile .queue-march {
  padding: 1px 3px;
  font-size: 5px;
}
html.is-mobile .queue-tabs { gap: 1px; }
html.is-mobile .queue-tab {
  min-height: 18px;
  padding: 2px 2px;
  font-size: clamp(6px, 1.6vw, 7px);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
html.is-mobile .queue-tab.on {
  box-shadow: inset 0 0 0 1px #fff4d4;
}

html.is-mobile #map-bar {
  top: auto;
  bottom: calc(8px + var(--mobile-bottom-stack) + var(--touch-target) + 8px);
  left: 8px;
  right: 8px;
  max-width: none;
  justify-content: center;
  z-index: 11;
}
html.is-mobile #map-bar input[type="number"],
html.is-mobile #map-bar button {
  min-height: var(--touch-target);
  font-size: 14px;
}

html.is-mobile #map-home {
  left: 8px;
  right: 8px;
  top: auto;
  bottom: calc(8px + var(--mobile-bottom-stack));
  width: auto;
  z-index: 12;
  min-height: var(--touch-target);
  padding: 6px 12px;
  font-size: 14px;
  text-align: center;
}
html.is-mobile body[data-game-view="map"] #panel.map-detail {
  top: auto;
  left: 8px;
  right: 8px;
  bottom: calc(16px + var(--mobile-bottom-stack) + var(--touch-target) * 2);
  width: auto;
  max-height: min(32vh, 260px);
  z-index: 8;
  border-width: 3px;
  box-shadow: 0 -8px 22px rgba(0, 0, 0, 0.4);
}

html.is-mobile #panel:not(.map-detail) {
  top: auto;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-height: min(40vh, 380px);
  z-index: 8;
  border-width: 3px 0 0;
  box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.45);
}
html.is-mobile #panel h2 {
  position: sticky;
  top: 0;
  z-index: 1;
}
html.is-mobile #panel button {
  display: block;
  width: 100%;
  min-height: var(--touch-target);
  margin: var(--btn-gap) 0 0;
  white-space: normal;
  text-align: center;
  font-size: 14px;
}
html.is-mobile #panel input,
html.is-mobile #panel select {
  width: 100%;
  max-width: 100%;
  min-height: var(--touch-target);
  font-size: 14px;
  margin-top: 4px;
}
html.is-mobile #panel label { display: block; margin-top: 8px; }
html.is-mobile #panel .tax-row input[type="range"] { width: auto; flex: 1; }

html.is-mobile #side {
  display: none;
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  max-height: min(42vh, 400px);
  overflow: hidden;
  padding: 0;
  border-width: 3px 0 0;
  border-color: #d7b56a;
  box-shadow: 0 -12px 28px rgba(0, 0, 0, 0.5);
}
html.is-mobile body[data-sheet="lord"] #side,
html.is-mobile body[data-sheet="castles"] #side,
html.is-mobile body[data-sheet="messages"] #side {
  display: flex;
  flex-direction: column;
}
html.is-mobile .mobile-sheet-head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  padding: 6px 8px 6px 14px;
  background: linear-gradient(#f3d48a, #e2b45a);
  border-bottom: 2px solid #b8883a;
}
html.is-mobile .mobile-sheet-head h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  color: #3a2412;
}
html.is-mobile #mobile-sheet-close {
  min-height: var(--touch-target);
  min-width: 64px;
  margin: 0;
  padding: 6px 10px;
  background: #3a2412;
  color: #f6e7c1;
  border-color: #140c07;
  box-shadow: none;
  text-align: center;
  font-size: 14px;
}
html.is-mobile #side .side-pane { display: none; }
html.is-mobile body[data-sheet="lord"] #side [data-pane="lord"],
html.is-mobile body[data-sheet="castles"] #side [data-pane="castles"],
html.is-mobile body[data-sheet="messages"] #side [data-pane="messages"] {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 12px 12px 16px;
  -webkit-overflow-scrolling: touch;
}
html.is-mobile .side-player { font-size: 22px; }
html.is-mobile .side-race { font-size: 16px; }
html.is-mobile .leaderboard-tabs button { font-size: 13px; min-height: var(--touch-target); }
html.is-mobile .leaderboard-list { max-height: none; }
html.is-mobile .leaderboard-row { font-size: 15px; }
html.is-mobile .side-empty,
html.is-mobile #chat label,
html.is-mobile #chat-log,
html.is-mobile #reports .report { font-size: 15px; line-height: 1.4; }
html.is-mobile [data-pane="castles"] .castle-row {
  display: none;
}
html.is-mobile #castle-dock {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  justify-content: center;
  position: relative;
  z-index: 25;
  min-height: var(--castle-dock-height);
  padding: 4px 6px;
  background: linear-gradient(#3a2414, #2a180e);
  border-top: 2px solid #d7b56a;
}
html.is-mobile #castle-dock .castle-row {
  margin-bottom: 0;
}
html.is-mobile #castle-dock .castle-arrow {
  display: none;
}
html.is-mobile .castle-row .castle-arrow {
  width: 36px;
  min-width: 36px;
  height: 52px;
  font-size: 24px;
}
html.is-mobile .castle-scroll button {
  height: 56px;
  min-height: 36px;
}
html.is-mobile #new-game,
html.is-mobile #chat button,
html.is-mobile #chat input {
  min-height: var(--touch-target);
  font-size: 14px;
  text-align: center;
}
html.is-mobile #chat input { text-align: left; }

html.is-mobile .mobile-nav {
  display: flex;
  flex: 0 0 auto;
  position: relative;
  z-index: 30;
  align-items: stretch;
  gap: 3px;
  min-height: calc(48px + env(safe-area-inset-bottom));
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  background: linear-gradient(#3a2414, #140c07);
  border-top: 2px solid #d7b56a;
}
html.is-mobile .mobile-nav button {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--touch-target);
  margin: 0;
  padding: 4px 2px;
  font-size: clamp(10px, 3vw, 13px);
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
  background: transparent;
  color: #f6e7c1;
  border: 2px solid transparent;
  box-shadow: none;
}
html.is-mobile .mobile-nav button.on {
  background: linear-gradient(#ffe7a8, #e0a23a);
  color: #3a2412;
  border-color: #6b4320;
  box-shadow: inset 0 1px 0 #fff1cc;
}

html.is-mobile #academy-window {
  z-index: 60;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  background: rgba(20, 12, 7, 0.55);
}
html.is-mobile .academy-card {
  width: 100%;
  height: 100%;
  max-height: 100%;
  border-radius: 0;
  overflow: hidden;
}
html.is-mobile .academy-top,
html.is-mobile .academy-split {
  grid-template-columns: 1fr;
}
html.is-mobile .academy-split {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}
html.is-mobile .academy-list,
html.is-mobile .academy-queue { max-height: none; min-height: 0; }
html.is-mobile .academy-title { padding-right: 64px; }
html.is-mobile .academy-title button,
html.is-mobile .academy-x {
  width: var(--touch-target);
  height: var(--touch-target);
  top: 6px;
}
html.is-mobile .academy-tools button,
html.is-mobile .academy-tech button,
html.is-mobile .academy-offer button {
  float: none;
  display: block;
  width: 100%;
  min-height: var(--touch-target);
  margin-top: var(--btn-gap);
  font-size: 14px;
}
html.is-mobile .academy-study { grid-template-columns: 1fr auto; }

html.is-mobile #store-window,
html.is-mobile #leaderboard-window {
  z-index: 60;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  background: rgba(20, 12, 7, 0.55);
}
html.is-mobile .store-card,
html.is-mobile .leaderboard-card {
  width: 100%;
  height: 100%;
  max-height: 100%;
  border-radius: 0;
}
html.is-mobile .store-title,
html.is-mobile .leaderboard-title { padding-right: 64px; }
html.is-mobile .store-title button,
html.is-mobile .leaderboard-title button {
  width: var(--touch-target);
  height: var(--touch-target);
  top: 6px;
}
html.is-mobile .hud-action-btn {
  min-height: var(--touch-target);
  font-size: clamp(10px, 3vw, 13px);
  padding: 4px 10px;
}

html.is-mobile .auth {
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: auto;
  align-items: center;
  padding:
    max(16px, env(safe-area-inset-top))
    16px
    max(16px, env(safe-area-inset-bottom));
}
html.is-mobile .auth-card {
  width: 100%;
  max-width: 440px;
}
html.is-mobile .auth-card label { font-size: 15px; }
html.is-mobile .auth-card input,
html.is-mobile .auth-actions button {
  min-height: 40px;
  font-size: 15px;
}
html.is-mobile .auth-lead { font-size: 16px; line-height: 1.4; }

html.is-mobile #toast {
  z-index: 70;
  bottom: calc(56px + env(safe-area-inset-bottom));
  max-width: calc(100% - 24px);
  text-align: center;
  font-size: 14px;
}

html.is-mobile button {
  touch-action: manipulation;
}
