:root {
  --bg: #f6f7fb;
  --green: #18b553;
  --amber: #ffb54c;
  --header: #e8dfd1;
  --text: #1a1a1a;
  --muted: #999;
  --card: #fff;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.num-editor-input {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

html, body {
  margin: 0;
  padding: 0;
  background: #e9edf3;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

button, .ghost, .actions, .quota-bar, .match-toggle, .swipe-hint, .tabbar {
  touch-action: manipulation;
}

button, input { font-family: inherit; }

.app {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  padding-bottom: calc(72px + var(--safe-b));
  position: relative;
}

.banner {
  width: 100%;
  display: block;
  max-height: 160px;
  object-fit: cover;
  background: #ddd;
}

.view { display: none; padding: 12px; }
.view.active { display: block; }

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.04);
}

.card + .card { margin-top: 12px; }

.grid {
  display: grid;
  grid-template-columns: 68px repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.num-cell {
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.06);
  text-align: center;
  font-weight: 800;
  font-size: 18px;
  padding: 8px 4px;
  color: #161616;
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

.num-cell::placeholder { color: #c8c8c8; font-weight: 700; }

.sum-lock {
  min-height: 48px;
  border-radius: 12px;
  background: #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  color: #161616;
}

.sum-lock.is-zero { color: #c8c8c8; font-weight: 700; }

.auto-tag {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  line-height: 1;
  font-weight: 700;
  color: #128a3e;
}

.row-label {
  background: var(--header);
  color: #000;
  border-radius: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  min-height: 48px;
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
  padding: 4px 2px;
}

.player-label {
  font-weight: 400;
}

.auth-input {
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
  border: 1px solid #e6e6e6;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 16px;
  text-align: left;
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

#account-guest .auth-input {
  min-height: 30px;
  margin-top: 6px;
  padding: 4px 12px;
  border-radius: 8px;
}

#account-guest .name-actions {
  margin-top: 10px;
}

#account-guest .auth-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

#account-guest .auth-row .primary,
#account-guest .auth-row .ghost {
  flex: 0 0 auto;
  padding: 6px 16px;
}

#account-guest .auth-row .linkish {
  display: inline;
  margin: 0;
  padding: 6px 2px;
  white-space: nowrap;
}

#account-guest .auth-code {
  width: 76px;
  min-width: 76px;
  max-width: 76px;
  min-height: 30px;
  margin: 0 0 0 auto;
  padding: 4px 8px;
  border: 1px solid #e6e6e6;
  border-radius: 8px;
  font-size: 13px;
  text-align: left;
  -webkit-user-select: text;
  user-select: text;
}

.linkish {
  display: block;
  margin: 10px auto 0;
  background: none;
  border: none;
  color: #888;
  font-size: 13px;
  font-weight: 500;
  padding: 4px;
}

.name-setup { margin-top: 0; }
.name-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}
.name-list input {
  flex: 0 0 calc((100% - 32px) / 5);
  width: calc((100% - 32px) / 5);
  min-width: calc((100% - 32px) / 5);
  max-width: none;
  min-height: 44px;
  border: 1px solid #e6e6e6;
  border-radius: 10px;
  background: #fff;
  text-align: center;
  font-weight: 400;
  font-size: 15px;
  padding: 8px 4px;
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

.match-toggle {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  color: #666;
  font-size: 12px;
  line-height: 1.45;
  font-weight: 500;
}

.match-toggle input {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  padding: 0;
  flex: 0 0 auto;
  accent-color: var(--green);
}

.header {
  background: var(--header);
  color: #000;
  border-radius: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  height: auto;
  min-height: 36px;
  font-size: 12px;
  line-height: 1.25;
  text-align: center;
  padding: 4px 2px;
}

.cell, .wind {
  width: 100%;
  min-height: 44px;
  border-radius: 10px;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
}

.cell {
  border: none;
  background: #fff;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.06);
  padding: 8px 4px;
  color: #000;
}

.wind {
  border: 2px solid var(--green);
  background: #fff;
  color: #000;
  padding: 0;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.grid, .header, .row-label, .players-grid, .p-name, .p-hint, .swipe-hint {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.wind.active { background: var(--green); color: #fff; }
.reset-btn { border-color: var(--amber); font-size: 14px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  margin-bottom: 12px;
}

.seat-btn {
  flex: 1 1 0;
  min-width: 0;
  height: 52px;
  min-height: 52px;
  max-height: 52px;
  padding: 8px 4px;
  border: none;
  border-radius: 12px;
  background: var(--green);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}

.price-col {
  display: flex;
  flex: 0 0 84px;
  align-items: center;
}

#btn-last-hand {
  background: #fff;
  color: #1a1a1a;
  font-weight: 400;
  border: 1px solid #e6e6e6;
}

.seat-players {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.seat-chip {
  min-height: 36px;
  max-width: 100%;
  padding: 6px 12px;
  border: none;
  border-radius: 12px;
  background: var(--green);
  color: #fff;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.2;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: grab;
}

.seat-chip i {
  margin-left: 6px;
  font-style: normal;
  font-size: 12px;
  font-weight: 400;
  color: #fff;
}

.seat-chip.is-seated {
  box-shadow: inset 0 0 0 2px #fff;
}

#seat-modal .modal {
  padding-left: 22px;
  padding-right: 22px;
  overflow-x: hidden;
}

.seat-board {
  display: grid;
  width: 100%;
  box-sizing: border-box;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas:
    ". north ."
    "west table east"
    ". south .";
  gap: 18px 12px;
  margin: 22px 0 8px;
  justify-items: center;
  align-items: center;
  touch-action: none;
}

.seat-slot {
  position: relative;
  width: 100%;
  max-width: 108px;
  min-width: 0;
  box-sizing: border-box;
  min-height: 84px;
  padding: 8px 6px;
  border: 1.5px solid #d0d0d0;
  border-radius: 12px;
  background: #d0d0d0;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
}

.seat-dir {
  position: absolute;
  top: 5px;
  left: 6px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1;
  color: #fff;
  text-align: left;
}

.seat-dir b {
  margin-left: 2px;
  font-weight: 400;
}

.seat-who {
  width: 100%;
  max-width: 96px;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.2;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-slot[data-wind="N"] { grid-area: north; }
.seat-slot[data-wind="W"] { grid-area: west; }
.seat-slot[data-wind="E"] { grid-area: east; }
.seat-slot[data-wind="S"] { grid-area: south; }

.seat-slot.is-filled {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.seat-slot.is-snap {
  transform: scale(1.04);
  border-style: solid;
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.85);
}

.seat-slot.is-picking {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9);
}

.seat-table {
  grid-area: table;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: #e8f8ee;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.seat-picker {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #f0f0f0;
}

.seat-picker-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

.seat-picker-list button {
  min-height: 36px;
  border: none;
  border-radius: 12px;
  background: var(--green);
  color: #fff;
  padding: 6px 12px;
  font-size: 16px;
  font-weight: 400;
  text-align: center;
  cursor: pointer;
}

#btn-seat-close {
  background: #ffd84a;
  color: #3a2a00;
}

#seat-modal .modal-actions {
  justify-content: space-between;
  align-items: center;
}

.auto-rotate {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 400;
}

.auto-rotate input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.seat-ghost {
  position: fixed;
  z-index: 90;
  transform: translate(-50%, -60%);
  pointer-events: none;
  background: var(--green);
  color: #fff;
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 16px;
  font-weight: 400;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.16);
}

.price-sub {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  font-weight: 500;
  position: relative;
  z-index: 1;
}

.primary, .ghost, .secondary, .nav-btn, .mini {
  border: none;
  cursor: pointer;
}

.primary {
  background: var(--green);
  color: #fff;
  border-radius: 12px;
  padding: 8px 22px;
  font-weight: 700;
}

#btn-compute {
  flex: 0 0 76px;
  width: 76px;
  min-width: 76px;
  height: 52px;
  min-height: 52px;
  max-height: 52px;
  margin-left: 8px;
  padding: 6px 2px 5px;
  gap: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  align-self: center;
}

.btn-title { display: block; font-size: 16px; line-height: 1.1; white-space: nowrap; }
.btn-sub { display: block; font-size: 10px; line-height: 1.1; opacity: 0.9; font-weight: 500; white-space: nowrap; }

.secondary {
  background: var(--amber);
  color: #000;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
}

.ghost {
  flex: 1;
  background: #fff;
  color: #000;
  border-radius: 12px;
  padding: 10px 8px;
  border: 1px solid #ddd;
  font-weight: 600;
}

.actions, .actions2, .modal-actions {
  display: flex;
  gap: 8px;
}

.actions { margin-top: 10px; }
.actions2 { margin-top: 8px; }
.actions2 button {
  flex: 1;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 10px;
  font-weight: 600;
}

.players-grid {
  display: grid;
  grid-template-columns: 64px repeat(4, 1fr);
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}

.p-hint { color: var(--muted); font-size: 12px; text-align: center; }
.p-name { font-weight: 700; text-align: center; font-size: 13px; word-break: break-all; }

.section-title { font-weight: 700; margin: 4px 0 8px; }

.note { color: var(--muted); font-size: 12px; margin-top: 8px; line-height: 1.5; }

.row-item { padding: 10px 0; border-bottom: 1px solid #eee; }
.meta { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.wl-line { font-size: 14px; line-height: 1.5; }
.score-line { font-size: 14px; }
.pos { color: #128a3e; }
.neg { color: #d4380d; }

.mini {
  margin-top: 8px;
  background: #f3f4f6;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}

.full {
  width: 100%;
  margin-top: 10px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 12px;
  font-weight: 600;
}

.primary.full {
  background: var(--green);
  color: #fff;
  border: none;
}

.empty { color: var(--muted); text-align: center; padding: 28px 0; }

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 480px;
  display: flex;
  background: #fff;
  border-top: 1px solid #eee;
  padding-bottom: var(--safe-b);
  z-index: 30;
}

.tabbar button {
  flex: 1;
  background: transparent;
  border: none;
  padding: 10px 0 8px;
  font-size: 13px;
  color: #888;
  font-weight: 600;
}

.tabbar button.active { color: var(--green); }

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal-mask.show { display: flex; }

.modal {
  background: #fff;
  width: 100%;
  max-width: 400px;
  border-radius: 16px;
  padding: 16px;
  max-height: 80vh;
  overflow: auto;
}

.modal-actions { justify-content: flex-end; margin-top: 14px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-b));
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  z-index: 80;
  display: none;
  max-width: 80%;
  text-align: center;
}

.toast.show { display: block; }

.swipe-hint {
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.stepper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.06);
  overflow: hidden;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: ew-resize;
  --nudge: 0px;
}

.stepper-shift {
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateX(var(--nudge));
  transition: transform 0.22s cubic-bezier(0.22, 0.9, 0.28, 1);
  z-index: 1;
}

.stepper.is-dragging .stepper-shift { transition: none; }
.stepper.is-armed .stepper-num { animation: hold-ready 0.22s ease; }

@keyframes hold-ready {
  0% { transform: scale(1); }
  45% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.stepper-num {
  font-weight: 800;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  color: #161616;
  line-height: 1;
}

.stepper[data-value="0"] .stepper-num {
  color: #c8c8c8;
  font-weight: 700;
}

.stepper-chev {
  position: absolute;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-top: -4px;
  border-right: 1.5px solid #d5d5d5;
  border-bottom: 1.5px solid #d5d5d5;
  transition: border-color 0.2s ease, opacity 0.2s ease;
  opacity: 0.85;
  z-index: 1;
}

.stepper-chev.left { left: 7px; transform: rotate(135deg); }
.stepper-chev.right { right: 7px; transform: rotate(-45deg); }

.stepper-num.tick-inc { animation: num-inc 0.32s cubic-bezier(0.16, 0.84, 0.3, 1); }
.stepper-num.tick-dec { animation: num-dec 0.32s cubic-bezier(0.16, 0.84, 0.3, 1); }

.price-stepper {
  width: 84px;
  height: 52px;
  min-height: 52px;
  max-height: 52px;
  flex-direction: column;
  gap: 1px;
  padding: 6px 8px 5px;
}

@keyframes num-inc {
  0% { transform: translateX(-8px) scale(0.78); opacity: 0.15; }
  58% { transform: translateX(1px) scale(1.14); opacity: 1; }
  100% { transform: none; }
}

@keyframes num-dec {
  0% { transform: translateX(8px) scale(0.78); opacity: 0.15; }
  58% { transform: translateX(-1px) scale(1.14); opacity: 1; }
  100% { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .stepper-num.tick-inc,
  .stepper-num.tick-dec,
  .stepper.is-armed .stepper-num,
  .stepper-shift {
    animation: none;
    transition: none;
  }
}

.quota-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}
.quota-bar .ghost { flex: 0 0 auto; min-width: 88px; }
.quota { font-size: 28px; font-weight: 700; color: var(--green); margin-bottom: 8px; }
.tier {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid #eee;
}
.tier-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tier-hint { color: #e0a000; font-size: 12px; line-height: 1.4; font-weight: 600; }
.wechat-id { margin-top: 2px; font-size: 16px; font-weight: 800; letter-spacing: 0.4px; }
.wechat-qr { display: block; width: 100%; height: auto; margin-top: 8px; border-radius: 8px; }
.buy {
  background: var(--amber);
  color: #000;
  border: none;
  border-radius: 12px;
  padding: 8px 12px;
  font-weight: 700;
  white-space: nowrap;
}
.test-hint {
  margin: 8px 4px 0;
  color: #8a5a00;
  font-size: 12px;
  line-height: 1.5;
}
.num-editor-input {
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  background: #f6f7fb;
  text-align: center;
  font-size: 22px;
  font-weight: 800;
}
