/* Quiet tabletop palette. Visual treatment only; layout and game behavior live elsewhere. */
:root {
  color-scheme: light;
  --bg: #eeeae2;
  --table: #284c40;
  --rack: #f8f5ed;
  --line: #ccc9bc;
  --ink: #253d33;
  --muted: #606e61;
  --gold: #ebc780;
  --amber: #f1c58c;
  --pine: #264b3d;
  --paper: #fcfaf4;
  --brass: #80622d;
}
body {
  background: var(--bg);
}
header {
  padding-bottom: 4px;
}
.brand {
  gap: 12px;
}
.seal {
  background: var(--pine);
  color: #f8edcf;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 24px;
}
.brand h1 {
  letter-spacing: 0.04em;
  font-weight: 600;
}
.brand small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}
button:not(.tile) {
  border-radius: 8px;
  background-color: var(--paper);
  border-color: var(--line);
  color: var(--ink);
  transition:
    background-color 120ms,
    border-color 120ms;
}
button:not(.tile):hover {
  background-color: #e5e8dc;
  border-color: #94a191;
}
button:not(.tile):disabled {
  opacity: 1;
  color: #92988c;
  border-color: #dddcd1;
  background-color: #edece4;
}
button:focus-visible,
summary:focus-visible {
  outline-color: #a27527;
  outline-offset: 3px;
}
.header-actions button {
  min-height: 44px;
  padding: 8px 16px;
  font-size: 13px;
  background: transparent;
}
#new-game {
  border-color: #809182;
}
.brief {
  padding: 4px 2px 8px;
}
.brief strong {
  font-size: 15px;
  font-weight: 650;
}
.brief p {
  margin-top: 4px;
  color: var(--muted);
}
.session-meta {
  gap: 1px;
}
.session-meta > span:first-child {
  color: var(--ink);
  font-size: 13px;
}
.session-meta b {
  display: inline-block;
  margin-left: 4px;
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
#save-status {
  font-size: 11px;
  color: var(--muted);
}
.board {
  border-radius: 16px;
  border: 1px solid #36584a;
  background: var(--table);
  box-shadow: inset 0 2px 9px #102b2526;
}
.board-top {
  color: #d0dfcd;
  font-size: 12px;
}
#status {
  color: #efd39a;
  font-size: 12px;
}
.board #board-scroll {
  scrollbar-color: #91a791 transparent;
}
.board #board-scroll:focus-visible {
  outline-color: var(--gold);
}
.groups .meld {
  background: #1e4034;
  border-color: #57715c;
  border-radius: 9px;
}
.groups .handle,
.groups .handle:hover {
  background: transparent;
  border: none;
}
.grip {
  background: #a8bda3;
  opacity: 0.72;
}
.groups .handle:hover .grip {
  background: var(--gold);
}
.groups .meld.invalid {
  background: #414d35;
  border-color: #dbad66;
}
.groups .meld-label {
  color: #f5d59e;
}
.groups .place-actions {
  background: #eae7dd;
  border: 1px solid var(--line);
}
.groups .place-actions button {
  background: var(--paper);
  color: var(--ink);
}
.empty-table {
  color: #c6d9c5;
}
.empty-table span {
  color: #f3edda;
  font-size: 26px;
}
.empty-table p {
  font-size: 14px;
}
.group-drop {
  border-color: #efd39a;
  background: #efd39a18;
}
.tile {
  box-shadow: 0 3px 4px #0a201e33;
}
.tile.selected {
  outline: 3px solid #bf8a31;
  outline-offset: 2px;
}
.board .tile.selected {
  outline-color: #f2cb7d;
}
.rack {
  background: var(--rack);
  border-radius: 14px;
  border: 1px solid #d4d1c3;
  padding-top: 16px;
}
.rack-top {
  margin-bottom: 12px;
}
.rack-top h2 {
  font-size: 15px;
  font-weight: 650;
}
.rack-top h2 b {
  color: var(--brass);
  font-size: 22px;
  font-weight: 600;
}
.tools {
  gap: 6px;
}
.tools button {
  min-height: 40px;
  font-size: 12px;
  padding: 6px 12px;
  background: transparent;
}
.tools button[aria-pressed="true"] {
  background: var(--pine);
  border-color: var(--pine);
  color: var(--paper);
}
.rack-viewport {
  background: #e4dfd1;
  border-radius: 9px;
  scrollbar-color: #88917f transparent;
}
.rack-browse {
  color: var(--muted);
}
.rack-browse button {
  min-height: 36px;
}
.selection-label {
  color: #556655;
  font-size: 12px;
}
.selection-tools button {
  min-height: 36px;
}
.actions {
  gap: 8px;
}
.actions button {
  font-weight: 550;
}
button.primary,
#submit {
  background: var(--pine);
  border-color: var(--pine);
  color: #fff9e8;
  font-weight: 650;
}
button.primary:hover,
#submit:hover {
  background: #345e49;
  border-color: #345e49;
}
#submit:disabled {
  background: #c4cbc0;
  border-color: #c4cbc0;
  color: #627260;
}
#draw {
  background: #e8e9de;
  border-color: #bdc4b4;
}
.rack-hint,
footer {
  color: #657160;
}
.rack-hint {
  font-size: 11px;
}
footer {
  font-size: 11px;
}
footer button,
footer button:hover {
  background: transparent !important;
  border: 0 !important;
  color: #657160 !important;
}
.pending {
  background: #f4e5c8;
  border: 1px solid #bda472;
  color: #473e2c;
  border-radius: 12px;
}
.pending-caption,
.pending-caption small {
  color: #6a542f;
}
.error-bar,
.save-warning {
  background: #f4e3c4;
  color: #5b4223;
  border-color: #c4a16c;
}
.error-bar button,
.save-warning button {
  background: #fcf5e7;
  color: #5b4223;
}
.toast {
  background: #263f33;
  color: #fff5de;
  border: 1px solid #506652;
  box-shadow: 0 5px 18px #132a2524;
  border-radius: 9px;
  font-size: 13px;
}
#state-panel {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--line);
}
dialog {
  background: var(--paper);
  border-color: #c7c5b6;
  border-radius: 16px;
  box-shadow: 0 16px 48px #18291e33;
}
dialog::backdrop {
  background: #162b256e;
}
.dialog-content h2 {
  color: var(--pine);
}
.dialog-content p {
  color: #596754;
}
.rules-dialog h3 {
  color: var(--pine);
}
.special-guide article {
  padding: 10px 0;
  border-bottom: 1px solid #e1dfd2;
}
@media (max-width: 700px) {
  .app {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  header {
    padding-bottom: 0;
  }
  .seal {
    padding: 6px 8px;
    font-size: 20px;
  }
  .brand h1 {
    font-size: 18px;
    letter-spacing: 0;
  }
  .header-actions button {
    min-height: 44px;
    padding: 6px 10px;
    font-size: 12px;
  }
  .brief {
    padding: 0 0 2px;
  }
  .brief strong {
    font-size: 13px;
  }
  .session-meta b {
    font-size: 20px;
  }
  #save-status {
    font-size: 10px;
  }
  .rack {
    padding: 10px 12px;
  }
  .rack-top {
    margin-bottom: 8px;
  }
  .rack-top h2 {
    font-size: 13px;
  }
  .rack-top h2 b {
    font-size: 18px;
  }
  .tools {
    gap: 4px;
  }
  .tools button {
    min-height: 44px;
    padding: 4px 6px;
    font-size: 11px;
  }
  .rack-hint {
    font-size: 10px;
  }
  .rack-browse {
    gap: 4px;
    font-size: 10px;
  }
  .rack-browse button {
    min-height: 36px;
    font-size: 11px;
    padding: 3px 6px;
  }
  .empty-table span {
    font-size: 22px;
  }
  .empty-table p {
    font-size: 12px;
  }
}
@media (max-height: 550px) and (min-width: 701px) {
  .tools button {
    padding: 4px 6px;
    font-size: 10px;
  }
  .rack-top {
    margin-bottom: 4px;
  }
  .header-actions button {
    padding: 5px 10px;
  }
}
@media (prefers-reduced-motion: reduce) {
  button:not(.tile) {
    transition: none;
  }
}
/* Keep the short laptop layout clear without squeezing its primary actions. */
@media (min-width: 701px) and (min-height: 551px) and (max-height: 700px) {
  .app {
    padding: 12px 24px;
    gap: 8px;
  }
  .brand small,
  .brief p {
    display: none;
  }
  .brief {
    padding: 0;
  }
  .board {
    min-height: 110px;
  }
  .rack {
    padding: 10px 16px;
  }
  .rack-top {
    margin-bottom: 6px;
  }
}
/* Labels for the controls players use every turn stay legible. */
.tools button,
.header-actions button {
  font-size: 14px;
}
@media (max-width: 700px) {
  .tools button {
    font-size: 14px;
    padding-left: 6px;
    padding-right: 6px;
  }
  .header-actions button {
    font-size: 14px;
    padding-left: 8px;
    padding-right: 8px;
  }
  .rack-top h2,
  .brief strong {
    font-size: 14px;
  }
}
@media (max-height: 550px) and (min-width: 701px) {
  .tools {
    flex-wrap: wrap;
  }
  .tools button {
    font-size: 12px;
  }
}
/* Compact rack toolbar: two recognizable sorting glyphs on the title row. */
.rack .rack-top {
  flex-wrap: nowrap;
  margin-bottom: 6px;
}
.rack .tools {
  flex-wrap: nowrap;
  gap: 6px;
  margin-left: auto;
}
.rack .tools button {
  display: grid;
  place-items: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 8px;
}
.tools svg {
  width: 26px;
  height: 26px;
  pointer-events: none;
}
.rack .selection-tools {
  min-height: 0;
  margin: 0;
}
.rack .selection-tools:not(:has(button:not([hidden]))) {
  display: none;
}
.rack .selection-tools .selection-label {
  display: none;
}
.rack .actions {
  margin-top: 8px;
}
.rack .rack-hint {
  margin-top: 5px;
}
@media (min-height: 551px) and (max-width: 700px) {
  .app .rack .rack-viewport {
    max-height: calc(var(--th) * 3 + 26px);
  }
  .app.has-pending .rack .rack-viewport {
    max-height: calc(var(--th) * 2 + 18px);
  }
  .rack {
    padding-top: 8px;
    padding-bottom: 8px;
  }
}
@media (max-height: 550px) and (min-width: 701px) {
  .rack .rack-top {
    margin-bottom: 6px;
  }
  .rack .rack-viewport {
    min-height: calc(var(--th) * 2 + 18px);
  }
  .rack .rack-hint #input-hint {
    display: none;
  }
  .rack .rack-hint {
    justify-content: flex-end;
  }
}
:root {
  --group-head: 16px;
}
.rack-counts {
  display: flex;
  align-items: baseline;
  gap: 14px;
  white-space: nowrap;
}
.pool-label {
  color: var(--muted);
  font-size: 12px;
}
.pool-label b {
  font: 600 17px Arial;
  color: var(--ink);
  margin-left: 3px;
  font-variant-numeric: tabular-nums;
}
.groups .meld-head,
.groups .handle {
  height: var(--group-head);
  min-height: var(--group-head);
}
.groups .meld-label {
  top: 0;
  line-height: 16px;
}
.grip {
  height: 2px;
  width: 24px;
}
.opening-notice {
  position: fixed;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  padding: 12px 18px;
  max-width: calc(100vw - 24px);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 200ms ease;
}
button.opening-notice,
button.opening-notice:hover {
  background: #f5e6c8;
  color: #344834;
  border-color: #bda572;
  box-shadow: 0 5px 18px #18372b26;
}
.opening-notice.visible {
  opacity: 1;
}
@media (max-width: 700px), (max-height: 550px) and (min-width: 701px) {
  :root {
    --tw: 38px;
    --th: 54px;
  }
  .hand {
    grid-template-columns: repeat(auto-fill, var(--tw));
  }
  .tile .number {
    font-size: 25px;
  }
  .tile .dot {
    width: 5px;
    height: 5px;
    left: calc(50% - 2.5px);
  }
  .rack-counts {
    gap: 10px;
  }
  .rack-top h2 {
    font-size: 13px;
  }
  .rack-top h2 b {
    font-size: 17px;
    margin-left: 4px;
  }
  .pool-label {
    font-size: 11px;
  }
  .pool-label b {
    font-size: 15px;
  }
  #save-status {
    font-size: 10px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .opening-notice {
    transition: none;
  }
}
button.opening-notice {
  transition: opacity 200ms ease;
}
@media (prefers-reduced-motion: reduce) {
  button.opening-notice {
    transition: none;
  }
}
/* A shared footer keeps secondary actions clear of the phone's rounded edge. */
footer {
  height: auto;
  min-height: 32px;
  gap: 12px;
  position: relative;
}
.footer-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: none;
}
.footer-actions details {
  position: static;
}
.footer-actions summary {
  cursor: pointer;
  min-height: 32px;
  display: flex;
  align-items: center;
  font-size: 11px;
}
.footer-actions summary::before {
  content: "▸";
  margin-right: 5px;
}
.footer-actions details[open] summary::before {
  content: "▾";
}
.footer-actions button {
  min-height: 32px;
}
.footer-actions #state-panel {
  bottom: 38px;
  max-width: 100%;
}
.rack-hint:has(#input-hint:only-child) {
  margin-bottom: 0;
}
@media (max-height: 550px) and (min-width: 701px) {
  .app {
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    padding: 10px max(16px, calc(var(--safe-right) + 12px))
      max(12px, calc(var(--safe-bottom) + 8px))
      max(16px, calc(var(--safe-left) + 12px));
    grid-template-rows: 42px minmax(0, 1fr) 32px;
  }
  .rack .rack-hint {
    display: none;
  }
  footer {
    min-height: 32px;
    padding: 0 4px;
  }
  .footer-actions {
    gap: 20px;
  }
  footer #save-status {
    margin-left: auto;
    margin-right: auto;
  }
}
@media (max-width: 700px) {
  footer {
    gap: 6px;
    font-size: 10px;
  }
  .footer-actions {
    gap: 10px;
  }
  .footer-actions summary,
  .footer-actions button {
    font-size: 10px;
  }
}

/* A quiet victory lap through the player's actual completed groups. */
.result-dialog.victory { width: 560px; }
.victory .dialog-content { padding: 24px; }
.victory #result-title { font-size: clamp(24px, 5vw, 32px); color: var(--pine); }
.victory #result-description { font-size: 14px; margin-bottom: 8px; }
.victory-sparks { color: #ae7b26; font-size: 28px; letter-spacing: 24px; padding-left: 24px; animation: victory-glow 1.4s ease-out both; }
.victory-sparks span { display: inline-block; transform: translateY(-7px); }
#victory-stats { margin: 0 0 12px; font-size: 14px; }
#victory-groups { background: #284c40; border: 1px solid #45685a; border-radius: 14px; padding: 16px 10px; min-height: 102px; }
.victory-group { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.victory-group[hidden] { display: none; }
.victory-group .tile { --tw: 38px; --th: 54px; width: 38px; height: 54px; flex: 0 0 38px; margin: 0; opacity: 1; animation: victory-tile 480ms cubic-bezier(.2,.8,.2,1) var(--tile-delay) both; }
.victory-group .tile .number { font-size: 25px; }
.victory-group .tile .dot { width: 5px; height: 5px; left: calc(50% - 2.5px); }
.victory-controls { display: flex; align-items: center; justify-content: center; gap: 20px; margin-top: 8px; }
.victory-controls button { width: 44px; min-height: 44px; margin: 0; }
#victory-progress { font-size: 14px; font-variant-numeric: tabular-nums; }
.result-dialog #victory-play { width: auto; min-height: 44px; margin: 0; font-size: 14px; }
@keyframes victory-tile { from { opacity: 0; transform: translateY(18px) rotate(-5deg) scale(.9); } to { opacity: 1; transform: none; } }
@keyframes victory-glow { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: scale(1); } }
@media (max-height: 550px) and (min-width: 701px) {
  .result-dialog.victory { width: 720px; }
  .victory .dialog-content { display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; padding: 18px 24px; }
  .victory .eyebrow, .victory #result-title, .victory #result-description, .victory #again, .victory #view-board { grid-column: 1; }
  #victory-replay { grid-column: 2; grid-row: 1 / 6; align-self: center; }
}
@media (prefers-reduced-motion: reduce) {
  .victory-group .tile, .victory-sparks { animation: none; }
}
@media (max-height: 550px) and (min-width: 701px) {
  .victory #result-title { font-size: 24px; margin-bottom: 4px; }
  .victory .dialog-content { padding: 12px 20px; }
  .victory .eyebrow { margin: 0 0 8px; }
  .victory-sparks { display: none; }
  #victory-stats { margin-bottom: 8px; }
  #victory-groups { min-height: 114px; max-height: 130px; overflow-y: auto; padding: 8px; }
  .victory-group { gap: 4px; }
  .victory-group .tile { width: 32px; height: 46px; flex-basis: 32px; }
  .victory-group .tile .number { font-size: 23px; }
  .victory-controls { margin-top: 4px; }
}
@media (max-width: 700px) {
  .victory .dialog-content { padding: 18px; }
  #victory-groups { max-height: min(210px, 28dvh); overflow-y: auto; }
}
.board-top #status { margin-left: auto; }
.board-top #tidy-table { flex: none; min-height: 32px; padding: 4px 9px; margin-left: 10px; font-size: 12px; color: #f5e6c8; background: #ffffff0d; border: 1px solid #ffffff35; border-radius: 7px; }
.board-top #tidy-table:hover { background: #ffffff1a; }
