:root { --card-width: 82px; --card-step: 28px; color-scheme: light; font-family: Inter, ui-sans-serif, system-ui, sans-serif; color: #24425e; background: #f0f6fc; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { max-width: 1320px; margin: 28px auto; padding: 0 24px; }
.page-header { display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap; border-bottom: 1px solid #d4e2f0; padding-bottom: 18px; }
h1 { font-family: inherit; font-weight: 650; margin: 8px 0 0; font-size: 32px; }
h2 { font-size: 20px; font-weight: 500; }
#status { color: #53718d; min-height: 24px; font-size: 14px; }
#login-panel { max-width: 420px; margin: 40px auto; padding: 24px; background: #ffffff; border-radius: 12px; }
label { display: block; margin: 14px 0; }
input, button { font: inherit; border-radius: 7px; padding: 10px 18px; border: 1px solid #bfd3e7; }
input { width: 100%; margin-top: 6px; background: #f6faff; color: #24425e; }
button { cursor: pointer; background: #397dcc; color: #ffffff; font-weight: 600; }
button:hover:not(:disabled) { filter: brightness(1.12); }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible { outline: 3px solid #2268b5; outline-offset: 4px; }
.secondary, #logout-button, #reconnect { background: #e6f0fb; color: #2c5e90; border-color: #c3d8ec; }
#account-info { display: flex; align-items: center; justify-content: flex-end; gap: 14px; margin-left: auto; font-size: 14px; }
#account-info span { overflow-wrap: anywhere; }
#logout-button { padding: 6px 12px; font-size: 13px; }
#lobby { max-width: 720px; margin: 40px auto; }
.table-row { display: flex; align-items: center; gap: 14px; padding: 24px; border: 1px solid #d0e0ef; background: #ffffff; border-radius: 12px; margin: 16px 0; }
.table-row strong { margin-right: auto; }
.table-row button:disabled { background: #dce7f1; color: #64809a; }
.table-toolbar { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }
.board-scroll { overflow-x: auto; padding: 8px 0; }
.card-table { container-type: inline-size; position: relative; min-width: 800px; height: 740px; border: 2px solid #8ab9e3; border-radius: 24px; background: radial-gradient(ellipse at center, #d6ebff, #afd4f4 85%); box-shadow: 0 8px 24px #426d9614; }
.table-mark { position: absolute; top: 45%; left: 50%; transform: translate(-50%, -50%); width: 280px; height: 84px; color: #689aca; font: 600 28px system-ui, sans-serif; text-align: center; letter-spacing: .15em; white-space: nowrap; }
.player { position: absolute; width: 126px; text-align: center; z-index: 2; }
.player-info { position: relative; z-index: 1; height: 88px; padding: 9px; border: 1px solid #b4d1ee; border-radius: 10px; background: #f2f8fff2; }
.player strong { display: block; overflow-wrap: anywhere; font-size: 14px; height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-info > span { display: block; font-size: 11px; color: #557593; margin-top: 4px; }
.player-north { top: 18px; left: 20px; width: calc(100% - 40px); min-height: 112px; padding: 0 148px; }
.player-north .player-info { position: absolute; left: 0; width: 126px; top: 136px; }
.player-south { bottom: 20px; right: 20px; }
.player-west { left: 20px; top: 220px; width: 126px; }
.player-east { right: 20px; top: 220px; width: 126px; }
.active-player .player-info { border-color: #175bb0; box-shadow: 0 0 0 3px #5eacff55, 0 0 28px #5eacff22; }
.active-player .player-info > span { color: #175bb0; }
.card-backs, .revealed-cards, .played {
  display: grid; grid-template-columns: repeat(auto-fit, var(--card-step));
  justify-content: center; align-content: start; gap: 8px 0;
  padding: 8px calc(var(--card-width) - var(--card-step)) 0 0;
}
.card-backs img, .revealed-cards img, .played img, .hand-card img {
  display: block; width: var(--card-width); height: auto; border-radius: 7px;
}
.card-backs, .revealed-cards, .played { --card-width: 56px; --card-step: 16px; }
.card-backs img { box-shadow: 0 1px 3px #0005; }
.player-north .card-backs, .player-north .revealed-cards { padding-top: 0; }
.player-west .player-info, .player-east .player-info { width: 126px; margin: 0 auto; }
.played { position: absolute; max-height: 170px; overflow-y: auto; overflow-x: hidden; z-index: 1; }
.played-north { top: 112px; left: 27%; width: 46%; }
.played-south { bottom: 242px; left: 27%; width: 46%; }
.played-west { left: 220px; top: 265px; width: calc(50% - 240px); }
.played-east { right: 220px; top: 265px; width: calc(50% - 240px); }
.played.passed-play { display: flex; justify-content: center; align-items: center; min-height: 84px; padding: 8px 0 0; }
.pass-label { color: #315a84; font-size: 22px; font-weight: 600; padding: 10px; }
#result { position: absolute; top: 58%; left: 50%; transform: translate(-50%, -50%); width: max-content; max-width: 280px; padding: 12px 20px; border: 1px solid #8ab9e3; border-radius: 16px; background: #f2f8ff; color: #24425e; text-align: center; line-height: 1.8; overflow-wrap: anywhere; z-index: 3; }
.settled .table-mark { display: none; }
.player-north .revealed-cards { grid-auto-rows: 28px; padding-bottom: 54px; }
.played.revealed-cards { grid-auto-rows: 26px; padding-bottom: 54px; max-height: 170px; }
.settled .hand-card:disabled { opacity: 1; }
.table-hand { position: absolute; bottom: 16px; left: 20px; right: 20px; padding-top: 8px; }
.hand-toolbar { display: flex; min-height: 56px; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; }
#turn-actions { display: flex; gap: 10px; align-items: center; }
.hand-scroll { margin: 0 144px; overflow-x: auto; padding-top: 22px; }
#hand { user-select: none; -webkit-user-select: none; display: grid; grid-template-columns: repeat(var(--card-count, 27), minmax(0, 28px)); min-width: calc(var(--card-count, 27) * 28px + 62px); padding: 3px 58px 18px 4px; min-height: 130px; justify-content: center; }
.hand-card { width: var(--card-width); align-self: start; padding: 0; border: 0; background: transparent; border-radius: 7px; position: relative; transition: transform .14s ease, box-shadow .14s ease; }
.hand-card img { display: block; width: 100%; height: auto; border-radius: 7px; }
.hand-card.selected { transform: translateY(-16px); box-shadow: 0 0 0 3px #2479d4, 0 8px 18px #0007; }
.hand-card:disabled { opacity: .8; }
#hand-empty { text-align: center; color: #53718d; padding: 16px; }
@media (max-width: 720px) { body { padding: 0 12px; margin-top: 18px; } h1 { font-size: 27px; } .table-row { padding: 18px 12px; gap: 8px; } .table-row button { padding: 10px 14px; } }
@media (prefers-reduced-motion: reduce) { .hand-card { transition: none; } }


#trick-status, #multiplier-status { position: absolute; left: 0; width: 100%; margin: 0; color: #365d84; letter-spacing: normal; white-space: normal; }
#trick-status { top: 0; font: 600 20px/1.5 system-ui, sans-serif; }
#multiplier-status { top: 44px; font: 15px/1.5 system-ui, sans-serif; }

#play-error { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); width: max-content; max-width: 90%; margin: 0 0 10px; padding: 10px 16px; background: #fff2ee; color: #9a4030; border: 1px solid #e3b3a4; border-radius: 8px; text-align: center; z-index: 4; opacity: 1; transition: opacity .3s ease; pointer-events: none; }
#play-error.fading { opacity: 0; }
@media (prefers-reduced-motion: reduce) { #play-error { transition: none; } }

/* Side stacks stay centered on the board independently of badge placement. */
.card-table .player-west,
.card-table .player-east {
  top: 0; bottom: 0; width: 194px; pointer-events: none;
}
.card-table .player-west .player-info { position: absolute; top: calc(60% - 44px); left: 0; margin: 0; }
.card-table .player-east .player-info { position: absolute; top: calc(56% - 44px); right: 0; margin: 0; }
.player-west .card-backs, .player-east .card-backs {
  position: absolute; top: 50%; width: 56px; transform: translateY(-50%);
  grid-template-columns: 56px; grid-auto-rows: 5px;
  gap: 0; padding: 0 0 72px;
}
.player-west .card-backs { right: 0; }
.player-east .card-backs { left: 0; }

.player-avatar { position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); width: calc(100% + 2px); aspect-ratio: 1; background: #72afe2; border: 1px solid #599bd1; border-radius: 8px; }
#identity-button { padding: 2px 0; border: 0; background: transparent; color: #2c5e90; }
#profile-dialog { width: min(360px, 90vw); border: 1px solid #bfd3e7; border-radius: 12px; padding: 24px; color: #24425e; }
#profile-dialog::backdrop { background: #17395755; }
.profile-actions { display: flex; justify-content: flex-end; gap: 10px; }
#profile-error { color: #9a4030; }

.player-avatar { overflow: visible; }
.player-avatar img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 7px; }
#profile-photo-preview { display: block; width: 100px; height: 100px; object-fit: cover; border-radius: 8px; margin: 16px auto; }

#photo-crop-canvas { display: block; width: 100%; max-width: 280px; aspect-ratio: 1; margin: auto; touch-action: none; cursor: grab; background: #e6f0fb; }
#photo-crop { margin: 16px 0; }
#profile-dialog { max-height: 90vh; overflow-y: auto; }

#reconnect-status { position: absolute; top: 54%; left: 50%; transform: translate(-50%, -50%); width: max-content; max-width: 90%; margin: 0; padding: 8px 12px; background: #f2f8fff2; color: #315a84; border-radius: 8px; text-align: center; z-index: 4; }

.turn-fuse { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); pointer-events: none; }
.turn-fuse rect { fill: none; stroke-width: 5; stroke-linecap: round; }
.turn-seconds { position: absolute; right: 5px; bottom: 5px; min-width: 24px; padding: 2px 4px; border-radius: 5px; background: #f2f8fff2; color: #24425e; font: 600 13px/1.4 system-ui, sans-serif; }

#card-counter { position: absolute; right: 20px; top: 18px; width: 260px; padding: 8px; border: 1px solid #aac9e5; border-radius: 10px; background: #f2f8fff2; z-index: 3; }
#card-counter > strong { display: block; margin-bottom: 5px; font-size: 12px; }
#card-counter-grid { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
.counter-cell { text-align: center; font-size: 11px; }
.counter-cell span, .counter-cell b { display: block; }
.counter-cell b { font-size: 14px; }
.empty-count { opacity: .4; }
.player-avatar { pointer-events: auto; }
.player:has(.player-avatar:hover), .player:has(.player-avatar:focus-within) { z-index: 6; }
.play-history { display: none; position: absolute; z-index: 1; left: 100%; top: 0; width: 310px; max-height: 270px; overflow: auto; padding: 12px; border: 1px solid #aac9e5; border-radius: 10px; background: #f2f8ff; box-shadow: 0 5px 18px #24425e33; text-align: left; color: #24425e; cursor: default; }
.player-east .play-history, .player-south .play-history { left: auto; right: 100%; }
.player-south .play-history { top: auto; bottom: 0; }
.player-avatar:hover .play-history, .player-avatar:focus-within .play-history { display: block; }
.history-title { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.history-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.history-row > span { flex: 0 0 22px; font-size: 11px; }
.history-cards { display: flex; overflow-x: auto; padding-bottom: 4px; flex: 1; min-width: 0; }
.player-avatar .history-cards img { width: 42px; height: auto; flex: 0 0 42px; margin-right: -26px; border-radius: 4px; }
.player-avatar .history-cards img:last-child { margin-right: 0; }

@container (max-width: 1000px) {
  #card-counter { top: 132px; width: 190px; }
  .counter-cell { font-size: 10px; white-space: nowrap; }
}
