:root {
  --bg-deep: #1a110b;
  --bg-wood: #2d1b11;
  --bg-wood-light: #432819;
  --sand-paper: #f5ead4;
  --sand-card: #efe0c1;
  --sand-border: #cfa86a;
  --gold: #e6b85c;
  --gold-bright: #ffd97d;
  --gold-dim: #9c7432;
  --faience: #22a7b8;
  --faience-dark: #136875;
  --faience-light: #6be4ef;
  --ebony: #26201d;
  --ebony-light: #4b4039;
  --terracotta: #d95d39;
  --water-blue: #2f80ed;
  --text-light: #f9f1e1;
  --text-muted: #cbb99b;
  --text-dark: #2c1c12;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-box: 0 18px 42px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at 18% 12%, rgba(230, 184, 92, 0.14), transparent 42%),
    radial-gradient(circle at 82% 88%, rgba(34, 167, 184, 0.14), transparent 45%),
    linear-gradient(160deg, #1b120c 0%, #2a1a11 55%, #160e09 100%);
  color: var(--text-light);
  overflow-x: hidden;
}

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 16px 28px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* 顶部导航栏 */
.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(67, 40, 25, 0.92), rgba(37, 22, 13, 0.96));
  border: 1px solid rgba(230, 184, 92, 0.35);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-home {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(230, 184, 92, 0.28);
  color: var(--gold-bright);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  transition: transform 0.15s ease, background 0.15s ease;
}

.back-home:hover {
  background: rgba(230, 184, 92, 0.2);
  transform: translateY(-1px);
}

.title-block h1 {
  margin: 0;
  font-size: clamp(18px, 2.3vw, 23px);
  color: var(--gold-bright);
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-block .subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* 通用按钮 */
.btn {
  appearance: none;
  border: 1px solid rgba(230, 184, 92, 0.38);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-light);
  border-radius: 10px;
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.16s ease;
  user-select: none;
}

.btn:hover:not(:disabled) {
  background: rgba(230, 184, 92, 0.2);
  border-color: var(--gold-bright);
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-gold {
  background: linear-gradient(135deg, #e5b654, #c78f2e);
  color: #24140a;
  border-color: #ffe299;
  box-shadow: 0 4px 14px rgba(230, 184, 92, 0.35);
}

.btn-gold:hover:not(:disabled) {
  background: linear-gradient(135deg, #f3c867, #d69c35);
  color: #1c0f06;
}

.btn-faience {
  background: linear-gradient(135deg, #25b0c2, #177c8a);
  color: #fff;
  border-color: #7eeaf5;
}

/* 双面棋盒切换条 + 对局模式条 */
.switcher-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(42, 26, 16, 0.85);
  border: 1px solid rgba(230, 184, 92, 0.25);
  border-radius: var(--radius-md);
}

.box-tabs {
  display: inline-flex;
  background: rgba(15, 9, 5, 0.55);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid rgba(230, 184, 92, 0.22);
  gap: 4px;
}

.box-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.box-tab.active {
  background: linear-gradient(135deg, #e6b85c, #bd8328);
  color: #241409;
  box-shadow: 0 3px 10px rgba(230, 184, 92, 0.3);
}

.mode-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.mode-select {
  background: rgba(20, 12, 8, 0.85);
  color: var(--gold-bright);
  border: 1px solid rgba(230, 184, 92, 0.35);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

/* 双方状态栏 */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: stretch;
}

.player-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: rgba(45, 27, 17, 0.82);
  border: 2px solid rgba(230, 184, 92, 0.18);
  transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.2s ease;
}

.player-card.active {
  border-color: var(--gold-bright);
  box-shadow: 0 0 0 3px rgba(230, 184, 92, 0.2), 0 8px 20px rgba(0, 0, 0, 0.35);
  background: linear-gradient(135deg, rgba(78, 47, 28, 0.94), rgba(46, 27, 16, 0.94));
}

.player-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-light);
}

.player-role {
  font-size: 12px;
  color: var(--text-muted);
}

.player-progress {
  text-align: right;
}

.progress-num {
  font-size: 18px;
  font-weight: 800;
  color: var(--gold-bright);
}

.progress-label {
  font-size: 11px;
  color: var(--text-muted);
}

.turn-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  background: rgba(15, 9, 5, 0.55);
  border: 1px solid rgba(230, 184, 92, 0.25);
  min-width: 96px;
}

.turn-badge .turn-num {
  font-size: 12px;
  color: var(--text-muted);
}

.turn-badge .turn-who {
  font-size: 14px;
  font-weight: 800;
  color: var(--gold-bright);
  margin-top: 2px;
}

/* 棋盒主舞台 */
.wooden-box-stage {
  position: relative;
  background: linear-gradient(175deg, #4b2d1b 0%, #311d11 48%, #22130b 100%);
  border: 3px solid #7d532b;
  border-radius: 22px;
  padding: 18px 18px 22px;
  box-shadow:
    var(--shadow-box),
    inset 0 2px 0 rgba(255, 224, 150, 0.22),
    inset 0 -10px 24px rgba(0, 0, 0, 0.55);
  transition: transform 0.35s ease;
}

.wooden-box-stage.flipping {
  transform: perspective(1000px) rotateX(12deg) scale(0.985);
}

.box-engraving {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px dashed rgba(230, 184, 92, 0.3);
  font-size: 12px;
  color: var(--gold);
  letter-spacing: 1px;
}

.hieroglyph-strip {
  font-size: 15px;
  letter-spacing: 4px;
  opacity: 0.85;
  user-select: none;
}

/* 底部控制与掷具台 */
.control-dock {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 14px;
  align-items: stretch;
}

.throw-tray {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(53, 32, 19, 0.92), rgba(30, 18, 11, 0.95));
  border: 1px solid rgba(230, 184, 92, 0.3);
  border-radius: var(--radius-lg);
}

.dice-visual {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 62px;
}

.roll-readout {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.roll-steps {
  font-size: 22px;
  font-weight: 800;
  color: var(--gold-bright);
  line-height: 1.1;
}

.roll-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.btn-roll-main {
  padding: 13px 22px;
  font-size: 15px;
  border-radius: 13px;
  min-width: 136px;
  justify-content: center;
}

.event-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 14px 16px;
  background: rgba(29, 18, 11, 0.88);
  border: 1px solid rgba(230, 184, 92, 0.22);
  border-radius: var(--radius-lg);
}

.event-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.event-text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-light);
}

/* 响应式 */
@media (max-width: 860px) {
  .control-dock {
    grid-template-columns: 1fr;
  }
  .scoreboard {
    grid-template-columns: 1fr 1fr;
  }
  .turn-badge {
    grid-column: 1 / -1;
    flex-direction: row;
    gap: 10px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 10px 10px max(22px, env(safe-area-inset-bottom));
  }
  .btn, .mode-select {
    min-height: 38px;
    font-size: 12.5px;
  }
  .wooden-box-stage {
    padding: 12px 10px 16px;
  }
  .box-tab {
    padding: 7px 11px;
    font-size: 13px;
  }
  .hieroglyph-strip {
    display: none;
  }
}
