/* 大话骰 H5 · 酒桌绿呢 + 暖金，手机优先 */
:root {
  --felt-1: #0c3327;
  --felt-2: #08261d;
  --felt-3: #14503c;
  --gold: #e2b55c;
  --gold-soft: #f4d99a;
  --cream: #f7efdd;
  --muted: #9db9a9;
  --red: #e15b52;
  --green: #4fc48a;
  --panel: rgba(6, 30, 22, .72);
  --panel-2: rgba(9, 41, 30, .92);
  --line: rgba(226, 181, 92, .22);
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --app-max: 560px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--cream);
  background: radial-gradient(ellipse at 50% 0%, #11513b 0%, var(--felt-1) 42%, var(--felt-2) 100%);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
.felt-grain {
  position: fixed; inset: 0; pointer-events: none; opacity: .16; z-index: 0;
  background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.035) 0 1px, transparent 1px 3px),
                    repeating-linear-gradient(-45deg, rgba(0,0,0,.06) 0 1px, transparent 1px 3px);
}
button, input { font-family: inherit; }
button { cursor: pointer; border: none; color: inherit; }
.hidden { display: none !important; }

.screen {
  position: relative; z-index: 1;
  width: 100%; max-width: var(--app-max); height: 100%;
  margin: 0 auto; display: none;
  box-shadow: 0 0 80px rgba(0,0,0,.45);
}
.screen.active { display: flex; flex-direction: column; }

/* ------------------------------ 首屏 ------------------------------ */
.home-wrap {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  padding: 24px 22px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.brand { text-align: center; margin-bottom: 26px; }
.brand-dice { display: flex; justify-content: center; gap: 10px; margin-bottom: 16px; }
.brand-dice .die:nth-child(1) { transform: rotate(-12deg); }
.brand-dice .die:nth-child(2) { transform: rotate(10deg); }
.brand h1 {
  margin: 0; font-size: 42px; letter-spacing: 10px; font-weight: 800;
  color: var(--gold-soft);
  text-shadow: 0 2px 0 #7a5420, 0 8px 24px rgba(0,0,0,.5);
}
.brand-sub { margin: 8px 0 0; font-size: 11px; letter-spacing: 4px; color: var(--muted); }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 22px 20px; box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
.field-label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 8px 2px; letter-spacing: 1px; }
.input {
  width: 100%; height: 48px; padding: 0 14px; font-size: 16px;
  color: var(--cream); background: rgba(0,0,0,.28);
  border: 1px solid rgba(226,181,92,.28); border-radius: 12px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(226,181,92,.12); }
.input::placeholder { color: rgba(157,185,169,.55); }

.btn { display: block; width: 100%; border-radius: 13px; font-size: 16px; font-weight: 700; transition: transform .12s, filter .2s, opacity .2s; }
.btn:active { transform: scale(.975); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary {
  height: 52px; margin-top: 18px; color: #2b1c05;
  background: linear-gradient(180deg, #f6d68d, #d9a342);
  box-shadow: 0 6px 0 #8c6320, 0 12px 22px rgba(0,0,0,.3);
  letter-spacing: 2px;
}
.btn-primary:active { box-shadow: 0 3px 0 #8c6320, 0 6px 14px rgba(0,0,0,.3); }
.btn-arrow { float: right; margin-right: 4px; }
.btn-ghost {
  height: 48px; background: rgba(226,181,92,.1);
  border: 1px solid rgba(226,181,92,.42); color: var(--gold-soft);
}
.btn-subtle {
  height: 42px; margin-top: 14px; font-size: 14px; font-weight: 500;
  background: transparent; color: var(--muted); border: 1px dashed rgba(157,185,169,.3);
}
.or-line { display: flex; align-items: center; gap: 12px; margin: 20px 0 16px; color: var(--muted); font-size: 12px; }
.or-line::before, .or-line::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.join-row { display: flex; gap: 10px; }
.code-input { flex: 1; text-transform: uppercase; letter-spacing: 8px; text-align: center; font-weight: 700; font-size: 20px; }
.join-row .btn { width: 96px; flex: none; }
.home-tip { margin: 12px 2px 0; min-height: 16px; font-size: 12px; color: var(--red); line-height: 1.5; }
.home-footer { text-align: center; margin-top: 22px; font-size: 12px; color: var(--muted); }
.link-btn { background: none; color: var(--gold-soft); text-decoration: underline; font-size: 12px; padding: 4px; }
.dot-sep { margin: 0 8px; opacity: .5; }

/* ------------------------------ 房间布局 ------------------------------ */
.topbar {
  flex: none; height: 58px; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; padding-top: env(safe-area-inset-top);
  background: rgba(4, 22, 16, .55); border-bottom: 1px solid var(--line);
}
.icon-btn {
  width: 36px; height: 36px; flex: none; border-radius: 10px;
  background: rgba(255,255,255,.06); border: 1px solid var(--line);
  font-size: 20px; line-height: 1; color: var(--gold-soft);
}
.icon-btn:active { background: rgba(226,181,92,.2); }
.sound-btn.muted { color: #6c8377; text-decoration: line-through; }
.room-chip {
  display: flex; align-items: baseline; gap: 8px; padding: 6px 14px;
  background: rgba(226,181,92,.1); border: 1px solid var(--line); border-radius: 10px;
}
.room-chip-label { font-size: 10px; color: var(--muted); }
.room-chip strong { font-size: 20px; letter-spacing: 5px; color: var(--gold-soft); }
.top-right { margin-left: auto; display: flex; gap: 6px; }

.conn-bar {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: 5px 14px; font-size: 11px; color: var(--muted);
  background: rgba(0,0,0,.16);
}
.conn-dot { width: 7px; height: 7px; border-radius: 50%; background: #c9a24a; }
.conn-bar.ok .conn-dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.conn-bar.poll .conn-dot { background: #e8b24a; }
.conn-bar.off .conn-dot { background: var(--red); }

.table-area { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 14px 6px; }
.players { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.players::-webkit-scrollbar { display: none; }
.player {
  flex: 1 0 76px; min-width: 76px; max-width: 120px; text-align: center;
  padding: 9px 6px 8px; border-radius: 13px;
  background: rgba(4, 24, 17, .55); border: 1px solid rgba(255,255,255,.07);
  position: relative; transition: border-color .25s, background .25s, transform .25s;
}
.player.turn { border-color: var(--gold); background: rgba(226,181,92,.13); box-shadow: 0 0 18px rgba(226,181,92,.22); }
.player.me { background: rgba(20, 80, 60, .6); }
.player.loser { border-color: rgba(225,91,82,.75); background: rgba(225,91,82,.13); box-shadow: 0 0 16px rgba(225,91,82,.2); }
.player.out { opacity: .42; filter: grayscale(.7); }
.player.offline::after {
  content: '离线'; position: absolute; top: 4px; right: 4px;
  font-size: 9px; color: #fff; background: #8a5a4a; border-radius: 5px; padding: 1px 4px;
}
.avatar {
  width: 34px; height: 34px; margin: 0 auto 5px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #0c3327;
  background: linear-gradient(145deg, #f0d59a, #c69642);
}
.player.is-ai .avatar { background: linear-gradient(145deg, #9fd7bb, #5c9a7d); }
.pname { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pname .host-tag { color: var(--gold); font-size: 10px; }
.pdice-count { font-size: 10px; color: var(--muted); margin-top: 3px; }
.pips-row { display: flex; justify-content: center; gap: 3px; margin-top: 5px; }
.pips-row i { width: 5px; height: 5px; border-radius: 50%; background: var(--gold); opacity: .85; }
.p-reveal { display: flex; justify-content: center; flex-wrap: wrap; gap: 2px; margin-top: 6px; }

.stage {
  margin: 10px 0 8px; padding: 14px 12px 12px; text-align: center;
  border-radius: 18px; border: 1px solid var(--line);
  background: radial-gradient(ellipse at 50% 0%, rgba(30,96,70,.5), rgba(5,28,20,.65));
  box-shadow: inset 0 0 40px rgba(0,0,0,.25);
}
.phase-label { font-size: 11px; letter-spacing: 3px; color: var(--muted); }
.bid-display { min-height: 62px; display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 4px; }
.bid-placeholder { font-size: 15px; color: rgba(157,185,169,.6); }
.big-num { font-size: 52px; font-weight: 800; line-height: 1; color: var(--gold-soft); text-shadow: 0 4px 18px rgba(226,181,92,.35); }
.big-word { font-size: 19px; color: var(--cream); margin: 0 2px; }
.big-face { width: 52px; height: 52px; }
.zhai-tag { display: inline-block; font-size: 12px; padding: 3px 9px; border-radius: 20px; color: #2b1c05; background: var(--gold); font-weight: 700; }
.bid-meta { font-size: 12px; color: var(--muted); min-height: 17px; }
.bid-meta b { color: var(--gold-soft); font-weight: 600; }

.history { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin-bottom: 8px; }
.history .hitem { font-size: 11px; padding: 3px 8px; border-radius: 20px; background: rgba(255,255,255,.05); color: var(--muted); }
.history .hitem.latest { background: rgba(226,181,92,.16); color: var(--gold-soft); }
.history .hitem.open-item { background: rgba(225,91,82,.18); color: #ffab9f; }

/* 结算 */
.reveal {
  border-radius: 16px; padding: 14px; margin-bottom: 8px;
  background: rgba(4, 24, 17, .78); border: 1px solid var(--line);
  animation: pop .35s ease;
}
.reveal-title { font-size: 22px; font-weight: 800; color: var(--gold-soft); letter-spacing: 4px; text-align: center; }
.reveal-result { text-align: center; font-size: 14px; margin: 8px 0 12px; line-height: 1.7; }
.reveal-result .num { font-size: 30px; font-weight: 800; color: var(--gold); margin: 0 4px; }
.reveal-result .lose { color: #ff9b8f; font-weight: 700; }
.reveal-result .win { color: var(--green); font-weight: 700; }
.drink-banner {
  text-align: center; margin: 10px 0 14px; padding: 12px 10px;
  border-radius: 13px; border: 1px solid rgba(225,91,82,.5);
  background: linear-gradient(180deg, rgba(225,91,82,.16), rgba(225,91,82,.07));
  animation: pop .4s ease;
}
.drink-banner .who { font-size: 20px; font-weight: 800; color: var(--gold-soft); line-height: 1.5; }
.drink-banner .cups { font-size: 32px; font-weight: 800; color: #ff9b8f; margin: 0 2px; }
.drink-banner .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.reveal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.reveal-row { background: rgba(255,255,255,.04); border-radius: 10px; padding: 7px 9px; }
.reveal-row.loser { border: 1px solid rgba(225,91,82,.6); background: rgba(225,91,82,.1); }
.reveal-row .rr-head { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; }
.reveal-row .rr-dice { display: flex; gap: 3px; margin-top: 5px; flex-wrap: wrap; }
.reveal-row .rr-match { color: var(--gold); font-weight: 700; }

/* ------------------------------ 底部操作区 ------------------------------ */
.bottom-panel {
  flex: none; padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(4,22,16,.55), rgba(3,18,13,.95));
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(0,0,0,.25);
}
.my-dice-head { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--muted); margin-bottom: 7px; }
.my-dice-head b { color: var(--gold-soft); font-size: 13px; }
.wild-hint { color: rgba(226,181,92,.75); }
.my-dice { display: flex; justify-content: center; gap: 8px; min-height: 56px; align-items: center; }
.my-dice .empty-tip { font-size: 13px; color: var(--muted); }

/* 骰子 */
.die {
  position: relative; display: grid; flex: none;
  grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  width: 50px; height: 50px; padding: 5px;
  border-radius: 11px; background: linear-gradient(150deg, #fffaf0, #e8dcc2);
  box-shadow: 0 4px 0 #b9a98a, 0 7px 12px rgba(0,0,0,.4), inset 0 1px 2px rgba(255,255,255,.9);
}
.die.small { width: 46px; height: 46px; }
.die.tiny { width: 24px; height: 24px; padding: 2px; border-radius: 5px; box-shadow: 0 2px 0 #b9a98a, 0 3px 6px rgba(0,0,0,.3); }
.die .pip { width: 9px; height: 9px; border-radius: 50%; background: #1d3b30; align-self: center; justify-self: center; opacity: 0; }
.die.tiny .pip { width: 4px; height: 4px; }
.die .pip:nth-child(1) { grid-area: 1 / 1; }
.die .pip:nth-child(2) { grid-area: 1 / 2; }
.die .pip:nth-child(3) { grid-area: 1 / 3; }
.die .pip:nth-child(4) { grid-area: 2 / 1; }
.die .pip:nth-child(5) { grid-area: 2 / 2; }
.die .pip:nth-child(6) { grid-area: 2 / 3; }
.die .pip:nth-child(7) { grid-area: 3 / 1; }
.die .pip:nth-child(8) { grid-area: 3 / 2; }
.die .pip:nth-child(9) { grid-area: 3 / 3; }
.die[data-face="1"] .pip:nth-child(5),
.die[data-face="2"] .pip:nth-child(1), .die[data-face="2"] .pip:nth-child(9),
.die[data-face="3"] .pip:nth-child(1), .die[data-face="3"] .pip:nth-child(5), .die[data-face="3"] .pip:nth-child(9),
.die[data-face="4"] .pip:nth-child(1), .die[data-face="4"] .pip:nth-child(3), .die[data-face="4"] .pip:nth-child(7), .die[data-face="4"] .pip:nth-child(9),
.die[data-face="5"] .pip:nth-child(1), .die[data-face="5"] .pip:nth-child(3), .die[data-face="5"] .pip:nth-child(5), .die[data-face="5"] .pip:nth-child(7), .die[data-face="5"] .pip:nth-child(9),
.die[data-face="6"] .pip:nth-child(1), .die[data-face="6"] .pip:nth-child(3), .die[data-face="6"] .pip:nth-child(4), .die[data-face="6"] .pip:nth-child(6), .die[data-face="6"] .pip:nth-child(7), .die[data-face="6"] .pip:nth-child(9) { opacity: 1; }
.die[data-face="1"] .pip { background: #c43d34; }
.die.wild { box-shadow: 0 0 0 2px var(--gold), 0 4px 0 #b9a98a, 0 7px 16px rgba(226,181,92,.5); }
.die[data-face="0"] { background: linear-gradient(150deg, #2c5a47, #1b4234); box-shadow: 0 4px 0 #0e2a20, 0 7px 12px rgba(0,0,0,.4); }
.die[data-face="0"]::after {
  content: '?'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: rgba(226,181,92,.45); font-size: 20px; font-weight: 800;
}
.die.tiny[data-face="0"]::after { font-size: 12px; }
@keyframes shake {
  0%,100% { transform: translate(0,0) rotate(0); }
  20% { transform: translate(-6px,-8px) rotate(-18deg); }
  45% { transform: translate(7px,3px) rotate(16deg); }
  70% { transform: translate(-4px,6px) rotate(-9deg); }
}
.my-dice.shaking .die { animation: shake .5s ease-in-out 2; }
@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(8px); } to { opacity: 1; transform: none; } }

.controls { margin-top: 10px; min-height: 52px; }
.ctrl-row { display: flex; gap: 8px; align-items: center; }
.ctrl-note { font-size: 11px; color: var(--muted); text-align: center; margin-top: 8px; line-height: 1.6; }
.ctrl-note.err { color: #ff9b8f; }

.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button {
  width: 34px; height: 40px; border-radius: 10px; font-size: 20px;
  background: rgba(255,255,255,.08); border: 1px solid var(--line); color: var(--gold-soft);
}
.stepper .step-val { min-width: 42px; text-align: center; font-size: 26px; font-weight: 800; color: var(--gold-soft); }
.step-label { font-size: 11px; color: var(--muted); margin-right: 2px; }
.face-picker { display: flex; gap: 4px; flex: 1; justify-content: flex-end; }
.face-picker button {
  width: 34px; height: 38px; border-radius: 9px; font-size: 17px; font-weight: 800;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); color: var(--cream);
}
.face-picker button.sel { background: var(--gold); color: #2b1c05; border-color: var(--gold); box-shadow: 0 3px 0 #8c6320; }
.face-picker button:disabled { opacity: .28; }

.action-row { display: flex; gap: 8px; margin-top: 9px; }
.action-row .btn { height: 46px; }
.btn-bid { flex: 2; background: linear-gradient(180deg, #f6d68d, #d9a342); color: #2b1c05; box-shadow: 0 4px 0 #8c6320; letter-spacing: 4px; font-size: 17px; }
.btn-open { flex: 1; background: linear-gradient(180deg, #ef7167, #c8403a); color: #fff; box-shadow: 0 4px 0 #7e2823; letter-spacing: 3px; }
.btn-next { background: linear-gradient(180deg, #f6d68d, #d9a342); color: #2b1c05; box-shadow: 0 4px 0 #8c6320; letter-spacing: 3px; }
.btn-start { background: linear-gradient(180deg, #f6d68d, #d9a342); color: #2b1c05; box-shadow: 0 4px 0 #8c6320; letter-spacing: 3px; }
.chip-toggle {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 20px;
  font-size: 12px; background: rgba(255,255,255,.06); border: 1px solid var(--line); color: var(--muted);
}
.chip-toggle.on { background: var(--gold); color: #2b1c05; border-color: var(--gold); font-weight: 700; }
.chip-toggle:disabled { opacity: .3; }
.sub-row { display: flex; gap: 8px; margin-top: 9px; align-items: center; }
.sub-row .btn { height: 38px; font-size: 13px; background: rgba(255,255,255,.07); border: 1px solid var(--line); color: var(--muted); }
.waiting-tip { font-size: 13px; color: var(--muted); text-align: center; padding: 8px 0; line-height: 1.7; }
.waiting-tip b { color: var(--gold-soft); }

/* ------------------------------ 弹窗 / 提示 ------------------------------ */
.modal-mask {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.66); padding: 20px; backdrop-filter: blur(3px);
}
.modal {
  position: relative; width: 100%; max-width: 400px; max-height: 82vh; overflow-y: auto;
  background: linear-gradient(160deg, #104534, #08271d);
  border: 1px solid var(--line); border-radius: 18px; padding: 22px 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6); animation: pop .25s ease;
}
.modal-close { position: absolute; top: 10px; right: 12px; width: 30px; height: 30px; background: none; font-size: 26px; color: var(--muted); }
.modal h2 { margin: 0 0 14px; font-size: 19px; color: var(--gold-soft); letter-spacing: 2px; }
.modal h3 { margin: 16px 0 8px; font-size: 14px; color: var(--gold); }
.modal p, .modal li { font-size: 13px; line-height: 1.85; color: rgba(247,239,221,.85); }
.modal ol { padding-left: 20px; margin: 0; }
.modal .kbd { display: inline-block; padding: 1px 6px; border-radius: 5px; background: rgba(226,181,92,.16); color: var(--gold-soft); font-weight: 700; }
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.07); font-size: 13px; }
.setting-row select {
  background: rgba(0,0,0,.3); color: var(--cream); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; font-size: 13px;
}
.switch { width: 44px; height: 24px; border-radius: 14px; background: rgba(255,255,255,.15); position: relative; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch.on { background: var(--gold); }
.switch.on::after { transform: translateX(20px); }
.invite-code { text-align: center; font-size: 40px; letter-spacing: 12px; font-weight: 800; color: var(--gold-soft); margin: 6px 0 4px; }
.invite-link { font-size: 11px; color: var(--muted); text-align: center; word-break: break-all; line-height: 1.6; }
.qr-box { text-align: center; margin-top: 12px; }
.qr-box img { width: 160px; height: 160px; background: #fff; border-radius: 10px; padding: 6px; }
.qr-box .btn { margin-top: 10px; height: 36px; font-size: 13px; background: rgba(255,255,255,.08); border: 1px solid var(--line); }
.modal .btn-full { height: 44px; margin-top: 14px; background: linear-gradient(180deg,#f6d68d,#d9a342); color: #2b1c05; border-radius: 11px; font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 12px);
  z-index: 80; max-width: 88%; padding: 10px 18px; border-radius: 22px;
  background: rgba(8, 32, 24, .96); border: 1px solid var(--line);
  color: var(--cream); font-size: 13px; text-align: center;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(225,91,82,.7); color: #ffb3aa; }

@media (min-width: 600px) {
  :root { --app-max: 560px; }
  .brand h1 { font-size: 46px; }
}
@media (max-height: 700px) {
  .stage { padding: 9px 10px; }
  .bid-display { min-height: 52px; }
  .big-num { font-size: 42px; }
  .big-face { width: 44px; height: 44px; }
  .my-dice { min-height: 48px; }
  .die { width: 44px; height: 44px; }
}
