/* 13: fit the whole game on one screen. Table and hand on the left, helper and buttons beside the table. */

/* Shared: compact title, seats, table and hand. */
#roomMain .card-game-thirteen { min-height: 0; padding: 12px 16px; }
#roomMain .card-game-thirteen > .chip { display: none; }
#roomMain .card-game-thirteen > h2 { display: none; }
#roomMain .card-game-thirteen > .room-turn { margin: 0 0 4px; font-size: 14px; }
/* Your own seat is the hand right below the table. */
.card-game-thirteen .thirteen-table .table-seat[data-seat="bottom"] { display: none; }

.card-game-thirteen .thirteen-table { gap: 6px; margin: 0 auto; }
.card-game-thirteen .thirteen-table .table-seat {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  column-gap: 6px;
  max-width: 150px;
  padding: 4px 8px;
  text-align: left;
}
.card-game-thirteen .thirteen-table .table-seat .seat-avatar { grid-row: span 2; width: 26px; margin: 0; }
.card-game-thirteen .thirteen-table .table-seat b { font-size: 12px; line-height: 1.2; }
.card-game-thirteen .thirteen-table .table-seat span:not(.seat-avatar) { font-size: 11px; line-height: 1.2; }
#roomMain .card-game-thirteen .thirteen-table .table-felt { min-height: 140px; padding: 6px; }
.card-game-thirteen .thirteen-table .table-felt h3 { margin: 0; font-size: 14px; }

.card-game-thirteen .thirteen-hand { margin-top: 8px; padding: 6px 10px 8px; }
.card-game-thirteen .thirteen-hand h3 { margin: 0; font-size: 16px; }
.card-game-thirteen .thirteen-hand .hand-head { gap: 4px 10px; }
.card-game-thirteen .thirteen-hand .hand-sort button { min-height: 32px; padding: 3px 9px; }
.card-game-thirteen .thirteen-hand .hand-tip { margin: 0; }
.card-game-thirteen .thirteen-hand > .playing-cards { flex-wrap: nowrap; gap: 4px; padding: 6px 0 2px; }
#roomMain .card-game-thirteen .thirteen-hand > .playing-cards .playing-card {
  flex: 0 1 54px;
  width: auto;
  min-width: 0;
  padding: 2px;
  font-size: clamp(13px, calc(1.4vw / var(--site-zoom, 1)), 19px);
}

.thirteen-side { text-align: left; }
.thirteen-side .selection-status { margin: 0 0 6px; font-weight: 700; }
.thirteen-side .room-wait { margin: 0 0 6px; padding: 6px 10px; font-size: 13px; }
.thirteen-side .hand-guide { margin: 0 0 6px; }
.thirteen-side .hand-guide label { margin: 6px 0 0; }
.thirteen-side .board-rules { margin: 0; font-size: 13px; }
.thirteen-side .board-rules p { font-size: 12px; line-height: 1.45; }

/* Wide screens: two columns inside the stage, the page fits without scrolling. */
@media (min-width: 900px) {
  /* The room bar shares a row with the background picker. */
  body:has(.card-game-thirteen) .game-controls-bar { margin-bottom: 0; }
  body:has(.card-game-thirteen) .room-toolbar { margin: -42px 0 8px; padding-left: 230px; min-height: 40px; }
  body:has(.card-game-thirteen) .room-toolbar small { margin-top: 2px; }
  body:has(.card-game-thirteen) #roomMain .stage-card { margin-bottom: 12px; }

  #roomMain .card-game-thirteen {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(230px, calc(24vw / var(--site-zoom, 1)), 300px);
    grid-template-rows: auto auto auto auto;
    column-gap: 16px;
    align-content: start;
  }
  #roomMain .card-game-thirteen > * { grid-column: 1; min-width: 0; }
  #roomMain .card-game-thirteen > h2 { grid-row: 1; }
  #roomMain .card-game-thirteen > .room-turn { grid-row: 2; }
  #roomMain .card-game-thirteen > .thirteen-table { grid-row: 3; }
  #roomMain .card-game-thirteen > .thirteen-hand { grid-row: 4; }
  /* The side panel takes the height of the table and scrolls inside if the helper is long. */
  #roomMain .card-game-thirteen > .thirteen-side {
    grid-column: 2;
    grid-row: 1 / 4;
    contain: size;
    overflow-y: auto;
    padding: 10px 12px;
    border: 1px solid var(--ui-border, var(--ink));
    border-radius: 12px;
    background: var(--ui-inset, #fff3cf);
  }
  #roomMain .card-game-thirteen > .actions {
    grid-column: 2;
    grid-row: 4;
    align-self: end;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin: 8px 0 0;
  }
  #roomMain .card-game-thirteen > .actions button { width: 100%; min-height: 40px; margin: 0; padding: 6px 8px; font-size: 13px; }
  #roomMain .card-game-thirteen > .actions button:first-child { grid-column: 1 / -1; min-height: 46px; font-size: 15px; }
}

/* Phones: played cards become one thin row, the hand is two rows of seven, the helper sits below. */
@media (max-width: 680px) {
  /* The room bar is one short row. */
  body:has(.card-game-thirteen) .room-toolbar { margin: 4px 0 6px; align-items: center; }
  body:has(.card-game-thirteen) .room-code { min-height: 34px; padding: 2px 10px; }
  body:has(.card-game-thirteen) .room-toolbar small { margin: 0; }
  body:has(.card-game-thirteen) .room-toolbar button { min-height: 36px; padding: 4px 10px; }
  .thirteen-workspace:has(.card-game-thirteen) { gap: 6px; }

  #roomMain .card-game-thirteen { padding: 10px 8px 0; }
  .card-game-thirteen .thirteen-table .table-seat { grid-template-columns: 1fr; justify-items: center; padding: 3px 2px; text-align: center; }
  .card-game-thirteen .thirteen-table .table-seat .seat-avatar { grid-row: auto; width: 24px; }
  .card-game-thirteen .thirteen-table .table-seat[data-seat="top"] { grid-template-columns: 22px auto; justify-content: center; column-gap: 6px; text-align: left; }
  .card-game-thirteen .thirteen-table .table-seat[data-seat="top"] .seat-avatar { grid-row: span 2; width: 22px; }
  #roomMain .card-game-thirteen > .room-turn { margin: 0 0 2px; }
  /* Play, Pass and Waiting room in one row. */
  #roomMain .card-game-thirteen > .actions:not(:empty) { flex-wrap: nowrap; gap: 6px; padding-top: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  #roomMain .card-game-thirteen > .actions button { flex: 1 1 0; min-width: 0; min-height: 44px; margin: 0; padding: 4px 6px; font-size: 13px; line-height: 1.15; overflow-wrap: normal; word-break: normal; hyphens: none; }
  #roomMain .card-game-thirteen > .actions button:first-child { flex-grow: 1.6; }
  .card-game-thirteen .thirteen-table .table-seat b { max-width: 100%; font-size: 11px; }
  #roomMain .card-game-thirteen .thirteen-table .table-felt { min-height: 130px; }
  .card-game-thirteen .thirteen-hand { padding: 4px 6px 6px; }
  .card-game-thirteen .thirteen-hand .hand-tip { display: none; }
  .card-game-thirteen .thirteen-hand > .playing-cards { flex-wrap: wrap; }
  #roomMain .card-game-thirteen .thirteen-hand > .playing-cards .playing-card { flex: 0 0 calc((100% - 24px) / 7); font-size: 15px; }
  .thirteen-side { margin-top: 8px; }
}

/* Table: the previous play sits beside the current play (not below), and the table keeps one height,
   so the hand and buttons never move down as plays get bigger. */
#roomMain .card-game-thirteen .thirteen-table .table-felt {
  display: grid;
  grid-template-columns: auto;
  align-content: center;
  justify-content: center;
  justify-items: center;
  column-gap: 14px;
  row-gap: 2px;
  height: 150px;
  min-height: 0;
  overflow: hidden;
}
#roomMain .card-game-thirteen .thirteen-table .table-felt:has(> .thirteen-previous) { grid-template-columns: auto auto; }
#roomMain .card-game-thirteen .thirteen-table .table-felt > h3,
#roomMain .card-game-thirteen .thirteen-table .table-felt > p { grid-column: 1 / -1; }
#roomMain .card-game-thirteen .thirteen-table .table-felt .playing-cards { flex-wrap: nowrap; padding: 4px 0; }
#roomMain .card-game-thirteen .thirteen-table .table-felt > .thirteen-previous {
  display: grid;
  justify-items: center;
  gap: 2px;
  margin: 0;
  padding-left: 12px;
  border-left: 2px dashed #ffffff55;
}
#roomMain .card-game-thirteen .thirteen-table .table-felt .thirteen-previous .last-play-label { flex-basis: auto; margin: 0; white-space: nowrap; font-size: 10px; }
#roomMain .card-game-thirteen .thirteen-table .table-felt .thirteen-previous .playing-cards { gap: 0; }
#roomMain .card-game-thirteen .thirteen-table .table-felt .thirteen-previous .playing-card + .playing-card { margin-left: -9px; }
#roomMain .card-game-thirteen .thirteen-table .table-felt > div:not(.thirteen-previous) .playing-card { width: clamp(26px, calc(3.4vw / var(--site-zoom, 1)), 44px); font-size: clamp(13px, calc(1.4vw / var(--site-zoom, 1)), 18px); }
#roomMain .card-game-thirteen .thirteen-table .table-felt > div:not(.thirteen-previous) .playing-card + .playing-card { margin-left: -4px; }
#roomMain .card-game-thirteen .thirteen-table .table-felt .thirteen-previous .playing-card { width: clamp(18px, calc(2.2vw / var(--site-zoom, 1)), 28px); }

@media (max-width: 680px) {
  #roomMain .card-game-thirteen .thirteen-table .table-felt { height: 130px; column-gap: 8px; }
  #roomMain .card-game-thirteen .thirteen-table .table-felt > .thirteen-previous { padding-left: 6px; }
  #roomMain .card-game-thirteen .thirteen-table .table-felt > div:not(.thirteen-previous) .playing-card + .playing-card { margin-left: -6px; }
  #roomMain .card-game-thirteen .thirteen-table .table-felt .thirteen-previous .playing-card + .playing-card { margin-left: -11px; }
  #roomMain .card-game-thirteen .thirteen-table .table-felt .thirteen-previous .last-play-label { font-size: 8px; }
}

/* Played cards: one horizontal strip above the game (newest on the left), on every screen size. */
.thirteen-workspace:has(.card-game-thirteen) .thirteen-history {
  position: static;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: none;
  min-width: 0;
  margin: 0;
  padding: 6px 10px;
}
.thirteen-workspace:has(.card-game-thirteen) .thirteen-history h3 { flex: none; margin: 0; font-size: 12px; max-width: 76px; line-height: 1.15; }
.thirteen-workspace:has(.card-game-thirteen) .thirteen-history p { margin: 0; font-size: 12px; }
.thirteen-workspace:has(.card-game-thirteen) .thirteen-history ol {
  display: flex;
  flex: 1;
  gap: 4px;
  min-width: 0;
  max-height: none;
  margin: 0;
  padding: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
.thirteen-workspace:has(.card-game-thirteen) .thirteen-history li {
  flex: none;
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 2px 8px;
  border: 0;
  font-size: 12px;
  white-space: nowrap;
}
.thirteen-workspace:has(.card-game-thirteen) .thirteen-history li + li { border-left: 1px solid var(--ui-border, var(--line)); }
.thirteen-workspace:has(.card-game-thirteen) .thirteen-history li:first-child { background: #f8d63355; border-radius: 6px; }
@media (min-width: 900px) {
  .thirteen-workspace:has(.card-game-thirteen) { grid-template-rows: auto auto; row-gap: 10px; }
  .thirteen-workspace:has(.card-game-thirteen) > .thirteen-history { grid-column: 1 / -1; grid-row: 1; }
  .thirteen-workspace:has(.card-game-thirteen) > .stage-card { grid-column: 2; grid-row: 2; align-self: start; }
  .thirteen-workspace:has(.card-game-thirteen) > .room-chat { grid-column: 1; grid-row: 2; }
}
@media (max-width: 680px) {
  #roomMain .card-game-thirteen .thirteen-table .table-felt > p { margin: 0; font-size: 11px; line-height: 1.2; max-width: 150px; }
  #roomMain .card-game-thirteen .thirteen-table .table-felt > p.last-play-label { font-size: 9px; }
  #roomMain .card-game-thirteen .thirteen-table .table-felt > .playing-cards .playing-card { width: 22px; font-size: 11px; }
}

/* Best-of-5 scoreboard in the side panel. */
.match-board { margin: 0 0 8px; padding: 8px 10px; border: 2px solid var(--ink); border-radius: 12px; background: #fffaf0; color: #252046; }
.match-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; }
.match-pot { padding: 1px 8px; border: 2px solid var(--ink); border-radius: 999px; background: #f8d633; font-weight: 800; font-size: 12px; white-space: nowrap; }
.match-board ul { display: grid; gap: 2px; margin: 6px 0 0; padding: 0; list-style: none; }
.match-board li { display: flex; justify-content: space-between; gap: 8px; padding: 1px 6px; border-radius: 6px; font-size: 13px; }
.match-board li b { color: #e2a400; letter-spacing: 2px; }
.match-board li.match-lead { background: #f8d63340; font-weight: 700; }
.log-bet { color: #a23255; }
#thirteenStake { margin-bottom: 8px; }

/* Hand and match results float over the table instead of pushing it down. */
#roomMain .card-game-thirteen { position: relative; }
#roomMain .card-game-thirteen > .prompt {
  position: absolute;
  z-index: 8;
  top: 42%;
  left: 50%;
  width: max-content;
  max-width: min(90%, 460px);
  margin: 0;
  padding: 12px 22px;
  font-size: clamp(18px, calc(2.2vw / var(--site-zoom, 1)), 24px);
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 10px 30px #0004;
}
@media (min-width: 900px) {
  #roomMain .card-game-thirteen > .prompt { left: calc((100% - clamp(230px, calc(24vw / var(--site-zoom, 1)), 300px) - 16px) / 2); }
}
