/* Realm Rumble — TV screen.
   Ten-foot UI: sizes in vw/vh so the same page reads on a 1080p TV, a 4K TV and
   a laptop. Storybook-fantasy palette: night violet, parchment and gold. */

:root {
  --night: #120d26;
  --panel: rgba(22, 15, 44, .82);
  --panel-edge: rgba(224, 180, 90, .55);
  --gold: #e8c26a;
  --gold-hi: #ffe39a;
  --parch: #f3e6c8;
  --ink: #f6f0ff;
  --dim: #b4a8d4;
  --good: #8ff0a4;
  --bad: #ff9b8a;
  --title: "Cinzel Decorative", "Cinzel", Georgia, "Times New Roman", serif;
  --head: "Cinzel", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  /* Shown for the instant before sky.js paints, or if it ever fails. */
  background: linear-gradient(180deg, #0d0a24, #251a4d 40%, #4a2f6b 70%, #1d1733);
}
body.noCursor, body.noCursor * { cursor: none !important; }
#sky { position: fixed; inset: 0; display: block; }
canvas { display: block; }
[hidden] { display: none !important; }

.kicker { font-family: var(--head); font-size: 1.1vw; letter-spacing: .32em; text-transform: uppercase; color: var(--gold); }
.panel {
  background: var(--panel);
  border: .18vw solid var(--panel-edge);
  border-radius: 1.4vw;
  box-shadow: 0 0 0 .3vw rgba(0,0,0,.25), 0 1.5vh 4vh rgba(0,0,0,.45), inset 0 0 3vw rgba(140, 100, 255, .08);
  backdrop-filter: blur(4px);
}

/* ---------------- Lobby ---------------- */
#lobby {
  position: absolute; inset: 0;
  display: grid; grid-template-rows: auto auto 1fr; justify-items: center; align-content: start;
  gap: 2.4vh; padding: 3.5vh 4vw 3vh;
  overflow: hidden;
}
.crest { text-align: center; }
#gameName {
  font-family: var(--title); font-weight: 900;
  font-size: 5.6vw; line-height: 1;
  background: linear-gradient(180deg, #fff6d0 0%, #f2cf74 45%, #b9842c 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 .4vh 0 #3b2560) drop-shadow(0 0 2vw rgba(255, 210, 120, .35));
}
.tagline { font-family: var(--head); font-size: 1.6vw; color: var(--parch); margin-top: 1vh; letter-spacing: .06em; text-shadow: 0 2px 6px rgba(0,0,0,.6); }
#lobbyCols { display: grid; grid-template-columns: auto 1fr; gap: 2vw; width: min(100%, 86vw); }
.join { padding: 2.2vh 2vw; text-align: center; display: grid; gap: 1.2vh; justify-items: center; align-content: start; }
#code { font-family: var(--head); font-weight: 800; font-size: 5.6vw; letter-spacing: .2em; line-height: 1; color: var(--gold-hi); text-shadow: 0 0 1.5vw rgba(255, 210, 120, .35); padding-left: .2em; }
#qr { width: 15vw; height: 15vw; border-radius: .8vw; background: #fff; border: .4vw solid #fff; }
#joinUrl { font-size: 1.3vw; color: var(--parch); }
.court { padding: 2.2vh 2vw; display: grid; gap: 1.6vh; align-content: start; }
#count { color: var(--dim); letter-spacing: .1em; }
#seats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1vw; }
.seat {
  position: relative; border-radius: 1vw; padding: 1vh .5vw 1.2vh; text-align: center;
  background: rgba(255,255,255,.05); border: .15vw dashed rgba(232, 194, 106, .3);
  min-height: 13vh; display: grid; align-content: center; justify-items: center; gap: .4vh;
}
.seat.filled { border-style: solid; border-color: var(--seat, var(--gold)); background: linear-gradient(180deg, rgba(255,255,255,.1), rgba(255,255,255,.03)); }
.seat img { width: 5.6vw; height: 5.6vw; border-radius: 50%; box-shadow: 0 0 0 .25vw var(--seat, transparent), 0 .6vh 1.4vh rgba(0,0,0,.5); }
.seat .nm { font-weight: 800; font-size: 1.15vw; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .pt { font-size: .85vw; color: var(--dim); }
.seat .tag { position: absolute; top: .5vh; right: .5vw; font-size: .75vw; background: var(--gold); color: #2a1a05; border-radius: 99px; padding: .1vh .5vw; font-weight: 800; letter-spacing: .05em; }
.seat .tag.away { background: #6b5a8a; color: #fff; }
.seat.empty .hint { color: rgba(232, 194, 106, .5); font-family: var(--head); font-size: .95vw; }
#settings { display: grid; grid-template-columns: repeat(3, auto); gap: 1.2vw; justify-content: start; align-items: center; }
.setting { display: grid; gap: .5vh; }
.setting .lbl { font-size: .85vw; letter-spacing: .2em; text-transform: uppercase; color: var(--dim); }
.seg { display: flex; gap: .3vw; }
.seg button, .tvbtn {
  font: inherit; font-weight: 700; font-size: 1vw; cursor: pointer;
  border: .12vw solid rgba(232, 194, 106, .45); background: rgba(255,255,255,.06); color: var(--ink);
  border-radius: 99px; padding: .7vh .9vw;
}
.seg button.on { background: var(--gold); color: #2a1a05; border-color: var(--gold); }
#lobbyButtons { display: flex; gap: 1vw; flex-wrap: wrap; align-items: center; }
.tvbtn.primary { background: linear-gradient(180deg, #ffe39a, #d9a646); color: #2a1a05; border-color: #ffe39a; font-size: 1.4vw; padding: 1.1vh 2.4vw; font-family: var(--head); font-weight: 800; box-shadow: 0 .5vh 0 #8a6220; }
.tvbtn:disabled { opacity: .4; cursor: default; }
#status { color: var(--dim); font-size: 1.05vw; }
.how { width: min(100%, 86vw); padding: 1.8vh 2vw; display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.2vw; align-self: start; }
.how h3 { grid-column: 1 / -1; margin: 0; font-family: var(--head); font-size: 1.1vw; letter-spacing: .3em; text-transform: uppercase; color: var(--gold); }
.how .mv { font-size: 1.02vw; line-height: 1.35; color: var(--parch); }
.how .mv b { color: var(--gold-hi); display: block; font-size: 1.1vw; }
.how .cost { color: var(--gold); font-weight: 800; }

/* ---------------- Play ---------------- */
#stage {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr);
}
header {
  grid-column: 1 / -1;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 1.6vh 2.5vw 0;
}
.wordmark {
  font-family: var(--title); font-weight: 900; font-size: 2vw;
  background: linear-gradient(180deg, #fff6d0, #e3b55a 60%, #a8742a);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 0 #2b1b4a);
}
#turnBox { text-align: center; padding: 1vh 2.4vw 1.2vh; border-radius: 1.2vw; background: var(--panel); border: .15vw solid var(--panel-edge); min-width: 30vw; }
#roundLabel { font-family: var(--head); font-size: 1vw; letter-spacing: .3em; text-transform: uppercase; color: var(--gold); }
#roundLabel.final { color: #ff9bd0; }
#turnLine { display: flex; gap: .8vw; align-items: center; justify-content: center; margin-top: .4vh; }
#turnFace { width: 3.2vw; height: 3.2vw; border-radius: 50%; }
#turnName { font-family: var(--head); font-weight: 800; font-size: 2vw; }
#turnDoing { font-size: 1.1vw; color: var(--parch); min-height: 1.5em; margin-top: .3vh; }
#timerWrap { justify-self: end; position: relative; width: 5vw; height: 5vw; }
#timerRing { width: 100%; height: 100%; transform: rotate(-90deg); }
#timerRing circle { fill: none; stroke-width: 4; }
#timerRing .track { stroke: rgba(255,255,255,.15); }
#timerRing .fill { stroke: var(--gold); stroke-linecap: round; stroke-dasharray: 106.8; transition: stroke-dashoffset .25s linear, stroke .3s; }
#timerRing .fill.low { stroke: #ff7a7a; }
#timerText { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--head); font-weight: 800; font-size: 1.5vw; }

#boardWrap { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; overflow: hidden; }

#rail {
  grid-column: 2; grid-row: 2;
  margin: 1.5vh 1.5vw 2vh 0; padding: 1.6vh 1vw;
  width: 21vw; overflow: hidden;
  display: flex; flex-direction: column; gap: .7vh;
  background: var(--panel); border: .15vw solid var(--panel-edge); border-radius: 1.2vw;
}
#rail h3 { margin: 0 0 .4vh; font-family: var(--head); font-size: .95vw; letter-spacing: .28em; text-transform: uppercase; color: var(--gold); display: flex; justify-content: space-between; }
#rail h3 span { color: var(--dim); letter-spacing: .1em; }
.row { display: grid; grid-template-columns: auto auto 1fr auto; gap: .6vw; align-items: center; padding: .55vh .6vw; border-radius: .8vw; border: .12vw solid transparent; transition: background .3s, border-color .3s; }
.row.now { background: rgba(232, 194, 106, .16); border-color: var(--gold); box-shadow: 0 0 1.4vw rgba(232, 194, 106, .25); }
.row.done { opacity: .7; }
.row .ord { font-family: var(--head); font-weight: 800; font-size: .9vw; color: var(--dim); width: 1.2vw; text-align: center; }
.row img { width: 2.8vw; height: 2.8vw; border-radius: 50%; box-shadow: 0 0 0 .2vw var(--c); }
.row .who { min-width: 0; }
.row .nm { font-weight: 800; font-size: 1.05vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: .8vw; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.35; }
.row .sub .gold { color: var(--gold-hi); font-weight: 700; }
.row .pts { font-family: var(--head); font-weight: 800; font-size: 1.7vw; text-align: right; line-height: 1; }
.row .pts small { display: block; font-family: system-ui, sans-serif; font-size: .65vw; font-weight: 600; color: var(--dim); letter-spacing: .1em; text-transform: uppercase; }
.row.leader .pts { color: var(--gold-hi); }
.crown { font-size: .9vw; margin-left: .2vw; }
/* Eight or more players: tighter rows so all ten fit on screen. */
#rail.dense { gap: .3vh; padding: 1.2vh .8vw; }
#rail.dense .row { padding: .3vh .5vw; }
#rail.dense .row img { width: 2.2vw; height: 2.2vw; }
#rail.dense .row .nm { font-size: .95vw; }
#rail.dense .row .sub { font-size: .72vw; line-height: 1.25; }
#rail.dense .row .pts { font-size: 1.4vw; }
body.playing #rail { margin-bottom: 7vh; }

#chronicle {
  position: absolute; left: 1.2vw; bottom: 2vh; width: 17.5vw;
  background: var(--panel); border: .15vw solid var(--panel-edge); border-radius: 1vw;
  padding: 1.2vh 1vw; pointer-events: none;
}
#chronicle h3 { margin: 0 0 .6vh; font-family: var(--head); font-size: .85vw; letter-spacing: .28em; text-transform: uppercase; color: var(--gold); }
#log { display: grid; gap: .45vh; }
#log div { font-size: .88vw; line-height: 1.3; color: var(--parch); display: flex; gap: .5vw; align-items: flex-start; }
#log div:first-child { color: #fff; font-weight: 600; }
#log div:nth-child(n+4) { opacity: .65; }
#log .pip { flex: none; width: .7vw; height: .7vw; border-radius: 50%; margin-top: .35vw; }
#legend {
  position: absolute; left: 1.5vw; top: 13vh; width: 15vw;
  font-size: .82vw; color: var(--dim); line-height: 1.5; pointer-events: none;
  background: rgba(18, 12, 38, .55); border-radius: .8vw; padding: 1vh .8vw;
}
#legend b { color: var(--parch); }

/* Round banner */
#banner {
  position: fixed; inset: 0; display: grid; place-content: center; text-align: center;
  background: radial-gradient(ellipse at center, rgba(10, 6, 24, .7), rgba(10, 6, 24, .35) 60%, transparent);
  animation: fadeInOut 2s ease both; pointer-events: none;
}
#bannerText { font-family: var(--title); font-weight: 900; font-size: 6vw; color: var(--gold-hi); text-shadow: 0 .5vh 0 #3b2560, 0 0 3vw rgba(255, 210, 120, .5); }
#bannerSub { font-family: var(--head); font-size: 1.8vw; color: var(--parch); margin-top: 1vh; }
@keyframes fadeInOut { 0% { opacity: 0; transform: scale(.94); } 15% { opacity: 1; transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }

/* Fate reveal */
#fate { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(8, 4, 20, .55); }
#fate .card {
  width: 30vw; padding: 3vh 2vw 3.4vh; text-align: center; border-radius: 1.6vw;
  background: linear-gradient(180deg, #2c1f52, #1a1235);
  border: .3vw solid var(--gold); box-shadow: 0 0 6vw rgba(232, 194, 106, .45), 0 2vh 6vh rgba(0,0,0,.6);
  animation: flipIn .6s cubic-bezier(.2, 1.4, .4, 1) both;
}
#fate.good .card { border-color: #8ff0a4; box-shadow: 0 0 6vw rgba(143, 240, 164, .4), 0 2vh 6vh rgba(0,0,0,.6); }
#fate.bad .card { border-color: #ff9b8a; box-shadow: 0 0 6vw rgba(255, 155, 138, .35), 0 2vh 6vh rgba(0,0,0,.6); }
#fate .who { font-family: var(--head); font-size: 1.1vw; letter-spacing: .25em; text-transform: uppercase; color: var(--dim); }
#fate .icon { font-size: 7vw; line-height: 1.15; margin: 1vh 0; filter: drop-shadow(0 0 1.5vw rgba(255, 230, 160, .6)); }
#fate .name { font-family: var(--title); font-weight: 900; font-size: 2.6vw; color: var(--gold-hi); }
#fate.good .name { color: var(--good); }
#fate.bad .name { color: var(--bad); }
#fate .text { font-size: 1.4vw; color: var(--parch); margin-top: 1.2vh; line-height: 1.35; }
@keyframes flipIn { from { transform: perspective(60vw) rotateY(80deg) scale(.7); opacity: 0; } to { transform: none; opacity: 1; } }

/* End curtain */
#curtain {
  position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 2.2vh; text-align: center;
  background: radial-gradient(ellipse at center, rgba(22, 12, 48, .92), rgba(10, 6, 24, .96));
}
#winner { display: grid; justify-items: center; gap: 1vh; margin-top: 5vw; }
#winner .face { position: relative; }
#winner img { width: 12vw; height: 12vw; border-radius: 50%; box-shadow: 0 0 0 .5vw var(--c), 0 0 5vw rgba(255, 210, 120, .5); }
#winner .bigcrown { position: absolute; left: 50%; top: -5.4vw; transform: translateX(-50%); font-size: 6vw; filter: drop-shadow(0 .5vh 0 rgba(0,0,0,.4)); animation: bob 2.4s ease-in-out infinite; }
#winner .nm { font-family: var(--title); font-weight: 900; font-size: 4vw; color: var(--gold-hi); text-shadow: 0 .5vh 0 #3b2560; }
#winner .sub { font-size: 1.4vw; color: var(--parch); }
@keyframes bob { 50% { transform: translateX(-50%) translateY(-.8vh); } }
#standings { display: grid; gap: .8vh; min-width: 40vw; }
.stand { display: grid; grid-template-columns: 3vw auto 1fr auto auto; gap: 1vw; align-items: center; padding: .8vh 1.2vw; border-radius: 1vw; background: rgba(255,255,255,.06); text-align: left; }
.stand .rk { font-family: var(--head); font-weight: 800; font-size: 1.6vw; color: var(--gold); }
.stand img { width: 3vw; height: 3vw; border-radius: 50%; box-shadow: 0 0 0 .2vw var(--c); }
.stand .nm { font-weight: 800; font-size: 1.3vw; }
.stand .det { font-size: 1vw; color: var(--dim); }
.stand .pts { font-family: var(--head); font-weight: 800; font-size: 1.8vw; }
/* Big games: standings in two columns and a smaller portrait so everything fits. */
#curtain.many #standings { grid-template-columns: 1fr 1fr; column-gap: 1.2vw; min-width: 64vw; }
#curtain.many .stand { padding: .5vh 1vw; }
#curtain.many #winner img { width: 8vw; height: 8vw; }
#curtain.many #winner .bigcrown { top: -4vw; font-size: 4.4vw; }
#curtain.many #winner { margin-top: 3.5vw; }
#curtain.many #winner .nm { font-size: 3vw; }
#curtainActions { display: flex; gap: 1vw; }
#curtainNote { color: var(--dim); font-size: 1.1vw; }

/* Corner links */
#homeLink, #newRoomLink {
  position: fixed; bottom: 1.4vh; z-index: 5; font: inherit; font-size: .95vw; cursor: pointer;
  background: rgba(18, 12, 38, .6); color: var(--dim); border: .1vw solid rgba(232, 194, 106, .3); border-radius: 99px; padding: .6vh 1vw;
}
#homeLink { left: 1.4vw; }
#newRoomLink { right: 1.4vw; }
#homeLink.armed, #newRoomLink.armed { color: #fff; background: #8a2d4a; }
body.playing #homeLink { left: auto; right: 9.5vw; }

@media (prefers-reduced-motion: reduce) {
  #banner, #fate .card, #winner .bigcrown { animation: none; }
}
