/* 中秋博饼 · 家庭版 —— 主题与布局 */

:root {
  --bg-0: #1d0807;
  --bg-1: #3a100d;
  --bg-2: #521712;
  --panel: rgba(255, 243, 226, 0.07);
  --panel-line: rgba(232, 190, 110, 0.22);
  --panel-solid: #35120f;
  --gold: #e0b054;
  --gold-soft: #f2d493;
  --gold-deep: #a97a24;
  --paper: #fdf8ef;
  --red: #b8252c;
  --red-bright: #d8353c;
  --jade: #3d7f68;
  --text: #f8efe3;
  --text-dim: #cbb49f;
  --text-mute: #9c8672;
  --shadow-lg: 0 1.4rem 3.2rem rgba(0, 0, 0, 0.5);
  --radius: 0.9rem;
  --font-sans: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  --font-serif: "Songti SC", "STSong", "Noto Serif SC", "SimSun", Georgia, serif;
}

html { font-size: 16px; }
html.bigfont { font-size: 21px; }
@media (max-width: 70rem) {
  html { font-size: 15px; }
  html.bigfont { font-size: 18px; }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  color: var(--text);
  background:
    radial-gradient(120% 80% at 50% -10%, #6b1f16 0%, transparent 60%),
    radial-gradient(90% 60% at 50% 110%, #5a1a13 0%, transparent 55%),
    linear-gradient(160deg, var(--bg-1), var(--bg-0));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }
.dim { color: var(--text-mute); }

.screen { position: fixed; inset: 0; }

/* ---------------- 通用控件 ---------------- */

.btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-line);
  border-radius: 0.7rem;
  padding: 0.75rem 1.3rem;
  min-height: 3rem;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.16s ease, box-shadow 0.16s ease;
  touch-action: manipulation;
}
.btn:hover { background: rgba(255, 255, 255, 0.15); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn.primary {
  background: linear-gradient(180deg, var(--red-bright), var(--red));
  border-color: rgba(255, 200, 200, 0.35);
  box-shadow: 0 0.4rem 1.2rem rgba(184, 37, 44, 0.4);
}
.btn.primary:hover { background: linear-gradient(180deg, #e34449, #c62b32); }

.btn.ghost { background: rgba(255, 255, 255, 0.05); }
.btn.sm { font-size: 0.86rem; padding: 0.5rem 0.85rem; min-height: 2.5rem; }
.btn.big { font-size: 1.15rem; padding: 1rem 2.2rem; min-height: 3.6rem; }

.btn.roll {
  font-family: var(--font-serif);
  font-size: 1.7rem;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  font-weight: 700;
  color: #40120c;
  background: linear-gradient(180deg, #fbe6b0, var(--gold) 55%, #c8933a);
  border: 1px solid #ffeec4;
  border-radius: 1rem;
  padding: 1rem 1.6rem;
  min-height: 4.4rem;
  width: 100%;
  box-shadow: 0 0.6rem 1.6rem rgba(224, 176, 84, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.7);
}
.btn.roll:hover { background: linear-gradient(180deg, #fff0c6, #e8bd63 55%, #d3a044); }
.btn.roll:active { transform: scale(0.985); }
.btn.roll.busy { opacity: 0.6; }

.input {
  font-family: inherit;
  font-size: 1.1rem;
  color: var(--text);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--panel-line);
  border-radius: 0.7rem;
  padding: 0.8rem 1rem;
  min-height: 3.2rem;
  width: 100%;
}
.input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.input::placeholder { color: var(--text-mute); }

/* ---------------- 登录墙 ---------------- */

.gate {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(70% 55% at 50% 22%, rgba(224, 176, 84, 0.16), transparent 65%);
}

.gate-card {
  width: min(26rem, 100%);
  text-align: center;
  background: linear-gradient(180deg, rgba(60, 20, 16, 0.9), rgba(30, 10, 9, 0.94));
  border: 1px solid var(--panel-line);
  border-radius: 1.4rem;
  padding: 2rem 1.6rem 1.6rem;
  box-shadow: var(--shadow-lg);
}

.gate-moon { font-size: 3.4rem; line-height: 1; filter: drop-shadow(0 0 1.2rem rgba(240, 210, 140, 0.6)); }

.gate-title {
  font-family: var(--font-serif);
  font-size: 2.3rem;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  margin: 0.6rem 0 0.2rem;
  color: var(--gold-soft);
  text-shadow: 0 0 1.6rem rgba(224, 176, 84, 0.4);
}

.gate-sub { color: var(--text-dim); margin: 0 0 1.2rem; font-size: 1rem; }

.pw-dots {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  min-height: 1.5rem;
  margin-bottom: 0.5rem;
}
.pw-dots i {
  width: 1rem; height: 1rem;
  border-radius: 50%;
  border: 2px solid var(--gold-deep);
  background: transparent;
  transition: background 0.14s ease, transform 0.14s ease;
}
.pw-dots i.on { background: var(--gold); transform: scale(1.15); }

.pw-error { min-height: 1.4rem; margin: 0 0 0.6rem; color: #ff9b9b; font-size: 0.95rem; }
.pw-error.shake { animation: shake 0.4s ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-0.4rem); }
  40% { transform: translateX(0.4rem); }
  60% { transform: translateX(-0.25rem); }
  80% { transform: translateX(0.25rem); }
}

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }

.key {
  font-family: inherit;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-line);
  border-radius: 0.85rem;
  min-height: 3.8rem;
  cursor: pointer;
  transition: background 0.14s ease, transform 0.1s ease;
  touch-action: manipulation;
}
.key:hover { background: rgba(255, 255, 255, 0.15); }
.key:active { transform: scale(0.95); }
.key-fn { font-size: 1.05rem; color: var(--text-dim); }
.key-ok {
  font-size: 1.15rem;
  color: #3d120c;
  background: linear-gradient(180deg, #fbe6b0, var(--gold));
  border-color: #ffeec4;
}

/* ---------------- 组局 ---------------- */

.setup {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  overflow-y: auto;
}

.setup-card {
  width: min(44rem, 100%);
  background: linear-gradient(180deg, rgba(60, 20, 16, 0.86), rgba(28, 10, 9, 0.92));
  border: 1px solid var(--panel-line);
  border-radius: 1.4rem;
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}

.setup-title {
  font-family: var(--font-serif);
  font-size: 1.9rem;
  margin: 0 0 0.5rem;
  color: var(--gold-soft);
}
.setup-sub { color: var(--text-dim); margin: 0 0 1.4rem; }

.setup-input-row { display: flex; gap: 0.7rem; }
.setup-input-row .input { flex: 1; }

.setup-error { min-height: 1.4rem; margin: 0.5rem 0 0; color: #ff9b9b; font-size: 0.95rem; }

.chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0;
  margin: 0.6rem 0 1.4rem;
  min-height: 3.4rem;
}
.chips li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(224, 176, 84, 0.14);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  padding: 0.45rem 0.6rem 0.45rem 1rem;
  font-size: 1.05rem;
}
.chips li button {
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-mute);
  background: rgba(0, 0, 0, 0.25);
  border: none;
  border-radius: 50%;
  width: 1.9rem; height: 1.9rem;
  cursor: pointer;
  line-height: 1;
}
.chips li button:hover { color: #ff9b9b; background: rgba(255, 120, 120, 0.2); }

.setup-settings {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 1.1rem;
  background: rgba(0, 0, 0, 0.22);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}
.switch { display: flex; align-items: center; gap: 0.75rem; cursor: pointer; font-size: 1rem; }
.switch input { width: 1.5rem; height: 1.5rem; accent-color: var(--gold); cursor: pointer; flex: none; }

.setup-actions { display: flex; gap: 0.8rem; justify-content: flex-end; flex-wrap: wrap; }

/* ---------------- 游戏主界面 ---------------- */

.game { display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: linear-gradient(180deg, rgba(70, 22, 17, 0.92), rgba(40, 13, 11, 0.86));
  border-bottom: 1px solid var(--panel-line);
  flex: none;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-serif);
  font-size: 1.25rem;
  letter-spacing: 0.16em;
  color: var(--gold-soft);
  flex: none;
}

.topmeta { color: var(--text-dim); font-size: 0.92rem; flex: 1; min-width: 8rem; }
.topactions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(11rem, 14rem) minmax(0, 1fr) minmax(13rem, 17rem);
  gap: 0.75rem;
  padding: 0.75rem;
}

.panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  padding: 0.9rem;
  overflow: hidden;
}

.panel-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.1em;
  margin: 0 0 0.6rem;
  flex: none;
}
.panel-title + .panel-title { margin-top: 0.9rem; }

.panel-foot { display: flex; gap: 0.5rem; margin-top: 0.7rem; flex: none; }
.panel-foot .btn { flex: 1; }

/* 排行榜 */
.rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.rank-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.65rem;
  border-radius: 0.6rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid transparent;
}
.rank-list li.current {
  border-color: var(--gold);
  background: rgba(224, 176, 84, 0.16);
  box-shadow: 0 0 0 1px rgba(224, 176, 84, 0.3);
}
.rank-list .pos {
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--text-mute);
  width: 1.6rem;
  flex: none;
  text-align: center;
}
.rank-list li:nth-child(1) .pos { color: var(--gold); }
.rank-list .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.02rem; }
.rank-list .crown { color: var(--gold); flex: none; }
.rank-list .cnt { font-size: 0.95rem; color: var(--text-dim); flex: none; }

/* 舞台 */
.stage { display: flex; flex-direction: column; gap: 0.6rem; min-height: 0; }

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--panel-line);
  background: #120b09;
  box-shadow: inset 0 0 4rem rgba(0, 0, 0, 0.6);
}
.canvas-host { position: absolute; inset: 0; }

.canvas-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-align: center;
  padding: 1rem;
}

.turnbar {
  flex: none;
  text-align: center;
  padding: 0.5rem 0.8rem;
  border-radius: 0.7rem;
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid var(--panel-line);
}
.turn-who { font-size: 1.35rem; }
.turn-who b { color: var(--gold-soft); font-size: 1.55rem; }
.turn-hint { font-size: 0.95rem; color: var(--text-dim); margin-top: 0.15rem; }

/* 饼数库存 */
.stock-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  overflow-y: auto;
  flex: none;
  max-height: 42%;
}
.stock-item {
  display: grid;
  grid-template-columns: 3.2rem 1fr 2.6rem;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.98rem;
}
.stock-item .nm { color: var(--text); }
.stock-item .bar { height: 0.55rem; border-radius: 999px; background: rgba(0, 0, 0, 0.35); overflow: hidden; }
.stock-item .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold-deep)); }
.stock-item .num { text-align: right; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.stock-item.out .nm, .stock-item.out .num { color: var(--text-mute); text-decoration: line-through; }
.stock-item.out .bar i { background: #6a4038; }

/* 战绩流水 */
.log-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.92rem;
}
.log-item {
  padding: 0.45rem 0.6rem;
  border-radius: 0.55rem;
  background: rgba(0, 0, 0, 0.2);
  border-left: 0.22rem solid var(--text-mute);
  line-height: 1.4;
}
.log-item.gold { border-left-color: var(--gold); background: rgba(224, 176, 84, 0.12); }
.log-item.red { border-left-color: var(--red-bright); }
.log-item.dark { border-left-color: var(--jade); }
.log-item .l1 { display: flex; justify-content: space-between; gap: 0.5rem; }
.log-item .l1 b { color: var(--gold-soft); }
.log-item .l2 { color: var(--text-dim); }
.log-item .dice { letter-spacing: 0.08em; color: var(--text); font-variant-numeric: tabular-nums; }
.log-item .dice .r { color: #ff8a8a; font-weight: 700; }

/* ---------------- 浮层 ---------------- */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(12, 5, 4, 0.82);
  backdrop-filter: blur(6px);
  z-index: 40;
}

.result-card {
  width: min(34rem, 100%);
  text-align: center;
  padding: 2rem 1.8rem;
  border-radius: 1.4rem;
  background: linear-gradient(180deg, rgba(64, 22, 16, 0.96), rgba(26, 9, 8, 0.98));
  border: 2px solid var(--gold-deep);
  box-shadow: var(--shadow-lg), 0 0 4rem rgba(224, 176, 84, 0.22);
  animation: pop 0.34s cubic-bezier(0.2, 1.3, 0.4, 1);
}
.result-card.gold { border-color: var(--gold); box-shadow: var(--shadow-lg), 0 0 6rem rgba(224, 176, 84, 0.5); }
.result-card.red { border-color: var(--red-bright); }
.result-card.muted { border-color: #5d4a44; }

@keyframes pop {
  from { transform: scale(0.82); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.result-player { font-size: 1.15rem; color: var(--text-dim); margin-bottom: 0.4rem; }
.result-title {
  font-family: var(--font-serif);
  font-size: 3rem;
  letter-spacing: 0.16em;
  text-indent: 0.16em;
  color: var(--gold-soft);
  text-shadow: 0 0 2rem rgba(224, 176, 84, 0.55);
  margin-bottom: 1rem;
  line-height: 1.15;
}
.result-card.muted .result-title { color: var(--text-mute); text-shadow: none; font-size: 2.3rem; }
.result-card.red .result-title { color: #ff9b9b; text-shadow: 0 0 2rem rgba(216, 53, 60, 0.5); }

.result-dice { display: flex; justify-content: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }

.mini-die {
  width: 3.1rem;
  height: 3.1rem;
  border-radius: 0.6rem;
  background: linear-gradient(160deg, #fffdf7, #e9e0cd);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 0.3rem;
  box-shadow: 0 0.3rem 0.7rem rgba(0, 0, 0, 0.45), inset 0 -0.15rem 0.3rem rgba(0, 0, 0, 0.14);
}
.mini-die i {
  width: 68%;
  height: 68%;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #5b6474, #14171d);
  align-self: center;
  justify-self: center;
}
.mini-die i.red { background: radial-gradient(circle at 34% 30%, #f0576f, #8e0a20); }

.result-note { font-size: 1.1rem; color: var(--text-dim); margin-bottom: 1.4rem; min-height: 1.5rem; }

.confetti {
  position: absolute;
  top: -1.5rem;
  width: 0.55rem;
  height: 0.9rem;
  border-radius: 0.15rem;
  pointer-events: none;
  animation-name: confetti-fall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) rotate(760deg); opacity: 0.08; }
}

/* 规则浮层 */
.rules-card {
  width: min(46rem, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.8rem;
  border-radius: 1.4rem;
  background: linear-gradient(180deg, rgba(58, 20, 15, 0.97), rgba(26, 9, 8, 0.98));
  border: 1px solid var(--panel-line);
  box-shadow: var(--shadow-lg);
}
.rules-card h2 { font-family: var(--font-serif); color: var(--gold-soft); margin: 0 0 0.8rem; font-size: 1.7rem; }
.rules-lead { color: var(--text-dim); margin: 0 0 1rem; }
.rules-table { width: 100%; border-collapse: collapse; font-size: 0.98rem; }
.rules-table th, .rules-table td { padding: 0.5rem 0.6rem; text-align: left; border-bottom: 1px solid rgba(232, 190, 110, 0.16); }
.rules-table th { color: var(--gold); font-weight: 600; }
.rules-table td:last-child, .rules-table th:last-child { text-align: right; }
.rules-table tr.tone-gold td:first-child { color: var(--gold-soft); font-weight: 700; }
.rules-table tr.tone-red td:first-child { color: #ff9b9b; font-weight: 700; }
.rules-note { color: var(--text-mute); font-size: 0.92rem; line-height: 1.6; margin: 1rem 0 1.4rem; }

/* 轻提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%);
  padding: 0.8rem 1.4rem;
  border-radius: 999px;
  background: rgba(20, 8, 7, 0.95);
  border: 1px solid var(--panel-line);
  font-size: 1rem;
  z-index: 60;
  animation: pop 0.25s ease;
}

/* ---------------- 响应式 ---------------- */

@media (max-width: 62rem) {
  body { overflow: auto; }
  .screen.game { position: static; min-height: 100vh; }
  .layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .canvas-wrap { height: 44vh; min-height: 16rem; flex: none; }
  .stage { min-height: 0; }
  .panel { max-height: none; }
  .rank-list, .log-list { max-height: 14rem; overflow-y: auto; }
  .stock-list { max-height: none; }
  .topmeta { flex-basis: 100%; }
}

@media (max-width: 34rem) {
  .setup-input-row { flex-direction: column; }
  .setup-actions { flex-direction: column-reverse; }
  .setup-actions .btn { width: 100%; }
  .mini-die { width: 2.5rem; height: 2.5rem; }
  .result-title { font-size: 2.2rem; }
}