:root {
  --ink: #1a120c;
  --parchment: #f6e7c8;
  --gold: #f0c86a;
  --gold-deep: #a8752d;
  --wood: #3b2416;
  --wood-2: #5a3822;
  --good: #2f9e45;
  --bad: #d4533c;
  --line: rgba(240, 200, 106, 0.7);
  color: var(--parchment);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background: #100c09;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }

.hidden { display: none !important; }

#lobby {
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}
#menu-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.shade { pointer-events: none; z-index: 0; }
.panel { z-index: 2; }
.shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(10, 7, 5, 0.82) 0%, rgba(10, 7, 5, 0.45) 48%, rgba(10, 7, 5, 0.62) 100%);
}
.panel {
  position: relative;
  z-index: 1;
  max-width: 640px;
  padding: 48px 28px 40px;
}
.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--gold);
}
h1 {
  font-family: Palatino, Georgia, serif;
  font-size: clamp(56px, 8vw, 92px);
  line-height: 0.9;
  margin: 0;
  color: #fff6df;
  text-shadow: 0 4px 0 #2a160c, 0 14px 30px rgba(0, 0, 0, 0.45);
}
.lede { max-width: 46ch; font-size: 18px; line-height: 1.45; color: #f3e2c4; }
.name { display: block; margin: 18px 0 12px; }
.name span { display: block; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold); }
.name input, .join input {
  background: rgba(20, 12, 8, 0.78);
  border: 2px solid var(--gold-deep);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 0;
}
.row, .practice, .join { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.primary, .practice button, .join button, #copy, #rematch, #special, #evolve, #sell, #mute, #leave {
  background: linear-gradient(#6a4328, #3c2416);
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 3px 0 #24140c;
}
.primary { background: linear-gradient(#d7a441, #8a5a16); color: #24160c; font-weight: 800; }
button:hover:not(:disabled) { filter: brightness(1.08); }
.practice { margin-top: 14px; }
.practice span { letter-spacing: 0.14em; text-transform: uppercase; font-size: 12px; color: var(--gold); }
.rules { padding-left: 18px; max-width: 58ch; color: #f0e0c4; }
.rules li { margin: 6px 0; }
.error { min-height: 1.2em; color: #ffb4a8; font-weight: 800; }

#match {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #100c09;
}
#top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  background: linear-gradient(#2a1a10, #1a100b);
  border-bottom: 3px solid var(--gold-deep);
}
.who { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; min-width: 0; }
.who.foe { direction: rtl; }
.who.foe .who-copy, .who.foe .hp, .who.foe em { direction: ltr; }
.who-copy { display: flex; flex-direction: column; min-width: 0; }
.who-copy strong { font-family: Palatino, Georgia, serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-copy span, #clock { color: var(--gold); font-size: 13px; }
.hp {
  height: 16px;
  background: #2a1212;
  border: 2px solid var(--gold);
  border-radius: 99px;
  overflow: hidden;
  min-width: 80px;
}
.hp span { display: block; height: 100%; width: 100%; background: linear-gradient(#8dff72, #1f8a32); }
.hp.foe span { background: linear-gradient(#ff8d78, #a42318); }
.who em { font-style: normal; font-weight: 800; min-width: 4.5ch; }
.mid { display: flex; gap: 8px; align-items: center; }
#mute, #leave { padding: 6px 10px; border-radius: 9px; }

#stage { flex: 1; min-height: 0; position: relative; background: #101820; }
#view { width: 100%; height: 100%; object-fit: contain; display: block; }
#banner, #count {
  position: absolute;
  left: 50%;
  top: 16%;
  transform: translateX(-50%);
  pointer-events: none;
  font-family: Palatino, Georgia, serif;
  color: #fff8e6;
  text-shadow: 0 4px 0 #2a160c, 0 10px 24px rgba(0, 0, 0, 0.5);
}
#banner { font-size: clamp(32px, 5vw, 68px); opacity: 0; }
#banner.show { animation: banner 1.5s ease forwards; }
#count { top: 28%; font-size: clamp(48px, 8vw, 104px); }
@keyframes banner {
  0% { opacity: 0; transform: translateX(-50%) scale(0.86); }
  12% { opacity: 1; transform: translateX(-50%) scale(1); }
  72% { opacity: 1; }
  100% { opacity: 0; }
}
.overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(22, 13, 9, 0.9);
  border: 3px solid var(--gold);
  border-radius: 16px;
  padding: 18px 22px;
  text-align: center;
  min-width: min(420px, 92vw);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.4);
}
#room-code {
  display: block;
  font-family: Palatino, Georgia, serif;
  font-size: 64px;
  letter-spacing: 0.18em;
  margin: 4px 0 10px;
}
#end h2 { font-family: Palatino, Georgia, serif; font-size: 48px; margin: 0; }
#end-kicker { margin: 0; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold); }

#dock {
  display: flex;
  gap: 10px;
  align-items: stretch;
  padding: 8px 10px 10px;
  overflow-x: auto;
  background:
    linear-gradient(180deg, rgba(255, 214, 140, 0.16), transparent 30%),
    repeating-linear-gradient(90deg, #4e301d 0 14px, #412716 14px 28px);
  border-top: 4px solid var(--gold);
}
body[data-age="1"] #dock { border-top-color: #d7e4f5; }
body[data-age="2"] #dock { border-top-color: #f2d48a; }
body[data-age="3"] #dock { border-top-color: #c5d2b2; }
body[data-age="4"] #dock { border-top-color: #8ee7ff; background:
  linear-gradient(180deg, rgba(120, 210, 255, 0.16), transparent 30%),
  repeating-linear-gradient(90deg, #1b2438 0 14px, #141b2c 14px 28px); }

.res { width: 168px; min-width: 168px; display: flex; flex-direction: column; gap: 6px; }
.gold, .xp {
  background: rgba(16, 9, 6, 0.55);
  border: 2px solid var(--gold-deep);
  border-radius: 10px;
  padding: 6px 8px;
}
.gold { display: flex; justify-content: space-between; align-items: baseline; }
.gold strong { color: var(--gold); font-size: 22px; }
.xp-top { display: flex; justify-content: space-between; font-size: 12px; }
.xp-track { height: 8px; background: #2a2118; border-radius: 99px; overflow: hidden; margin-top: 4px; }
.xp-track span { display: block; height: 100%; width: 0; background: linear-gradient(#fff1b0, #e0a12a); }
#queue { display: flex; flex-wrap: wrap; gap: 4px; min-height: 22px; }
.chip {
  background: rgba(16, 9, 6, 0.7);
  border: 1px solid var(--gold-deep);
  border-radius: 99px;
  padding: 2px 7px;
  font-size: 11px;
}
.chip button { background: none; border: 0; color: #ffb4a8; padding: 0 0 0 4px; }

.cards { display: flex; gap: 6px; }
.card, .slot {
  width: 92px;
  min-width: 92px;
  background: linear-gradient(#5b3a24, #322015);
  border: 2px solid #8d6233;
  border-radius: 12px;
  padding: 4px 4px 6px;
  text-align: left;
  position: relative;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 3px 0 #24140c;
}
.card canvas { width: 84px; height: 48px; display: block; background: rgba(0, 0, 0, 0.18); border-radius: 8px; }
.card b, .slot b { display: block; font-size: 11px; line-height: 1.15; }
.card em, .slot em { font-style: normal; color: var(--gold); font-weight: 800; }
.card small, .slot small { display: block; color: #f0ddc0; font-size: 10px; }
.card.broke em, .slot.broke em { color: #ff9d90; }
.card .count:empty { display: none; }
.card .count {
  position: absolute;
  top: 6px;
  right: 6px;
  background: #24160c;
  border: 1px solid var(--gold);
  border-radius: 99px;
  min-width: 16px;
  text-align: center;
  font-size: 11px;
  font-style: normal;
}
.card .meter {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 4px;
  height: 3px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 99px;
  overflow: hidden;
}
.card .meter i { display: block; height: 100%; width: 0; background: var(--gold); }
.slots { display: flex; gap: 6px; }
.slot { width: 74px; min-width: 74px; text-align: center; }
.slot.on { border-color: #fff1b8; box-shadow: 0 0 0 2px #fff1b8, 0 3px 0 #24140c; }
.slot .swatch {
  height: 28px;
  border-radius: 8px;
  margin-bottom: 4px;
  background: rgba(0, 0, 0, 0.25);
}
.actions { min-width: 180px; display: flex; flex-direction: column; gap: 6px; }
#special, #evolve, #sell { width: 100%; text-align: left; }
#special { min-height: 52px; }
#special strong, #evolve strong { display: block; }
#special small, #evolve small { color: #f0ddc0; }
.keys { margin: 0; font-size: 11px; max-width: 220px; color: #f0ddc0; }
.ready { box-shadow: inset 0 0 0 2px #fff1b0, 0 0 16px rgba(240, 200, 106, 0.45); }

@media (max-width: 1100px) {
  .keys { display: none; }
  .panel { padding-top: 28px; }
}
