: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-image {
  display: block; width: var(--card-width); height: auto; aspect-ratio: 20 / 27;
  background-repeat: no-repeat; border-radius: 7px;
}
.card-backs, .revealed-cards, .played { --card-width: 56px; --card-step: 16px; }
.revealed-cards, .played { --card-step: 20px; }
.card-backs .card-image { 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; bottom: 414px; left: 50%; transform: translateX(-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 .card-image { width: 100%; }
.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 .card-image { width: 42px; height: auto; flex: 0 0 42px; margin-right: -26px; border-radius: 4px; }
.player-avatar .history-cards .card-image:last-child { margin-right: 0; }

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

/* The active seat's previous action is replaced by a clock in its play area. */
.player-info > .remaining-count, .player-info > .player-rank { font-size: 14px; }
.remaining-count b, .player-info > .player-rank { font-weight: 700; }
.player-info > .remaining-count.low-count { color: #c42d36; }
.played.active-play { display: flex; justify-content: center; align-items: center; min-height: 84px; padding: 8px 0; overflow: visible; }
.play-timer { position: relative; width: 64px; height: 64px; border-radius: 8px; background: #f2f8ffe6; }
.play-timer .turn-seconds { inset: 0; display: flex; align-items: center; justify-content: center; padding: 0; background: transparent; font-size: 28px; }

#admin-panel { margin-top: 28px; padding: 20px; border: 1px solid #bfd3e7; border-radius: 12px; background: #fff; }
#admin-panel fieldset { border: 1px solid #d0e0ef; border-radius: 8px; }
#admin-panel input[type="checkbox"] { width: auto; margin: 0 8px 0 0; }
.admin-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.admin-table-scroll { overflow-x: auto; }
#admin-panel table { border-collapse: collapse; width: 100%; text-align: left; }
#admin-panel th, #admin-panel td { padding: 10px; border-bottom: 1px solid #d0e0ef; white-space: nowrap; }
#admin-panel td img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.admin-score-form { display: flex; gap: 8px; align-items: center; }
.admin-score-form input { width: 140px; margin: 0; }
#admin-message { min-height: 24px; }

/* Resource-free fireworks above confirmed played cards; never intercept input. */
.play-effects { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 4; border-radius: inherit; }
.play-effect { position: absolute; width: 0; height: 0; color: var(--effect-color); }
.play-effect-label { position: absolute; z-index: 1; transform: translate(-50%, -50%); white-space: nowrap; font: 900 34px/1.2 system-ui, sans-serif; letter-spacing: .08em; text-shadow: 0 2px 2px #fff, 0 0 5px #fff, 0 0 14px currentColor; animation: play-label-fade 3s linear both; }
.play-effect-spark { position: absolute; left: var(--burst-x); top: var(--burst-y); width: 5px; height: 5px; border-radius: 50%; background: currentColor; box-shadow: 0 0 6px currentColor; animation: play-firework 3s ease-out both; }
@keyframes play-label-fade { 0%, 33.333% { opacity: 1; } 100% { opacity: 0; } }
@keyframes play-firework {
  0% { opacity: 0; transform: translate(0, 0) scale(.4); }
  4% { opacity: 1; }
  35% { opacity: 1; transform: translate(var(--spark-x), var(--spark-y)) scale(1); }
  100% { opacity: 0; transform: translate(var(--spark-x), var(--spark-fall)) scale(.2); }
}
@media (prefers-reduced-motion: reduce) { .play-effect-spark { display: none; } }

/* Run labels drift only 16px across the center of the played cards. */
.play-effect-run .play-effect-label { animation: play-run-fade 1.8s linear both, play-run-drift 1.8s linear both; }
@keyframes play-run-fade {
  0%, 100% { opacity: 0; }
  33.333333%, 66.666667% { opacity: 1; }
}
@keyframes play-run-drift {
  from { transform: translate(calc(-50% - 8px), -50%); }
  to { transform: translate(calc(-50% + 8px), -50%); }
}
@media (prefers-reduced-motion: reduce) {
  .play-effect-run .play-effect-label { animation: play-run-fade 1.8s linear both; }
}

/* Compact account-header volume control; its panel does not move the table. */
#account-info { flex-wrap: wrap; }
#volume-control { position: relative; }
#volume-button { padding: 6px 12px; font-size: 13px; }
#volume-panel { position: absolute; right: 0; top: calc(100% + 10px); z-index: 20; width: 220px; padding: 14px; border: 1px solid #bfd3e7; border-radius: 10px; background: #f6faff; box-shadow: 0 6px 20px #24425e26; }
.volume-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.volume-heading label { margin: 0; }
#volume-value { font-variant-numeric: tabular-nums; }
#volume-slider { display: block; padding: 0; margin: 14px 0; accent-color: #397dcc; cursor: pointer; }
#volume-mute { width: 100%; padding: 6px 12px; font-size: 13px; }

/* Large-bomb ink thunder; the inherited layer clips every pixel. */
.ink-thunder-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.play-effect-ink .play-effect-label {
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "Noto Serif CJK SC", serif;
  font-size: 58px; font-weight: 900; letter-spacing: .14em;
  color: #f7e6ba; text-shadow: 0 2px 3px #080e12, 0 0 18px #a87d3433;
  animation: ink-label 2.6s ease-out both;
}
.play-effect-ink .play-effect-glyph {
  display: inline-block; transform-origin: 50% 50%;
  animation: ink-glyph-slam .42s linear both;
}
.play-effect-ink .play-effect-label::after {
  content: attr(data-seal); position: absolute; right: -25px; top: 9px;
  width: 18px; padding: 3px 1px; border: 1px solid #c0644e;
  color: #e3aa90; background: #782c23bb;
  font-family: inherit; font-size: 12px; font-weight: 500; line-height: 1.2;
  letter-spacing: 0; white-space: normal; text-align: center; text-shadow: none;
  transform: rotate(5deg);
  animation: ink-seal .15s ease-out var(--seal-delay) both;
}
@keyframes ink-label {
  0%, 64% { opacity: 1; transform: translate(-50%, -60%) scale(1) rotate(-7deg); }
  100% { opacity: 0; transform: translate(-50%, -66%) scale(1) rotate(-7deg); }
}
/* Scale and focus create a front-to-paper impact around each glyph's fixed center. */
@keyframes ink-glyph-slam {
  0% { opacity: 0; transform: scale(4.4); filter: blur(8px); }
  15% { opacity: 1; transform: scale(3.6); filter: blur(4px); animation-timing-function: cubic-bezier(.65, 0, 1, .5); }
  43% { opacity: 1; transform: scale(.88); filter: blur(0); animation-timing-function: ease-out; }
  66% { opacity: 1; transform: scale(1.06); filter: blur(0); animation-timing-function: ease-in-out; }
  100% { opacity: 1; transform: scale(1); filter: blur(0); }
}
@keyframes ink-seal { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .play-effect-ink .play-effect-glyph { animation: none; transform: none; filter: none; opacity: 1; }
  .ink-thunder-canvas { display: none; }
  .play-effect-ink .play-effect-label {
    color: #2563eb; font-size: 34px; text-shadow: 0 1px 3px #fff;
    animation: play-label-fade 2.6s linear both;
  }
  .play-effect-ink .play-effect-label::after { display: none; }
}

/* The landscape replaces only the felt visually; every card and control stays above it. */
.card-table { isolation: isolate; }
.ink-landscape-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  z-index: -1; border-radius: inherit; pointer-events: none;
}
.play-effect-landscape .play-effect-label {
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "Noto Serif CJK SC", serif;
  animation-duration: 2.2s, 2.2s;
}
@media (prefers-reduced-motion: reduce) {
  .ink-landscape-canvas { display: none; }
}
