* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at top, rgba(96, 165, 250, 0.1), transparent 34%),
    #111827;
  color: #f9fafb;
}

.page { max-width: 1080px; margin: 0 auto; padding: 20px 16px 40px; }
.screen[hidden] { display: none !important; }

.header-compact { margin-bottom: 16px; }
.title { margin: 0; font-size: 26px; font-weight: 900; }

.panel {
  padding: 18px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.hint { margin: 0 0 12px; color: #9ca3af; font-size: 13px; line-height: 1.55; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #d1d5db; }
.field.block { margin-bottom: 12px; }
.field input, .field select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #1f2937;
  color: #f9fafb;
  font: inherit;
}

.primary-button, .secondary-button {
  padding: 10px 16px;
  border-radius: 10px;
  border: 0;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.primary-button { background: #2563eb; color: #fff; }
.secondary-button { background: #374151; color: #e5e7eb; }
.primary-button:disabled, .secondary-button:disabled { opacity: 0.45; cursor: not-allowed; }

.join-row { display: flex; gap: 10px; align-items: flex-end; margin-top: 10px; }
.join-row .field { flex: 1; }
.join-spectate-btn { width: 100%; margin-top: 8px; }
.field-feedback { margin-top: 8px; font-size: 13px; color: #fca5a5; }
.field-feedback[hidden] { display: none; }

.room-topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.room-topbar-main {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-width: 0;
}
.help-toggle-btn {
  flex-shrink: 0;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 180, 67, 0.45);
  background: rgba(255, 180, 67, 0.12);
  color: #fde68a;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.help-panel {
  margin: -6px 0 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 180, 67, 0.25);
  background: rgba(15, 13, 20, 0.95);
  max-height: min(360px, 50vh);
  overflow-y: auto;
}
.help-panel[hidden] { display: none !important; }
.help-panel-inner { padding: 12px 14px; }
.help-title { margin: 0 0 8px; font-size: 14px; color: #fde68a; }
.help-list {
  margin: 0 0 10px;
  padding-left: 1.1rem;
  font-size: 12px;
  line-height: 1.55;
  color: #d1d5db;
}
.help-list li { margin-bottom: 6px; }
.help-close-btn { font-size: 12px; padding: 6px 12px; }

.player-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.player-list .player-kick {
  flex-shrink: 0;
  padding: 2px 8px;
  border: 0;
  border-radius: 6px;
  background: rgba(248, 113, 113, 0.18);
  color: #fca5a5;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.player-list .player-kick:hover { background: rgba(248, 113, 113, 0.32); }
.player-list .player-offline { opacity: 0.55; }
.player-list .player-spectator { border-left: 3px solid rgba(251, 191, 36, 0.55); }
.play-hint {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(96, 165, 250, 0.12);
  border: 1px solid rgba(96, 165, 250, 0.28);
  color: #bfdbfe;
  font-size: 13px;
  font-weight: 600;
}
.confirm-bar {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.35);
}
.confirm-bar[hidden] { display: none !important; }
.confirm-text { display: block; margin-bottom: 10px; font-size: 14px; font-weight: 700; color: #fde68a; }
.spectator-panel { margin-top: 14px; }
.spectator-panel[hidden] { display: none !important; }
.stat-pill {
  padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.08);
}
.stat-room-code {
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  user-select: none;
}
.stat-room-code:hover,
.stat-room-code:focus-visible {
  background: rgba(96, 165, 250, 0.14);
  border-color: rgba(96, 165, 250, 0.45);
  color: #dbeafe;
  outline: none;
}
.stat-room-code.is-copied {
  color: #86efac;
  border-color: rgba(134, 239, 172, 0.45);
  background: rgba(52, 211, 153, 0.12);
}

.round-start-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-top: 12px;
}
.round-slot-field {
  min-width: 148px;
  margin-bottom: 0;
}
.round-slot-field select {
  min-width: 132px;
  font-weight: 700;
}

.settings-feedback {
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: #86efac;
}
.settings-feedback[hidden] { display: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.room-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 14px;
}
@media (max-width: 860px) { .room-layout { grid-template-columns: 1fr; } }

.panel-title { margin: 0 0 10px; font-size: 15px; font-weight: 800; }
.player-list, .queue-list, .log-list { list-style: none; margin: 0; padding: 0; }
.player-list li, .queue-list li {
  padding: 8px 10px; border-radius: 10px; margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.04); font-size: 13px;
}
.log-list { max-height: 160px; overflow: auto; font-size: 12px; color: #9ca3af; }
.log-list li { padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }

.settings-grid { display: grid; gap: 10px; margin-bottom: 12px; }
.upload-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.field-label { font-size: 13px; color: #d1d5db; display: block; margin-bottom: 6px; }
.host-upload-block { margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.08); }
.hint-tight { margin: 8px 0 0; }

.library-pick {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.library-card {
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 14px 12px;
  background: rgba(255,255,255,0.04);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s;
  font-family: inherit;
  color: inherit;
}
.library-card:hover:not(:disabled) { border-color: #60a5fa; }
.library-card:disabled { opacity: 0.45; cursor: not-allowed; }
.library-card strong { display: block; font-size: 14px; margin-bottom: 4px; }
.library-card span { font-size: 11px; color: #9ca3af; }
.host-picker-back { margin-top: 10px; }
.host-picker-search {
  width: 100%;
  margin-top: 10px;
  box-sizing: border-box;
}
.picker-item img.lazy-img {
  background: rgba(255,255,255,0.06);
  min-height: 72px;
}

.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  margin-top: 10px;
  max-height: 280px;
  overflow: auto;
}
.picker-item {
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 6px;
  background: rgba(255,255,255,0.04);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, opacity 0.15s;
}
.picker-item:hover:not(.is-used):not(:disabled) {
  border-color: #60a5fa;
}
.picker-item.is-used {
  opacity: 0.35;
  cursor: not-allowed;
}
.picker-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}
.picker-item span {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  color: #9ca3af;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-boards {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
}
.live-board {
  flex: 1 1 140px;
  max-width: 220px;
  min-width: 120px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
}
.live-board-name {
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 8px;
}
.live-board-slots {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.live-board-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.live-board-row .rank-num {
  width: 20px;
  color: #93c5fd;
  font-weight: 800;
  flex-shrink: 0;
}
.live-board-row img {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
}

.action-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 10001;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.96);
  border: 1px solid rgba(255,255,255,0.14);
  color: #f9fafb;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.action-toast.is-ok { border-color: rgba(52, 211, 153, 0.45); }
.action-toast.is-wrong { border-color: rgba(248, 113, 113, 0.45); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 10002;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.55);
}
.modal[hidden] { display: none; }
.modal-panel {
  width: min(360px, 100%);
  padding: 18px;
  border-radius: 14px;
  background: #111827;
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.modal-title { margin: 0 0 12px; font-size: 16px; font-weight: 800; }
.upload-preview {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  margin-bottom: 12px;
}
.sort-timer {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 700;
  color: #fbbf24;
}
.sort-timer[hidden] { display: none; }

.thumb-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.thumb {
  width: 72px;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.03);
}
.thumb img { width: 100%; height: 56px; object-fit: cover; display: block; }
.thumb-name {
  display: block;
  padding: 4px 6px;
  font-size: 10px;
  color: #d1d5db;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thumb button {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border: 0; border-radius: 50%;
  background: rgba(0,0,0,0.65); color: #fff; font-size: 11px; cursor: pointer;
}

.play-layout {
  display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); gap: 16px;
}
@media (max-width: 720px) { .play-layout { grid-template-columns: 1fr; } }

.current-card {
  min-height: 280px; border-radius: 16px; padding: 12px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.1);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  cursor: grab;
}
.current-card.is-dragging { opacity: 0.55; cursor: grabbing; }
.current-card img { max-width: 100%; max-height: 220px; border-radius: 12px; pointer-events: none; }
.card-name { font-size: 15px; font-weight: 800; text-align: center; }
.current-card.placeholder { color: #6b7280; font-size: 14px; cursor: default; }

.slot-list { display: flex; flex-direction: column; gap: 8px; }
.rank-slot {
  display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 10px; align-items: center;
  min-height: 64px; padding: 8px 10px; border-radius: 12px;
  background: rgba(255,255,255,0.03); border: 1px dashed rgba(255,255,255,0.14);
  transition: border-color 0.15s, background 0.15s;
}
.rank-slot.is-over { border-color: #60a5fa; background: rgba(96,165,250,0.12); }
.rank-slot.is-pending { border-color: #fbbf24; background: rgba(251,191,36,0.14); border-style: solid; }
.rank-slot.filled { border-style: solid; border-color: rgba(255,255,255,0.12); }
.rank-slot.is-locked { opacity: 0.72; pointer-events: none; }
.rank-label { font-size: 13px; font-weight: 800; color: #93c5fd; text-align: center; }
.slot-card { display: flex; align-items: center; gap: 10px; min-width: 0; }
.slot-card img { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.slot-card span { font-size: 14px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-empty { color: #6b7280; font-size: 13px; cursor: pointer; }
.slot-empty:hover { color: #93c5fd; }

.progress-bar {
  height: 6px; border-radius: 999px; background: rgba(255,255,255,0.08); overflow: hidden; margin-top: 8px;
}
.progress-fill { height: 100%; background: linear-gradient(90deg, #2563eb, #60a5fa); width: 0; transition: width 0.2s; }

.scoring-panel { text-align: center; }
.scoring-label { font-size: 22px; font-weight: 900; margin-bottom: 6px; }
.scoring-timer { font-size: 14px; color: #fbbf24; margin-bottom: 16px; }
.scoring-list {
  display: flex; flex-direction: column; gap: 8px; max-width: 420px; margin: 0 auto 18px; text-align: left;
}
.scoring-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  background: rgba(255,255,255,0.04);
}
.scoring-item img { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; }
.score-slider { width: min(360px, 100%); margin: 12px auto; display: block; }
.score-value { font-size: 28px; font-weight: 900; color: #fbbf24; }

.result-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.result-table th, .result-table td {
  padding: 10px 8px; border-bottom: 1px solid rgba(255,255,255,0.08); text-align: left;
}

.others-progress { margin-top: 12px; font-size: 13px; color: #9ca3af; }
