:root {
  --felt: #14513c;
  --felt-dark: #0f3d2e;
  --felt-light: #1b6a4e;
  --ink: #f3f1e7;
  --muted: #b9cfc4;
  --card: #fdfcf7;
  --black-suit: #1a1d22;
  --red-suit: #c62833;
  --accent: #f2c14e;
  --cw: 64px;
  --ch: 92px;
  --chip: 34px;
}
@media (max-width: 600px) {
  :root { --cw: 52px; --ch: 76px; --chip: 30px; }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(ellipse at center, var(--felt-light), var(--felt) 55%, var(--felt-dark));
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

button, select, input { font: inherit; }
button {
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.25);
  color: var(--ink);
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
}
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: #2a2204; border-color: var(--accent); font-weight: 600; }

/* ---- top bar ---- */
#bar {
  display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; justify-content: space-between;
  padding: 8px max(10px, env(safe-area-inset-left)) 8px max(10px, env(safe-area-inset-right));
  background: rgba(0,0,0,.28);
}
#info { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; font-size: 14px; }
#info .pill { background: var(--card); color: var(--black-suit); border-radius: 6px; padding: 2px 8px; font-weight: 700; font-size: 16px; }
#info .red { color: var(--red-suit); }
#tricks { font-variant-numeric: tabular-nums; }
#dealno { color: var(--muted); }
#actions { display: flex; gap: 6px; }
#actions button { padding: 6px 10px; font-size: 14px; }

/* ---- table ---- */
#table {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(84px, 1fr) minmax(170px, 1.6fr) minmax(84px, 1fr);
  grid-template-rows: auto minmax(150px, 1fr) auto auto;
  gap: 6px;
  padding: 8px max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
  max-width: 980px; width: 100%; margin: 0 auto;
}
.seat { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-width: 0; }
.seat.north { grid-column: 1 / -1; }
.seat.south { grid-column: 1 / -1; }
#status { grid-column: 1 / -1; text-align: center; min-height: 1.4em; font-size: 15px; color: var(--accent); font-weight: 600; }

.seat-label { font-size: 13px; color: var(--muted); padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.seat.active .seat-label { background: var(--accent); color: #2a2204; font-weight: 700; }
.backs { font-size: 12px; color: var(--muted); border: 1px dashed rgba(255,255,255,.3); border-radius: 8px; padding: 8px 10px; text-align: center; }

/* suit rows (dummy and revealed hands) */
.rows { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; max-width: 100%; }
.suit-row { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; min-height: calc(var(--chip) * .8); }
.suit-row .sym { width: 20px; text-align: center; font-size: 18px; background: var(--card); border-radius: 4px; line-height: 1.25; }
.chip {
  min-width: var(--chip); height: calc(var(--chip) * 1.15); padding: 0 4px;
  background: var(--card); border: 0; border-radius: 6px;
  font-weight: 700; font-size: 17px; color: var(--black-suit);
  box-shadow: 0 1px 2px rgba(0,0,0,.4);
  display: inline-flex; align-items: center; justify-content: center;
}
.chip.red, .sym.red { color: var(--red-suit); }
.sym { color: var(--black-suit); }
.rows.small .chip { min-width: 22px; height: 26px; font-size: 14px; padding: 0 3px; border-radius: 4px; }
.rows.small .suit-row { gap: 2px; padding-left: 22px; }
.rows.small .suit-row .sym { margin-left: -22px; }
.rows.small .chip { min-width: 18px; }
.chip.playable { cursor: pointer; outline: 2px solid var(--accent); }
.chip.dim { opacity: .45; }
.void { color: var(--muted); font-size: 13px; padding-left: 4px; }

/* South's fanned cards */
.fan { display: flex; justify-content: center; width: 100%; padding-top: 10px; }
.card {
  flex: 0 0 auto; width: var(--cw); height: var(--ch);
  background: var(--card); color: var(--black-suit);
  border: 1px solid #9aa; border-radius: 7px; padding: 3px 0 0 5px;
  text-align: left; line-height: 1; position: relative;
  box-shadow: -1px 1px 3px rgba(0,0,0,.35);
  transition: transform .12s;
}
.card.red { color: var(--red-suit); }
.card .r { display: block; font-size: 20px; font-weight: 700; letter-spacing: -1px; }
.card .s { display: block; font-size: 18px; margin-top: 1px; }
.card .big { position: absolute; right: 6px; bottom: 4px; font-size: 30px; opacity: .85; }
.card.playable { cursor: pointer; transform: translateY(-8px); }
.card.playable:hover { transform: translateY(-16px); }
.card.dim { filter: brightness(.72); }
.card:disabled { opacity: 1; }

/* trick area */
#center { position: relative; min-height: 150px; cursor: pointer; }
.slot { position: absolute; width: calc(var(--cw) * .8); height: calc(var(--ch) * .8); }
.slot.n { top: 0; left: 50%; transform: translateX(-50%); }
.slot.s { bottom: 0; left: 50%; transform: translateX(-50%); }
.slot.w { top: 50%; left: calc(50% - var(--cw) * 1.45); transform: translateY(-50%); }
.slot.e { top: 50%; right: calc(50% - var(--cw) * 1.45); transform: translateY(-50%); }
.slot .card { width: 100%; height: 100%; padding: 2px 0 0 4px; }
.slot .card .r { font-size: 17px; }
.slot .card .s { font-size: 15px; }
.slot .card .big { font-size: 22px; right: 4px; bottom: 3px; }
.slot.win .card { outline: 3px solid var(--accent); }

/* play review */
#reviewPanel { grid-column: 1 / -1; background: rgba(0,0,0,.42); border-radius: 10px; padding: 8px 10px; font-size: 14px; line-height: 1.35; }
#reviewPanel[hidden] { display: none; }
#rvSummary { color: var(--muted); font-size: 13px; }
#rvMove { font-weight: 700; margin-top: 2px; }
#rvVerdict.bad { color: #ffb0a8; }
#rvVerdict.ok { color: #a9e5b9; }
#rvLayouts { color: var(--muted); font-size: 13px; }
#reviewPanel .cardtxt { background: var(--card); color: var(--black-suit); border-radius: 4px; padding: 0 4px; font-weight: 700; white-space: nowrap; }
#reviewPanel .cardtxt.red { color: var(--red-suit); }
.rv-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.rv-nav button { padding: 5px 10px; font-size: 14px; }
.card.mark-bad, .chip.mark-bad { outline: 3px solid #e5484d; transform: translateY(-8px); z-index: 2; }
.card.mark-ok, .chip.mark-ok { outline: 3px solid #46a758; transform: translateY(-8px); z-index: 2; }
.card.mark-wait, .chip.mark-wait { outline: 3px solid #9aa; transform: translateY(-8px); z-index: 2; }
.card.mark-best, .chip.mark-best { outline: 3px dashed var(--accent); z-index: 1; }
.chip.mark-bad, .chip.mark-ok, .chip.mark-wait { transform: none; }

/* overlays */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 14px; z-index: 10; }
.overlay[hidden] { display: none; }
.panel { background: #f6f4ec; color: #1d2420; border-radius: 14px; padding: 18px; width: min(430px, 100%); max-height: 100%; overflow: auto; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.panel h1 { margin: 0 0 12px; font-size: 22px; }
.panel label, .panel .label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.panel select, .panel input { width: 100%; padding: 9px; border-radius: 8px; border: 1px solid #b8b8a8; background: #fff; color: inherit; font-size: 16px; }
.panel .hint { font-size: 13px; color: #5a655f; margin: 6px 0 0; }
.panel .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.panel .buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.panel button { background: #e3e0d2; color: #1d2420; border-color: #c4c0ae; padding: 9px 14px; }
.panel button.primary { background: #14513c; color: #fff; border-color: #14513c; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.segmented button.on { background: #14513c; color: #fff; border-color: #14513c; }
.score { font-size: 26px; font-weight: 700; margin: 6px 0 0; }
.score.neg { color: var(--red-suit); }
.score.pos { color: #14513c; }

#toast { position: fixed; left: 50%; bottom: 20%; transform: translateX(-50%); background: rgba(0,0,0,.85); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 15px; z-index: 20; max-width: 92vw; text-align: center; }
#toast[hidden] { display: none; }
#toast .red { color: #ff8a8a; }

@media (max-width: 600px) {
  #info { font-size: 13px; }
  .suit-row .sym { font-size: 16px; }
  #table { gap: 4px; padding-top: 6px; }
}
@media (max-height: 640px) {
  #table { grid-template-rows: auto minmax(130px, 1fr) auto auto; }
  .fan { padding-top: 8px; }
}

/* narrow screens and tall content: never overflow sideways, scroll if needed */
#table { grid-template-columns: minmax(0, 1fr) minmax(130px, 1.5fr) minmax(0, 1fr); overflow-y: auto; overflow-x: hidden; }
#table > * { min-width: 0; }
.seat.north .rows { align-items: flex-start; }
.suit-row { max-width: 100%; }
#table.reviewing { grid-template-rows: auto minmax(120px, 1fr) auto auto auto; }
#table.reviewing #center { min-height: 120px; }
@media (max-width: 420px) {
  .rows.small .chip { min-width: 15px; padding: 0 1px; font-size: 13px; box-shadow: none; }
  .rows.small .suit-row { gap: 1px; padding-left: 19px; }
  .rows.small .suit-row .sym { margin-left: -19px; width: 17px; font-size: 14px; }
  .seat-label { font-size: 12px; padding: 2px 6px; white-space: normal; text-align: center; }
  .chip { min-width: 26px; font-size: 16px; }
}

/* ---- bidding ---- */
#table.bidding #center, #table.bidding .seat.north, #table.bidding .seat.west, #table.bidding .seat.east { display: none; }
#table.bidding { grid-template-rows: minmax(0, 1fr) auto; align-content: start; }
#bidPanel { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 0; }
#bidPanel[hidden] { display: none; }
.auction { display: grid; grid-template-columns: repeat(4, minmax(56px, 76px)); gap: 3px; background: rgba(0,0,0,.3); padding: 6px; border-radius: 10px; }
.auction .ah { text-align: center; font-weight: 700; font-size: 13px; color: var(--muted); padding-bottom: 2px; }
.auction .ah.vul { color: #ff9a9a; }
.auction .ac { min-height: 28px; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,.08); border: 0; border-radius: 5px; color: var(--ink); font-size: 15px; font-weight: 600; padding: 2px; }
.auction button.ac { cursor: pointer; }
.auction .ac.next { color: var(--accent); }
.auction .ac.mine { outline: 1px solid var(--accent); }
.call.red { color: #ff8f8f; }
.call.pass { color: var(--muted); font-weight: 400; }
.call.dbl { color: #ffb347; }
.bidbox { display: grid; grid-template-columns: repeat(5, minmax(48px, 62px)); gap: 4px; }
.bidbox button { padding: 6px 0; background: var(--card); color: var(--black-suit); border: 0; font-weight: 700; font-size: 16px; border-radius: 6px; }
.bidbox button.red { color: var(--red-suit); }
.bidbox button:disabled { opacity: .25; }
.bidbox .wide { grid-column: span 3; background: #2e7d4f; color: #fff; }
.bidbox .dbl { background: #b3261e; color: #fff; }
.bidbox .rdbl { background: #1d4f91; color: #fff; }
.bidwait { color: var(--accent); font-weight: 600; min-height: 1.4em; }
.bidhint { font-size: 12px; color: var(--muted); }
.bidresult { text-align: center; max-width: 420px; line-height: 1.4; }
.bidresult .buttons { display: flex; gap: 8px; justify-content: center; margin-top: 8px; flex-wrap: wrap; }

.panel.wide { width: min(620px, 100%); }
.panel .check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-top: 12px; }
.panel .check input { width: auto; }
.panel button.link { background: none; border: 0; padding: 0; color: #14513c; text-decoration: underline; cursor: pointer; }
#convList label { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; font-weight: 500; }
#convList input { width: auto; margin-top: 3px; }
#convList small { display: block; color: #5a655f; font-weight: 400; }
#brBody { font-size: 14px; line-height: 1.4; }
#brBody .auction { background: #14513c; margin: 8px 0; width: max-content; max-width: 100%; }
#brBody .handtxt { font-family: ui-monospace, Consolas, monospace; font-size: 14px; }
#brBody .red { color: var(--red-suit); }
#brBody .item { border-top: 1px solid #d8d4c2; padding: 8px 0; }
#brBody .item.diff { background: #fff4e0; margin: 0 -8px; padding: 8px; border-radius: 6px; }
#brBody .item .ok { color: #1e7a3c; font-weight: 600; }
#brBody .cardtxt { background: #fff; border: 1px solid #c9c5b3; border-radius: 4px; padding: 0 4px; font-weight: 700; white-space: nowrap; color: var(--black-suit); }
#brBody .cardtxt.red { color: var(--red-suit); }
#brBody h2 { font-size: 16px; margin: 14px 0 4px; }
#brBody table { border-collapse: collapse; margin: 6px 0; }
#brBody td, #brBody th { padding: 2px 10px 2px 0; text-align: left; }
#brBody .hands4 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; margin: 6px 0; }
.panel { overflow-x: hidden; }
#brBody .auction { grid-template-columns: repeat(4, minmax(0, 72px)); width: auto; max-width: 320px; }

/* ---- odds in the play review ---- */
#rvStats { margin-top: 6px; border-top: 1px solid rgba(255,255,255,.18); padding-top: 6px; font-size: 13px; }
#rvStats .st-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: 600; }
#rvStats .st-head button { padding: 1px 8px; font-size: 15px; background: var(--card); color: var(--black-suit); border: 0; }
#rvStats .st-head button.red { color: var(--red-suit); }
#rvStats .st-head button.on { outline: 2px solid var(--accent); }
#rvStats table { border-collapse: collapse; margin-top: 4px; width: 100%; max-width: 520px; }
#rvStats th { text-align: left; font-weight: 600; color: var(--muted); padding: 1px 8px 1px 0; }
#rvStats td { padding: 1px 8px 1px 0; }
#rvStats td.chg { color: var(--accent); font-weight: 700; }
#rvStats .note { color: var(--muted); margin-top: 3px; }

/* ---- one-decision problems ---- */
#problemPanel { grid-column: 1 / -1; background: rgba(0,0,0,.42); border-radius: 10px; padding: 8px 10px; font-size: 14px; line-height: 1.35; min-width: 0; }
#problemPanel[hidden] { display: none; }
#problemPanel .auction { width: max-content; max-width: 100%; margin: 6px 0; grid-template-columns: repeat(4, minmax(0, 64px)); }
#problemPanel .cardtxt { background: var(--card); color: var(--black-suit); border-radius: 4px; padding: 0 4px; font-weight: 700; white-space: nowrap; }
#problemPanel .cardtxt.red { color: var(--red-suit); }
#problemPanel .pb-title { font-weight: 700; }
#problemPanel .pb-ok { color: #a9e5b9; font-weight: 600; }
#problemPanel .pb-bad { color: #ffb0a8; font-weight: 600; }
#problemPanel table.pb { border-collapse: collapse; margin: 6px 0; }
#problemPanel table.pb th { text-align: left; color: var(--muted); font-weight: 600; padding: 1px 12px 1px 0; }
#problemPanel table.pb td { padding: 1px 12px 1px 0; }
#problemPanel .note { color: var(--muted); font-size: 13px; }
#problemPanel .pb-stats { margin-top: 6px; border-top: 1px solid rgba(255,255,255,.18); padding-top: 6px; font-size: 13px; }
#problemPanel .pb-stats .st-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: 600; }
#problemPanel .pb-stats .st-head button { padding: 1px 8px; font-size: 15px; background: var(--card); color: var(--black-suit); border: 0; }
#problemPanel .pb-stats .st-head button.red { color: var(--red-suit); }
#problemPanel .pb-stats .st-head button.on { outline: 2px solid var(--accent); }
#problemPanel .pb-stats table { border-collapse: collapse; margin-top: 4px; }
#problemPanel .pb-stats th { text-align: left; font-weight: 600; color: var(--muted); padding: 1px 8px 1px 0; }
#problemPanel .pb-stats td { padding: 1px 8px 1px 0; }
#problemPanel .pb-stats td.chg { color: var(--accent); font-weight: 700; }
#table.problem { grid-template-rows: auto minmax(120px, 1fr) auto auto auto; }
#table.problem #center { min-height: 120px; }

#problemPanel .pb-opts { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; max-width: 460px; }
#problemPanel .pb-opts button { text-align: left; padding: 9px 12px; background: var(--card); color: var(--black-suit); border: 0; font-weight: 600; }
#problemPanel .pb-lesson { margin-top: 6px; }
#problemPanel td.yes { color: #a9e5b9; }
#problemPanel td.no { color: #ffb0a8; }

/* play so far, in one-decision problems */
#problemPanel .pb-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
#problemPanel table.hist td { padding: 2px 10px 2px 0; }
#problemPanel table.hist td.led .cardtxt { text-decoration: underline; text-underline-offset: 2px; }
#problemPanel table.hist td.won .cardtxt { outline: 2px solid var(--accent); }
