/* ================= 全局 ================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg1: #0f172a;
  --bg2: #1e1b4b;
  --card-bg: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.12);
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --primary: #ff5c7a;
  --primary-hover: #ff7a93;
  --blue: #3b82f6;
  --green: #22c55e;
  --gold: #fbbf24;
  --red: #ef4444;
  --radius: 16px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: linear-gradient(160deg, var(--bg1) 0%, var(--bg2) 60%, #312e81 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
}

/* ================= 卡片 ================= */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 24px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.card h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

/* ================= 按钮 ================= */
.btn-primary, .btn-ghost, .btn-start, .btn-roll {
  border: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  border-radius: 10px;
  transition: transform 0.08s ease, filter 0.15s ease, opacity 0.15s ease;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #f43f5e);
  color: #fff;
  padding: 10px 22px;
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-primary:active:not(:disabled) { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-start {
  background: linear-gradient(135deg, var(--green), #16a34a);
  color: #fff;
  padding: 10px 22px;
}
.btn-start:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-start:hover:not(:disabled) { filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--card-border);
  padding: 7px 14px;
  font-size: 13px;
}
.btn-ghost:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.3); }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-block { width: 100%; }

.btn-roll {
  background: linear-gradient(135deg, var(--gold), #f59e0b);
  color: #1e293b;
  font-size: 18px;
  padding: 14px 40px;
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(251, 191, 36, 0.35);
}
.btn-roll:hover:not(:disabled) { filter: brightness(1.06); }
.btn-roll:disabled { opacity: 0.45; cursor: not-allowed; }

/* ================= 顶栏 ================= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(0, 0, 0, 0.25);
  border-bottom: 1px solid var(--card-border);
  flex-wrap: wrap;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
}

.room-meta { font-size: 13px; color: var(--text-dim); }
.room-meta strong { color: var(--gold); }
.player-info { font-size: 14px; }

/* ================= 首页（创建昵称） ================= */
.page-index {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.index-card {
  width: 100%;
  max-width: 420px;
  text-align: center;
  padding: 40px 32px;
}

.dice-logo {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 20px;
}

.index-card h1 { font-size: 30px; margin-bottom: 6px; }
.subtitle { color: var(--text-dim); margin-bottom: 24px; font-size: 14px; }

.text-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s ease;
  font-family: inherit;
}
.text-input:focus { border-color: var(--primary); }
.text-input::placeholder { color: #64748b; }

.error-tip { color: var(--red); font-size: 13px; margin-top: 8px; min-height: 18px; }
.error-tip[hidden] { display: none; }

.rules-tip {
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.7;
  margin-top: 18px;
}

/* ================= 房间列表页 ================= */
.rooms-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  max-width: 960px;
  margin: 28px auto;
  padding: 0 20px;
}

@media (max-width: 760px) {
  .rooms-layout { grid-template-columns: 1fr; }
}

.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.radio-row { display: flex; gap: 10px; }

.radio-option {
  flex: 1;
  cursor: pointer;
}
.radio-option input { display: none; }
.radio-option span {
  display: block;
  text-align: center;
  padding: 10px 0;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text-dim);
  transition: all 0.15s ease;
}
.radio-option input:checked + span {
  border-color: var(--primary);
  color: #fff;
  background: rgba(255, 92, 122, 0.18);
}

.select {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  outline: none;
  font-family: inherit;
}
.select:focus { border-color: var(--primary); }

.hint { font-size: 12px; color: var(--text-dim); font-weight: 400; margin-left: 8px; }

.table-wrap { overflow-x: auto; }

.rooms-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.rooms-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-dim);
  font-weight: 500;
  border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
}
.rooms-table td {
  padding: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  white-space: nowrap;
}
.rooms-table tr:hover td { background: rgba(255, 255, 255, 0.04); }

.room-id { font-weight: 700; color: var(--gold); }
.disabled-text { color: var(--text-dim); font-size: 13px; }

.empty-tip {
  text-align: center;
  color: var(--text-dim);
  padding: 32px 0 12px;
  font-size: 14px;
}
.empty-tip[hidden] { display: none; }

/* ================= 房间页：等待 ================= */
.game-area {
  max-width: 860px;
  margin: 24px auto;
  padding: 0 20px;
}

.notify-bar {
  text-align: center;
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.4);
  color: #93c5fd;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 16px;
}
.notify-bar[hidden] { display: none; }

.player-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.player-chip {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  min-width: 110px;
  padding: 16px 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  border-radius: 12px;
}
.player-chip.me { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.p-name { font-size: 15px; font-weight: 600; }
.p-status { font-size: 12px; color: var(--text-dim); }
.p-status.ready { color: var(--green); }

.waiting-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ================= 房间页：游戏表格 ================= */
.round-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
}

.countdown {
  color: var(--gold);
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 14px;
  font-weight: 700;
}
.countdown[hidden] { display: none; }

.table-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  margin-bottom: 20px;
}

.game-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.game-table th {
  padding: 12px 10px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 2px solid var(--card-border);
  text-align: center;
  white-space: nowrap;
}
.game-table th:first-child { text-align: left; color: var(--text-dim); font-weight: 500; }
.game-table th.me-col { color: var(--gold); }

.game-table td {
  padding: 12px 10px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  white-space: nowrap;
}
.game-table .round-label { text-align: left; color: var(--text-dim); font-size: 13px; }

.game-table tr.current-round td { background: rgba(59, 130, 246, 0.08); }

.game-table .cell { font-size: 20px; font-weight: 700; }
.game-table .cell.filled { color: #fff; }
.game-table .cell.pending { color: #475569; font-weight: 400; }

.game-table tr.total-row td {
  font-weight: 800;
  font-size: 18px;
  border-top: 2px solid var(--card-border);
  border-bottom: none;
}
.game-table tr.total-row .winner-cell { color: var(--gold); }

/* ================= 投掷面板 ================= */
.roll-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  flex-wrap: wrap;
  padding: 10px 0;
}

.roll-actions { text-align: center; }

/* ================= 骰子 ================= */
.die {
  width: 76px;
  height: 76px;
  background: #fff;
  border-radius: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}

.pip {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: transparent;
  align-self: center;
  justify-self: center;
  transition: background 0.1s ease;
}
.pip.on { background: #1e293b; }

/* ================= 结束横幅 ================= */
.finished-card {
  text-align: center;
  border-color: rgba(251, 191, 36, 0.5);
}
.finished-card h2 { font-size: 24px; margin-bottom: 20px; }
