/* The hand, live score and tile library are a single play surface. */
.ts-sim {
  --ts-jade: #173e34;
  --ts-ink: #17372f;
  --ts-gold: #d8bf82;
  --ts-line: #cec3a6;
  --ts-paper: #fffdf6;
  --ts-serif: var(--gd-serif, "Noto Serif TC", "Songti TC", serif);
  color: var(--ts-ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  margin: 0 auto 2rem;
  min-width: 0;
  scroll-margin-top: 7rem;
}

.ts-sim *, .ts-sim *::before, .ts-sim *::after { box-sizing: border-box; }
.ts-sim [hidden] { display: none !important; }
.ts-sim button, .ts-sim input, .ts-sim select { font: inherit; }
.ts-sim button { cursor: pointer; }
.ts-sim button:disabled { cursor: default; }
.ts-sim button, .ts-sim summary { touch-action: manipulation; }
.ts-sim button:focus-visible, .ts-sim select:focus-visible, .ts-sim input:focus-visible,
.ts-sim summary:focus-visible { outline: 3px solid #b27d21; outline-offset: 3px; }
.ts-sim h2, .ts-sim h3, .ts-sim p { margin: 0; }
.ts-sim h2 { font: 700 clamp(1.34rem, 2.2vw, 1.9rem)/1.35 var(--ts-serif); letter-spacing: .035em; }
.ts-sim button:not(.ts-tile), .ts-sim select, .ts-sim input { -webkit-tap-highlight-color: transparent; }
.ts-sim .ts-preset-groups, .ts-sim .ts-presets, .ts-sim .ts-actions, .ts-sim .ts-board-head,
.ts-sim .ts-library-head { display: flex; align-items: center; }
.ts-sim .ts-bar {
  display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "title groups actions" "presets presets presets";
  align-items: center; gap: .48rem 1rem; padding: 0 0 1rem;
}
.ts-sim .ts-presets-title { grid-area: title; font-size: 1.12rem; }
.ts-sim .ts-preset-groups { grid-area: groups; gap: .25rem; flex-wrap: wrap; }
.ts-sim .ts-preset-groups button {
  min-height: 2.75rem; background: transparent; border: 0; border-bottom: 2px solid transparent;
  padding: .35rem .65rem; color: #5e6458; font-size: .93rem; font-weight: 600;
}
.ts-sim .ts-preset-groups button[aria-pressed="true"] { border-bottom-color: #977439; color: var(--ts-jade); }
.ts-sim .ts-preset-groups button:hover { color: var(--ts-jade); }
.ts-sim .ts-presets { grid-area: presets; }
.ts-sim .ts-actions { grid-area: actions; justify-self: end; }
.ts-sim .ts-presets, .ts-sim .ts-actions { gap: .35rem; flex-wrap: wrap; }
.ts-sim .ts-presets button, .ts-sim .ts-actions button, .ts-sim .ts-method button {
  background: transparent; border: 1px solid var(--ts-line); color: var(--ts-ink);
  border-radius: .35rem; padding: .4rem .75rem; font-size: .89rem; line-height: 1.35;
  min-height: 2.45rem; font-weight: 650;
}
.ts-sim .ts-presets button[aria-pressed="true"], .ts-sim .ts-method button[aria-pressed="true"] {
  color: #fffdf1; background: var(--ts-jade); border-color: var(--ts-jade);
}
.ts-sim .ts-actions button { border-color: transparent; color: #5a594a; padding-inline: .55rem; }
.ts-sim .ts-actions button:disabled { color: #85857b; }
.ts-sim .ts-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(14.6rem, .31fr); gap: .85rem; align-items: stretch; }
.ts-sim .ts-layout > * { min-width: 0; }
.ts-sim .ts-board {
  position: relative; isolation: isolate; display: flex; flex-direction: column; justify-content: space-between;
  min-height: 19.4rem; border: 1px solid #31463b; border-radius: .8rem; overflow: hidden;
  padding: clamp(1.1rem, 2.5vw, 2rem) clamp(1.15rem, 2.3vw, 2rem);
  background:
    radial-gradient(ellipse at 43% 9%, #54836d6b, transparent 63%),
    repeating-linear-gradient(25deg, transparent 0 2px, #e9f6d705 2px 3px, transparent 3px 5px),
    repeating-linear-gradient(115deg, transparent 0 2px, #001c0d0a 2px 3px, transparent 3px 5px),
    linear-gradient(125deg, #234f42, #204839 55%, #153b31);
  color: #faf8e8;
  box-shadow: inset 0 0 0 3px #163a30, inset 0 0 0 4px #a18d61, inset 0 0 2.8rem #082a2366, 0 3px 5px #17372f12;
}
.ts-sim .ts-board::before, .ts-sim .ts-board::after {
  content: ""; position: absolute; pointer-events: none; z-index: -1;
  width: 3rem; height: 3rem; border: solid #dbcd9a6b; border-width: 1px 0 0 1px; top: .68rem; left: .68rem;
}
.ts-sim .ts-board::after { transform: rotate(180deg); inset: auto .68rem .68rem auto; }
.ts-sim .ts-board h2, .ts-sim .ts-board h3 { color: #fffcec; }
.ts-sim .ts-board-head { justify-content: space-between; gap: 1rem; }
.ts-sim .ts-count {
  color: #eadfbc; font: 600 .88rem/1.4 "Noto Sans TC", sans-serif; letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
}
.ts-sim .ts-board-middle { min-width: 0; margin: 1.35rem 0 1.15rem; }
.ts-sim .ts-rack {
  display: grid; grid-template-columns: repeat(17, minmax(0,1fr)); align-items: end; gap: clamp(1px,.2vw,4px);
  width: 100%; padding: 0 .25rem .52rem; min-height: 3.3rem;
  border-bottom: 4px solid #ac8954; border-radius: 0 0 .22rem .22rem;
  box-shadow: 0 2px 0 #5d472c, 0 6px 5px -3px #06291eda;
}
.ts-sim .ts-tile {
  --tile-border: #d7d1bd;
  display: inline-flex; justify-content: center; align-items: center; position: relative; vertical-align: bottom;
  padding: 0; appearance: none; color: var(--ts-ink); width: 100%; min-width: 0; aspect-ratio: 3 / 4;
  border: 1px solid var(--tile-border); border-radius: 13% / 10%;
  background: linear-gradient(145deg, #fffefa 5%, #fffdf3 48%, #ebe3ce);
  box-shadow: inset 1px 1px 1px #fff, inset -1px -2px 1px #c0bb9d, 0 2px 0 #bfb69a, 0 3px 0 #6e796b, 0 5px 4px -2px #082c27a8;
  transition: transform .12s ease, box-shadow .12s ease;
}
.ts-sim .ts-tile img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.ts-sim .ts-tile:active:not(:disabled) { transform: translateY(2px); }
.ts-sim .ts-tile:focus-visible { z-index: 1; outline-color: #e8be5e; }
.ts-sim .ts-win-tile, .ts-sim .ts-tile[aria-pressed="true"] {
  --tile-border: #c99d41; outline: 2px solid #ebcf81; outline-offset: 1px;
}
.ts-sim .ts-melds { display: flex; gap: .5rem .7rem; flex-wrap: wrap; align-items: end; margin-bottom: .95rem; }
.ts-sim .ts-melds:empty { display: none; }
.ts-sim .ts-melds button { color: #fffae7; }
.ts-sim .ts-board-foot { display: flex; align-items: center; flex-wrap: wrap; gap: .48rem .8rem; margin-top: .45rem; }
.ts-sim .ts-wait-title { font-weight: 700; font-size: .91rem; color: #f2dfab; }
.ts-sim .ts-waits { display: flex; gap: .44rem; flex-wrap: wrap; align-items: center; min-height: 2.4rem; }
.ts-sim .ts-wait-tile { width: 2.3rem; }
.ts-sim .ts-hint { flex-basis: 100%; font-size: .86rem; color: #e3e9dc; }
.ts-sim .ts-result {
  border: 1px solid #beaa7a; border-top: 3px solid #a78346; border-radius: .7rem;
  background: linear-gradient(150deg, #fffdf5, #f7f0dc);
  padding: clamp(1rem, 1.75vw, 1.55rem); align-content: start;
  box-shadow: 0 3px 6px #5042210a;
}
.ts-sim .ts-result h2 { color: #63553a; font-size: 1.15rem; }
.ts-sim .ts-score { display: flex; align-items: baseline; gap: .4rem; min-height: 3.4rem; color: #184539; margin-block: .15rem .1rem; }
.ts-sim .ts-score strong { font: 600 clamp(2.9rem, 4.45vw, 4.1rem)/1.04 Georgia, var(--ts-serif); font-variant-numeric: lining-nums tabular-nums; }
.ts-sim .ts-score span { color: #76613d; font: 700 1.05rem/1.3 var(--ts-serif); }
.ts-sim .ts-result-copy, .ts-sim .ts-groups { font-size: .9rem; color: #505b4f; line-height: 1.5; }
.ts-sim .ts-method {
  display: inline-grid; grid-template-columns: 1fr 1fr; background: #eee8d5;
  border: 1px solid #d8ceb3; border-radius: .4rem; padding: 2px; margin-top: .8rem;
}
.ts-sim .ts-method button { margin: 0; border: 0; border-radius: .27rem; min-height: 2.25rem; }
.ts-sim .ts-breakdown { list-style: none; margin: .7rem 0 0; padding: 0; }
.ts-sim .ts-breakdown:empty { display: none; }
.ts-sim .ts-breakdown li {
  display: flex; justify-content: space-between; align-items: baseline; gap: .6rem; border-top: 1px solid #cbbf9f;
  padding: .35rem 0; font-size: .88rem;
}
.ts-sim .ts-breakdown strong { white-space: nowrap; color: var(--ts-jade); font-variant-numeric: tabular-nums; }
.ts-sim .ts-library { margin-top: 1.2rem; padding: 1.1rem clamp(.95rem, 2vw, 1.8rem) 1.4rem; background: var(--ts-paper); border: 1px solid var(--ts-line); border-radius: .7rem; }
.ts-sim .ts-library-head { gap: .6rem 1rem; justify-content: space-between; flex-wrap: wrap; padding-bottom: .8rem; border-bottom: 1px solid #dcd4c1; }
.ts-sim .ts-library-head h2 { font-size: clamp(1.3rem, 2vw, 1.65rem); }
.ts-sim .ts-library-head label { display: flex; align-items: center; gap: .45rem; color: #545c4f; font-size: .9rem; }
.ts-sim select, .ts-sim input:not([type=checkbox]) { border: 1px solid #b6b39b; border-radius: .32rem; color: var(--ts-ink); background-color: #fffdf5; min-height: 2.5rem; max-width: 100%; padding: .35rem .6rem; }
.ts-sim input[type=checkbox] { accent-color: #255140; width: 1.1rem; height: 1.1rem; }
.ts-sim .ts-palette { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .8rem clamp(1.2rem,4%,3.5rem); margin-top: .85rem; }
.ts-sim .ts-suit { display: grid; grid-template-columns: auto minmax(0,1fr); align-items: center; gap: .5rem; min-width: 0; }
.ts-sim .ts-suit-name { color: #686454; font-size: .9rem; font-weight: 700; letter-spacing: .08em; white-space: nowrap; }
.ts-sim .ts-suit-tiles { display: grid; grid-template-columns: repeat(9, minmax(0,1fr)); gap: clamp(2px, .28vw, 5px); width: 100%; max-width: 31rem; }
.ts-sim .ts-pick-tile { box-shadow: inset 1px 1px 1px #fff, inset -1px -2px 1px #c0bb9d, 0 2px 0 #b0a994, 0 3px 2px #4d51441f; }
.ts-sim .ts-pick-tile:disabled { opacity: .35; }
.ts-sim .ts-settings { border-block: 1px solid var(--ts-line); margin-top: 1rem; color: #384b42; }
.ts-sim .ts-settings summary { padding: .83rem .15rem; color: var(--ts-ink); cursor: pointer; font-weight: 700; }
.ts-sim .ts-settings[open] summary { border-bottom: 1px solid #e0d9c7; }
.ts-sim .ts-setting-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%,12rem),1fr)); align-items: start; gap: .65rem 1.5rem; padding: 1rem .15rem; }
.ts-sim .ts-setting-grid label { font-size: .93rem; display: grid; gap: .28rem; }
.ts-sim .ts-setting-grid label:has(input[type=checkbox]) { display: flex; align-items: center; }
.ts-sim .ts-setting-grid select, .ts-sim .ts-setting-grid input:not([type=checkbox]) { width: 100%; }
@media (hover:hover) {
  .ts-sim .ts-presets button:hover:not([aria-pressed="true"]),
  .ts-sim .ts-actions button:hover:enabled, .ts-sim .ts-method button:hover:not([aria-pressed="true"]) { background: #ede7d4; }
  .ts-sim .ts-tile:hover:enabled { transform: translateY(-3px); --tile-border: #ba9c5b; }
}
@media (min-width: 761px) and (max-width: 1050px) {
  .ts-sim .ts-rack { grid-template-columns: repeat(9, minmax(0,1fr)); width: min(100%,27rem); margin-inline: auto; gap: .38rem .14rem; }
}
@media (max-width: 760px) {
  .ts-sim .ts-bar { grid-template-columns: 1fr auto; grid-template-areas: "title actions" "groups groups" "presets presets"; gap: .28rem .5rem; }
  .ts-sim .ts-presets button { min-height: 2.75rem; }
  .ts-sim .ts-layout { grid-template-columns: 1fr; gap: .65rem; }
  .ts-sim .ts-board { min-height: 0; padding: 1.3rem 1rem 1.2rem; }
  .ts-sim .ts-board-middle { margin-block: 1.1rem .95rem; }
  .ts-sim .ts-rack { grid-template-columns: repeat(9,minmax(0,1fr)); gap: .45rem .12rem; max-width: 26rem; margin-inline: auto; }
  .ts-sim .ts-result { padding: .9rem 1.1rem; }
  .ts-sim .ts-score { margin: .1rem 0; min-height: auto; }
  .ts-sim .ts-score strong { font-size: 2.5rem; }
  .ts-sim .ts-palette { grid-template-columns: 1fr; gap: .75rem; }
  .ts-sim .ts-suit-tiles { max-width: 30rem; }
  .ts-sim .ts-method button, .ts-sim .ts-actions button { min-height: 2.55rem; }
  .ts-sim .ts-wait-tile { width: 2.3rem; }
}
@media (max-width: 460px) {
  .ts-sim .ts-preset-groups { border-bottom: 1px solid #dfd7c4; }
  .ts-sim .ts-library { margin-top: .8rem; padding-inline: .7rem; }
  .ts-sim .ts-suit { gap: .3rem; }
  .ts-sim .ts-suit-name { font-size: .8rem; letter-spacing: 0; }
  .ts-sim .ts-presets button, .ts-sim .ts-actions button { padding-inline: .48rem; }
  .ts-sim .ts-actions { margin-left: auto; gap: .15rem; }
}
@media (prefers-reduced-motion:reduce) { .ts-sim .ts-tile { transition: none; } }

.ts-sim .ts-win-tile::after {
  content: "胡"; position: absolute; inset: -.55rem -.2rem auto auto; z-index: 1;
  display: grid; place-items: center; width: 1.1rem; height: 1.1rem;
  border-radius: 50%; background: #f0ce84; border: 1px solid #70592c; color: #433518;
  font: 700 .7rem/1 var(--ts-serif); pointer-events: none;
}
.ts-sim .ts-ghost {
  display: grid; place-items: center; align-self: end; min-width: 0; aspect-ratio: 3 / 4;
  border: 1px dashed #c4d0af88; border-radius: 12% / 9%; background: #c8dec209;
  color: #dce9d6; font-size: .76rem;
}
.ts-sim .ts-empty-hand { grid-column: 1 / -1; padding: .6rem 0; color: #e6eadb; font-size: .92rem; }
.ts-sim .ts-meld {
  display: inline-flex; flex-wrap: wrap; align-items: end; gap: .28rem;
  padding: .23rem .33rem .35rem; border: 1px solid #c6c5a65c; border-radius: .3rem;
  background: #103b2d66; line-height: 1;
}
.ts-sim .ts-meld-label { color: #f1dfb0; font-size: .78rem; padding: 0 .13rem .1rem; }
.ts-sim .ts-meld-tiles { display: inline-flex; align-items: end; gap: 1px; }
.ts-sim .ts-meld-tiles img {
  width: clamp(1.15rem,2.1vw,1.75rem); height: auto; aspect-ratio: 3 / 4; display: block;
  background: linear-gradient(145deg,#fffef6,#efe7ce); border: 1px solid #b9b7a0; border-radius: 12% / 9%;
  box-shadow: 0 2px 0 #9f9675; object-fit: contain;
}
.ts-sim .ts-groups details { margin-top: .5rem; }
.ts-sim .ts-groups summary { color: #285343; cursor: pointer; font-weight: 650; min-height: 2.2rem; padding-block: .35rem; }
.ts-sim .ts-groups ul { margin: .1rem 0 .5rem; padding-left: 1.2rem; }
.ts-sim .ts-mode-help, .ts-sim .ts-rule-note { color: #626555; font-size: .89rem; line-height: 1.55; }
.ts-sim .ts-mode-help { margin-top: .6rem; }
.ts-sim .ts-rule-note { margin-bottom: .85rem; }
.ts-sim .ts-feedback:not(:empty) {
  position: sticky; bottom: .8rem; z-index: 3; width: fit-content; max-width: 100%;
  margin: .7rem auto 0; padding: .48rem .9rem; border: 1px solid #bda872;
  border-radius: .38rem; background: #264c3f; box-shadow: 0 3px 8px #15362a33;
  color: #fffced; font-size: .91rem; pointer-events: none;
}
@media (max-width: 760px) {
  .ts-sim .ts-melds { gap: .34rem .45rem; }
  .ts-sim .ts-win-tile::after { width: .95rem; height: .95rem; inset: -.4rem -.15rem auto auto; }
}
