:root {
  --bg: #f6f8f3;
  --panel: rgba(255, 253, 249, 0.97);
  --surface: #edf5f2;
  --surface-strong: #e7f0f4;
  --line: rgba(37, 58, 73, 0.14);
  --ink: #172635;
  --muted: #65737d;
  --blue: #236eb6;
  --teal: #1d8872;
  --gold: #bd8128;
  --rose: #b84f66;
  --warn: #d45454;
  --shadow: 0 18px 34px rgba(29, 46, 62, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(35, 110, 182, 0.08), transparent 34%),
    linear-gradient(180deg, #fbfcf8 0%, var(--bg) 48%, #edf5f2 100%);
}

.player-body,
.admin-body {
  min-height: 100vh;
}

.player-shell,
.admin-shell {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.player-shell {
  display: grid;
  gap: 16px;
}

.panel,
.scoreboard-card,
.team-card,
.action-card,
.modal-card,
.player-result,
.admin-action-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel,
.scoreboard-card {
  padding: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

.panel-copy,
.helper-text,
.modal-copy {
  color: var(--muted);
  line-height: 1.6;
}

.field-group {
  margin-bottom: 16px;
}

.field-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

.field-group input,
.search-row input,
.admin-action-card input,
.admin-action-card select {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 16px;
}

.field-group input:focus,
.search-row input:focus,
.admin-action-card input:focus,
.admin-action-card select:focus {
  outline: none;
  border-color: rgba(44, 135, 217, 0.5);
  box-shadow: 0 0 0 3px rgba(44, 135, 217, 0.12);
}

.field-group input.invalid {
  border-color: var(--warn);
  box-shadow: 0 0 0 3px rgba(212, 84, 84, 0.14);
}

.admin-action-card input.invalid {
  border-color: var(--warn);
  box-shadow: 0 0 0 3px rgba(212, 84, 84, 0.14);
}

.primary-btn,
.ghost-btn,
.ghost-link,
.team-card button,
.action-card button,
.danger-btn,
.close-btn,
.player-result {
  border: 0;
  cursor: pointer;
  font: inherit;
}

.primary-btn {
  width: 100%;
  padding: 16px 20px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--teal) 0%, var(--blue) 100%);
  font-weight: 700;
}

.primary-btn:disabled,
.ghost-btn:disabled,
.danger-btn:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.ghost-btn,
.ghost-link,
.team-card button,
.action-card button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--blue);
  font-weight: 700;
  text-decoration: none;
}

.wide-btn {
  width: 100%;
}

.danger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 14px;
  border-radius: 8px;
  background: #c83d3d;
  color: #fff;
  font-weight: 800;
}

.team-picks,
.team-board,
.actions-grid,
.leaderboard-list,
.recent-logs,
.admin-actions,
.booth-status,
.player-results {
  display: grid;
  gap: 14px;
}

.team-card {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}

.team-card.compact {
  grid-template-columns: 82px 1fr;
}

.team-card > div {
  min-width: 0;
}

.team-card h3 {
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}

.character-frame {
  display: grid;
  position: relative;
  isolation: isolate;
  place-items: end center;
  width: 100%;
  aspect-ratio: 1 / 1.12;
  overflow: hidden;
  border: 1px solid var(--asset-line, var(--line));
  border-radius: 8px;
  background:
    linear-gradient(180deg, var(--asset-bg, #f3f7f6) 0%, rgba(255, 255, 255, 0.94) 100%);
}

.character-frame::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 6px;
}

.character-frame img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  padding: 7px;
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 13px 13px rgba(24, 36, 48, 0.16));
}

.team-card.compact .character-frame {
  aspect-ratio: 1 / 1.04;
}

.team-card.compact .character-frame img {
  padding: 5px;
}

.team-card.selected {
  outline: 3px solid rgba(29, 136, 114, 0.22);
}

.mobile-stats {
  margin-top: 16px;
}

.hero-stats {
  display: grid;
  gap: 10px;
}

.hero-stats div,
.summary-item,
.booth-item,
.selected-player {
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface);
}

.hero-stats span,
.summary-item span,
.booth-item span {
  display: block;
  color: var(--muted);
  margin-bottom: 4px;
}

.action-card,
.admin-action-card {
  padding: 16px;
}

.action-card p {
  color: var(--muted);
}

.log-item {
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface-strong);
}

.leaderboard-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface-strong);
}

.leaderboard-row.current {
  background: linear-gradient(135deg, rgba(29, 136, 114, 0.12), rgba(35, 110, 182, 0.12));
  border: 1px solid rgba(29, 136, 114, 0.22);
}

.leaderboard-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #dfecf7;
  color: var(--blue);
  font-weight: 700;
}

.leaderboard-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.log-item strong {
  display: block;
  margin-bottom: 6px;
}

.log-fold {
  display: grid;
  gap: 10px;
}

.log-fold summary {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--blue);
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

.log-fold summary::-webkit-details-marker {
  display: none;
}

.log-fold summary::after {
  content: "+";
  margin-left: 8px;
  font-size: 14px;
}

.log-fold[open] summary::after {
  content: "-";
}

.log-fold-list {
  display: grid;
  gap: 14px;
  margin-top: 10px;
}

.error-text {
  margin-bottom: 14px;
  color: var(--warn);
}

.form-divider {
  height: 1px;
  margin: 24px 0;
  background: linear-gradient(90deg, transparent, var(--line), transparent);
}

.secondary-head {
  margin-bottom: 12px;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 18, 31, 0.46);
}

.modal-card {
  position: relative;
  width: min(760px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 24px;
}

.close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-strong);
  font-size: 24px;
}

.modal-stats {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.event-box {
  display: grid;
  align-items: start;
  gap: 16px;
  padding: 16px;
  border: 1px solid rgba(189, 129, 40, 0.22);
  border-radius: 8px;
  background: linear-gradient(180deg, #fff8eb 0%, #fffdfa 100%);
}

.event-art {
  width: min(100%, 220px);
  max-width: 220px;
  margin: 0 auto;
  aspect-ratio: 1;
}

.event-art img {
  padding: 10px;
}

.event-effect {
  color: #c56b2c;
  font-weight: 700;
}

.admin-grid {
  display: grid;
  gap: 16px;
}

.admin-nav {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.admin-nav-btn {
  border: 0;
  cursor: pointer;
  padding: 10px 16px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font: inherit;
  font-weight: 700;
}

.admin-nav-btn.active {
  background: var(--surface-strong);
  color: var(--blue);
  box-shadow: inset 0 0 0 1px rgba(44, 135, 217, 0.16);
}

.lottery-panel {
  display: grid;
  gap: 18px;
}

.lottery-head {
  display: grid;
  gap: 14px;
}

.lottery-head h2 {
  margin-bottom: 0;
}

.lottery-draw-btn {
  align-self: end;
}

.lottery-stage {
  display: grid;
  place-items: center;
  min-height: 240px;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(29, 136, 114, 0.11), rgba(189, 129, 40, 0.1)),
    #f8fcff;
  border: 1px solid rgba(44, 135, 217, 0.16);
}

.lottery-roller {
  width: min(620px, calc(100vw - 80px));
  min-height: 96px;
  display: grid;
  place-items: center;
  padding: 20px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 16px 36px rgba(25, 61, 97, 0.12);
  color: var(--ink);
  font-size: clamp(28px, 6vw, 64px);
  font-weight: 800;
  text-align: center;
  word-break: break-word;
}

.lottery-roller.rolling {
  transform: translateY(-1px);
  filter: blur(0.2px);
}

.lottery-roller.winner {
  color: #1a7f64;
  box-shadow:
    0 16px 36px rgba(25, 61, 97, 0.12),
    0 0 0 4px rgba(26, 127, 100, 0.1);
}

.lottery-result {
  display: grid;
  gap: 12px;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 14px;
}

.player-result {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  background: var(--surface-strong);
}

.player-result strong {
  display: block;
  margin-bottom: 6px;
}

.admin-body .player-results,
.admin-body #admin-logs {
  height: 560px;
  padding-right: 4px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  align-content: start;
}

.admin-summary,
.summary-grid {
  display: grid;
  gap: 12px;
}

.admin-action-card {
  display: grid;
  gap: 10px;
}

.danger-zone {
  display: grid;
  gap: 12px;
  border-color: rgba(200, 61, 61, 0.24);
}

.danger-zone h2 {
  margin-bottom: 0;
}

.danger-confirm {
  display: grid;
  gap: 12px;
  padding-top: 4px;
}

.danger-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.empty-state {
  color: var(--muted);
}

@media (min-width: 900px) {
  .player-shell {
    grid-template-columns: minmax(0, 1fr) 360px;
    align-items: start;
  }

  .admin-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .danger-zone {
    grid-column: 1 / -1;
  }

  .lottery-head {
    grid-template-columns: 1fr 180px;
    align-items: end;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .event-box {
    grid-template-columns: 220px 1fr;
  }

  .event-art {
    margin: 0;
  }
}

@media (max-width: 520px) {
  .admin-body .player-results,
  .admin-body #admin-logs {
    height: 55vh;
    min-height: 280px;
  }

  .team-card,
  .team-card.compact {
    grid-template-columns: 86px 1fr;
  }

  .search-row {
    grid-template-columns: 1fr;
  }

  .leaderboard-row {
    align-items: flex-start;
  }
}
