:root {
  --felt-dark: #1B4332;
  --felt-darker: #143528;
  --felt-line: rgba(255, 255, 255, 0.06);

  --card-face: #FAF6EE;
  --card-edge: #E4DBC8;
  --ink: #1D1D1D;
  --ink-soft: #6B6459;

  --blue: #3C5B8F;
  --green: #2F6F4E;
  --red: #B5533C;
  --skipbo: #C9A227;

  --card-w: clamp(70px, 21vw, 92px);
  --card-h: calc(var(--card-w) * 1.4);
  --card-w-sm: min(70px, calc((100vw - 52px) / 5));
  --card-h-sm: calc(var(--card-w-sm) * 1.4);
  --cw: var(--card-w);

  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--felt-dark);
  background-image:
    radial-gradient(circle at 20% 15%, var(--felt-line), transparent 45%),
    radial-gradient(circle at 85% 90%, var(--felt-line), transparent 45%);
  font-family: var(--font-ui);
  color: var(--card-face);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---- Turn banner ---- */

.turn-banner {
  flex: 0 0 auto;
  padding: 10px 16px 9px;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.01em;
  background: linear-gradient(to bottom, rgba(20, 53, 40, 0.9), rgba(20, 53, 40, 0.4));
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--card-face);
}

.turn-banner--over {
  color: var(--skipbo);
}

/* ---- Table ---- */

#table {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel {
  padding: 6px 10px;
}

.panel--center {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: 0;
}

.panel--opponent { opacity: 0.86; }
.panel--self { border-top: 1px solid rgba(255, 255, 255, 0.06); }

.player-name {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(250, 246, 238, 0.6);
  margin-bottom: 4px;
  text-transform: uppercase;
}

.panel--self .player-name {
  color: var(--skipbo);
}

.player-name__stock {
  font-weight: 500;
  color: rgba(250, 246, 238, 0.45);
  text-transform: none;
}

.pile-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: flex-end;
}

/* ---- Piles (stock / discard / build) ---- */

.pile {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  flex-shrink: 0;
  --cw: var(--card-w);
}

.pile--sm {
  width: var(--card-w-sm);
  height: var(--card-h-sm);
  --cw: var(--card-w-sm);
}

.pile .card {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
}

.badge {
  position: absolute;
  top: -8px;
  right: -8px;
  z-index: 5;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--skipbo);
  color: #1D1D1D;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

/* ---- Center ---- */

.center-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.draw-pile {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  flex-shrink: 0;
}

.draw-pile .card {
  position: absolute;
  inset: 0;
}

.build-grid {
  display: grid;
  grid-template-columns: repeat(2, var(--card-w));
  grid-auto-rows: var(--card-h);
  gap: 10px;
  justify-content: center;
}

.pile--build {
  border-radius: 8px;
}

/* ---- Cards ---- */

.card {
  width: var(--cw);
  height: calc(var(--cw) * 1.4);
  border-radius: 8px;
  background: var(--card-face);
  border: 1px solid var(--card-edge);
  box-shadow: 0 2px 1px rgba(0, 0, 0, 0.15), 0 8px 16px -8px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
  --fam: transparent;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  border-radius: 8px 8px 0 0;
  background: var(--fam);
}

.card--blue { --fam: var(--blue); }
.card--green { --fam: var(--green); }
.card--red { --fam: var(--red); }
.card--skipbo { --fam: var(--skipbo); }

.card__number {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: calc(var(--cw) * 0.52);
  color: var(--ink);
  font-variant-numeric: oldstyle-nums;
}

.card--blue .card__number { color: var(--blue); }
.card--green .card__number { color: var(--green); }
.card--red .card__number { color: var(--red); }
.card--skipbo .card__number { color: var(--skipbo); }

.card__number--skipbo {
  font-size: calc(var(--cw) * 0.28);
  letter-spacing: -0.01em;
}

.card__corner {
  position: absolute;
  top: 9px;
  left: 8px;
  font-family: var(--font-display);
  font-size: calc(var(--cw) * 0.19);
  font-weight: 600;
  color: var(--ink-soft);
}

.card--back {
  background: var(--felt-darker);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background-image: repeating-linear-gradient(45deg, rgba(255,255,255,0.05) 0 6px, transparent 6px 12px);
}

.card--empty {
  background: transparent;
  border: 1.5px dashed rgba(250, 246, 238, 0.25);
  box-shadow: none;
  color: rgba(250, 246, 238, 0.3);
  font-family: var(--font-display);
  font-size: calc(var(--cw) * 0.32);
}

.card--selectable { cursor: pointer; touch-action: none; }

.card--selected {
  box-shadow: 0 0 0 3px var(--skipbo), 0 8px 16px -8px rgba(0, 0, 0, 0.5);
  z-index: 100;
}

/* ---- Hand ---- */

.hand-area {
  position: relative;
  flex: 0 0 auto;
  height: 164px;
  padding: 8px 10px 14px;
  background: linear-gradient(to bottom, transparent, var(--felt-darker) 60%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.hand {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  max-width: 100%;
  min-height: var(--card-h);
}

.hand .card {
  transition: transform 0.16s ease;
  transform-origin: bottom center;
}

.hand .card:hover { transform: translateY(-8px) scale(1.04); }

.hand .card--selected {
  transform: translateY(-10px) scale(1.06);
  z-index: 100;
}

.hand__empty {
  align-self: center;
  color: rgba(250, 246, 238, 0.4);
  font-size: 13px;
}

.end-turn {
  position: absolute;
  top: 8px;
  right: 12px;
  z-index: 10;
  background: rgba(250, 246, 238, 0.08);
  color: rgba(250, 246, 238, 0.7);
  border: 1px solid rgba(250, 246, 238, 0.18);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.end-turn:active { background: rgba(250, 246, 238, 0.16); }

/* ---- Overlay ---- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(10, 26, 19, 0.82);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.overlay.hidden { display: none; }

.overlay__card {
  width: 100%;
  max-width: 360px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--felt-darker);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 24px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.overlay__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 30px;
  text-align: center;
}

.overlay__sub {
  margin: 0;
  text-align: center;
  font-size: 14px;
  color: rgba(250, 246, 238, 0.55);
}

.overlay__card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 24px;
  text-align: center;
}

.overlay__label {
  font-size: 12px;
  letter-spacing: 0.05em;
  color: rgba(250, 246, 238, 0.55);
  text-transform: uppercase;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field__label {
  font-size: 12px;
  letter-spacing: 0.05em;
  color: rgba(250, 246, 238, 0.55);
  text-transform: uppercase;
}

.field__input {
  background: rgba(250, 246, 238, 0.06);
  border: 1px solid rgba(250, 246, 238, 0.16);
  border-radius: 10px;
  color: var(--card-face);
  font-family: var(--font-ui);
  font-size: 18px;
  padding: 14px;
  outline: none;
}

.field__input:focus { border-color: var(--skipbo); }

.stock-options { display: flex; gap: 8px; }

.chip {
  flex: 1;
  background: rgba(250, 246, 238, 0.06);
  border: 1px solid rgba(250, 246, 238, 0.16);
  color: var(--card-face);
  border-radius: 10px;
  padding: 13px 0;
  font-family: var(--font-ui);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

.chip--active {
  background: var(--skipbo);
  border-color: var(--skipbo);
  color: #1D1D1D;
}

.btn {
  background: var(--skipbo);
  color: #1D1D1D;
  border: none;
  border-radius: 14px;
  padding: 16px;
  font-family: var(--font-ui);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.btn:active { opacity: 0.88; }

/* ---- Toast ---- */

.toast {
  position: fixed;
  bottom: 150px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  background: rgba(29, 29, 29, 0.92);
  color: var(--card-face);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 13px;
  max-width: 86vw;
  text-align: center;
}

.toast.hidden { display: none; }

/* ---- Online / connection wizard ---- */

.btn--ghost {
  background: rgba(250, 246, 238, 0.06);
  color: var(--card-face);
  border: 1px solid rgba(250, 246, 238, 0.18);
}

.qr-holder {
  display: flex;
  justify-content: center;
  padding: 4px;
}

.qr-code {
  width: 190px;
  height: 190px;
  image-rendering: pixelated;
  background: #fff;
  border-radius: 8px;
  padding: 6px;
}

.scan-camera {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-height: 260px;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}

.scan-camera video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.code-box {
  width: 100%;
  min-height: 90px;
  background: rgba(250, 246, 238, 0.06);
  border: 1px solid rgba(250, 246, 238, 0.16);
  border-radius: 10px;
  color: var(--card-face);
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 10px;
  resize: vertical;
}

.status {
  text-align: center;
  font-size: 13px;
  color: rgba(250, 246, 238, 0.55);
}

#app.is-my-turn .panel--self {
  box-shadow: inset 0 2px 0 var(--skipbo);
}

.overlay__card--scroll {
  max-height: 86vh;
  overflow-y: auto;
}

.browser-step {
  background: rgba(250, 246, 238, 0.05);
  border: 1px solid rgba(250, 246, 238, 0.1);
  border-radius: 10px;
  padding: 10px 12px;
}

.browser-step__name {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 4px;
}

.browser-step__where {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--skipbo);
  word-break: break-all;
  margin-bottom: 3px;
}

.browser-step__action {
  font-size: 12px;
  color: rgba(250, 246, 238, 0.7);
  line-height: 1.4;
}

.privacy-note {
  font-size: 12px;
  line-height: 1.45;
  color: rgba(250, 246, 238, 0.8);
  background: rgba(201, 162, 39, 0.08);
  border: 1px solid rgba(201, 162, 39, 0.25);
  border-radius: 10px;
  padding: 10px 12px;
}

/* ---- Drag & drop ---- */

.card--dragging {
  z-index: 200;
  transition: none !important;
  box-shadow: 0 12px 24px -6px rgba(0, 0, 0, 0.55);
  cursor: grabbing;
}

.card--ghost {
  pointer-events: none;
  will-change: transform, opacity;
}

.card--snap-back {
  transition: transform 0.28s cubic-bezier(0.34, 1.4, 0.64, 1) !important;
}

.pile--drag-target .card {
  box-shadow: 0 0 0 3px var(--skipbo), 0 8px 16px -8px rgba(0, 0, 0, 0.5);
}

.pile--drag-target .card--empty {
  border-color: var(--skipbo);
}

/* ---- Short screens: keep cards compact ---- */

@media (max-height: 760px) {
  :root {
    --card-w: clamp(58px, 17vw, 76px);
  }
  .hand-area { height: 144px; }
}

/* ---- Landscape: tighten up ---- */

@media (orientation: landscape) {
  :root {
    --card-w: clamp(44px, 7.5vh, 60px);
    --card-w-sm: clamp(40px, 6.5vh, 52px);
  }
  .turn-banner { font-size: 16px; padding: 6px 12px 5px; }
  .hand-area { height: 118px; }
}
