:root {
  --umber: #1c1813;
  --umber-2: #26211a;
  --stone: #322b22;
  --stone-line: #4a4033;
  --parchment: #e9dfc7;
  --muted: #a69a80;
  --gold: #d4a845;
  --gold-hi: #f3d27a;
  --grace: #ffe6a0;
  --blood: #a4282a;
  --blood-hi: #d9463f;
  --limgrave: #56653f;
  --liurnia: #3e5a73;
  --altus: #7a6430;
  --caelid: #7a2f26;
  --display: "Cinzel", "Trajan Pro", Georgia, serif;
  --body: "EB Garamond", Garamond, Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(212,168,69,.08), transparent 70%),
    var(--umber);
  color: var(--parchment);
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.45;
  min-height: 100vh;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-weight: 500; margin: 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }

/* ---------------------------------------------------------- buttons */
.btn {
  background: var(--stone);
  border: 1px solid var(--stone-line);
  border-radius: 3px;
  padding: .5em 1.1em;
  cursor: pointer;
  font-size: 1rem;
  transition: border-color .15s, background .15s;
}
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--gold); color: #241b0b; border-color: var(--gold-hi); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--gold-hi); }
.btn.danger { border-color: var(--blood); }
.btn.small { padding: .3em .8em; font-size: .9rem; }
.btn.link { background: none; border: none; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; padding: .2em; }
.btn.link:hover { color: var(--parchment); }

/* ---------------------------------------------------------- home */
#home { max-width: 980px; margin: 0 auto; padding: 48px 20px 64px; }
.home-head { text-align: center; margin-bottom: 36px; }
.home-head h1 {
  font-family: var(--display);
  font-size: clamp(2.2rem, 7vw, 4.2rem);
  letter-spacing: .04em;
  color: var(--gold);
  text-shadow: 0 0 40px rgba(212,168,69,.35);
}
.lede { color: var(--muted); max-width: 34em; margin: 12px auto 0; font-size: 1.15rem; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field span { color: var(--muted); font-size: .95rem; }
.field input {
  background: var(--umber-2);
  border: 1px solid var(--stone-line);
  border-radius: 3px;
  color: var(--parchment);
  font: inherit;
  padding: .5em .7em;
}
.field input:focus { border-color: var(--gold); outline: none; }
#nameInput { max-width: 360px; }
.classes { border: none; padding: 0; margin: 28px 0; }
.classes legend { color: var(--muted); font-size: .95rem; margin-bottom: 10px; }
.class-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.class-card {
  display: flex; flex-direction: column; justify-content: flex-start;
  text-align: left;
  background: var(--umber-2);
  border: 1px solid var(--stone-line);
  border-radius: 3px;
  padding: 10px 12px;
  cursor: pointer;
}
.class-card:hover { border-color: var(--muted); }
.class-card[aria-pressed="true"] { border-color: var(--gold); background: #2e2618; box-shadow: inset 0 0 0 1px var(--gold); }
.class-card .cn { font-weight: 600; font-size: 1.1rem; }
.class-card .cs { color: var(--muted); font-size: .9rem; }
.class-card .cp { font-size: .9rem; margin-top: 4px; }
.class-card .cp em { color: var(--gold-hi); font-style: normal; }
.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.action-box { background: var(--umber-2); border: 1px solid var(--stone-line); border-radius: 3px; padding: 16px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.code-field input { width: 7em; text-transform: uppercase; letter-spacing: .2em; }
.hint { margin: 0; color: var(--muted); font-size: .95rem; }
.error { color: var(--blood-hi); min-height: 1.4em; }

/* ---------------------------------------------------------- lobby */
#lobby { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.lobby-box { width: min(560px, 100%); background: var(--umber-2); border: 1px solid var(--stone-line); border-radius: 3px; padding: 28px; }
.lobby-box h2 { font-family: var(--display); color: var(--gold); font-size: 1.5rem; margin-bottom: 14px; }
.share { display: flex; gap: 8px; }
.share input { flex: 1; min-width: 0; background: var(--umber); border: 1px solid var(--stone-line); color: var(--parchment); font: inherit; font-size: .95rem; padding: .4em .6em; border-radius: 3px; }
.code-big { color: var(--muted); }
.code-big strong { color: var(--parchment); letter-spacing: .2em; font-size: 1.2rem; }
.lobby-players { list-style: none; padding: 0; margin: 16px 0; display: flex; flex-direction: column; gap: 6px; }
.lobby-players li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--umber); border-radius: 3px; }
.lobby-players .tag { margin-left: auto; color: var(--muted); font-size: .9rem; }
#lobbyActions { margin: 18px 0 8px; }

/* ---------------------------------------------------------- game layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; padding: 14px; max-width: 1400px; margin: 0 auto; align-items: start; }
.board-wrap { position: relative; width: min(100%, calc(100vh - 28px)); aspect-ratio: 1; margin: 0 auto; }
.board { display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); gap: 3px; width: 100%; height: 100%; }
.board::before {
  /* Erdtree in the middle of the board */
  content: "";
  grid-area: 2 / 2 / 9 / 9;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200'%3E%3Cdefs%3E%3CradialGradient id='g' cx='50%25' cy='45%25' r='42%25'%3E%3Cstop offset='0' stop-color='%23f3d27a' stop-opacity='.55'/%3E%3Cstop offset='1' stop-color='%23d4a845' stop-opacity='0'/%3E%3C/radialGradient%3E%3C/defs%3E%3Ccircle cx='100' cy='88' r='72' fill='url(%23g)'/%3E%3Cg fill='none' stroke='%23d4a845' stroke-opacity='.35' stroke-width='1.4' stroke-linecap='round'%3E%3Cpath d='M100 190 C98 150 102 120 100 90'/%3E%3Cpath d='M100 120 C80 100 60 95 40 70'/%3E%3Cpath d='M100 110 C120 95 140 90 162 64'/%3E%3Cpath d='M100 95 C88 70 80 55 70 30'/%3E%3Cpath d='M100 92 C112 68 122 50 132 26'/%3E%3Cpath d='M100 90 C100 60 100 40 100 14'/%3E%3Cpath d='M70 92 C55 80 45 60 52 40'/%3E%3Cpath d='M132 90 C150 78 158 58 150 38'/%3E%3C/g%3E%3C/svg%3E") center / 85% no-repeat;
  opacity: .9;
  pointer-events: none;
}

.tile {
  position: relative;
  background: var(--stone);
  border-radius: 2px;
  border-top: 3px solid var(--region);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 3px 2px 2px;
  overflow: hidden;
  min-width: 0;
}
.tile[data-region="0"] { --region: var(--limgrave); }
.tile[data-region="1"] { --region: var(--liurnia); }
.tile[data-region="2"] { --region: var(--altus); }
.tile[data-region="3"] { --region: var(--caelid); }
.tile .glyph { font-size: clamp(.9rem, 2.1vw, 1.5rem); line-height: 1.1; }
.tile .tname { font-size: clamp(.5rem, .85vw, .72rem); line-height: 1.1; color: var(--muted); text-align: center; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile.corner .tname { color: var(--parchment); }
.tile.slain .glyph { opacity: .35; }
.tile.slain::after { content: "✓"; position: absolute; top: 2px; right: 4px; font-size: .7rem; color: var(--gold); }
.tile.active { box-shadow: 0 0 0 2px var(--gold-hi), 0 0 18px rgba(243,210,122,.4); z-index: 2; }
.tile .stain {
  position: absolute; left: 3px; top: 3px;
  width: 10px; height: 10px; border-radius: 50% 50% 50% 0;
  background: var(--blood-hi);
  box-shadow: 0 0 8px var(--blood-hi);
  transform: rotate(-45deg);
}
.tokens { position: absolute; bottom: 3px; left: 0; right: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; }
.token {
  width: clamp(11px, 1.6vw, 20px); height: clamp(11px, 1.6vw, 20px);
  border-radius: 50%;
  background: var(--c);
  border: 2px solid #120f0b;
  box-shadow: 0 1px 3px rgba(0,0,0,.6);
  font-size: clamp(.45rem, .75vw, .62rem);
  font-weight: 600;
  color: #120f0b;
  display: grid; place-items: center;
  font-family: var(--body);
}
.token.me { border-color: var(--parchment); }
.token.hop { animation: hop .16s ease-out; }
@keyframes hop { 50% { transform: translateY(-5px); } }

.g { display: inline-block; width: 1.4em; text-align: center; }
.g-grace { color: var(--grace); text-shadow: 0 0 10px rgba(255,230,160,.8); }
.g-enemy { color: #c8bca2; }
.g-fieldboss { color: #e2a45a; }
.g-demigod { color: var(--gold-hi); }
.g-treasure { color: #9fc6d9; }
.g-message { color: #d8c8a0; }
.g-merchant { color: #b8d0a0; }
.g-invasion { color: var(--blood-hi); }
.g-gate { color: var(--gold); }

/* ---------------------------------------------------------- center panel */
.panel {
  position: absolute;
  inset: calc((100% + 3px) / 9 + 8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 10px 16px;
  overflow-y: auto;
}
.panel > * { max-width: 30em; }
.turn-name { font-size: 1.15rem; color: var(--muted); }
.turn-name strong { color: var(--parchment); font-weight: 600; }
.card {
  background: rgba(28,24,19,.88);
  border: 1px solid var(--stone-line);
  border-radius: 3px;
  padding: 12px 16px;
  width: 100%;
}
.card h3 { font-size: 1.2rem; font-weight: 600; margin-bottom: 4px; }
.card p { margin: 0; }
.card.message h3 { font-style: italic; color: #f0e0b0; }
.card.death { border-color: var(--blood); }
.card.death h3 { color: var(--blood-hi); }
.card.victory h3, .card.treasure h3, .card.intro h3 { color: var(--gold-hi); }
.card.invasion { border-color: var(--blood); }
.card.grace h3 { color: var(--grace); }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.wait { color: var(--muted); font-style: italic; }

.die {
  width: 64px; height: 64px;
  border-radius: 10px;
  background: var(--parchment);
  color: #1c1813;
  display: grid; place-items: center;
  font-size: 2.2rem; font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,.6), inset 0 -3px 0 rgba(0,0,0,.15);
}
.die.roll { animation: tumble .55s cubic-bezier(.3,1.4,.5,1); }
@keyframes tumble { 0% { transform: rotate(-200deg) scale(.4); opacity: 0; } 100% { transform: none; opacity: 1; } }

/* combat */
.combat { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.foe-name { font-size: 1.35rem; font-weight: 600; }
.foe-name.boss { font-family: var(--display); color: var(--gold-hi); font-size: 1.25rem; }
.bar { height: 10px; background: #120f0b; border: 1px solid var(--stone-line); border-radius: 2px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--blood); transition: width .35s; }
.bar.you > i { background: #b33a2e; }
.bar.foe > i { background: #8a7a5a; }
.bar.boss > i { background: var(--gold); }
.stats { display: flex; justify-content: space-between; font-size: .95rem; color: var(--muted); }
.vs { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; text-align: left; }
.clog { list-style: none; padding: 0; margin: 0; font-size: .95rem; text-align: left; background: rgba(18,15,11,.7); border-radius: 3px; padding: 6px 10px; max-height: 9.5em; overflow-y: auto; }
.clog li { padding: 2px 0; border-bottom: 1px solid rgba(74,64,51,.5); }
.clog li:last-child { border: none; font-weight: 600; }
.clog .w-p { color: #e8d49a; }
.clog .w-e { color: #e07a6a; }
.clog .w-h { color: #a8d090; }
.clog .roll { color: var(--muted); font-weight: 400; }

.shop { list-style: none; padding: 0; margin: 0; width: 100%; display: flex; flex-direction: column; gap: 6px; }
.shop li { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: rgba(28,24,19,.88); border: 1px solid var(--stone-line); border-radius: 3px; padding: 6px 10px; text-align: left; }
.shop .d { color: var(--muted); font-size: .88rem; display: block; }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.levels .btn { display: flex; flex-direction: column; line-height: 1.2; }
.levels .btn small { color: var(--muted); }
.runes { color: var(--gold-hi); }

/* ---------------------------------------------------------- sidebar */
.side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.side-head { display: flex; justify-content: space-between; align-items: baseline; color: var(--muted); }
.players { display: flex; flex-direction: column; gap: 8px; }
.pcard { background: var(--umber-2); border: 1px solid var(--stone-line); border-left: 4px solid var(--c); border-radius: 3px; padding: 8px 10px; font-size: .95rem; }
.pcard.current { border-color: var(--gold); border-left-color: var(--c); box-shadow: 0 0 0 1px var(--gold) inset; }
.pcard .top { display: flex; align-items: baseline; gap: 6px; }
.pcard .nm { font-weight: 600; font-size: 1.05rem; }
.pcard .cl { color: var(--muted); }
.pcard .lv { margin-left: auto; color: var(--muted); }
.pcard .bar { margin: 5px 0 4px; height: 7px; }
.pcard .row { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); }
.pcard .row b { color: var(--parchment); font-weight: 500; }
.pcard .gr { color: var(--gold-hi); letter-spacing: 2px; }
.pcard .gear { margin-top: 4px; color: var(--muted); font-size: .85rem; line-height: 1.35; }
.pcard .gear b { color: var(--parchment); font-weight: 500; }
.pcard .host-skip { margin-top: 6px; }
.side-title { font-size: 1rem; color: var(--muted); margin-top: 6px; }
.log { list-style: none; margin: 0; padding: 0; font-size: .92rem; max-height: 36vh; overflow-y: auto; display: flex; flex-direction: column-reverse; }
.log li { padding: 3px 0; border-bottom: 1px solid rgba(74,64,51,.4); color: #cfc4aa; }
.log li.gold { color: var(--gold-hi); }
.log li.red { color: #e07a6a; }
.log li.grace { color: var(--grace); }
.log li.boss { color: #f0c27a; }

/* ---------------------------------------------------------- banner (the signature moment) */
.banner { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 50; opacity: 0; }
.banner.show { animation: banner 3.2s ease-in-out forwards; }
.banner-band {
  width: 100%;
  padding: 3.2vh 0 2.6vh;
  text-align: center;
  background: linear-gradient(90deg, transparent, rgba(8,6,4,.86) 18%, rgba(8,6,4,.86) 82%, transparent);
}
.banner-text { font-family: var(--display); font-size: clamp(2rem, 7.5vw, 6rem); padding: 0 16px; letter-spacing: .06em; line-height: 1; }
.banner-sub { color: var(--muted); margin-top: 10px; font-size: clamp(1rem, 2vw, 1.3rem); }
.banner.died .banner-text { color: var(--blood-hi); text-shadow: 0 0 30px rgba(164,40,42,.6); }
.banner.felled .banner-text, .banner.demigod .banner-text, .banner.victory .banner-text { color: var(--gold-hi); text-shadow: 0 0 34px rgba(243,210,122,.55); }
.banner.boss .banner-text { color: var(--parchment); font-size: clamp(1.6rem, 5vw, 4rem); }
.banner.invaded .banner-text, .banner.steal .banner-text { color: var(--blood-hi); font-size: clamp(1.6rem, 5vw, 4rem); }
@keyframes banner { 0% { opacity: 0; } 18% { opacity: 1; } 78% { opacity: 1; } 100% { opacity: 0; } }
.banner.show .banner-text { animation: banner-text 3.2s ease-out forwards; }
@keyframes banner-text { from { letter-spacing: .02em; } to { letter-spacing: .08em; } }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--blood); color: #fff; padding: 8px 16px; border-radius: 3px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; }
.toast.show { opacity: 1; }

/* ---------------------------------------------------------- rules */
.rules { max-width: 640px; background: var(--umber-2); color: var(--parchment); border: 1px solid var(--stone-line); border-radius: 3px; padding: 24px 28px; }
.rules::backdrop { background: rgba(0,0,0,.7); }
.rules h2 { font-family: var(--display); color: var(--gold); margin-bottom: 10px; }
.rules-tiles { padding-left: 0; list-style: none; }
.rules-tiles li { margin-bottom: 5px; }

/* ---------------------------------------------------------- responsive */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .board-wrap { width: min(100%, 92vh); }
  .log { max-height: 40vh; }
}
@media (max-width: 760px) {
  body { font-size: 17px; }
  .layout { padding: 8px; gap: 12px; }
  .board { gap: 2px; }
  .tile .tname { display: none; }
  .tile { justify-content: center; padding: 1px; }
  .tokens { bottom: 1px; }
  .board-wrap { aspect-ratio: auto; width: 100%; }
  .board { aspect-ratio: 1; height: auto; }
  .panel { position: static; inset: auto; padding: 14px 0 0; }
  .home-actions { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .banner.show { animation: banner 3.2s steps(1) forwards; }
}
