:root {
  /* Regulus palette. The slot names are historical; --rose and --beast are the
     two engine clan keys, worn here by Notoria (crimson) and Landell (azure). */
  --velvet: #120b14;
  --velvet-2: #1b1119;
  --velvet-3: #2a1a23;
  --felt: #4a171c;
  --felt-edge: #1d0a0c;
  --bone: #f4ece5;
  --bone-2: #decfca;
  --ink: #f4ece5;
  --ink-dark: #1a1016;
  --muted: #b09aa2;
  --muted-dark: #6b5560;
  --rose: #b22623;
  --beast: #2f6ba8;
  --unknown: #8b8496;
  --gilt: #d9b952;
  --gilt-2: #f2c685;
  --r-s: 6px;
  --r-m: 10px;
  --font: 'K2D', 'Noto Sans Thai', system-ui, sans-serif;
  --font-display: 'Kanit', 'Noto Sans Thai', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--velvet);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
}
[hidden] { display: none !important; }
svg { width: 1em; height: 1em; display: inline-block; vertical-align: -0.15em; flex: none; }
a { color: var(--gilt-2); }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; margin: 0 0 .5em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); font-size: .92rem; }
strong { font-weight: 600; }

:focus-visible { outline: 3px solid var(--gilt-2); outline-offset: 2px; }

/* ---------------- buttons & inputs */

button {
  font: inherit;
  font-size: .95rem;
  color: var(--ink);
  background: var(--velvet-3);
  border: 1px solid #6a3b50;
  border-radius: var(--r-s);
  padding: .5em .95em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .45em;
  min-height: 40px;
}
button:hover:not(:disabled) { background: #3a2532; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--gilt); color: var(--ink-dark); border-color: var(--gilt); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--gilt-2); }
button.danger { background: var(--rose); border-color: var(--rose); color: #fff; }
button.danger:hover:not(:disabled) { background: #cc3733; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover:not(:disabled) { background: var(--velvet-2); color: var(--ink); }
.icon-btn { min-height: 32px; min-width: 32px; padding: 0 .5em; justify-content: center; }

input, select {
  font: inherit;
  color: var(--ink);
  background: var(--velvet);
  border: 1px solid #6a3b50;
  border-radius: var(--r-s);
  padding: .5em .7em;
  min-height: 42px;
  width: 100%;
}
input::placeholder { color: #8a7280; }

.pill {
  font-style: normal;
  font-size: .72rem;
  padding: .05em .5em;
  border-radius: 99px;
  background: var(--velvet-3);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: .3em;
  vertical-align: .1em;
}
.pill-you { background: var(--gilt); color: var(--ink-dark); }
.pill-off { background: #4a2b33; color: #e7b4c0; }

/* ---------------- header */

.bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .55rem 1.25rem;
  border-bottom: 1px solid #4a2635;
}
.brand { display: flex; align-items: center; text-decoration: none; }
.brand img { height: 26px; width: auto; display: block; }
.bar-room { color: var(--muted); white-space: nowrap; }
.lang-short { display: none; }
.bar-room strong { color: var(--gilt-2); letter-spacing: .12em; }
.bar-tools { margin-left: auto; display: flex; gap: .25rem; }

.conn {
  text-align: center;
  background: #7a1f22;
  color: #ffe3ea;
  padding: .35rem 1rem;
  font-size: .9rem;
}

/* ---------------- home */

.home {
  max-width: 30rem;
  margin: 0 auto;
  padding: 9vh 1.25rem 3rem;
  text-align: center;
}
.home-logo {
  width: min(100%, 21rem);
  height: auto;
  margin: 0 auto;
  display: block;
  filter: drop-shadow(0 6px 18px rgba(178, 38, 35, .45));
}
.home-title {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 6vw, 2.4rem);
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  line-height: 1.1;
  margin: .5em 0 .35em;
  color: var(--gilt-2);
}
.home-tag { color: var(--muted); font-size: 1.05rem; margin: 0 auto 2.2rem; max-width: 26rem; }
.home-form { display: grid; gap: .8rem; text-align: left; }
.home-form label { display: grid; gap: .3rem; color: var(--muted); font-size: .92rem; }
.home-form > button { justify-content: center; min-height: 48px; font-size: 1.05rem; }
.home-or { text-align: center; color: var(--muted); font-size: .9rem; margin-top: .6rem; }
.home-join { display: flex; gap: .5rem; }
.home-join input { text-transform: uppercase; letter-spacing: .2em; text-align: center; }

/* ---------------- room layout */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  min-height: calc(100vh - 58px);
}
.stage { padding: 1.25rem; display: flex; align-items: center; justify-content: center; min-width: 0; }
.rail {
  border-left: 1px solid #4a2635;
  background: var(--velvet-2);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 58px);
  position: sticky;
  top: 0;
}
.panel { padding: 1rem 1.1rem; border-bottom: 1px solid #4a2635; overflow-y: auto; max-height: 60%; flex: none; }
.panel:empty { display: none; }
.is-lobby .panel { display: none; }

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

.lobby { width: 100%; max-width: 34rem; }
.lobby-code { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.6rem; flex-wrap: wrap; }
.code { font-family: var(--font-display); font-size: 3.2rem; font-weight: 700; letter-spacing: .18em; color: var(--gilt-2); line-height: 1; }
.seat-list { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: .35rem; }
.seat-row {
  display: flex; align-items: center; gap: .75rem;
  background: var(--velvet-2);
  border-radius: var(--r-s);
  padding: .35rem .5rem .35rem .8rem;
  min-height: 46px;
}
.seat-row.is-me { box-shadow: inset 3px 0 0 var(--gilt); }
.seat-n { color: var(--muted); width: 1.4em; text-align: right; font-variant-numeric: tabular-nums; }
.seat-name { flex: 1; display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.seat-tools { display: flex; gap: .25rem; }
.lobby-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.2rem; }

/* ---------------- table */

.table {
  position: relative;
  width: 100%;
  max-width: 1100px;
  aspect-ratio: 16 / 11;
  max-height: calc(100vh - 100px);
}
.felt {
  position: absolute;
  inset: 13% 15%;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 42%, #6e2126 0%, var(--felt) 55%, #2e0e12 100%);
  box-shadow: 0 0 0 10px var(--felt-edge), 0 0 0 12px #6b4a1c, 0 30px 60px rgba(10, 0, 5, .55);
}
.centre {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 40%;
  text-align: center;
  color: var(--bone);
  font-size: 1.05rem;
}
.centre strong { color: var(--gilt-2); }

.plaque {
  position: absolute;
  left: var(--x); top: var(--y);
  transform: translate(-50%, -50%);
  width: 150px;
  background: var(--bone);
  color: var(--ink-dark);
  border: 2px solid transparent;
  border-radius: var(--r-m);
  padding: .45rem .55rem .5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .3rem;
  text-align: center;
  font-size: .88rem;
  line-height: 1.25;
  box-shadow: 0 6px 0 var(--plaque-edge);
  --plaque-edge: #1c0b13;
  transition: border-color .2s, box-shadow .2s;
  min-height: 0;
}
button.plaque { cursor: pointer; }
button.plaque:hover { background: #f3e9d7; }

/* Faction colours. p.clan is non-null only for you and once the game is over,
   so painting the border from it never shows what viewFor() redacted. */
.plaque.clan-rose { --plaque-edge: var(--rose); border-color: var(--rose); }
.plaque.clan-beast { --plaque-edge: var(--beast); border-color: var(--beast); }
.plaque.clan-inquisitor { --plaque-edge: var(--gilt); border-color: var(--gilt); }

.plaque.is-me { background: #f3e7c9; box-shadow: 0 6px 0 var(--plaque-edge), 0 0 0 2px var(--gilt) inset; }
.plaque.is-waiting { border-color: var(--gilt); box-shadow: 0 6px 0 var(--plaque-edge), 0 0 18px rgba(212, 168, 75, .55); }
.plaque.is-selectable { border-style: dashed; border-color: var(--muted-dark); }
.plaque.is-selected { border-style: solid; border-color: var(--rose); background: #fbe9e3; }
.plaque.is-target { border-color: var(--rose); }
.plaque.is-offline { opacity: .7; }
.plaque.is-captured { outline: 3px dashed var(--rose); outline-offset: 4px; }

.plaque-name { font-weight: 600; font-size: .95rem; max-width: 100%; overflow-wrap: anywhere; }
.plaque .pill { font-size: .66rem; }
.mini-bot { color: var(--muted-dark); }
.ident { font-size: .8rem; color: var(--muted-dark); display: inline-flex; gap: .3em; align-items: center; }
.ident.clan-rose svg { color: var(--rose); }
.ident.clan-beast svg { color: var(--beast); }
.ident.clan-inquisitor svg { color: #a37a1f; }

.tokens { display: flex; gap: .3rem; }
.tok {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem;
  color: #fff;
  flex: none;
}
.tok svg { width: 17px; height: 17px; }
.tok-empty { border: 2px dashed #b9a78d; }
.tok-rank { background: var(--gilt); color: var(--ink-dark); }
.tok-rose { background: var(--rose); }
.tok-beast { background: var(--beast); }
.tok-unknown { background: var(--unknown); }

.cards { display: flex; gap: .25rem; flex-wrap: wrap; justify-content: center; }
.card {
  width: 24px; height: 30px;
  border-radius: 4px;
  background: var(--velvet-2);
  color: var(--gilt-2);
  display: inline-flex; align-items: center; justify-content: center;
}
.card svg { width: 15px; height: 15px; }
.card-shield { color: #9fd4ff; }
.card-curse { color: #c9a6ff; }
.card-curse.is-true { color: #ff9fb4; box-shadow: 0 0 0 2px #ff9fb4 inset; }

.note {
  font-size: .74rem;
  border-radius: 99px;
  padding: .05em .55em;
  background: #efe3cc;
  border: 1px solid var(--bone-2);
  display: inline-flex; align-items: center; gap: .3em;
}
.note-clue svg { color: var(--ink-dark); }
.note-peek.clan-rose { border-color: var(--rose); }
.note-peek.clan-beast { border-color: var(--beast); }
.note-offer { background: var(--beast); color: #fff; border-color: var(--beast); }
.note-leader { background: var(--gilt); border-color: var(--gilt); }
.note-captured { background: var(--rose); color: #fff; border-color: var(--rose); }
.inline-dagger { display: none; }

.dagger {
  position: absolute;
  left: var(--x); top: var(--y);
  font-size: 64px;
  color: var(--gilt);
  transform: translate(-50%, -50%) rotate(var(--r));
  transition: left .6s cubic-bezier(.5, 0, .2, 1), top .6s cubic-bezier(.5, 0, .2, 1), transform .45s cubic-bezier(.5, 0, .2, 1);
  filter: drop-shadow(0 4px 3px rgba(0, 0, 0, .55));
  pointer-events: none;
  z-index: 2;
}
.dagger.is-attacking { color: var(--gilt-2); }
.dagger svg { width: 1em; height: 1em; }

.result h2 { font-size: 1.6rem; margin: .2em 0; }
.result-mark { font-size: 2.6rem; }
.result-rose .result-mark { color: #e8716a; }
.result-beast .result-mark { color: #7cb8e8; }
.result-inquisitor .result-mark { color: var(--gilt-2); }

/* ---------------- action panel */

.mycard {
  border-radius: var(--r-m);
  background: var(--velvet);
  padding: .65rem .8rem;
  margin-bottom: 1rem;
  border-left: 4px solid var(--unknown);
}
.mycard.clan-rose { border-left-color: var(--rose); }
.mycard.clan-beast { border-left-color: var(--beast); }
.mycard.clan-inquisitor { border-left-color: var(--gilt); }
.mycard summary { display: flex; gap: .7rem; align-items: center; cursor: pointer; list-style: none; }
.mycard summary::-webkit-details-marker { display: none; }
.mycard-mark { font-size: 1.9rem; }
.clan-rose .mycard-mark { color: #e8716a; }
.clan-beast .mycard-mark { color: #7cb8e8; }
.clan-inquisitor .mycard-mark { color: var(--gilt-2); }
.mycard-clan { font-size: .85rem; color: var(--muted); }
.mycard p { margin: .55rem 0 0; }
.mycard-ability { font-size: .93rem; }
.mycard-clues { display: grid; gap: .15rem; font-size: .88rem; color: var(--muted); }

.act h3 { font-size: 1.02rem; }
.act p { margin: .4rem 0; }
.btns { display: flex; flex-wrap: wrap; gap: .5rem; margin: .7rem 0 .3rem; }
.btns.col { flex-direction: column; align-items: stretch; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0; }
.chip { min-height: 34px; padding: .25em .75em; border-radius: 99px; font-size: .9rem; }
.chip.is-selected { background: var(--rose); border-color: var(--rose); color: #fff; }
.token-btn { padding-left: .4em; }
.token-btn .tok { width: 26px; height: 26px; }
.status { color: var(--muted); }
.status strong { color: var(--ink); }
.curse-pick { display: grid; grid-template-columns: auto 1fr; gap: .3rem .6rem; align-items: center; margin: .5rem 0; font-size: .92rem; }
.curse-pick select { grid-column: 1 / -1; }
.host-tools { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; padding-top: .8rem; border-top: 1px solid #4a2635; }

/* ---------------- feed */

.feed { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.feed-tabs { display: flex; gap: .25rem; padding: .5rem .75rem 0; }
.feed-tabs button { background: transparent; border: none; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); }
.feed-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--gilt); }
.feed-title { padding: .45rem .3rem; color: var(--muted); }
.badge { background: var(--rose); color: #fff; border-radius: 99px; font-size: .72rem; padding: 0 .45em; }
.feed-list { list-style: none; margin: 0; padding: .6rem 1.1rem; overflow-y: auto; flex: 1; font-size: .9rem; display: grid; align-content: start; gap: .3rem; }
.feed-list strong { color: var(--bone); }
.log { color: var(--muted); }
.log-attack, .log-capture { color: var(--ink); }
.log-capture, .log-gameover { color: #f0a39c; }
.sys { color: var(--muted); font-style: italic; }
.msg.mine strong { color: var(--gilt-2); }
.chat-form { display: flex; gap: .5rem; padding: .6rem .75rem .75rem; border-top: 1px solid #4a2635; }

/* ---------------- dialog & toast */

.rules {
  max-width: 44rem;
  width: calc(100% - 2rem);
  background: var(--bone);
  color: var(--ink-dark);
  border: none;
  border-radius: var(--r-m);
  padding: 1.6rem 1.8rem;
  max-height: 88vh;
}
.rules::backdrop { background: rgba(20, 5, 12, .7); }
.rules dl { margin: 0 0 1.2rem; }
.rules dt { font-weight: 600; margin-top: .8rem; display: flex; gap: .5rem; align-items: center; }
.rules dd { margin: .15rem 0 0; line-height: 1.6; max-width: 70ch; }
.rank-n { display: inline-flex; width: 1.6em; height: 1.6em; border-radius: 50%; background: var(--gilt); justify-content: center; align-items: center; font-size: .82rem; }
.rules button { margin-top: .5rem; }

.toast {
  position: fixed;
  left: 50%; bottom: 1.5rem;
  transform: translate(-50%, 150%);
  background: var(--bone);
  color: var(--ink-dark);
  padding: .65rem 1.1rem;
  border-radius: var(--r-s);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  transition: transform .25s, visibility .25s;
  visibility: hidden;
  z-index: 10;
  max-width: calc(100% - 2rem);
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }

/* ---------------- smaller screens */

@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(0, 1fr) 330px; }
  .plaque { width: 128px; font-size: .82rem; }
  .tok { width: 24px; height: 24px; }
  .tok svg { width: 15px; height: 15px; }
}

@media (max-width: 860px) {
  .bar { padding: .5rem 1rem; gap: .6rem; }
  .bar-tools button { padding: .4em .6em; }
  .lang-long { display: none; }
  .lang-short { display: inline; }
  .layout { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; border-left: none; }
  .panel { max-height: none; }
  .feed { height: 60vh; }
  .stage { padding: 1rem; display: block; }
  .table { aspect-ratio: auto; max-height: none; display: flex; flex-direction: column; gap: .8rem; }
  .felt, .dagger { display: none; }
  .centre { position: static; transform: none; width: auto; order: -1; text-align: left; }
  .centre p { margin: 0; }
  .seats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem .5rem; padding-bottom: 6px; }
  .plaque { position: relative; left: auto; top: auto; transform: none; width: auto; }
  .plaque.has-dagger .inline-dagger { display: block; position: absolute; top: -10px; right: -6px; font-size: 26px; color: var(--gilt); transform: rotate(35deg); filter: drop-shadow(0 2px 1px rgba(0,0,0,.6)); }
  .result { text-align: center; }
  .code { font-size: 2.6rem; }
  /* show the actions before the table on phones */
  #room:not(.is-lobby) .rail { order: -1; }
  #room:not(.is-lobby) .feed { order: 2; }
  #room:not(.is-lobby) { display: flex; flex-direction: column; }
  #room:not(.is-lobby) .rail { display: contents; }
  #room:not(.is-lobby) .panel { order: -1; border-bottom: 1px solid #4a2635; background: var(--velvet-2); }
  #room:not(.is-lobby) .stage { order: 0; }
  #room:not(.is-lobby) .feed { background: var(--velvet-2); border-top: 1px solid #4a2635; }
}

@media (prefers-reduced-motion: reduce) {
  .dagger, .toast, .plaque { transition: none; }
}

/* ---------------- character art

   One 400x400 crop per character, keyed by the engine character name. It is
   only ever rendered for a character the view already revealed. */

.portrait {
  width: 44px;
  height: 44px;
  flex: none;
  display: block;
}
.plaque .portrait-sm { width: 48px; height: 48px; margin-bottom: -.2rem; }
.mycard .portrait-md { width: 54px; height: 54px; }
.rules .portrait-sm { width: 38px; height: 38px; }

@media (max-width: 1180px) {
  .plaque .portrait-sm { width: 40px; height: 40px; }
}
