:root {
  --wood-dark: #1d120a;
  --wood: #3a2414;
  --parchment: #f1e2bf;
  --parchment-dark: #d9c294;
  --ink: #2b1d0e;
  --gold: #d9a441;
  --red: #b23a2a;
  --blue: #2f5fb3;
  --green: #3d8a3a;
  --card-w: 128px;
  --tower-max: 250px; /* tower height at the victory target; read by app.js */
  --roof-h: 46px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: 'Crimson Text', Georgia, serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 190, 90, 0.18), transparent 60%),
    repeating-linear-gradient(90deg, #2a1a0e 0 120px, #24160b 120px 122px, #2d1c0f 122px 240px),
    var(--wood-dark);
  overflow: hidden;
}
body { height: 100dvh; }
button, .hand { touch-action: manipulation; }

.hidden { display: none !important; }

h1, h2, h3, .title { font-family: 'Cinzel', Georgia, serif; }

.title {
  margin: 0;
  font-size: 64px;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--gold);
  text-shadow: 0 2px 0 #5a3a10, 0 4px 12px rgba(0, 0, 0, 0.6);
}
.title.small { font-size: 28px; }
.title.win { color: #f5c94a; }
.title.lose { color: #c4483a; }

.parchment {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, 0.35), transparent 60%),
    radial-gradient(ellipse at 80% 90%, rgba(120, 80, 30, 0.18), transparent 60%),
    var(--parchment);
  border: 3px solid #6b4a22;
  border-radius: 8px;
  box-shadow: 0 0 0 2px #2a1a08, 0 8px 24px rgba(0, 0, 0, 0.55), inset 0 0 40px rgba(110, 70, 20, 0.25);
}

.btn {
  font-family: 'Cinzel', Georgia, serif;
  font-weight: 600;
  font-size: 14px;
  padding: 7px 14px;
  border: 2px solid #5a3a14;
  border-radius: 6px;
  background: linear-gradient(#e8cf96, #c9a25c);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 2px 0 #5a3a14;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); box-shadow: 0 1px 0 #5a3a14; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: linear-gradient(#f3c75c, #c98a1e); }
.btn.danger { background: linear-gradient(#e08a7a, #b04a36); color: #fff8ec; }
.btn.big { width: 100%; font-size: 18px; padding: 12px; }
.btn.searching { animation: pulse 1.2s infinite; }

@keyframes pulse { 50% { filter: brightness(1.25); } }

input, select {
  font-family: inherit;
  font-size: 16px;
  padding: 6px 8px;
  border: 2px solid #8a6a3a;
  border-radius: 5px;
  background: #fbf3df;
  color: var(--ink);
}

.error { color: #a12a1a; min-height: 1.4em; margin-top: 8px; font-weight: bold; }
.hint { font-size: 14px; font-style: italic; color: #6a5030; margin: 6px 0; }

.screen { position: absolute; inset: 0; }

/* ------------------------------------------------------------------ login */

#screen-login { display: flex; align-items: center; justify-content: center; }
.login-box { padding: 30px 50px; text-align: center; max-width: 640px; }
.login-box .subtitle { font-style: italic; font-size: 18px; margin: 4px 0 18px; }
.login-cards { display: flex; justify-content: center; gap: 12px; margin-bottom: 20px; }
.login-cards .card:nth-child(1) { transform: rotate(-7deg) translateY(8px); }
.login-cards .card:nth-child(3) { transform: rotate(7deg) translateY(8px); }
#login-form { display: flex; gap: 8px; justify-content: center; }
#name-input { width: 280px; }

/* ------------------------------------------------------------------ lobby */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 24px;
  background: linear-gradient(#1a0f07, #2b1a0c);
  border-bottom: 3px solid #6b4a22;
  color: var(--parchment);
}
.tavern-sign { font-family: 'Cinzel', serif; font-size: 18px; color: var(--parchment-dark); }
.whoami { margin-left: auto; font-size: 18px; }

.lobby {
  display: grid;
  grid-template-columns: 280px 1fr 340px;
  gap: 18px;
  padding: 18px;
  height: calc(100% - 66px);
}
.panel { padding: 14px 16px; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.panel h2 { margin: 0 0 10px; font-size: 20px; border-bottom: 2px solid #b0915a; padding-bottom: 4px; }
.play-panel { overflow-y: auto; }
.play-panel h2:not(:first-child) { margin-top: 18px; }

.player-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 0 1 auto; }
.player {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  border-bottom: 1px dashed #c4a873;
}
.player:hover:not(.self) { background: rgba(217, 164, 65, 0.35); }
.player.self { cursor: default; font-weight: bold; }
.player .pname { font-size: 17px; }
.player .badge { font-size: 12px; padding: 1px 6px; border-radius: 8px; background: #d8c497; white-space: nowrap; }
.player.status-searching .badge { background: #f0cf6a; }
.player.status-playing .badge { background: #c9a2a2; }
.player.status-playing { opacity: 0.7; }

.challenge { margin-top: 10px; padding: 8px 10px; border-radius: 6px; border: 2px solid #8a6a3a; background: #fbf0d5; }
.challenge.incoming { border-color: #c98a1e; box-shadow: 0 0 10px rgba(217, 164, 65, 0.7); animation: pulse 1.5s infinite; }
.challenge .rules { font-size: 13px; color: #5a4020; margin: 4px 0; }
.challenge .row { display: flex; gap: 8px; margin-top: 6px; }

.chat-log { flex: 1; overflow-y: auto; padding: 6px; background: rgba(255, 250, 235, 0.55); border: 1px solid #c4a873; border-radius: 4px; font-size: 16px; }
.chat-log.small { font-size: 14px; flex: 0 0 140px; }
.chat-line { margin: 2px 0; word-wrap: break-word; }
.chat-line.system { font-style: italic; color: #7a5a30; }
.chat-line .time { color: #9a8060; font-size: 12px; }
.chat-form { display: flex; gap: 6px; margin-top: 8px; }
.chat-form input { flex: 1; min-width: 0; }

.bot-row { display: flex; gap: 8px; margin-top: 10px; }
.bot-row select { flex: 1; min-width: 0; }
.preset-row { display: flex; align-items: center; gap: 8px; font-weight: bold; margin-bottom: 8px; }
.preset-row select { flex: 1; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.settings-grid label { display: flex; flex-direction: column; font-size: 13px; font-weight: bold; }
.settings-grid input { width: 100%; padding: 3px 6px; font-size: 15px; }

/* ------------------------------------------------------------------ cards */

.card {
  position: relative;
  width: var(--card-w);
  height: calc(var(--card-w) * 1.45);
  border-radius: 8px;
  border: 3px solid #2a1a08;
  padding: 4px;
  display: flex;
  flex-direction: column;
  font-family: 'Crimson Text', Georgia, serif;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5);
  user-select: none;
  flex-shrink: 0;
}
.card-red { background: linear-gradient(160deg, #e9b39a, #b8553c 70%, #8a3020); }
.card-blue { background: linear-gradient(160deg, #a9c3ef, #4a78c8 70%, #2a4c8a); }
.card-green { background: linear-gradient(160deg, #b4dca2, #4f9a45 70%, #2e6a2a); }

.card-name {
  font-family: 'Cinzel', Georgia, serif;
  font-weight: 800;
  font-size: calc(var(--card-w) * 0.085);
  text-align: center;
  background: rgba(255, 245, 220, 0.85);
  border-radius: 4px;
  padding: 1px 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-art {
  position: relative;
  margin-top: 4px;
  height: calc(var(--card-w) * 0.62);
  border: 2px solid #2a1a08;
  border-radius: 3px;
  overflow: hidden;
  background: #000;
}
.art-bg { position: absolute; inset: 0; width: 100%; height: 100%; }
.art-glyph {
  position: absolute;
  left: 50%;
  top: 54%;
  transform: translate(-50%, -50%);
  font-size: calc(var(--card-w) * 0.34);
  line-height: 1;
  text-shadow: 0 3px 6px rgba(0, 0, 0, 0.6);
}
.art-accent {
  position: absolute;
  right: 6%;
  top: 6%;
  font-size: calc(var(--card-w) * 0.15);
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7));
}
.card-text {
  flex: 1;
  margin-top: 4px;
  padding: 2px 4px 2px;
  font-size: calc(var(--card-w) * 0.088);
  line-height: 1.15;
  text-align: center;
  background: rgba(255, 245, 220, 0.85);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: calc(var(--card-w) * 0.1);
}
.card-cost {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: calc(var(--card-w) * 0.24);
  height: calc(var(--card-w) * 0.24);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-size: calc(var(--card-w) * 0.12);
  color: #fff;
  border: 2px solid #2a1a08;
  text-shadow: 0 1px 2px #000;
}
.card-red .card-cost { background: radial-gradient(circle at 35% 35%, #f08a6a, #9a2a16); }
.card-blue .card-cost { background: radial-gradient(circle at 35% 35%, #8ab4ff, #1c3f8a); }
.card-green .card-cost { background: radial-gradient(circle at 35% 35%, #8ad67a, #1e5e1a); }

.card-back {
  background:
    repeating-linear-gradient(45deg, rgba(255, 220, 140, 0.15) 0 6px, transparent 6px 12px),
    radial-gradient(circle, #7a2a1a, #3a0e06);
  align-items: center;
  justify-content: center;
}
.back-emblem {
  font-family: 'Cinzel', serif;
  font-weight: 800;
  color: var(--gold);
  font-size: calc(var(--card-w) * 0.5);
  text-shadow: 0 2px 4px #000;
}
.card.mini { --card-w: 34px; border-width: 2px; padding: 0; border-radius: 4px; }

/* ------------------------------------------------------------------ game */

.game { display: grid; grid-template-columns: 1fr 280px; height: 100%; }
.board { display: flex; flex-direction: column; min-width: 0; padding: 8px 14px; position: relative; }

.hud { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; color: var(--parchment); }
.hud-name { font-family: 'Cinzel', serif; font-size: 22px; font-weight: 800; transition: opacity 0.4s, text-shadow 0.4s; }
.hud-name.idle { opacity: 0.5; }
.hud-name.active { text-shadow: 0 0 12px currentColor; }
.turn-arrow { display: inline-block; margin: 0 8px; opacity: 0; font-size: 18px; vertical-align: middle; }
.hud-name.active .turn-arrow { opacity: 1; animation: nudge 0.9s ease-in-out infinite; }
.hud-name.opp.active .turn-arrow { animation-name: nudgeLeft; }
@keyframes nudge { 50% { transform: translateX(5px); } }
@keyframes nudgeLeft { 50% { transform: translateX(-5px); } }
.hud-name.you { color: #ff9a7a; }
.hud-name.opp { color: #8ab4ff; text-align: right; }
.bot-tag { font-size: 12px; background: #8ab4ff; color: #102040; padding: 1px 6px; border-radius: 6px; vertical-align: middle; }
.hud-center { text-align: center; }
.turn-banner {
  font-family: 'Cinzel', serif;
  font-size: 24px;
  font-weight: 800;
  padding: 3px 28px;
  border-radius: 8px;
  border: 2px solid transparent;
  transition: background 0.4s, color 0.4s;
}
.turn-banner.mine {
  color: #2b1d0e;
  background: linear-gradient(#f3c75c, #c98a1e);
  border-color: #fff0b0;
  animation: bannerGlow 1.6s ease-in-out infinite;
}
.turn-banner.theirs {
  color: #e8f0ff;
  background: linear-gradient(#3a6ad2, #1c3a7a);
  border-color: #8ab4ff;
  box-shadow: 0 0 12px rgba(100, 150, 255, 0.5);
}
.turn-banner.over { color: var(--parchment-dark); }
.turn-number { font-size: 13px; color: var(--parchment-dark); letter-spacing: 1px; text-transform: uppercase; }
@keyframes bannerGlow {
  0%, 100% { box-shadow: 0 0 10px rgba(243, 199, 92, 0.5); }
  50% { box-shadow: 0 0 28px rgba(255, 215, 110, 0.95); }
}
.turn-timer { font-size: 18px; color: var(--parchment); min-height: 1.2em; }
.turn-timer.urgent { color: #ff6a5a; font-weight: bold; }
.goal { text-align: center; color: var(--parchment-dark); font-style: italic; font-size: 14px; }

.field { flex: 1; display: grid; grid-template-columns: 150px 1fr 150px; gap: 10px; min-height: 0; align-items: end; }

.stats { display: flex; flex-direction: column; gap: 8px; align-self: center; }
.stats-name { font-family: 'Cinzel', serif; text-align: center; color: var(--parchment); font-weight: 800; }
.stats-name.you { color: #ff9a7a; }
.stats-name.opp { color: #8ab4ff; }
.res {
  border: 3px solid #2a1a08;
  border-radius: 8px;
  padding: 6px 8px;
  color: #fff;
  text-shadow: 0 1px 2px #000;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5), inset 0 0 18px rgba(0, 0, 0, 0.35);
  position: relative;
}
.res-red { background: linear-gradient(#c8553c, #7a2010); }
.res-blue { background: linear-gradient(#4f7fd2, #1c3a7a); }
.res-green { background: linear-gradient(#55a54a, #1e5a1a); }
.res-gen { display: flex; justify-content: space-between; font-family: 'Cinzel', serif; font-weight: 800; font-size: 15px; }
.res-gen-val { font-size: 22px; color: #ffe08a; }
.res-icon { position: absolute; right: 8px; bottom: 4px; font-size: 22px; opacity: 0.85; }
.res-stock { font-size: 16px; }
.res-stock-val { font-weight: bold; font-size: 20px; }

.castles { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; height: 100%; min-height: 0; }
.castle { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.castle-structures { display: flex; align-items: flex-end; gap: 10px; }
.castle.opp .castle-structures { flex-direction: row-reverse; }
.tower { width: 58px; display: flex; flex-direction: column; transition: height 0.7s ease; }
.tower .roof {
  height: var(--roof-h);
  flex-shrink: 0;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  background: linear-gradient(90deg, #7a1a10, #d24a2a 50%, #7a1a10);
}
.tower.opp .roof { background: linear-gradient(90deg, #142a6a, #3a6ad2 50%, #142a6a); }
.tower-body {
  flex: 1;
  margin: 0 4px;
  background:
    repeating-linear-gradient(0deg, transparent 0 11px, rgba(0, 0, 0, 0.35) 11px 12px),
    repeating-linear-gradient(90deg, transparent 0 15px, rgba(0, 0, 0, 0.25) 15px 16px),
    linear-gradient(90deg, #6e6a62, #b2ab9c 45%, #6e6a62);
  border: 2px solid #2a2520;
  border-bottom: none;
}
.wall-wrap { display: flex; align-items: flex-end; }
.wall {
  width: 26px;
  transition: height 0.7s ease;
  background:
    repeating-linear-gradient(0deg, transparent 0 8px, #3a1e0e 8px 9px),
    repeating-linear-gradient(90deg, transparent 0 12px, rgba(58, 30, 14, 0.7) 12px 13px),
    linear-gradient(90deg, #8a4a2a, #c2703e 50%, #8a4a2a);
  border: 2px solid #3a1e0e;
  border-bottom: none;
}
.plaques { display: flex; gap: 10px; margin: 6px 0 4px; }
.castle.opp .plaques { flex-direction: row-reverse; }
.plaque {
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-size: 18px;
  min-width: 44px;
  text-align: center;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--parchment);
  border: 2px solid #6b4a22;
}
.plaque.tower-val::before { content: '🏰 '; font-size: 13px; }
.plaque.wall-val::before { content: '🧱 '; font-size: 13px; }

.table-cards {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  min-width: 440px;
}
.table-slot { position: relative; --card-w: 96px; margin-left: -34px; transition: all 0.3s; }
.table-slot:first-child { margin-left: 0; }
.table-slot.latest-slot { --card-w: 128px; margin-left: -14px; z-index: 2; }
.table-cards .card { opacity: 0.7; }
.table-cards .card.latest { opacity: 1; }
.table-cards .card.by-you { box-shadow: 0 0 0 3px rgba(255, 140, 110, 0.8), 0 3px 8px rgba(0, 0, 0, 0.5); }
.table-cards .card.by-opp { box-shadow: 0 0 0 3px rgba(130, 170, 255, 0.8), 0 3px 8px rgba(0, 0, 0, 0.5); }
.table-cards .card.fresh { animation: dealIn 0.5s ease-out; }
.table-cards .card.discarded { filter: grayscale(0.7) brightness(0.8); }
.stamp {
  position: absolute;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%) rotate(-18deg);
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-size: 15px;
  color: #c4241a;
  border: 3px solid #c4241a;
  border-radius: 4px;
  padding: 0 6px;
  background: rgba(255, 240, 220, 0.8);
  pointer-events: none;
}
@keyframes dealIn {
  from { transform: translateY(160px) scale(0.6); opacity: 0; }
}

.opp-hand { display: flex; justify-content: center; gap: 4px; margin-top: 6px; opacity: 0.85; }

.hand-area { padding-top: 6px; }
.hand-hint { text-align: center; color: var(--parchment-dark); font-style: italic; min-height: 1.3em; font-size: 15px; }
.hand { display: flex; justify-content: center; gap: 10px; padding: 6px 0 4px; min-height: calc(var(--card-w) * 1.45 + 14px); }
.hand-slot { position: relative; transition: transform 0.15s; }
.hand .card { cursor: pointer; }
.hand .card.unaffordable { filter: saturate(0.5) brightness(0.8); }
.hand .card.waiting { cursor: default; }
.hand .card.playable { box-shadow: 0 0 0 2px #ffe08a, 0 0 14px rgba(255, 210, 110, 0.75); }
.hand-slot:hover { transform: translateY(-14px) scale(1.06); z-index: 2; }
.hand.discard-mode .card { box-shadow: 0 0 0 3px #ff6a5a, 0 0 14px rgba(255, 90, 70, 0.7); }
.discard-btn {
  position: absolute;
  left: 50%;
  bottom: -4px;
  transform: translateX(-50%);
  font-size: 11px;
  font-family: 'Cinzel', serif;
  font-weight: 800;
  border: 2px solid #5a1a10;
  border-radius: 10px;
  background: #e07a6a;
  color: #fff;
  padding: 1px 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.hand-slot:hover .discard-btn { opacity: 1; }

.game-side { margin: 8px; padding: 10px 12px; display: flex; flex-direction: column; min-height: 0; }
.game-side h3 { margin: 10px 0 6px; font-size: 16px; border-bottom: 2px solid #b0915a; }
.side-buttons { display: flex; gap: 8px; }
.side-buttons .btn { flex: 1; }
.game-log { flex: 1; overflow-y: auto; font-size: 14px; background: rgba(255, 250, 235, 0.55); border: 1px solid #c4a873; border-radius: 4px; padding: 4px 6px; }

.float-delta {
  position: fixed;
  z-index: 50;
  transform: translate(-50%, -50%);
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-size: 24px;
  pointer-events: none;
  text-shadow: 0 2px 3px #000;
  animation: floatUp 1.5s ease-out forwards;
}
.float-delta.up { color: #7dff6a; }
.float-delta.down { color: #ff5a4a; }
@keyframes floatUp {
  from { opacity: 1; margin-top: 0; }
  to { opacity: 0; margin-top: -50px; }
}

/* ------------------------------------------------------------------ overlays */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 5, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
}
.modal { padding: 24px 36px; text-align: center; max-width: 520px; }
.modal p { font-size: 19px; }
.modal-buttons { display: flex; gap: 12px; justify-content: center; }
.modal.wide { max-width: 92vw; width: 1200px; max-height: 90vh; display: flex; flex-direction: column; }
.deck-head { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
.deck-head h2 { margin: 0; }
.deck-filters { display: flex; gap: 6px; flex: 1; justify-content: center; }
.btn.filter.active { background: linear-gradient(#f3c75c, #c98a1e); }
.deck-grid { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; overflow-y: auto; padding: 8px; }

.toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--parchment); border: 2px solid #6b4a22; border-radius: 6px; padding: 8px 16px; font-size: 17px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5); transition: opacity 0.5s; }
.toast.error { border-color: #a12a1a; color: #a12a1a; }
.toast.gold { background: linear-gradient(#f3d27a, #e0a840); font-weight: bold; }
.toast.fade { opacity: 0; }

/* ------------------------------------------------------------------ turn state */

.board::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s;
  z-index: 0;
}
.board.turn-you::before {
  opacity: 1;
  background: radial-gradient(ellipse at 30% 100%, rgba(255, 190, 90, 0.22), transparent 55%);
}
.board.turn-opp::before {
  opacity: 1;
  background: radial-gradient(ellipse at 70% 0%, rgba(90, 140, 255, 0.2), transparent 55%);
}
.board > * { position: relative; z-index: 1; }
.board > .turn-splash { position: absolute; z-index: 30; }

.stats, .castle { transition: opacity 0.5s, filter 0.5s; }
.stats.idle, .castle.idle { opacity: 0.6; filter: saturate(0.6) brightness(0.85); }
.stats.active .res { animation: resGlowYou 1.8s ease-in-out infinite; }
#stats-opp.active .res { animation-name: resGlowOpp; }
@keyframes resGlowYou {
  0%, 100% { box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5), 0 0 6px rgba(255, 160, 110, 0.4); }
  50% { box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5), 0 0 18px rgba(255, 160, 110, 0.9); }
}
@keyframes resGlowOpp {
  0%, 100% { box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5), 0 0 6px rgba(130, 170, 255, 0.4); }
  50% { box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5), 0 0 18px rgba(130, 170, 255, 0.9); }
}

.castle { position: relative; }
.castle.active::before {
  content: '';
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 0;
  height: 70%;
  border-radius: 50% 50% 0 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 100%, rgba(255, 180, 100, 0.35), transparent 70%);
  animation: auraPulse 2s ease-in-out infinite;
}
.castle.opp.active::before { background: radial-gradient(ellipse at 50% 100%, rgba(110, 160, 255, 0.35), transparent 70%); }
@keyframes auraPulse { 50% { opacity: 0.55; } }

.tower { position: relative; }
.tower .flag {
  position: absolute;
  left: 50%;
  top: -24px;
  width: 2px;
  height: 26px;
  background: #3a2a1a;
}
.tower .flag::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 1px;
  width: 22px;
  height: 13px;
  background: #e0503a;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  transform-origin: left center;
}
.tower.opp .flag::after { background: #4a7ae0; left: auto; right: 2px; transform-origin: right center; clip-path: polygon(100% 0, 0 50%, 100% 100%); }
.castle.active .tower .flag::after { animation: wave 0.8s ease-in-out infinite; }
@keyframes wave { 50% { transform: scaleX(0.75) skewY(8deg); } }

.turn-splash {
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-size: 54px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  letter-spacing: 3px;
}
.turn-splash.mine { color: #ffd86a; text-shadow: 0 0 20px rgba(255, 200, 80, 0.9), 0 4px 0 #5a3a10, 0 6px 16px #000; }
.turn-splash.theirs { color: #b8d0ff; text-shadow: 0 0 20px rgba(110, 160, 255, 0.9), 0 4px 0 #102040, 0 6px 16px #000; }
.turn-splash.show { animation: splash 1.5s ease-out forwards; }
@keyframes splash {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  30% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
}

.opp-hand .card { transition: box-shadow 0.4s; }
.opp-hand.thinking .card { animation: think 1.4s ease-in-out infinite; box-shadow: 0 0 8px rgba(130, 170, 255, 0.8); }
.opp-hand.thinking .card:nth-child(2) { animation-delay: 0.1s; }
.opp-hand.thinking .card:nth-child(3) { animation-delay: 0.2s; }
.opp-hand.thinking .card:nth-child(4) { animation-delay: 0.3s; }
.opp-hand.thinking .card:nth-child(5) { animation-delay: 0.4s; }
.opp-hand.thinking .card:nth-child(6) { animation-delay: 0.5s; }
.opp-hand.thinking .card:nth-child(7) { animation-delay: 0.6s; }
.opp-hand.thinking .card:nth-child(8) { animation-delay: 0.7s; }
@keyframes think { 50% { transform: translateY(5px); } }

.hand-area { border-radius: 14px; transition: background 0.5s, box-shadow 0.5s; }
.hand-area.my-turn {
  background: linear-gradient(rgba(255, 200, 90, 0), rgba(255, 200, 90, 0.14));
  box-shadow: inset 0 -3px 0 rgba(255, 210, 110, 0.6);
}
.hand-area.my-turn .hand-hint { color: #ffe08a; font-weight: bold; }
.hand-area.their-turn .hand { opacity: 0.75; }
.dots span { animation: dot 1.2s infinite; opacity: 0; }
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot { 30%, 70% { opacity: 1; } }

/* ------------------------------------------------------------------ effects */

.fx-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 45; }

.num { display: inline-block; }
.num.pop-up { animation: popUp 0.7s ease-out; }
.num.pop-down { animation: popDown 0.7s ease-out; }
@keyframes popUp {
  30% { transform: scale(1.5); color: #7dff6a; text-shadow: 0 0 10px #7dff6a; }
}
@keyframes popDown {
  20% { transform: scale(1.4) translateX(-3px); color: #ff5a4a; text-shadow: 0 0 10px #ff5a4a; }
  40% { transform: scale(1.3) translateX(3px); }
}
.res.glow-up { animation: glowUp 0.9s ease-out !important; }
.res.glow-down { animation: glowDown 0.9s ease-out !important; }
@keyframes glowUp { 30% { box-shadow: 0 0 24px 6px rgba(255, 230, 120, 0.9); filter: brightness(1.3); } }
@keyframes glowDown { 30% { box-shadow: 0 0 24px 6px rgba(255, 70, 50, 0.9); filter: brightness(0.8); } }

.build-glow { animation: buildGlow 1s ease-out; }
@keyframes buildGlow {
  30% { filter: brightness(1.45) drop-shadow(0 0 10px rgba(255, 220, 110, 0.95)); }
}
.shake { animation: shake 0.55s ease-in-out; }
@keyframes shake {
  15% { transform: translateX(-5px) rotate(-1.5deg); filter: brightness(0.8) sepia(0.5) hue-rotate(-30deg) saturate(2); }
  30% { transform: translateX(5px) rotate(1.5deg); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(3px); }
  80% { transform: translateX(-1px); }
}
.board.quake { animation: quake 0.5s ease-in-out; }
@keyframes quake {
  20% { transform: translate(-6px, 3px); }
  40% { transform: translate(6px, -3px); }
  60% { transform: translate(-4px, 2px); }
  80% { transform: translate(3px, -1px); }
}

.table-cards .card.by-opp.fresh { animation-name: dealInTop; }
@keyframes dealInTop {
  from { transform: translateY(-200px) scale(0.6) rotate(-10deg); opacity: 0; }
}
.table-owner {
  position: absolute;
  left: 50%;
  bottom: -10px;
  transform: translateX(-50%);
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-size: 11px;
  padding: 0 7px;
  border-radius: 8px;
  white-space: nowrap;
  max-width: 110%;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid #000;
  z-index: 3;
}
.table-owner.you { background: #ff9a7a; color: #3a1008; }
.table-owner.opp { background: #8ab4ff; color: #0c1c40; }
.table-slot:not(.latest-slot) .table-owner { opacity: 0.8; font-size: 10px; }

/* ------------------------------------------------------------------ chronicle */

.log-entry {
  position: relative;
  margin: 3px 0;
  padding: 3px 6px 3px 8px;
  border-left: 4px solid #b0915a;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.3);
  line-height: 1.35;
}
.log-entry.you { border-left-color: #e0603a; background: rgba(255, 150, 110, 0.14); }
.log-entry.opp { border-left-color: #3a6ad2; background: rgba(110, 150, 255, 0.14); }
.log-entry.kind-info, .log-entry.kind-discard { font-style: italic; color: #5a4020; }
.log-entry.kind-end { font-weight: bold; background: rgba(255, 210, 100, 0.45); border-left-color: #c98a1e; }
.log-entry.new { animation: logIn 0.9s ease-out; }
@keyframes logIn {
  from { transform: translateX(30px); opacity: 0; background: rgba(255, 220, 110, 0.9); }
  40% { transform: none; opacity: 1; }
}
.log-turn { float: right; font-size: 10px; color: #9a8060; margin-left: 4px; }
.log-who { font-weight: bold; font-style: normal; }
.log-who.you { color: #b0381a; }
.log-who.opp { color: #1c4aa8; }
.card-chip {
  display: inline-block;
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-style: normal;
  font-size: 12px;
  padding: 0 4px 0 6px;
  border-radius: 4px;
  border: 1px solid #2a1a08;
  color: #fff;
  text-shadow: 0 1px 1px #000;
  cursor: help;
  white-space: nowrap;
}
.chip-red { background: linear-gradient(#c8553c, #8a3020); }
.chip-blue { background: linear-gradient(#4f7fd2, #2a4c8a); }
.chip-green { background: linear-gradient(#55a54a, #2e6a2a); }
.chip-cost {
  display: inline-block;
  margin-left: 4px;
  min-width: 15px;
  text-align: center;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.35);
  font-size: 10px;
}
.log-fx { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; margin-top: 2px; font-size: 11px; }
.fx-who { font-weight: bold; margin-right: 2px; }
.fx-who.you { color: #b0381a; }
.fx-who.opp { color: #1c4aa8; }
.fx-chip { padding: 0 5px; border-radius: 7px; font-weight: bold; border: 1px solid rgba(0, 0, 0, 0.3); }
.fx-chip.up::before { content: '▲ '; font-size: 8px; }
.fx-chip.down::before { content: '▼ '; font-size: 8px; }
.fx-chip.up { box-shadow: inset 0 -2px 0 rgba(40, 160, 40, 0.6); }
.fx-chip.down { box-shadow: inset 0 -2px 0 rgba(200, 40, 30, 0.7); }
.fx-stone { background: #d8d2c4; color: #3a3428; }
.fx-red { background: #f2c0ae; color: #6a1e0e; }
.fx-blue { background: #c4d6f6; color: #1a3470; }
.fx-green { background: #c6e6bc; color: #1c4a18; }

.card-preview { position: fixed; z-index: 70; pointer-events: none; --card-w: 150px; animation: previewIn 0.15s ease-out; }
@keyframes previewIn { from { opacity: 0; transform: scale(0.9); } }

@media (prefers-reduced-motion: reduce) {
  .turn-banner.mine, .stats.active .res, .castle.active::before, .opp-hand.thinking .card,
  .hud-name.active .turn-arrow, .board.quake { animation: none !important; }
}

@media (max-height: 760px) {
  :root { --card-w: 108px; }
  .table-slot { --card-w: 84px; }
  .table-slot.latest-slot { --card-w: 108px; }
}

.sound-controls {
  position: fixed;
  left: 10px;
  bottom: 10px;
  z-index: 60;
  display: flex;
  gap: 6px;
}
.sound-controls button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid #8a6a3a;
  background: rgba(43, 26, 12, 0.75);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.sound-controls button:hover { opacity: 1; }
.sound-controls button.off { filter: grayscale(1); opacity: 0.4; }

/* ------------------------------------------------------------ learning */

.btn.link {
  margin-top: 14px;
  background: none;
  border: none;
  box-shadow: none;
  color: #6b4a22;
  text-decoration: underline;
  font-size: 15px;
}
.learn-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px 10px;
  border: 1px dashed #a3824a;
  border-radius: 6px;
  background: rgba(255, 245, 210, 0.5);
}
.learn-row { flex-wrap: wrap; }
.learn-row span { flex-basis: 100%; font-style: italic; }
.learn-row .btn { flex: 1; }

/* How to play */
.modal.rules { width: 900px; text-align: left; }
.rules .deck-head h2 { flex: 1; }
.rules-body { overflow-y: auto; padding: 0 8px 8px; font-size: 17px; line-height: 1.45; }
.rules-body h3 { margin: 18px 0 6px; border-bottom: 2px solid #b0915a; color: #5a3a14; }
.rules-body p { font-size: 17px; margin: 6px 0; }
.rules-body ul, .rules-body ol { margin: 4px 0; padding-left: 24px; }
.rules-body li { margin: 3px 0; }
.rules-lead { font-size: 19px !important; font-style: italic; }
.rules-split { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; }
.rules-cards { display: flex; gap: 8px; --card-w: 104px; }
.rules-table { border-collapse: collapse; margin: 6px 0; }
.rules-table th, .rules-table td { padding: 4px 12px; border-bottom: 1px solid #c4a873; text-align: left; }
.rules-table .row-red td:first-child { color: var(--red); font-weight: bold; }
.rules-table .row-blue td:first-child { color: var(--blue); font-weight: bold; }
.rules-table .row-green td:first-child { color: var(--green); font-weight: bold; }
.rules-cta { text-align: center; margin-top: 16px !important; }
@media (max-width: 760px) {
  .rules-split { grid-template-columns: 1fr; }
  .rules-cards { flex-wrap: wrap; }
}

/* Tutorial coach */
.board > .coach { position: absolute; z-index: 25; }
.coach {
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, 92%);
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  animation: coachIn 0.35s ease-out;
}
@keyframes coachIn { from { opacity: 0; transform: translate(-50%, -10px); } }
.coach-face {
  font-size: 40px;
  line-height: 1;
  width: 56px;
  height: 56px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(#f8e7b8, #c9a35a);
  border: 2px solid #6b4a22;
}
.coach-body { flex: 1; min-width: 0; }
.coach-name { font-family: 'Cinzel', serif; font-weight: 800; color: #7a4a14; font-size: 14px; }
.coach-text { font-size: 17px; line-height: 1.35; margin: 2px 0 6px; }
.coach-buttons { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.coach-progress { flex: 1; font-size: 13px; color: #8a6a3a; }
.coach-buttons .btn.hidden { display: none; }

.tut-glow { animation: tutGlow 1.4s ease-in-out infinite !important; border-radius: 8px; }
@keyframes tutGlow {
  0%, 100% { box-shadow: 0 0 0 2px rgba(255, 224, 138, 0.5), 0 0 8px rgba(255, 210, 110, 0.4); }
  50% { box-shadow: 0 0 0 3px #ffe08a, 0 0 26px rgba(255, 210, 110, 0.95); }
}
#hand.tut-locked .hand-slot:not(.tut-target) { opacity: 0.55; }
.hand-slot.tut-target { animation: tutBob 1.2s ease-in-out infinite; }
.hand-slot.tut-target .card { box-shadow: 0 0 0 3px #ffe08a, 0 0 24px rgba(255, 210, 110, 0.95) !important; }
@keyframes tutBob { 50% { transform: translateY(-10px); } }
.hand-slot.tut-target:hover { animation: none; }

/* Card effect preview */
.hand-preview {
  position: fixed;
  z-index: 65;
  pointer-events: none;
  min-width: 220px;
  max-width: 340px;
  padding: 8px 12px;
  background: rgba(30, 18, 8, 0.94);
  color: var(--parchment);
  border: 2px solid #b08a4a;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
  font-size: 15px;
  animation: previewIn 0.12s ease-out;
}
.pv-title { font-family: 'Cinzel', serif; font-weight: 800; color: #ffe08a; font-size: 14px; margin-bottom: 4px; }
.pv-sides { display: flex; gap: 14px; }
.pv-side ul { list-style: none; margin: 0; padding: 0; }
.pv-side li { white-space: nowrap; }
.pv-who { font-family: 'Cinzel', serif; font-size: 12px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; }
.pv-side.you .pv-who { color: #ff9a7a; }
.pv-side.opp .pv-who { color: #8ab4ff; }
.pv-stat { display: inline-block; min-width: 62px; color: #d9c294; }
.pv-red .pv-stat { color: #ffb08a; }
.pv-blue .pv-stat { color: #a9c3ef; }
.pv-green .pv-stat { color: #a6e09a; }
.pv-delta { font-size: 13px; font-weight: bold; }
.pv-delta.up, .pv-badge.up { color: #8aff7a; }
.pv-delta.down, .pv-badge.down { color: #ff7a6a; }
.pv-none { font-style: italic; color: #b8a888; }
.pv-note { margin-top: 4px; font-style: italic; color: #e8d6a8; }
.pv-note.need { color: #ffa08a; }
.pv-note.win { color: #ffe08a; font-weight: bold; font-style: normal; }
.pv-badge {
  display: inline-block;
  margin-left: 5px;
  padding: 0 5px;
  vertical-align: middle;
  line-height: 1.3;
  border-radius: 8px;
  background: rgba(20, 12, 4, 0.85);
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-size: 14px;
  animation: badgePulse 1s ease-in-out infinite;
}
@keyframes badgePulse { 50% { opacity: 0.55; } }

/* ------------------------------------------------------------ small screens */

/* The Chronicle drawer, only used when the side panel doesn't fit. */
.side-toggle, .side-backdrop, .side-close { display: none; }

.hand-preview.touch { display: flex; gap: 10px; align-items: flex-start; min-width: 0; max-width: calc(100vw - 16px); }
.hand-preview .pv-card { --card-w: 112px; flex: none; color: var(--ink); }
.hand-preview .pv-details { min-width: 0; }
.hand-preview.touch .pv-sides { flex-wrap: wrap; gap: 4px 14px; }

@media (hover: none) {
  .hand-slot:hover { transform: none; }
  .hand-slot.selected { transform: translateY(-10px) scale(1.05); z-index: 2; }
  .hand-slot.selected .card { box-shadow: 0 0 0 3px #fff6c0, 0 0 16px rgba(255, 220, 120, 0.95); }
  .discard-btn { pointer-events: none; }
  .hand-slot.selected .discard-btn { opacity: 1; pointer-events: auto; }
  .sound-controls button { opacity: 0.85; }
}

/* Lobby: two columns on tablets, one scrolling column on phones. */
@media (max-width: 1000px) {
  .tavern-sign { display: none; }
  .lobby {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "players play" "chat play";
  }
  .players-panel { grid-area: players; }
  .chat-panel { grid-area: chat; }
  .play-panel { grid-area: play; }
}
@media (max-width: 640px) {
  #screen-login, #screen-lobby { overflow-y: auto; }
  #screen-login { align-items: flex-start; padding: 16px 12px 56px; }
  .login-box { padding: 20px 16px; width: 100%; }
  .title { font-size: 36px; letter-spacing: 2px; }
  .title.small { font-size: 19px; letter-spacing: 1px; }
  .login-box .subtitle { font-size: 16px; }
  .login-cards { --card-w: 88px; gap: 4px; }
  #login-form { flex-direction: column; }
  #name-input { width: 100%; }

  .topbar { gap: 12px; padding: 8px 12px; }
  .whoami { font-size: 15px; text-align: right; }
  .lobby {
    grid-template-columns: 1fr;
    grid-template-areas: "players" "play" "chat";
    height: auto;
    gap: 12px;
    padding: 12px 12px 56px;
  }
  .panel { overflow: visible; }
  .player { padding: 10px 8px; }
  .chat-panel .chat-log { flex: none; height: 260px; }
  .settings-grid input, .chat-form input, select { font-size: 16px; } /* no zoom on focus in iOS */

  .overlay { padding: 8px; }
  .modal { padding: 16px; }
  .modal.wide { max-width: 100%; max-height: 100%; }
  .deck-head { flex-wrap: wrap; gap: 8px; }
  .deck-head h2 { flex: 1 1 100%; font-size: 19px; order: -1; }
  .rules .deck-head h2 { flex-basis: 0; order: 0; }
  .deck-filters { justify-content: flex-start; flex-wrap: wrap; }
  .deck-grid { --card-w: 104px; gap: 8px; padding: 4px; }
  .rules-body, .rules-body p { font-size: 16px; }
  .rules-lead { font-size: 17px !important; }
  .rules-body ul, .rules-body ol { padding-left: 20px; }
  .rules-table { font-size: 14px; }
  .rules-table th, .rules-table td { padding: 4px 5px; }
  .modal p { font-size: 17px; }
  .modal-buttons { flex-wrap: wrap; }

  .sound-controls button { width: 30px; height: 30px; font-size: 14px; }
}

/* Game, any cramped screen: side panel becomes a drawer, everything shrinks. */
@media (max-width: 1100px), (max-height: 560px) {
  .game { grid-template-columns: 1fr; }
  .game-side {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(340px, 88vw);
    margin: 0;
    z-index: 50;
    border-radius: 8px 0 0 8px;
    transform: translateX(110%);
    transition: transform 0.25s ease-out;
  }
  .game.side-open .game-side { transform: none; }
  .side-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 49;
    background: rgba(10, 5, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
  }
  .game.side-open .side-backdrop { opacity: 1; pointer-events: auto; }
  .side-close { display: block; flex: none !important; }
  .side-toggle {
    display: grid;
    place-items: center;
    position: fixed;
    top: 6px;
    right: 6px;
    z-index: 48;
    width: 38px;
    height: 38px;
    font-size: 19px;
    border-radius: 8px;
    border: 2px solid #8a6a3a;
    background: rgba(43, 26, 12, 0.85);
    cursor: pointer;
  }
  .side-toggle.news::after {
    content: '';
    position: absolute;
    top: -4px;
    right: -4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ff6a4a;
    border: 2px solid #2a1a08;
  }
  .chat-log.small { flex-basis: 160px; }
  .card-preview { --card-w: 128px; }

  body:has(#screen-game:not(.hidden)) .sound-controls { top: 6px; bottom: auto; left: 6px; }
  body:has(.game.side-open) .sound-controls { z-index: 40; }
  .sound-controls button { width: 30px; height: 30px; font-size: 14px; }

  .board { padding: 6px 8px; }
  .hud-name { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .turn-arrow { margin: 0 4px; font-size: 13px; }
  .hud-center { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px 8px; }
  .turn-banner { font-size: 16px; padding: 2px 14px; }
  .turn-number { font-size: 11px; }
  .turn-timer { font-size: 15px; min-height: 0; }
  .goal { font-size: 12px; }
  .turn-splash { font-size: 34px; letter-spacing: 1px; }
  .coach { top: 50px; padding: 8px 10px; gap: 8px; }
  .coach-face { width: 40px; height: 40px; font-size: 26px; }
  .coach-text { font-size: 15px; }

  .stats { gap: 4px; min-width: 0; }
  .stats-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .res { padding: 3px 6px; border-width: 2px; border-radius: 6px; }
  .res-gen { flex-wrap: wrap; gap: 0 4px; font-size: 11px; }
  .res-label { font-size: 10px; }
  .res-gen-val { font-size: 16px; }
  .res-stock { font-size: 13px; }
  .res-stock-val { font-size: 15px; }
  .res-stock-label { display: none; }
  .res-icon { font-size: 14px; right: 5px; bottom: 3px; }

  .castle-structures { gap: 5px; }
  .tower { width: 40px; }
  .wall { width: 18px; }
  .tower .flag { top: -18px; height: 20px; }
  .tower .flag::after { width: 16px; height: 10px; }
  .plaques { gap: 4px; margin: 4px 0 2px; }
  .plaque { font-size: 14px; min-width: 0; padding: 1px 4px; }
  .plaque.tower-val::before, .plaque.wall-val::before { font-size: 10px; }

  .table-cards { min-width: 0; }
  .table-slot { margin-left: -20px; }
  .table-slot.latest-slot { margin-left: -8px; }
  .table-owner { font-size: 9px; padding: 0 5px; bottom: -8px; }
  .table-slot:not(.latest-slot) .table-owner { font-size: 8px; }
  .stamp { font-size: 10px; border-width: 2px; }

  .hand-area { padding-top: 2px; }
  .hand-hint { font-size: 13px; }
  .hand {
    gap: 6px;
    padding: 16px 4px 4px;
    overflow-x: auto;
    justify-content: safe center;
  }
  .discard-btn { font-size: 10px; padding: 1px 5px; }
}

/* Phones and tablets held upright: the table goes on top, each side's
   resources stand beside its own castle, and the hand fits the width. */
@media (max-width: 900px) and (orientation: portrait) {
  /* Leaves room for the HUD, the table and the hand on any phone height. */
  :root { --tower-max: clamp(110px, calc(100dvh - 600px), 260px); --roof-h: 32px; }
  .hud {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "center center" "you opp";
    gap: 2px 8px;
  }
  .hud-center { grid-area: center; min-height: 38px; padding: 0 80px; }
  #hud-you { grid-area: you; }
  #hud-opp { grid-area: opp; }
  .opp-hand { margin-top: 4px; }
  .card.mini { --card-w: 24px; }
  .field {
    grid-template-columns: clamp(84px, 20vw, 140px) 1fr 1fr clamp(84px, 20vw, 140px);
    grid-template-rows: auto 1fr;
    grid-template-areas: "table table table table" "sy cy co so";
    gap: 6px;
  }
  .castles { display: contents; }
  #stats-you { grid-area: sy; }
  #castle-you { grid-area: cy; }
  .table-cards { grid-area: table; padding: 6px 0 10px; }
  #castle-opp { grid-area: co; }
  #stats-opp { grid-area: so; }
  .castle { min-width: 0; }
  .table-slot { --card-w: clamp(54px, 15vw, 96px); }
  .table-slot.latest-slot { --card-w: clamp(72px, 20vw, 128px); }
  .hand { --card-w: clamp(50px, calc((100vw - 28px) / var(--hand-n, 6) - 6px), 112px); }
}

/* Phones held sideways: the desktop layout, squeezed into very little height. */
@media (max-height: 560px) and (orientation: landscape) {
  :root { --tower-max: 90px; --roof-h: 24px; }
  .hud { padding: 0 48px 0 80px; }
  .goal { font-size: 11px; }
  .opp-hand { display: none; }
  .field { grid-template-columns: 112px 1fr 112px; gap: 6px; }
  .stats { align-self: end; }
  .stats-name { font-size: 12px; }
  .res { padding: 2px 6px; }
  .res-gen-val { font-size: 14px; }
  .res-stock-val { font-size: 14px; }
  .tower .flag { display: none; }
  .table-slot { --card-w: 52px; }
  .table-slot.latest-slot { --card-w: 70px; }
  .hand-hint { font-size: 12px; min-height: 1.1em; }
  .hand { --card-w: clamp(50px, calc((100vw - 28px) / var(--hand-n, 6) - 6px), 68px); padding-top: 10px; }
  .hand-preview .pv-card { --card-w: 96px; }
  .coach { top: 36px; }
  .coach-text { font-size: 14px; }
}
