/* Sacri-Ledge — Handcrafted Cardboard, Parchment & Ink-Wash Theme
 * Inspired by Cardboard Kaiju, Sky Whale Salvage, and Inkbound Courier.
 */
:root {
  --ink: #2b2420;
  --ink-soft: #5c4d44;
  --paper: #faf3e0;
  --paper-warm: #f3e5c8;
  --paper-deep: #e6d2ad;
  --cardboard: #c49a6c;
  --cardboard-dark: #9c7448;
  --vermilion: #e63946;
  --coral: #ff7a59;
  --sunflower: #f4d35e;
  --teal: #2a9d8f;
  --cobalt: #457b9d;
  --plum: #7b2cbf;
  --cream: #fffaf0;
  --tape: rgba(232, 236, 224, 0.72);
  --shadow: 4px 5px 0 rgba(43, 36, 32, 0.28);
  --font-display: Georgia, "Palatino Linotype", "Book Antiqua", serif;
  --font-ui: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--cardboard-dark);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-user-select: none;
  user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Cards: pinned parchment sheets with masking tape corners and hard ink outlines */
.card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(860px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding: 22px 24px 20px;
  background:
    radial-gradient(circle at 12% 10%, rgba(255, 250, 240, 0.7), transparent 45%),
    repeating-linear-gradient(0deg, rgba(130, 98, 62, 0.03) 0 2px, transparent 2px 6px),
    var(--paper);
  border: 3px solid var(--ink);
  border-radius: 10px;
  box-shadow: 7px 9px 0 rgba(43, 36, 32, 0.34);
  z-index: 10;
}

.card::before,
.card::after {
  content: "";
  position: absolute;
  top: -10px;
  width: 68px;
  height: 20px;
  background: var(--tape);
  border: 1px solid rgba(140, 130, 110, 0.45);
  pointer-events: none;
}
.card::before {
  left: 18px;
  transform: rotate(-7deg);
}
.card::after {
  right: 18px;
  transform: rotate(6deg);
}

/* Phase visibility */
body[data-phase="playing"] #lobby,
body[data-phase="results"] #lobby {
  display: none;
}
body:not([data-phase="results"]) #results {
  display: none;
}
body:not([data-phase="playing"]) #hud {
  display: none;
}

/* Header & brand */
.brand {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 2px dashed rgba(43, 36, 32, 0.25);
}

.brand-title h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(26px, 4vw, 36px);
  letter-spacing: 0.02em;
  line-height: 1.05;
  color: var(--ink);
}

.brand-title h1 span {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 9px;
  font-size: 0.55em;
  vertical-align: middle;
  background: var(--vermilion);
  color: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 5px;
  transform: rotate(-2deg);
  box-shadow: 2px 2px 0 var(--ink);
}

.brand-title .tag {
  margin: 6px 0 0;
  font-size: 13.5px;
  color: var(--ink-soft);
}

/* Account pill (Sovereign Forge auth) */
.account-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.account-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
}

.account-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--cardboard);
  border: 1.5px solid var(--ink);
}
.account-dot.online {
  background: var(--teal);
}

/* Play Mode & Playlist Toolbar */
.playlist-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.mode-group,
.pool-group {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.mode-btn.active,
#edit-pool-btn.active,
#show-hidden-btn.active {
  background: var(--vermilion);
  color: var(--cream);
}

/* Game selector ribbon (14 quick 1-round party games) */
.game-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin-bottom: 12px;
  padding: 8px 9px;
  background: var(--paper-warm);
  border: 2px solid var(--ink);
  border-radius: 8px;
}

.game-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 6px;
  font-weight: 800;
  font-size: 11.5px;
  box-shadow: 1px 2px 0 var(--ink);
}

.game-pill.disabled-game {
  opacity: 0.48;
  border-style: dashed;
  box-shadow: none;
  text-decoration: line-through;
}

.game-pill .stars-tag {
  font-size: 10.5px;
  color: #b45309;
  font-weight: 900;
}

/* Post-game rating bar on results card */
.rate-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 6px 0 10px;
  padding: 8px 10px;
  background: var(--paper-warm);
  border: 2px solid var(--ink);
  border-radius: 8px;
}

.rate-label {
  font-size: 12.5px;
  font-weight: 800;
}

.rate-stars {
  display: inline-flex;
  gap: 3px;
}

.star-btn {
  padding: 2px 6px;
  font-size: 16px;
  line-height: 1;
  background: var(--cream);
  color: rgba(43, 36, 32, 0.25);
  box-shadow: 1px 1px 0 var(--ink);
}

.star-btn.lit {
  color: #d97706;
  background: var(--sunflower);
}

.game-pill.active {
  background: var(--sunflower);
}

.game-pill.upcoming {
  opacity: 0.65;
  border-style: dashed;
  box-shadow: none;
  font-weight: 700;
}

.game-pill .stamp {
  font-size: 9.5px;
  padding: 2px 5px;
  background: var(--teal);
  color: var(--cream);
  border-radius: 4px;
  letter-spacing: 0.05em;
}

.game-pill.upcoming .stamp {
  background: var(--ink-soft);
}

/* Columns */
.cols {
  display: grid;
  grid-template-columns: 1.25fr 0.95fr;
  gap: 20px;
}

@media (max-width: 720px) {
  .cols {
    grid-template-columns: 1fr;
  }
}

h2,
h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 17px;
  color: var(--ink);
}

/* Inputs & buttons */
.name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
}

input[type="text"],
#name,
#chat-input {
  font-family: var(--font-ui);
  font-size: 14px;
  padding: 6px 10px;
  background: var(--cream);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 6px;
  outline: none;
}

#name {
  flex: 1;
  min-width: 0;
  font-weight: 700;
}

input:focus {
  box-shadow: 0 0 0 2px var(--sunflower);
}

button {
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 13.5px;
  padding: 7px 13px;
  background: var(--cream);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 7px;
  cursor: pointer;
  box-shadow: 2px 3px 0 var(--ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.12s ease;
}

button:hover:not(:disabled) {
  background: var(--sunflower);
  transform: translate(-1px, -1px);
  box-shadow: 3px 4px 0 var(--ink);
}

button:active:not(:disabled) {
  transform: translate(1px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.primary {
  background: var(--vermilion);
  color: var(--cream);
}

button.primary:hover:not(:disabled) {
  background: var(--coral);
}

button.small {
  padding: 4px 9px;
  font-size: 12px;
  box-shadow: 1px 2px 0 var(--ink);
}

/* Seat count selector (4 / 6 / 8 players) */
.seat-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12.5px;
  font-weight: 700;
}

.seat-picks {
  display: inline-flex;
  gap: 5px;
}

.seat-picks button {
  padding: 3px 9px;
  font-size: 12px;
  box-shadow: 1px 2px 0 var(--ink);
}

.seat-picks button.active {
  background: var(--sunflower);
}

/* Lobby player slots (compact 2-column grid for 4-8 players) */
.slots {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

@media (max-width: 520px) {
  .slots {
    grid-template-columns: 1fr;
  }
}

.slots li {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  background: rgba(255, 250, 240, 0.55);
  border: 2px dashed rgba(43, 36, 32, 0.35);
  border-radius: 7px;
  font-size: 13px;
  color: var(--ink-soft);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slots li.on {
  background: var(--cream);
  border-style: solid;
  border-color: var(--ink);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 2px 2px 0 rgba(43, 36, 32, 0.18);
}

.slots .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  flex-shrink: 0;
}

.slots .host {
  margin-left: auto;
  font-size: 10px;
  padding: 2px 6px;
  background: var(--sunflower);
  color: var(--ink);
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  letter-spacing: 0.06em;
}

.waiting {
  margin: 6px 0 10px;
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 600;
}

.invite {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px;
  padding: 8px 10px;
  background: var(--paper-warm);
  border: 1.5px solid rgba(43, 36, 32, 0.35);
  border-radius: 7px;
  font-size: 12.5px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-bottom: 12px;
}

/* How to play accordion */
.how {
  background: rgba(255, 250, 240, 0.65);
  border: 2px solid rgba(43, 36, 32, 0.3);
  border-radius: 7px;
  padding: 8px 11px;
  font-size: 12.5px;
}

.how summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--ink);
}

.how ul {
  margin: 8px 0 2px;
  padding-left: 18px;
  line-height: 1.45;
}

.how kbd {
  padding: 1px 5px;
  background: var(--cream);
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 800;
}

.how .mag { color: var(--plum); }
.how .shd { color: var(--cobalt); }
.how .tur { color: var(--coral); }
.how .frz { color: var(--vermilion); }

/* Right column: Unified 5-tab Leaderboard & Friends */
.panel-box {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 2px 3px 0 rgba(43, 36, 32, 0.16);
}

.lb-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0 0 8px;
}

.lb-tab {
  padding: 3px 7px;
  font-size: 11.5px;
  font-weight: 800;
  border-radius: 5px;
  box-shadow: 1px 1px 0 var(--ink);
  background: var(--paper);
}

.lb-tab.active {
  background: var(--vermilion);
  color: var(--cream);
}

.lb-meta {
  font-size: 11px;
  color: var(--ink-soft);
  margin: 0 0 6px;
}

.tally {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.tally th,
.tally td {
  text-align: left;
  padding: 5px 6px;
  border-bottom: 1px dashed rgba(43, 36, 32, 0.22);
}

.tally th:nth-child(n + 2),
.tally td:nth-child(n + 2) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.tally tr.me td {
  font-weight: 800;
  background: rgba(244, 211, 94, 0.28);
}

.tally tr.empty td {
  text-align: center;
  color: var(--ink-soft);
  font-style: italic;
}

.tally .ai {
  font-size: 10px;
  padding: 1px 4px;
  background: var(--paper-deep);
  border: 1px solid var(--ink);
  border-radius: 3px;
}

/* Friends list */
.friends-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: grid;
  gap: 5px;
  max-height: 135px;
  overflow-y: auto;
}

.friends-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12.5px;
  padding: 4px 6px;
  background: var(--paper);
  border: 1.5px solid rgba(43, 36, 32, 0.22);
  border-radius: 5px;
}

.friends-empty {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin: 4px 0 0;
}

/* Results card */
#results {
  width: min(520px, calc(100vw - 24px));
}

.ranking {
  list-style: none;
  margin: 10px 0 14px;
  padding: 0;
  display: grid;
  gap: 6px;
}

.ranking li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 7px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.ranking li.win {
  background: var(--sunflower);
  box-shadow: 3px 3px 0 var(--ink);
}

/* In-game HUD scores */
#hud {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 8;
  pointer-events: none;
}

#scores {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#scores li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  min-width: 148px;
  padding: 6px 10px;
  background: var(--cream);
  border: 2.5px solid var(--ink);
  border-left-width: 7px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  box-shadow: 3px 3px 0 rgba(43, 36, 32, 0.28);
}

#scores li.me {
  background: var(--sunflower);
}

/* Chat drawer */
#chat {
  position: fixed;
  right: 12px;
  bottom: 12px;
  width: min(300px, calc(100vw - 24px));
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

#chat-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#unread {
  padding: 1px 6px;
  background: var(--vermilion);
  color: var(--cream);
  border-radius: 999px;
  font-size: 11px;
}

#chat-body {
  display: none;
  width: 100%;
  margin-top: 8px;
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 9px;
  box-shadow: 5px 6px 0 rgba(43, 36, 32, 0.32);
  overflow: hidden;
}

#chat.open #chat-body {
  display: block;
}

#chat-log {
  list-style: none;
  margin: 0;
  padding: 10px;
  height: 190px;
  overflow-y: auto;
  font-size: 12.5px;
  line-height: 1.4;
  user-select: text;
}

#chat-log li {
  margin-bottom: 5px;
  word-break: break-word;
}

#chat-log li b {
  margin-right: 5px;
}

#chat-log li.sys {
  color: var(--ink-soft);
  font-style: italic;
}

#chat-form {
  display: flex;
  gap: 6px;
  padding: 8px;
  background: var(--paper-warm);
  border-top: 2px solid var(--ink);
}

#chat-input {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  padding: 5px 8px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
