/* ============================================================
 * 建德麻将 · 原创界面样式
 * 全部原创：深绿牌桌 + 暖木边框 + CSS 绘制牌面，无任何第三方素材。
 * ============================================================ */
:root {
  --felt: #0f6b4f;
  --felt-dark: #094a37;
  --felt-edge: #073726;
  --wood: #6b4423;
  --wood-light: #8b5e34;
  --gold: #f2c14e;
  --ink: #1c2b24;
  --paper: #f7f3e8;
  --red: #c62828;
  --green: #2e7d32;
  --blue: #1565c0;
  --shadow: 0 6px 16px rgba(0, 0, 0, .35);
  --tile-w: 44px;
  --tile-h: 60px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: radial-gradient(circle at 50% 40%, #145c46, #072d22 90%);
  color: #fff; overflow: hidden; user-select: none;
}
button { font-family: inherit; cursor: pointer; }

#app { height: 100%; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  flex: 0 0 auto; height: 56px; display: flex; align-items: center;
  gap: 16px; padding: 0 18px;
  background: linear-gradient(180deg, rgba(0,0,0,.35), rgba(0,0,0,.08));
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { font-size: 26px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.4)); }
.title { font-size: 17px; font-weight: 700; white-space: nowrap; }
.title small { font-size: 11px; font-weight: 400; opacity: .7; margin-left: 6px; }
.topinfo { display: flex; gap: 8px; margin-left: auto; }
.chip {
  background: rgba(0,0,0,.28); border: 1px solid rgba(255,255,255,.12);
  padding: 5px 11px; border-radius: 20px; font-size: 12px; white-space: nowrap;
}
.chip b { color: var(--gold); font-size: 14px; }
.chip.joker { color: #ffe082; border-color: rgba(242,193,78,.4); }
.topbtns { display: flex; gap: 8px; }

.btn {
  border: none; border-radius: 8px; padding: 8px 14px; font-size: 13px;
  font-weight: 600; color: #fff; transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.95); }
.btn.ghost { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); }
.btn.ghost:hover { background: rgba(255,255,255,.2); }
.btn.primary { background: linear-gradient(180deg, #f5cf5c, #e0a92c); color: #4a3200; }
.btn.call { background: linear-gradient(180deg, #ff7a6e, #d84338); box-shadow: var(--shadow); }
.btn.call.win { background: linear-gradient(180deg, #ffd86e, #f0a500); color: #4a3200; font-size: 16px; }

/* ---------------- 牌桌 ---------------- */
.table {
  flex: 1 1 auto; position: relative; min-height: 0;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(255,255,255,.06), transparent 60%),
    var(--felt);
  border: 14px solid var(--wood);
  border-image: linear-gradient(135deg, var(--wood-light), var(--wood)) 1;
  box-shadow: inset 0 0 80px rgba(0,0,0,.4);
}

.seat { position: absolute; display: flex; align-items: center; gap: 8px; }
.seat-top { top: 10px; left: 50%; transform: translateX(-50%); flex-direction: column; }
.seat-bottom {
  bottom: 8px; left: 50%; transform: translateX(-50%);
  flex-direction: column; gap: 6px; width: 100%;
}
.seat-left { left: 10px; top: 50%; transform: translateY(-50%); flex-direction: column; }
.seat-right { right: 10px; top: 50%; transform: translateY(-50%); flex-direction: column; }

.seat-label { display: flex; align-items: center; gap: 6px; font-size: 12px; opacity: .9; }
.avatar {
  display: inline-flex; width: 26px; height: 26px; border-radius: 50%;
  align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
  background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.25);
}
.avatar.me { background: var(--gold); color: #4a3200; border-color: #fff3c4; }
.my-label { display: flex; align-items: center; gap: 8px; font-size: 12px; opacity: .85; }
.hint { opacity: .7; font-size: 11px; }

/* 对手背牌 */
.hand-back { display: flex; gap: 2px; }
.hand-back .tile-back {
  width: 20px; height: 30px; border-radius: 3px;
  background: linear-gradient(135deg, #1b7a86, #0e515c);
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 1px 2px rgba(0,0,0,.4), inset 0 0 0 2px rgba(255,255,255,.07);
}
.hand-back.vert { flex-direction: column; }
.hand-back.vert .tile-back { width: 30px; height: 18px; }

/* 副露 */
.melds { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; max-width: 60vw; }
.meld { display: flex; gap: 1px; padding: 2px; background: rgba(0,0,0,.22); border-radius: 5px; }
.meld .tile { width: 26px; height: 36px; font-size: 13px; }

/* ---------------- 中央 ---------------- */
.center {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(460px, 74vw); height: min(360px, 58vh);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.river-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 4px; width: 100%; height: 100%;
  background: rgba(0,0,0,.08); border-radius: 12px; padding: 8px;
}
.river { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 2px; padding: 3px; }
.river-2 { grid-column: 2; grid-row: 1; justify-content: center; }
.river-3 { grid-column: 1; grid-row: 2; justify-content: center; }
.river-1 { grid-column: 3; grid-row: 2; justify-content: center; }
.river-0 { grid-column: 2; grid-row: 2; justify-content: center; }
.river .tile { width: 26px; height: 36px; font-size: 13px; opacity: .95; }
.river .tile.fresh { box-shadow: 0 0 0 2px var(--gold), var(--shadow); }

.status {
  position: absolute; top: -28px; left: 50%; transform: translateX(-50%);
  white-space: nowrap; font-size: 13px; color: #e9f5ee;
  background: rgba(0,0,0,.3); padding: 4px 12px; border-radius: 14px;
}

/* 吃碰杠胡决策窗 */
.call-panel[hidden] { display: none; }
.call-panel {
  position: absolute; bottom: -8px; left: 50%; transform: translate(-50%, 100%);
  display: flex; gap: 8px; padding: 10px 14px; border-radius: 12px;
  background: rgba(8, 30, 22, .94); border: 1px solid rgba(242,193,78,.35);
  box-shadow: var(--shadow); z-index: 20; white-space: nowrap;
}

/* ---------------- 手牌 ---------------- */
.me-area {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; z-index: 6;
}
.me-area .melds { max-width: 92vw; }
.myhand { display: flex; gap: 3px; justify-content: center; flex-wrap: nowrap; max-width: 96vw; }
.tile {
  position: relative; flex: 0 0 auto;
  width: var(--tile-w); height: var(--tile-h);
  background: linear-gradient(180deg, #fffdf7, #efe9d8);
  border: 1px solid #cfc6ac; border-radius: 5px;
  box-shadow: 0 3px 0 #b9ae90, var(--shadow);
  color: var(--ink); font-weight: 700;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1; user-select: none;
}
.tile .num { font-size: 19px; }
.tile .suit { font-size: 12px; margin-top: 3px; opacity: .85; }
.tile .honor { font-size: 22px; }
.tile.wan .num, .tile.wan .suit { color: var(--red); }
.tile.tong .num, .tile.tong .suit { color: var(--blue); }
.tile.tiao .num, .tile.tiao .suit { color: var(--green); }
.tile.honor-z .honor { color: var(--ink); }
.tile.zhong .honor { color: var(--red); }
.tile.fa .honor { color: var(--green); }
.tile.joker {
  background: linear-gradient(180deg, #fff6cf, #f3d36b);
  border-color: var(--gold); box-shadow: 0 3px 0 #c99a1f, 0 0 12px rgba(242,193,78,.5);
}
.tile.joker .honor { color: #a06a00; }
.tile.joker::after {
  content: "财"; position: absolute; top: 2px; right: 3px;
  font-size: 9px; color: #a06a00; opacity: .7;
}
.myhand .tile { cursor: pointer; transition: transform .1s, box-shadow .1s; }
.myhand .tile:hover { transform: translateY(-8px); box-shadow: 0 8px 0 #b9ae90, var(--shadow); }
.myhand .tile.drawn { margin-left: 12px; }
.myhand .tile.selected { transform: translateY(-12px); box-shadow: 0 0 0 2px var(--gold), var(--shadow); }
.myhand .tile:disabled { cursor: default; opacity: .55; }
.tile.dim { opacity: .4; }

/* ---------------- 日志 ---------------- */
.logbar {
  flex: 0 0 auto; height: 26px; display: flex; align-items: center;
  padding: 0 16px; font-size: 11px; color: rgba(255,255,255,.65);
  background: rgba(0,0,0,.25); overflow: hidden; white-space: nowrap;
}

/* ---------------- 弹窗 ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.72); display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(440px, 92vw); max-height: 88vh; overflow-y: auto;
  background: linear-gradient(180deg, #123c2e, #0a2a20);
  border: 2px solid var(--gold); border-radius: 18px; padding: 26px;
  text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.result-emoji { font-size: 52px; }
.modal-card h2 { font-size: 24px; margin: 8px 0 14px; color: var(--gold); }
.result-fan { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
.result-hand { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; margin-bottom: 12px; }
.result-hand .tile { width: 34px; height: 46px; font-size: 12px; }
.result-hand .tile .num { font-size: 15px; }
.result-note { font-size: 12px; opacity: .75; line-height: 1.6; margin-bottom: 18px; }
.help-card { text-align: left; }
.help-card h2 { text-align: center; }
.help-card ul { list-style: none; line-height: 1.9; font-size: 13px; }
.help-card li { padding-left: 16px; position: relative; }
.help-card li::before { content: "•"; position: absolute; left: 2px; color: var(--gold); }
.help-card li b { color: var(--gold); }
.selfmade { font-size: 11px; opacity: .6; line-height: 1.6; margin: 12px 0 18px; }
.help-card .btn { display: block; margin: 0 auto; }

/* ---------------- 教练/采集状态 ---------------- */
.coachbar {
  flex: 0 0 auto; height: 34px; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; font-size: 12px;
  background: rgba(0,0,0,.22); border-bottom: 1px solid rgba(255,255,255,.06);
}
.mode-toggle { display: flex; align-items: center; gap: 6px; white-space: nowrap; cursor: pointer; }
.mode-toggle input { accent-color: var(--gold); }
.coach-text { opacity: .82; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- 座位动态位置 ---------------- */
.seat.pos-me { display: none; }
.seat.pos-top { top: 10px; left: 50%; transform: translateX(-50%); flex-direction: column; }
.seat.pos-bottom { bottom: 8px; left: 50%; transform: translateX(-50%); flex-direction: column; gap: 6px; width: 100%; }
.seat.pos-left { left: 10px; top: 50%; transform: translateY(-50%); flex-direction: column; }
.seat.pos-right { right: 10px; top: 50%; transform: translateY(-50%); flex-direction: column; }
.seat.active .avatar { background: var(--gold); color: #4a3200; border-color: #fff3c4; }
.badge {
  font-size: 10px; padding: 2px 6px; border-radius: 10px;
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.16);
}
.seat.is-human .badge { color: #ffe082; border-color: rgba(242,193,78,.5); }

/* ---------------- 设置弹窗 ---------------- */
.setup-card { width: min(560px, 94vw); text-align: left; }
.setup-card h2, .handover-card h2 { text-align: center; }
.setup-tip { font-size: 12px; opacity: .72; line-height: 1.6; margin: 8px 0 14px; text-align: center; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 16px; }
.preset { padding: 6px 10px; font-size: 12px; }
.seat-setup { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seat-setting {
  display: grid; grid-template-columns: 54px 1fr 1fr; align-items: center; gap: 6px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px; padding: 8px;
}
.seat-setting b { color: var(--gold); font-size: 13px; }
.seat-setting input, .seat-setting select, .setup-row select {
  width: 100%; min-width: 0; border: 1px solid rgba(255,255,255,.22);
  border-radius: 6px; padding: 6px; background: #0d3327; color: #fff; font-size: 12px;
}
.setup-row { display: flex; gap: 16px; margin: 14px 0 18px; }
.setup-row label { flex: 1; font-size: 12px; opacity: .9; }
.modal-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.handover-card { width: min(400px, 92vw); }
.handover { background: rgba(0,0,0,.9); }
.correction-card { width: min(520px, 94vw); text-align: left; }
.correction-card h2 { text-align: center; }
.corr-line {
  font-size: 13px; line-height: 1.6; padding: 8px 10px; margin-bottom: 8px;
  background: rgba(255,255,255,.06); border-radius: 8px;
}
.corr-label { display: block; font-size: 12px; opacity: .9; margin: 12px 0 6px; }
.corr-label select, .corr-label input {
  width: 100%; margin-top: 5px; border: 1px solid rgba(255,255,255,.22);
  border-radius: 6px; padding: 8px; background: #0d3327; color: #fff; font-size: 13px;
}
.corr-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.corr-tag { padding: 5px 9px; font-size: 11px; }
.corr-tag.active { background: linear-gradient(180deg, #f5cf5c, #e0a92c); color: #4a3200; }

/* ---------------- 响应式：平板 / 窄屏笔记本 ---------------- */
@media (max-width: 900px) {
  .topbar {
    height: auto; min-height: 52px; flex-wrap: wrap;
    gap: 6px 10px; padding: 6px 10px;
  }
  .brand { flex: 1 1 auto; }
  .title { font-size: 15px; }
  .topinfo { margin-left: auto; min-width: 0; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
  .topinfo::-webkit-scrollbar { display: none; }
  .topbtns { flex: 0 0 auto; overflow-x: auto; scrollbar-width: none; }
  .topbtns::-webkit-scrollbar { display: none; }
  .btn { padding: 7px 12px; font-size: 12px; white-space: nowrap; }
  .coachbar { height: auto; min-height: 30px; flex-wrap: wrap; gap: 4px 10px; padding: 4px 10px; }
  .coach-text { white-space: normal; line-height: 1.4; font-size: 11px; }
  .table { border-width: 8px; }
  :root { --tile-w: 38px; --tile-h: 52px; }
  .myhand { gap: 2px; }
}

/* ---------------- 响应式：手机竖屏 ---------------- */
@media (max-width: 600px) {
  .topbar { min-height: 0; padding: 5px 8px; gap: 4px 6px; }
  .brand { flex: 0 0 auto; gap: 6px; }
  .logo { font-size: 20px; }
  .title { font-size: 14px; }
  .title small { display: none; }
  .topinfo {
    order: 1; flex: 1 1 0; min-width: 0;
    margin-left: 6px; gap: 4px; overflow-x: auto;
  }
  .topbtns { order: 2; width: 100%; gap: 5px; padding-bottom: 1px; }
  .chip { padding: 3px 8px; font-size: 10px; }
  .chip b { font-size: 12px; }
  .btn { padding: 6px 10px; font-size: 11px; border-radius: 7px; }
  .coachbar { padding: 4px 8px; gap: 3px 8px; font-size: 10px; }
  .mode-toggle { font-size: 11px; }
  .coach-text {
    font-size: 10px; line-height: 1.35;
    display: -webkit-box; -webkit-box-orient: vertical;
    -webkit-line-clamp: 2; overflow: hidden;
  }
  .logbar, .rule-tip { display: none; }
  .table { border-width: 5px; }

  :root { --tile-w: 32px; --tile-h: 44px; }
  .tile .num { font-size: 15px; }
  .tile .suit { font-size: 10px; }
  .tile .honor { font-size: 18px; }
  .myhand {
    flex-wrap: wrap; column-gap: 2px; row-gap: 5px;
    max-width: 100%; padding: 0 4px; justify-content: center;
  }
  .myhand .tile.drawn { margin-left: 6px; }
  .myhand .tile:hover { transform: none; }
  .myhand .tile.selected { transform: translateY(-6px); }
  .me-area { bottom: 4px; gap: 4px; }
  .me-area .melds { max-width: 100%; gap: 3px; }
  .meld .tile { width: 20px; height: 28px; font-size: 10px; }
  .my-label { font-size: 10px; gap: 5px; }
  .hint { font-size: 10px; }

  .center { width: min(84vw, 340px); height: min(40vh, 300px); top: 43%; }
  .river-grid { gap: 2px; padding: 4px; }
  .river { gap: 1px; padding: 2px; }
  .river .tile { width: 17px; height: 24px; font-size: 9px; }
  .status {
    top: -22px; font-size: 10px; padding: 3px 8px;
    max-width: 86vw; overflow: hidden; text-overflow: ellipsis;
  }

  .seat.pos-top { top: 4px; gap: 3px; }
  .seat.pos-left { left: 2px; }
  .seat.pos-right { right: 2px; }
  .seat-label { font-size: 9px; gap: 3px; }
  .avatar { width: 20px; height: 20px; font-size: 11px; }
  .badge { font-size: 8px; padding: 1px 4px; }
  .seat.pos-left .seat-label, .seat.pos-right .seat-label { flex-direction: column; gap: 2px; }
  .seat.pos-left .who, .seat.pos-right .who { display: none; }
  .hand-back { gap: 1px; }
  .hand-back .tile-back { width: 11px; height: 17px; }
  .hand-back.vert .tile-back { width: 17px; height: 11px; }

  .call-panel {
    white-space: normal; flex-wrap: wrap; justify-content: center;
    left: 50%; bottom: 24px; width: min(94vw, 420px);
    padding: 8px; gap: 6px;
  }
  .btn.call { padding: 9px 12px; font-size: 13px; }

  .modal { padding: 8px; }
  .modal-card { width: 96vw; max-height: 92dvh; padding: 16px; border-radius: 14px; }
  .modal-card h2 { font-size: 19px; }
  .result-emoji { font-size: 40px; }
  .result-fan { font-size: 15px; }
  .help-card ul { font-size: 12px; line-height: 1.75; }
  .setup-card, .correction-card { width: 96vw; }
  .seat-setup { grid-template-columns: 1fr; }
  .seat-setting { grid-template-columns: 44px 1fr 1fr; padding: 6px; }
  .setup-row { flex-direction: column; gap: 8px; }
  .presets .preset { flex: 1 1 45%; }
  .corr-label select, .corr-label input,
  .seat-setting input, .seat-setting select, .setup-row select { font-size: 16px; }
  .modal-btns .btn { flex: 1 1 auto; }
}

/* ---------------- 响应式：手机横屏 ---------------- */
@media (max-height: 520px) and (orientation: landscape) {
  .topbar { min-height: 42px; padding: 4px 10px; flex-wrap: nowrap; }
  .title { font-size: 14px; }
  .title small { display: none; }
  .topinfo { order: 0; flex: 0 1 auto; margin-left: auto; }
  .topbtns { order: 1; width: auto; }
  .coachbar, .logbar, .rule-tip { display: none; }
  .table { border-width: 5px; }
  .btn { padding: 5px 9px; font-size: 11px; }
  .topbtns { gap: 4px; }
  :root { --tile-w: 28px; --tile-h: 38px; }
  .tile .num { font-size: 14px; }
  .tile .honor { font-size: 16px; }
  .myhand { flex-wrap: nowrap; }
  .me-area { bottom: 2px; gap: 2px; }
  .center { width: min(52vw, 420px); height: 50%; top: 46%; }
  .status { display: none; }
  .call-panel {
    top: 24px; bottom: auto; left: 50%; transform: translateX(-50%);
    width: auto; max-width: 80vw; padding: 6px 8px; white-space: nowrap;
  }
  .seat.pos-top { top: 2px; }
  .seat.pos-left, .seat.pos-right { top: 47%; }
  .hand-back .tile-back { width: 10px; height: 15px; }
  .hand-back.vert .tile-back { width: 15px; height: 10px; }
}
