:root {
  --ink: #0e1116;
  --surround: #161b23;
  --felt: #1b232d;
  --felt-edge: #2b3644;
  --brass: #7d6836;
  --brass-lit: #b8974a;
  --gold: #c9a227;
  --parchment: #e7dcc1;
  --parchment-dim: #9a927f;
  --blood: #7e2b2b;
  --card-back: #2a2a2e;
  --radius: 6px;
  --card-w: 84px;
  --card-h: 126px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--parchment);
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

h1, h2, .zone-label, .pile-label, .display {
  font-family: "Cinzel", Georgia, serif;
  letter-spacing: 0.02em;
}

/* ---------------------------------------------------------- gate screens */

.gate {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% 40%, #1d2530 0%, var(--ink) 70%);
}

.gate form {
  width: min(380px, 100%);
  padding: 40px 32px;
  background: var(--surround);
  border: 1px solid var(--brass);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.gate h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 600;
  color: var(--gold);
}

.gate p { margin: 0 0 24px; color: var(--parchment-dim); font-size: 14px; }

input[type="text"], input[type="password"], input[type="number"] {
  width: 100%;
  padding: 11px 13px;
  background: #0d1015;
  border: 1px solid var(--felt-edge);
  border-radius: 4px;
  color: var(--parchment);
  font: inherit;
}

input:focus-visible, button:focus-visible, .card:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

button {
  padding: 9px 14px;
  background: var(--surround);
  border: 1px solid var(--brass);
  border-radius: 4px;
  color: var(--parchment);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

button:hover:not(:disabled) { border-color: var(--brass-lit); color: #fff; }
button:disabled { opacity: 0.4; cursor: default; }

button.primary {
  width: 100%;
  margin-top: 16px;
  padding: 11px;
  background: var(--brass);
  border-color: var(--brass-lit);
  color: #12151a;
  font-weight: 600;
}

.error { margin-top: 14px; color: #d98a8a; font-size: 13px; }

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

.table {
  display: grid;
  grid-template-rows: 1fr auto 1fr auto;
  height: 100dvh;
  padding: 8px;
  gap: 8px;
  background:
    radial-gradient(ellipse at 50% 50%, #1e242e 0%, var(--ink) 75%);
}

.mat {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 6px;
  padding: 10px;
  background: var(--felt);
  border: 1px solid var(--felt-edge);
  border-radius: 10px;
}

.mat[data-rotate="180"] { transform: rotate(180deg); }

.mat-name {
  position: absolute;
  top: 6px;
  right: 12px;
  font-size: 11px;
  color: var(--parchment-dim);
}

.mat.is-you { border-color: var(--brass); }

.zone {
  position: relative;
  display: grid;
  place-items: center;
  border: 1px dashed var(--brass);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.18);
}

.zone.drop-target { border-style: solid; border-color: var(--gold); background: rgba(201, 162, 39, 0.1); }
.zone[data-zone="action"] { grid-row: span 2; }

.zone-label {
  position: absolute;
  top: 4px;
  left: 8px;
  font-size: 10px;
  color: var(--parchment-dim);
  pointer-events: none;
}

/* ---------------------------------------------------------------- center */

.center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 10px 14px;
  background: var(--surround);
  border: 1px solid var(--felt-edge);
  border-radius: 10px;
  min-height: 150px;
}

.pile { display: grid; justify-items: center; gap: 6px; }
.pile-label { font-size: 11px; color: var(--parchment-dim); }

.pile-slot {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  border: 1px dashed var(--brass);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
}

.pile-count {
  position: absolute;
  bottom: -9px;
  padding: 1px 7px;
  background: var(--surround);
  border: 1px solid var(--brass);
  border-radius: 10px;
  font-size: 11px;
}

.pile-actions { display: flex; gap: 4px; }
.pile-actions button { padding: 4px 7px; font-size: 11px; }

.guardian-spread {
  display: flex;
  gap: 4px;
  max-width: 34vw;
  overflow-x: auto;
  padding-bottom: 4px;
}

/* ----------------------------------------------------------------- dice */

.dice-area { display: grid; justify-items: center; gap: 8px; }

.dice-row { display: flex; gap: 8px; }

.die {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  background: var(--parchment);
  border-radius: 8px;
  color: #17181c;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22);
}

.die.empty { background: #232833; color: var(--parchment-dim); box-shadow: none; }
.die.tumbling { animation: tumble 0.14s steps(1) infinite; }

@keyframes tumble {
  0% { transform: rotate(-7deg) scale(1.04); }
  50% { transform: rotate(6deg) scale(0.97); }
  100% { transform: rotate(-3deg) scale(1.02); }
}

.dice-controls { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.dice-controls input[type="range"] { width: 82px; accent-color: var(--gold); }
.dice-total { font-size: 13px; color: var(--gold); }

/* ---------------------------------------------------------------- cards */

.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--radius);
  background: var(--card-back);
  background-size: cover;
  border: 1px solid #000;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  cursor: grab;
  touch-action: none;
  position: relative;
}

.card.facedown::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid #3c3c45;
  border-radius: 3px;
}

.card.dragging { opacity: 0.55; cursor: grabbing; }
.card.selected { outline: 2px solid var(--gold); outline-offset: 1px; }
.card.stacked { position: absolute; }

.loose-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.loose-layer .card { position: absolute; pointer-events: auto; }

/* ----------------------------------------------------------------- hand */

.hand {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--surround);
  border: 1px solid var(--brass);
  border-radius: 10px;
}

.hand-cards {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  min-height: var(--card-h);
  padding: 2px;
}

.hand.collapsed .hand-cards { min-height: 34px; }
.hand.collapsed .hand-cards .card { height: 30px; width: 46px; background-position: top; }

.toolbar { display: flex; flex-wrap: wrap; gap: 6px; }
.toolbar button { padding: 6px 9px; font-size: 12px; }

/* --------------------------------------------------------------- tokens */

.token-tray {
  position: fixed;
  right: 10px;
  bottom: 150px;
  width: 116px;
  padding: 8px;
  background: var(--surround);
  border: 1px solid var(--brass);
  border-radius: 8px;
  z-index: 40;
}

.token-tray h2 { margin: 0 0 6px; font-size: 11px; color: var(--parchment-dim); font-weight: 500; }
.token-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }

.token {
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  background: var(--blood);
  border: 1px solid #a85454;
  border-radius: 50%;
  color: #ffeaea;
  font-size: 11px;
  font-weight: 700;
  cursor: grab;
  touch-action: none;
}

.token.placed { position: absolute; z-index: 30; width: 24px; height: 24px; font-size: 13px; }

/* ----------------------------------------------------------- log + zoom */

.log {
  position: fixed;
  left: 10px;
  bottom: 150px;
  width: 210px;
  max-height: 168px;
  overflow-y: auto;
  padding: 8px 10px;
  background: rgba(14, 17, 22, 0.92);
  border: 1px solid var(--felt-edge);
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--parchment-dim);
  z-index: 40;
}

.log b { color: var(--parchment); font-weight: 500; }

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(6, 8, 11, 0.86);
  z-index: 100;
}

.overlay.open { display: grid; }
.overlay img { max-height: 84vh; border-radius: 10px; box-shadow: 0 20px 60px #000; }

.sheet {
  width: min(880px, 100%);
  max-height: 84vh;
  overflow-y: auto;
  padding: 20px;
  background: var(--surround);
  border: 1px solid var(--brass);
  border-radius: 10px;
}

.sheet h2 { margin: 0 0 14px; font-size: 18px; color: var(--gold); }

.search-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
}

.search-grid .card { width: 100%; height: auto; aspect-ratio: 2 / 3; }

.seat-picker { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }

@media (max-width: 820px) {
  :root { --card-w: 62px; --card-h: 93px; }
  .log, .token-tray { display: none; }
  .center { gap: 12px; }
}
