:root {
  --felt: #1f5d3a;
  --felt-dark: #174a2d;
  --ink: #f4f1e8;
  --muted: #b9cfc0;
  --card: #fbf8f0;
  --card-edge: #d8d2c2;
  --red: #c62828;
  --green: #2e7d32;
  --yellow: #c79100;
  --black: #1d1d1d;
  --chicken: #8d4e1f;
  --accent: #f2c14e;
  --card-w: min(calc((100vw - 32px - 30px) / 7), 64px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--felt);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

button {
  font: inherit;
  color: var(--black);
  background: var(--card);
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
}
button:disabled { opacity: 0.45; }
button.primary { background: var(--accent); font-weight: 600; min-width: 160px; }

/* Header */
.scores {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--felt-dark);
}
.score { display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.score span { font-size: 12px; color: var(--muted); }
.score strong { font-size: 24px; }
.score small { font-size: 12px; color: var(--accent); }
.info { text-align: center; font-size: 13px; color: var(--muted); line-height: 1.5; }
.info .trump { color: var(--ink); font-weight: 600; }

/* Table */
.table {
  position: relative;
  flex: 1;
  min-height: 300px;
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "left top right" "left middle right";
  gap: 8px;
  padding: 12px 0;
}
.seat { text-align: center; font-size: 13px; color: var(--muted); position: relative; }
.seat.top { grid-area: top; }
.seat.left { grid-area: left; align-self: center; }
.seat.right { grid-area: right; align-self: center; }
.seat .name { color: var(--ink); font-weight: 600; font-size: 15px; }
.seat .name em { font-style: normal; font-weight: 400; font-size: 11px; color: var(--accent); }
.seat.turn .name { color: var(--accent); }
.bubble {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  background: var(--card);
  color: var(--black);
  border-radius: 12px;
  font-weight: 600;
}

.middle {
  grid-area: middle;
  position: relative;
  min-height: 220px;
}
.middle .note { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.middle .bubble.mine { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); white-space: nowrap; }
.played { position: absolute; transform: translate(-50%, -50%); }
.played.top { left: 50%; top: 22%; }
.played.bottom { left: 50%; top: 78%; }
.played.left { left: 12%; top: 50%; }
.played.right { left: 88%; top: 50%; }
.played.won .card { box-shadow: 0 0 0 3px var(--accent); }
.tap {
  position: absolute;
  inset: 0;
  width: 100%;
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-size: 13px;
  padding-bottom: 0;
}

/* Cards */
.card {
  width: var(--card-w);
  aspect-ratio: 5 / 7;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 8px;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  font-weight: 800;
  font-size: calc(var(--card-w) * 0.48);
  line-height: 1;
}
.card.red { color: var(--red); }
.card.green { color: var(--green); }
.card.yellow { color: var(--yellow); }
.card.black { color: var(--black); }
.card.chicken { color: var(--chicken); font-size: calc(var(--card-w) * 0.2); }

/* Hand */
.hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
  padding: 8px 0;
  min-height: calc(var(--card-w) * 1.4 + 16px);
}
/* --per-row cards across: cards shrink to fit, and the row is capped so it breaks evenly */
.hand {
  --hand-card: min(var(--card-w), calc((100vw - 32px - (var(--per-row) - 1) * 5px) / var(--per-row)));
  max-width: calc(var(--per-row) * var(--hand-card) + (var(--per-row) - 1) * 5px);
  margin: 0 auto;
  width: 100%;
}
.hand .card { width: var(--hand-card); font-size: calc(var(--hand-card) * 0.48); }
.hand .card[role="button"] { cursor: pointer; }
.hand .card.dim { opacity: 0.4; }
.hand .card { position: relative; }
.hand .card.picked { transform: translateY(-8px); box-shadow: 0 0 0 3px var(--accent); background: #efe6cc; }
/* Cards that just came from the nest get a small dot */
.hand .card.fresh::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.status { text-align: center; min-height: 22px; font-size: 14px; color: var(--muted); }

/* Controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  padding: 8px 0 14px;
  min-height: 60px;
}
.controls.bids button { min-width: 56px; padding: 8px 6px; }
.controls.bids .pass { background: var(--felt-dark); color: var(--ink); min-width: 80px; }
.controls.bids .solo { background: var(--accent); }
.controls .ask { width: 100%; text-align: center; font-size: 14px; }
.controls .trump.red { color: var(--red); }
.controls .trump.green { color: var(--green); }
.controls .trump.yellow { color: var(--yellow); }
.controls .trump.black { color: var(--black); }

/* Round summary and game over */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 16px;
}
.panel {
  background: var(--card);
  color: var(--black);
  border-radius: 14px;
  padding: 20px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.panel h2 { margin: 0 0 12px; font-size: 20px; }
.panel table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.panel th, .panel td { padding: 6px; text-align: right; }
.panel th:first-child, .panel td:first-child { text-align: left; }

/* Trump badge in the header */
.trump-badge {
  display: inline-block;
  margin-top: 2px;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 700;
  color: #fff;
}
.trump-badge.red { background: var(--red); }
.trump-badge.green { background: var(--green); }
.trump-badge.yellow { background: #f2c230; color: var(--black); }
.trump-badge.black { background: var(--black); box-shadow: 0 0 0 1px var(--muted); }

button.link {
  background: none;
  color: var(--muted);
  min-height: 32px;
  padding: 4px 8px;
  text-decoration: underline;
  font-size: 13px;
}
.status button.link { margin-left: 8px; color: var(--accent); }

/* Previous trick */
.peek { display: flex; justify-content: center; gap: 10px; margin-bottom: 8px; }
.peek-play { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; }
.peek-play.won .card { box-shadow: 0 0 0 3px var(--accent); }

/* Chicken drawing */
.card.chicken .chicken-art { width: 88%; height: auto; display: block; }

/* Rules page */
.rules-overlay { place-items: start center; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.panel.rules { text-align: left; max-width: 480px; margin: max(16px, env(safe-area-inset-top)) 0 32px; line-height: 1.45; font-size: 15px; }
.panel.rules h2 { text-align: center; }
.panel.rules h3 { margin: 18px 0 6px; font-size: 16px; }
.panel.rules p { margin: 6px 0; }
.panel.rules ul { margin: 6px 0; padding-left: 20px; }
.panel.rules li { margin: 4px 0; }
.panel.rules table { width: auto; margin: 6px 0; }
.panel.rules td { text-align: left; padding: 2px 14px 2px 0; }
.panel.rules .primary { display: block; margin: 20px auto 0; }

/* High bidder marker */
.bid-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
}

/* Settings */
.panel.settings { text-align: left; }
.panel.settings h2 { text-align: center; }
.toggle { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; font-size: 16px; }
.toggle input { width: 22px; height: 22px; margin-top: 2px; flex: none; }
.toggle small { display: block; color: #666; font-size: 13px; margin-top: 2px; }
.panel.settings .note { font-size: 13px; color: #555; }
.panel.settings button { display: block; margin: 12px auto 0; }
.panel.settings button:not(.primary) { border: 1px solid #b9b2a0; }
