:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1a2030;
  --border: #30363d;
  --border-light: #21262d;
  --text: #e6edf3;
  --text-dim: #c9d1d9;
  --text-mute: #8b949e;
  --accent: #1f6feb;
  --accent-hover: #388bfd;
  --good: #39d353;
  --warn: #d2991b;
  --bad: #f85149;
  --gold: #d2991b;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  --radius: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei UI", "Segoe UI", "PingFang SC", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button, input, select {
  font: inherit;
  outline: none;
}

button {
  border: 0;
  cursor: pointer;
  transition: all 0.15s ease;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #484f58;
}

/* Layout */
.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

/* ── Left sidebar ── */
.map-pane {
  border-right: 1px solid var(--border-light);
  background: #0a0e14;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pane-head h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.pane-head p {
  font-size: 12px;
  color: var(--text-mute);
  margin-top: 3px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent);
  font-size: 18px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-button:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.search-row input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  font-size: 13px;
  transition: border-color 0.15s;
}

.search-row input:focus {
  border-color: var(--accent);
}

.search-row input::placeholder {
  color: var(--text-mute);
}

.map-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  flex: 1;
}

.map-item {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--surface-2);
  cursor: pointer;
  transition: all 0.12s ease;
  text-align: left;
}

.map-item:hover {
  border-color: var(--border);
  background: var(--surface);
}

.map-item.active {
  border-color: var(--accent);
  background: rgba(31, 111, 235, 0.08);
}

.map-item.active:hover {
  border-color: var(--accent);
}

.map-thumb {
  width: 44px;
  height: 44px;
  border-radius: 5px;
  object-fit: cover;
  background: var(--surface);
}

.map-item strong {
  display: block;
  font-size: 13px;
  color: var(--text);
}

.map-item span {
  display: block;
  color: var(--text-mute);
  font-size: 11px;
  margin-top: 2px;
}

/* ── Main area ── */
.room-pane {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

h1, h2, h3, p {
  margin: 0;
}

/* ── Map summary ── */
.map-summary {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

.preview-wrap {
  aspect-ratio: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.preview-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.summary-main {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.summary-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.summary-top h2 {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}

.summary-top p {
  color: var(--text-mute);
  font-size: 12px;
  margin-top: 3px;
}

.badge {
  min-width: 68px;
  text-align: center;
  border-radius: 999px;
  padding: 5px 12px;
  background: var(--surface-2);
  color: var(--text-mute);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.on {
  background: rgba(57, 211, 83, 0.12);
  color: var(--good);
}

.description {
  line-height: 1.55;
  color: var(--text-dim);
  font-size: 13px;
}

/* ── Controls grid ── */
.control-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.05fr) minmax(340px, 0.95fr);
  gap: 16px;
}

.form-panel, .players-panel, .log-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.form-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--text-mute);
  font-size: 12px;
  font-weight: 500;
}

label input, label select, .player-select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0d1117;
  color: var(--text);
  padding: 0 10px;
  font-size: 13px;
  transition: border-color 0.15s;
}

label input:focus, label select:focus, .player-select:focus {
  border-color: var(--accent);
}

label input::placeholder {
  color: var(--text-mute);
}

label select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b949e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
}

/* ── Buttons ── */
.primary-button, .secondary-button, .danger-button, .join-button {
  min-height: 40px;
  border-radius: 6px;
  padding: 0 16px;
  font-weight: 600;
  font-size: 13px;
}

.primary-button {
  background: #238636;
  color: #fff;
  border: 1px solid #2ea043;
}

.primary-button:hover {
  background: #2ea043;
}

.primary-button:active {
  background: #196c2e;
}

.secondary-button {
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.secondary-button:hover {
  background: var(--border);
  color: var(--text);
}

.danger-button {
  background: rgba(248, 81, 73, 0.1);
  color: var(--bad);
  border: 1px solid rgba(248, 81, 73, 0.3);
}

.danger-button:hover {
  background: var(--bad);
  color: #fff;
}

.join-button {
  background: rgba(31, 111, 235, 0.1);
  color: var(--accent);
  border: 1px solid rgba(31, 111, 235, 0.3);
}

.join-button:hover {
  background: var(--accent);
  color: #fff;
}

.primary-button:disabled, .join-button:disabled {
  background: var(--surface-2);
  color: #484f58;
  border-color: transparent;
  cursor: not-allowed;
}

/* ── Players panel ── */
.players-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.slot-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-slots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 6px;
  max-height: 200px;
  overflow: auto;
  padding: 2px 0;
}

.map-slot {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 7px;
  align-items: center;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  background: #0d1117;
}

.map-slot.fixed {
  background: rgba(210, 153, 27, 0.06);
  border-color: rgba(210, 153, 27, 0.3);
}

.map-slot.controlled {
  border-color: var(--accent);
  background: rgba(31, 111, 235, 0.06);
}

.slot-index {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  font-size: 11px;
}

.slot-detail {
  min-width: 0;
}

.slot-detail strong, .slot-detail small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-detail strong {
  font-size: 12px;
  color: var(--text);
}

.slot-detail small {
  color: var(--text-mute);
  font-size: 11px;
  margin-top: 1px;
}

.slot-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) minmax(140px, 170px) 70px;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #0d1117;
}

.slot-row.joined {
  border-color: var(--accent);
  background: rgba(31, 111, 235, 0.06);
}

.slot-row.playable {
  border-color: var(--border);
}

.slot-no {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
}

.slot-info {
  min-width: 0;
}

.slot-info strong, .slot-info span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-info strong {
  font-size: 13px;
}

.player-select {
  min-width: 0;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.action-row button {
  flex: 1;
}

/* ── Log panel ── */
.log-panel {
  min-height: 180px;
  display: flex;
  flex-direction: column;
}

.status-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-actions .secondary-button {
  min-height: 32px;
  font-size: 12px;
  padding: 0 10px;
}

.events {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 240px;
  overflow: auto;
  font-family: Consolas, "Cascadia Code", "Microsoft YaHei UI", monospace;
  font-size: 12px;
  flex: 1;
}

.event-line {
  display: grid;
  grid-template-columns: 125px 1fr;
  gap: 8px;
  border-bottom: 1px solid var(--border-light);
  padding: 5px 0;
}

.event-line .time {
  color: var(--text-mute);
}

.event-line.warn .msg {
  color: var(--warn);
}

.event-line.error .msg {
  color: var(--bad);
}

/* ── Responsive ── */
@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .map-pane {
    max-height: 340px;
    border-right: 0;
    border-bottom: 1px solid var(--border-light);
  }

  .map-summary, .control-grid {
    grid-template-columns: 1fr;
  }
}
