:root {
  --bg: #1b3a2b; --panel: #fffdf6; --ink: #222; --muted: #6b6b6b; --line: #d9d2bf;
  --bam: #7a2fc4; --dgreen: #1b7a3a; --crak: #c0262c; --dot: #1f56b5; --accent: #e0a526;
  --tw: 34px; --th: 46px; --sw: 24px; --sh: 32px; --tnw: 18px; --tnh: 24px; --side: 170px; --rackmin: 76px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.4 system-ui, sans-serif; background: #12261c; color: var(--ink); }
header { display: flex; gap: 14px; align-items: center; padding: 8px 16px; background: #0c1a13; color: #eee; }
header h1 { font-size: 18px; margin: 0; }
header nav a { color: #cfd; margin-right: 10px; text-decoration: none; padding: 3px 6px; border-radius: 4px; }
header nav a.active, header nav a:hover { background: #2a4a3a; }
.spacer { flex: 1; }
button { font: inherit; padding: 6px 12px; border: 1px solid #8a7a3a; background: var(--accent); border-radius: 5px; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
button.secondary { background: #eee6cc; border-color: var(--line); }
button.danger { background: #d9534f; color: #fff; border-color: #b33; }
main { display: grid; grid-template-columns: minmax(640px, 1fr) 360px; gap: 12px; padding: 12px; align-items: start; }
aside { position: sticky; top: 8px; max-height: calc(100vh - 16px); overflow-y: auto; }
#hintsBody { max-height: 480px; overflow-y: auto; }
#table { position: relative; background: var(--bg); border-radius: 10px; min-height: 0; padding: 10px; color: #eee;
  display: grid; grid-template-columns: var(--side) 1fr var(--side); grid-template-rows: auto auto 1fr auto; gap: 8px; }
#status { grid-column: 1 / 4; text-align: center; padding: 6px; background: #0c1a13aa; border-radius: 6px; font-weight: 600; }
.seat.top { grid-column: 2; grid-row: 2; }
.seat.left { grid-column: 1; grid-row: 3; }
.seat.right { grid-column: 3; grid-row: 3; }
#center { grid-column: 2; grid-row: 3; background: #153021; border-radius: 8px; padding: 8px; overflow: auto; min-height: 230px; max-height: 330px; }
.seat.bottom { grid-column: 1 / 4; grid-row: 4; }
.seatname { font-weight: 600; margin-bottom: 4px; }
.seatname .wind { color: var(--accent); }
.seatname.turn::after { content: ' ◀ turn'; color: var(--accent); }
.hiddenrack { display: flex; flex-wrap: wrap; gap: 2px; }
.sets { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.set { display: flex; gap: 1px; padding: 2px; background: #0c1a1355; border-radius: 4px; }
.set.mine .tile { cursor: default; }
#rack { display: flex; flex-wrap: wrap; gap: 3px; padding: 8px; background: #0c1a13; border-radius: 8px; min-height: var(--rackmin); }
#actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: center; }
#discards { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 6px; }
#centerInfo { font-size: 13px; color: #cfe; }

/* tiles */
.tile { width: var(--tw); height: var(--th); border-radius: 5px; background: #fbf7e8; border: 1px solid #8f8566; box-shadow: 0 2px 0 #b8ad88;
  display: inline-flex; align-items: center; justify-content: center; user-select: none; cursor: pointer; color: #222; position: relative; overflow: hidden; }
.tile .glyph { width: 100%; height: 100%; display: block; pointer-events: none; }
.tile.small { width: var(--sw); height: var(--sh); }
.tile.tiny { width: var(--tnw); height: var(--tnh); border-radius: 3px; }
.tile.j { background: #fffaf0; border-color: #8f8566; }
.tile.back { background: repeating-linear-gradient(45deg, #2d6e4b, #2d6e4b 4px, #26603f 4px, #26603f 8px); border-color: #0f3a24; cursor: default; box-shadow: none; }
.tile.selected { transform: translateY(-10px); outline: 3px solid var(--accent); }
.tile.new { outline: 2px dashed #7fd1ff; }
.tile.advice-discard { box-shadow: 0 3px 0 #d9534f; }
.tile.advice-keep { box-shadow: 0 3px 0 #3c9a52; }
.tile.advice-maybe { box-shadow: 0 3px 0 #e0a526; }
.tile.ghost { opacity: .25; box-shadow: none; }
.tile.dead { opacity: .45; }
.tile.swap { outline: 2px solid #ff7bd0; cursor: pointer; }
.tile.lastdisc { outline: 3px solid #ff7b7b; }

aside section { background: var(--panel); border-radius: 8px; padding: 10px; margin-bottom: 12px; }
aside h2 { font-size: 14px; margin: 0 0 6px; display: flex; justify-content: space-between; }
.small { font-size: 12px; font-weight: normal; }
#log { max-height: 220px; overflow-y: auto; font-size: 12px; color: #333; }
#log div { padding: 1px 0; border-bottom: 1px dotted #eee; }
.hand { border: 1px solid var(--line); border-radius: 6px; padding: 6px; margin-bottom: 6px; background: #fff; }
.hand .hd { display: flex; justify-content: space-between; gap: 6px; font-weight: 600; }
.hand .rule { font-size: 11px; color: var(--muted); }
.hand .tag { font-size: 11px; padding: 1px 5px; border-radius: 9px; background: #eee; }
.hand .tag.c { background: #f3d6d6; } .hand .tag.near { background: #d6f0d9; }
.hand .groups { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.grp { display: flex; gap: 1px; padding: 1px; border-radius: 3px; background: #f4efdd; }
.suggest { background: #fff6d6; border: 1px solid #e3c96a; border-radius: 6px; padding: 7px; margin-bottom: 8px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; background: #eee; margin: 0 4px 0 0; font-size: 12px; }
table.sc { width: 100%; border-collapse: collapse; }
table.sc td, table.sc th { padding: 2px 6px; text-align: right; } table.sc td:first-child, table.sc th:first-child { text-align: left; }
.result { background: #fff6d6; color: #222; border-radius: 8px; padding: 10px; margin-top: 8px; }
.err { color: #ffb3b3; min-height: 18px; }
.page { max-width: 980px; margin: 16px auto; background: var(--panel); border-radius: 10px; padding: 16px 20px; }
.page table { border-collapse: collapse; width: 100%; margin-bottom: 18px; }
.page th, .page td { border-bottom: 1px solid var(--line); padding: 5px 8px; text-align: left; }
.page th { background: #f3eedb; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 18px; }
.cards div { background: #f3eedb; border-radius: 8px; padding: 10px; text-align: center; }
.cards b { display: block; font-size: 24px; }
@media (max-width: 1100px) { main { grid-template-columns: minmax(0, 1fr); } aside { position: static; max-height: none; } }
.tile.new { outline: 3px solid #2aa8ff; background: #eaf6ff; margin-left: 8px; }
.tile.dragging { opacity: .4; }
#rack .tile { cursor: grab; }

button { touch-action: manipulation; }
.tile { -webkit-tap-highlight-color: transparent; touch-action: manipulation; -webkit-touch-callout: none; }
button.on { background: #2aa8ff; border-color: #1678b8; color: #fff; }
.tile.picked { transform: translateY(-10px); outline: 3px solid #2aa8ff; }
body { overflow-x: hidden; }
.page { overflow-x: auto; }

/* larger screens: scale tiles up (phones keep the compact sizes above) */
@media (min-width: 768px) {
  :root { --tw: 44px; --th: 59px; --sw: 30px; --sh: 40px; --tnw: 22px; --tnh: 29px; --side: 200px; --rackmin: 90px; }
  #center { min-height: 260px; max-height: 380px; }
}
@media (min-width: 1200px) {
  :root { --tw: 48px; --th: 65px; --sw: 34px; --sh: 46px; --tnw: 24px; --tnh: 32px; --side: 220px; --rackmin: 98px; }
  #center { min-height: 300px; max-height: 440px; }
}
@media (min-width: 1600px) {
  :root { --tw: 56px; --th: 75px; --sw: 40px; --sh: 54px; --tnw: 28px; --tnh: 37px; --side: 250px; --rackmin: 110px; }
  main { grid-template-columns: minmax(900px, 1fr) 400px; }
  #center { min-height: 340px; max-height: 500px; }
}

/* phones */
@media (max-width: 700px) {
  body { font-size: 15px; }
  header { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  header h1 { font-size: 16px; }
  header nav a { padding: 8px 8px; margin-right: 2px; }
  .spacer { display: none; }
  button, select { min-height: 44px; }
  button { padding: 8px 14px; }
  main { padding: 6px; gap: 8px; }
  #table { grid-template-columns: 1fr 1fr; grid-template-rows: auto; padding: 8px; }
  #status, .seat.top, .seat.left, .seat.right, #center, .seat.bottom { grid-column: auto; grid-row: auto; }
  #status, .seat.top, #center, .seat.bottom { grid-column: 1 / 3; }
  .seat.top { grid-row: 2; } .seat.left { grid-row: 3; grid-column: 1; } .seat.right { grid-row: 3; grid-column: 2; }
  #center { grid-row: 4; min-height: 120px; max-height: 220px; }
  .seat.bottom { grid-row: 5; }
  .hiddenrack { gap: 1px; }
  #rack { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; padding: 6px; }
  #rack .tile { width: 100%; height: auto; aspect-ratio: 3 / 4; }
  #rack .tile.new { margin-left: 0; }
  .tile.small { width: 26px; height: 35px; }
  #actions { gap: 8px; }
  #actions button { flex: 1 1 auto; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .page { margin: 8px; padding: 12px; }
}

.hand { cursor: pointer; }
.hand.locked { border: 2px solid #c98a00; background: #fff8e1; }
.lockbar { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin: 4px 0; font-weight: 600; }
.deadbanner { background: #7a1f1f; color: #fff; border: 1px solid #ff8a8a; border-radius: 6px; padding: 6px 10px; margin: 6px 0; font-weight: 600; }

.playing-as { font-size: 13px; color: #cfd; }
.playing-as a { color: #9fd; margin-left: 2px; }

/* win celebration: pointer-events pass through except the banner, so the win summary stays usable */
.celebrate { position: fixed; inset: 0; z-index: 1000; pointer-events: none; overflow: hidden; transition: opacity .6s; }
.celebrate.out { opacity: 0; }
.celebrate-banner { position: absolute; top: 18%; left: 50%; transform: translateX(-50%); text-align: center; pointer-events: auto; cursor: pointer;
  background: rgba(27, 58, 43, .88); border: 3px solid #ffd23f; border-radius: 16px; padding: 12px 28px; color: #ffd23f;
  box-shadow: 0 0 40px rgba(255, 210, 63, .6); animation: celePop .7s cubic-bezier(.2, 1.6, .4, 1) both, celeGlow 1.2s ease-in-out .7s 3; }
.celebrate-banner .big { font-size: clamp(36px, 10vw, 84px); font-weight: 900; letter-spacing: 2px; line-height: 1.1; }
.celebrate-banner .sub { font-size: clamp(16px, 4vw, 28px); color: #fff; }
.confetti { position: absolute; top: -20px; width: 9px; height: 14px; border-radius: 2px; opacity: 0; animation: confettiFall linear forwards; will-change: transform; }
@keyframes celePop { from { transform: translateX(-50%) scale(0) rotate(-12deg); } to { transform: translateX(-50%) scale(1) rotate(0); } }
@keyframes celeGlow { 50% { box-shadow: 0 0 70px rgba(255, 210, 63, 1); } }
@keyframes confettiFall { 0% { opacity: 1; transform: translate3d(0, 0, 0) rotate(0); } 100% { opacity: 1; transform: translate3d(var(--dx), 110vh, 0) rotate(var(--rot)); } }

/* bot-win consolation: muted toast near the bottom so the win summary stays visible */
.consolation .celebrate-banner { top: auto; bottom: 6%; padding: 8px 22px; border: 2px solid #8aa; box-shadow: 0 2px 16px rgba(0, 0, 0, .35); color: #cfe0e6; animation: consoleIn .5s ease-out both; }
.consolation .celebrate-banner .big { font-size: clamp(30px, 8vw, 52px); }
.consolation .celebrate-banner .sub { font-size: clamp(15px, 3.5vw, 22px); color: #fff; }
.consolation .celebrate-banner .tiny { font-size: 13px; opacity: .8; }
@keyframes consoleIn { from { opacity: 0; transform: translateX(-50%) translateY(20px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
#wallCounter { display: inline-block; margin-top: 4px; padding: 2px 8px; border-radius: 10px; background: #0c1a13; color: #fff; font-size: 13px; font-weight: 600; }
#wallCounter.low { background: #7a2d12; }

/* multi-suit pattern colouring in the hints panel (mirrors the NMJL card's per-suit ink) */
.pat .ps { font-weight: 700; }
.pat .psA { color: #1b7a33; } .pat .psB { color: #c62828; } .pat .psC { color: #1a1a1a; } .pat .psD { color: #1565c0; }
