:root {
  --paper: #f8f8f5;
  --table: #e0e4da;
  --table-line: #cdd5cb;
  --ink: #394b60;
  --muted: #56687b;
  --line: #dce3ea;
  --white: #fffdf5;
  --tile-edge: #3c424a;
  --tile-number: #171d29;
  --hint: #507399;
  --hint-ink: #345982;
  --hint-bg: #eef5fc;
  --error: #99372e;
  --success: #2b684c;
  --cell-size: 48px;
  --square-hand-size: 60px;
  --control-shadow: 0 3px 8px #40577014;
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 300px; }
h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, .board-viewport:focus-visible { outline: 3px solid #386896; outline-offset: -3px; }
#app {
  max-width: 436px;
  min-height: 100dvh;
  margin-inline: auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
#app.playing-layout {
  height: 100dvh;
  min-height: 510px;
  display: grid;
  grid-template-rows: auto minmax(calc(2 * var(--cell-size) + 8px), 1fr) auto;
  gap: 10px;
}
#app.playing-layout:has(.polygon-viewport[data-mode="triangle"]) { grid-template-rows: auto minmax(122px, 1fr) auto; }
#app.playing-layout:has(.polygon-viewport[data-mode="hex"]) { grid-template-rows: auto minmax(108px, 1fr) auto; }
.primary, .secondary, .draw-button {
  min-height: 44px;
  min-width: 44px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  font-size: 14px;
  font-weight: 650;
}
.primary { color: white; background: #3b5a7c; border-color: #3b5a7c; box-shadow: var(--control-shadow); }
.primary:disabled { background: #e7ebee; color: #596775; border-color: var(--line); box-shadow: none; }
.secondary { background: #fcfdfe; box-shadow: var(--control-shadow); }
.secondary:disabled { color: #677787; background: #edf0f1; box-shadow: none; }
.full { width: 100%; }
.text-button { border: 0; border-radius: 10px; background: transparent; min-width: 44px; min-height: 44px; padding: 4px 5px; font-size: 12px; color: var(--hint-ink); }
.text-button:disabled { opacity: .55; }
.game-header { display: grid; gap: 4px; }
.topbar { display: flex; min-height: 49px; align-items: center; justify-content: space-between; gap: 8px; padding-bottom: 5px; border-bottom: 1px solid #e5e8e4; }
.wordmark { display: flex; align-items: center; gap: 2px; color: var(--ink); font-size: clamp(22px, 6.8vw, 30px); line-height: 1.1; font-weight: 900; white-space: nowrap; }
.brand-mark { display: block; width: 32px; height: 32px; flex-shrink: 0; }
.mode-trigger { display: flex; justify-content: center; align-items: center; gap: 8px; white-space: nowrap; font-size: 13px; color: var(--hint-ink); }
.chevron { width: 7px; height: 7px; border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); margin: -3px 2px 0 0; }
.game-meta { display: flex; align-items: center; gap: 6px; }
.stats { display: flex; flex: 1; gap: 5px; align-items: center; min-width: 0; }
.stats > div { display: flex; flex: 1; justify-content: space-between; align-items: baseline; gap: 4px; padding: 6px 8px; border-radius: 10px; font-size: 11px; white-space: nowrap; }
.stats .stat-hand { background: #eaf0f7; color: #385779; }
.stats .stat-pool { background: #e9efe6; color: #41624b; }
.stats strong { font-size: 19px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.stats small { font-size: .82em; }
.goal { margin-right: auto; font-size: 11px; font-weight: 650; color: #4b6053; white-space: nowrap; }
.game-nav { display: flex; }
.table-area { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.board-viewport {
  flex: 1;
  min-height: calc(2 * var(--cell-size) + 8px);
  overflow: hidden auto;
  overscroll-behavior: contain;
  touch-action: pan-y pinch-zoom;
  scrollbar-width: none;
  background: var(--table);
  border-radius: 19px;
  box-shadow: inset 0 0 0 1px var(--table-line), inset 0 0 0 3px #ffffff6b;
  align-content: safe center;
}
.board-viewport::-webkit-scrollbar { display: none; }
.board {
  display: grid;
  grid-template-columns: repeat(var(--columns), var(--cell-size));
  grid-template-rows: repeat(var(--rows), var(--cell-size));
  width: max-content;
  margin: 7px auto;
  isolation: isolate;
  position: relative;
}
.card-frame, .hand-domino, .drag-float {
  border: 3px solid var(--white);
  background: var(--card-color);
  border-radius: 7px;
  box-shadow: inset 0 0 0 1px var(--tile-edge), 0 0 0 1px var(--tile-edge), 0 2px 0 1px #4b4d54;
  pointer-events: none;
}
.card-frame { z-index: 0; margin: 2px; position: relative; }
.card-frame.horizontal::after, .card-frame.vertical::after { content: ""; position: absolute; }
.card-frame.horizontal::after { left: 50%; top: 3px; bottom: 3px; border-left: 1px solid #fffdf577; }
.card-frame.vertical::after { top: 50%; left: 3px; right: 3px; border-top: 1px solid #fffdf577; }
.cell { z-index: 1; display: flex; align-items: center; justify-content: center; position: relative; pointer-events: none; }
.number { display: block; width: 100%; height: 100%; overflow: visible; }
.number text, .polygon-number { font-family: "Arial Black", "Segoe UI Black", sans-serif; font-weight: 900; fill: #fffdf5; stroke: var(--tile-number); paint-order: stroke fill; }
.number text { font-size: 52px; stroke-width: 7px; stroke-linejoin: round; filter: drop-shadow(2px 4px 0 var(--tile-number)); }
.target-layer, .hint-layer { position: absolute; inset: 0; pointer-events: none; }
.target-layer { z-index: 3; overflow: hidden; }
.target-cell { position: absolute; border: 3px solid; border-radius: 6px; box-shadow: inset 0 0 0 1px var(--white); }
.target-cell.valid { border-color: var(--success); background: #2b684c24; }
.target-cell.invalid { border-color: var(--error); background: #99372e24; }
.hint-layer { z-index: 2; display: grid; grid-template-columns: repeat(var(--columns),var(--cell-size)); grid-template-rows: repeat(var(--rows),var(--cell-size)); }
.hint-frame, .hand-slot.hinted::after { position: relative; border: 2px solid var(--hint); border-radius: 8px; box-shadow: inset 0 0 0 2px var(--white); }
.hint-frame { margin: 1px; }
.hand-slot.hinted::after { content: ''; position: absolute; inset: 0; pointer-events: none; }
.hint-frame::before, .hand-slot.hinted::before, .hint-marker {
  content: '◆';
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  width: 14px;
  height: 14px;
  border: 1px solid var(--hint);
  background: #fcfdff;
  border-radius: 50%;
  color: var(--hint-ink);
  font: 700 9px/12px sans-serif;
  text-align: center;
}
.hint-marker { content: normal; position: static; flex: 0 0 14px; }
.hint-marker::after { content: '◆'; }
.play-controls { min-width: 0; }
.play-message { display: grid; align-items: center; height: 49px; }
.play-message > * { grid-area: 1 / 1; }
.feedback, .placement-check { font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; padding-inline: 6px; }
.feedback { color: var(--muted); }
.feedback.success { color: var(--success); }
.feedback.error { color: var(--error); }
.placement-check:not(:empty) { justify-self: start; background: #eaf0f7; font-weight: 650; color: var(--hint-ink); padding: 6px 9px; border-radius: 8px; }
.play-message:has(.placement-check:not(:empty)) .feedback.neutral,
.has-hint .feedback, .has-hint .placement-check, .play-message:has(.result-banner) .feedback {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
}
.hint-panel { display: flex; align-items: center; gap: 8px; height: 49px; padding-inline: 9px 3px; border: 1px solid #aec1d7; border-radius: 13px; background: var(--hint-bg); box-shadow: var(--control-shadow); }
.hint-copy { flex: 1; min-width: 0; line-height: 1.3; font-size: 12px; }
.hint-copy strong { color: var(--hint-ink); }
.hint-detail { color: var(--muted); font-size: 11px; }
.hint-next { display: flex; align-items: center; }
.hint-next [data-act="check"] { font-size: 12px; background: transparent; border: 0; border-left: 1px solid #d1deed; border-radius: 0 8px 8px 0; box-shadow: none; color: var(--hint-ink); white-space: nowrap; }
.check-slot .hint-ready { background: var(--hint-bg); color: var(--hint-ink); border-color: #9db5cf; }
.hand-area .section-label { height: 44px; display: flex; align-items: center; justify-content: space-between; padding-inline: 2px; }
.section-label h2 { font-size: 16px; font-weight: 750; }
.hand-tools, .hint-tools { display: flex; }
.hand-tools [data-act="reset"]:disabled { visibility: hidden; }
.hand-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 7px; }
.hand-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 75px;
  padding: 0;
  border: 1px solid #dae0e4;
  border-radius: 10px;
  position: relative;
  background: #edf0f2;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}
.hand-slot.selected { border-color: #66849d; background: #dee8f1; box-shadow: inset 0 0 0 1px #66849d; }
.hand-slot.empty { background: #f3f5f4; color: #637990; touch-action: auto; }
.hand-domino, .drag-float { display: grid; grid-template-columns: 1fr 1fr; flex-shrink: 0; width: var(--square-hand-size); height: calc(var(--square-hand-size) / 2); }
.hand-domino > span, .drag-float > span { min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; }
.hand-domino > span + span, .drag-float > span + span { border-left: 1px solid #fffdf577; }
.hand-domino.vertical, .drag-float.vertical { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; width: calc(var(--square-hand-size) / 2); height: var(--square-hand-size); }
.hand-domino.vertical > span + span, .drag-float.vertical > span + span { border-left: 0; border-top: 1px solid #fffdf577; }
.hand-domino .number { width: calc(var(--square-hand-size) / 2); height: calc(var(--square-hand-size) / 2); flex-shrink: 0; }
.hand-domino .number text { font-size: 60px; stroke-width: 8px; }
.hand-slot.drag-source .hand-domino { opacity: .22; }
.drag-float { position: fixed; z-index: 20; opacity: .82; box-shadow: 0 5px 9px #26334650; }
.actions { display: grid; grid-template-columns: 1.12fr 1fr; gap: 8px; margin-top: 12px; }
.check-slot > button { width: 100%; }
.draw-button { background: #e5edf7; color: var(--hint-ink); border-color: #c8d6e6; box-shadow: var(--control-shadow); }
.has-hint .draw-button:not(.danger) { background: #f4f7fa; color: #536578; border-color: var(--line); }
.draw-button.danger { color: var(--error); background: #f9eae6; border-color: #e4c7c1; }
.draw-button:disabled { opacity: .66; }
.result-banner { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #eaf0ef; padding: 0 8px; border-radius: 10px; font-size: 12px; }

.welcome { padding-top: clamp(18px,8dvh,74px); }
.welcome-brand { display: grid; justify-items: center; text-align: center; gap: 10px; margin-bottom: 24px; }
.welcome-brand .brand-mark { width: 70px; height: 70px; border: 1px solid var(--line); border-radius: 19px; box-shadow: var(--control-shadow); background: #eff3f7; }
.welcome-brand h1 { font-size: clamp(29px,9vw,38px); letter-spacing: .025em; line-height: 1.2; font-weight: 900; }
.welcome-brand p { font-size: 14px; color: var(--muted); line-height: 1.55; }
.welcome-controls { display: grid; gap: 12px; padding: 16px; border-radius: 20px; background: #fcfcfa; border: 1px solid var(--line); box-shadow: 0 8px 27px #40577010; }
.welcome-controls h2 { font-size: 16px; }
.welcome-controls .primary { min-height: 49px; }
.mode-choices { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 7px; }
.mode-choice { display: grid; justify-items: center; gap: 3px; padding: 7px 3px; white-space: nowrap; font-size: 12px; box-shadow: none; }
.mode-choice[aria-pressed="true"] { border-color: var(--hint); background: #edf3fa; box-shadow: inset 0 0 0 1px var(--hint); }
.rules-list { padding-left: 20px; font-size: 14px; line-height: 1.65; }
.rules-list li { margin-bottom: 9px; }
.formula { white-space: nowrap; font-weight: 650; }
.fine { font-size: 12px; color: var(--muted); line-height: 1.7; margin: 12px 0 18px; }
.config-error { white-space: pre-line; color: var(--error); font-size: 12px; }
.launch-link { display: flex; align-items: center; justify-content: center; min-height: 48px; border-radius: 12px; text-decoration: none; font-weight: 650; }
.loading { margin-top: 42px; text-align: center; font-size: 14px; color: var(--muted); }

dialog { width: min(390px,calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 20px; overflow: auto; border: 1px solid var(--line); border-radius: 20px; background: var(--paper); color: var(--ink); box-shadow: 0 16px 55px #243c5544; }
dialog::backdrop { background: #22395268; }
dialog h2 { font-size: 21px; line-height: 1.36; margin: 0 0 12px; }
dialog > p { font-size: 14px; line-height: 1.6; }
.dialog-actions { display: flex; gap: 8px; margin-top: 17px; }
.dialog-actions button { flex: 1; }
.result-heading { display: flex; align-items: center; gap: 5px; margin-bottom: 4px; }
.result-heading h2 { margin: 0; }
.result-heading.won { color: var(--success); }
.summary-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 6px; margin: 16px 0; }
.summary-stats span { font-size: 11px; text-align: center; padding: 8px 2px; border-radius: 9px; background: #edf1f5; }
.summary-stats strong { display: block; font-size: 23px; }

@media (min-width: 360px) {
  :root { --cell-size: 52px; --square-hand-size: 66px; }
  .stats { gap: 7px; }
  .stats > div { padding: 7px 11px; }
  .stats strong { font-size: 22px; }
  .goal { font-size: 12px; }
}
@media (max-width: 359px) {
  #app.playing-layout { padding-block: max(10px,env(safe-area-inset-top)) max(10px,env(safe-area-inset-bottom)); gap: 8px; }
  .topbar { min-height: 44px; padding-bottom: 2px; }
  .game-meta { gap: 2px; }
  .goal { font-size: 10px; letter-spacing: -.03em; }
  .stats > div { padding-inline: 4px; }
  .hand-grid { gap: 6px; }
  .hand-slot { height: 72px; }
  .actions { margin-top: 8px; }
}
@media (orientation: landscape) and (min-width: 570px) and (max-height: 600px) {
  #app.playing-layout { max-width: 1000px; min-height: 352px; padding-top: max(6px,env(safe-area-inset-top)); padding-bottom: max(6px,env(safe-area-inset-bottom)); grid-template-columns: minmax(220px,1fr) minmax(275px,352px); grid-template-rows: 46px minmax(0,1fr); gap: 8px 16px; }
  #app.playing-layout:has(.polygon-viewport[data-mode]) { grid-template-rows: 46px minmax(0,1fr); }
  .game-header { grid-column: 1 / -1; grid-row: 1; grid-template-columns: auto minmax(0,352px); align-items: center; justify-content: space-between; gap: 9px; }
  .topbar { min-height: 44px; border: 0; padding: 0; }
  .wordmark { font-size: 23px; }
  .table-area { grid-row: 2; grid-column: 1; }
  .play-controls { grid-row: 2; grid-column: 2; align-self: center; }
  .actions { margin-top: 8px; }
  .hand-slot { height: 71px; }
}
@media (orientation: landscape) and (max-width: 680px) and (min-width: 570px) and (max-height: 600px) {
  :root { --cell-size: 44px; --square-hand-size: 60px; }
  .goal { display: none; }
}
@media (min-width: 720px) and (min-height: 680px) {
  :root { background: #edf0ed; }
  #app { background: var(--paper); border-inline: 1px solid #dce2dd; }
  #app.playing-layout { height: min(100dvh, 900px); }
}
@media (prefers-reduced-motion: no-preference) {
  .hand-slot:not(.drag-source) .hand-domino { animation: card-settle 125ms ease-out; }
  @keyframes card-settle { from { opacity: .72; } to { opacity: 1; } }
}
