/* Table action row, paper modal overlays, score table, and toasts. */

/* ------------------------------------------------------------- action row */

.action-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--u) * 1.1);
  pointer-events: auto;
  white-space: nowrap;
}

.action-panel[hidden] {
  display: none;
}

.table-screen .action-panel .btn {
  min-width: 0;
  min-height: 0;
  height: max(40px, calc(var(--u) * 4.4));
  padding: 0 calc(var(--u) * 2.8);
  border-radius: calc(var(--u) * 0.5);
  font-size: max(13px, calc(var(--u) * 1.65));
}

.action-meta {
  min-width: calc(var(--u) * 9);
  color: var(--muted);
  font-size: calc(var(--u) * 1.3);
  text-align: right;
}

.action-meta:empty {
  visibility: hidden;
}

/* ---------------------------------------------------------------- overlay */

.table-overlay {
  position: absolute;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: max(16px, var(--safe-top)) max(16px, var(--safe-right))
    max(16px, var(--safe-bottom)) max(16px, var(--safe-left));
  overflow-y: auto;
  background: var(--scrim);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.table-overlay[hidden] {
  display: none;
}

.table-overlay .panel {
  position: relative;
  width: min(460px, 100%);
  padding: 24px 26px 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--modal);
  box-shadow: var(--shadow-paper);
  color: var(--text);
  transform: translateY(14px);
  opacity: 0;
  transition:
    transform 0.24s var(--ease-out),
    opacity 0.18s ease;
  pointer-events: auto;
}

.table-overlay .panel.is-open {
  transform: translateY(0);
  opacity: 1;
}

.table-overlay .panel[hidden] {
  display: none;
}

.table-overlay .panel-title {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.score-panel.panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  grid-template-areas:
    "main ledger"
    "foot ledger";
  gap: 18px 36px;
  width: min(780px, 100%);
  padding: 30px 32px 28px;
}

.result-main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.result-seal {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  margin-bottom: 8px;
  border-radius: 8px;
  background: var(--accent-fill);
  box-shadow:
    inset 0 0 0 5px var(--accent-fill),
    inset 0 0 0 7px rgba(255, 253, 248, 0.75);
  color: #fffdf8;
  font: 900 50px / 1 var(--font-seal);
  transform: rotate(-6deg);
}

.result-seal--loss {
  background: var(--text);
  box-shadow:
    inset 0 0 0 5px var(--text),
    inset 0 0 0 7px color-mix(in srgb, var(--bg-solid) 75%, transparent);
  color: var(--bg-solid);
}

.score-panel.is-open .result-seal {
  animation: sealStamp 0.32s var(--ease-out) 0.08s both;
}

@keyframes sealStamp {
  from { transform: scale(1.6) rotate(-16deg); opacity: 0; }
  to { transform: rotate(-6deg); opacity: 1; }
}

.result-title {
  margin: 0;
  font: 400 clamp(32px, 4.4vw, 44px) / 1 var(--font-display);
}

.table-overlay .result-text {
  max-width: 34ch;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.result-stamps {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 6px;
}

.result-stamps:empty {
  display: none;
}

.result-ledger {
  grid-area: ledger;
}

.score-panel .result-kicker {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.score-panel .ledger + .result-kicker {
  margin-top: 22px;
}

.ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
  font-variant-numeric: tabular-nums;
}

.ledger td {
  padding: 7px 0;
  border-top: 1px solid var(--line);
  white-space: nowrap;
}

.ledger-value {
  text-align: right;
}

.ledger--players .ledger-value {
  padding-left: 16px;
}

.ledger-key {
  color: var(--muted);
}

.ledger--players .ledger-key {
  overflow: hidden;
  max-width: 0;
  width: 100%;
  color: var(--text);
  text-overflow: ellipsis;
}

.ledger-sum td {
  border-top: 1.5px solid var(--text);
  color: var(--text);
  font-weight: 700;
}

.ledger-up,
.ledger-you .ledger-key {
  color: var(--accent);
  font-weight: 700;
}

.ledger .ledger-level {
  padding-left: 16px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.result-role {
  margin-left: 6px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 400;
}

.result-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--av3);
  vertical-align: -1px;
}

.result-dot--left {
  background: var(--av1);
}

.result-dot--right {
  background: var(--av2);
}

.panel-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.result-actions {
  grid-area: foot;
  align-self: end;
  flex-direction: row;
  justify-content: flex-start;
}

/* ------------------------------------------------------------- quit panel */

.table-overlay .quit-panel {
  width: min(360px, 100%);
}

.panel-message {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

/* ------------------------------------------------------------------ toast */

/*
 * The app's shared toast normally sits at the bottom of the stage, where the
 * hand lives. Lift it into the open middle of the table while the table is
 * the visible screen.
 */
#stage:has(> .table-screen:not([style*='display: none'])) > .toast.app-toast {
  top: 24%;
  bottom: auto;
}

/* Never let a gameplay/hint toast sit on top of a modal score/quit panel. */
#stage:has(> .table-screen .table-overlay:not([hidden])) > .toast.app-toast {
  display: none;
}

/* --------------------------------------------------------- reduced motion */

@media (orientation: portrait), (max-width: 640px) {
  .score-panel.panel {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "main"
      "ledger"
      "foot";
    gap: 22px;
    padding: 24px 22px 22px;
  }

  .result-seal {
    width: 68px;
    height: 68px;
    font-size: 40px;
  }

  .result-actions .btn {
    flex: 1;
  }

  .ledger .ledger-level {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .table-overlay .panel,
  .score-panel.is-open .result-seal {
    transition: none !important;
    animation: none !important;
  }
}
