html { font-size: 150%; }

:root {
  --bg: #17181c;
  --panel: #1f2126;
  --panel-2: #26282f;
  --border: #34363d;
  --text: #e8e9ec;
  --text-dim: #9a9ca3;
  --accent: #5b8def;
  --green: #4caf6d;
  --red: #e0554f;
  --yellow: #d8a13a;
  --mono: 'Consolas', 'SFMono-Regular', Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  padding-bottom: 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 1.05rem; margin: 0; }
.panel-label { color: var(--accent); font-weight: 600; }

.badge {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
}
.badge-active { background: rgba(76,175,109,0.18); color: var(--green); }
.badge-inactive { background: rgba(224,85,79,0.18); color: var(--red); }
.badge-unknown { background: rgba(154,156,163,0.18); color: var(--text-dim); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px 0;
  overflow-x: auto;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 10px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

main { max-width: 720px; margin: 0 auto; padding: 16px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { font-size: 1rem; margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }

.hint { color: var(--text-dim); font-size: 0.82rem; margin: -4px 0 12px; }

.status-detail { font-size: 0.88rem; color: var(--text-dim); margin-bottom: 12px; line-height: 1.6; }

.player-list { display: flex; flex-direction: column; gap: 6px; }
.player-empty { color: var(--text-dim); font-size: 0.85rem; }
.player-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
}
.player-name { font-weight: 600; flex-shrink: 0; }
.player-name::before { content: '🟢 '; font-size: 0.7rem; }
.player-coords { color: var(--text-dim); font-family: var(--mono); font-size: 0.78rem; white-space: nowrap; margin-right: auto; }
.player-coords.pending { font-style: italic; }
.player-save-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  flex-shrink: 0;
}
.player-save-btn:hover { border-color: var(--accent); }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.btn-row-sticky {
  position: sticky;
  bottom: 0;
  background: var(--panel);
  padding: 10px 0 4px;
  margin-top: 0;
  border-top: 1px solid var(--border);
  z-index: 5;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  color: #0e0f11;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-green { background: var(--green); }
.btn-red { background: var(--red); color: #fff; }
.btn-yellow { background: var(--yellow); }
.btn-blue { background: var(--accent); color: #fff; }
.btn-active-engine { outline: 2px solid var(--green); }

.connection-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 0.9rem; }
.connection-label { color: var(--text-dim); }
.connection-value { font-family: var(--mono); letter-spacing: 1px; }

.card-danger { border-color: var(--red); }
.card-danger h2 { color: var(--red); }
.card-danger code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); font-size: 0.85em; }
.card-danger input[type=text] { width: 100%; margin-bottom: 10px; }

.save-msg { font-size: 0.82rem; color: var(--green); }
.save-msg.error { color: var(--red); }

.console-log {
  background: #0c0d10;
  border: 1px solid var(--border);
  border-radius: 8px;
  height: 320px;
  overflow-y: auto;
  padding: 10px;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}

.command-form { display: flex; gap: 8px; margin-top: 10px; }
.command-form input {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
}

input[type=text], select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.88rem;
}

.prop-form { display: flex; flex-direction: column; gap: 10px; }

.prop-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 12px;
  background: var(--panel-2);
}
.prop-section summary {
  cursor: pointer;
  padding: 10px 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  list-style: none;
}
.prop-section summary::-webkit-details-marker { display: none; }
.prop-section summary::before { content: '▸ '; color: var(--text-dim); }
.prop-section[open] summary::before { content: '▾ '; }
.prop-section-grid {
  display: flex;
  flex-direction: column;
  padding-bottom: 4px;
}

.prop-field {
  display: grid;
  grid-template-columns: minmax(140px, 260px) 1fr;
  column-gap: 20px;
  row-gap: 6px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.prop-field:last-child { border-bottom: none; }
.prop-field label { font-size: 0.9rem; color: var(--text); font-weight: 600; }
.prop-field input, .prop-field select { width: 100%; }
.prop-field .bool-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.prop-field.bool .bool-row label { color: var(--text); flex: 1; }
.prop-field.bool .bool-row input { width: auto; flex: 0 0 auto; transform: scale(1.3); }
.field-desc { grid-column: 1 / -1; font-size: 0.78rem; color: var(--text-dim); line-height: 1.6; }

@media (max-width: 640px) {
  .prop-field { grid-template-columns: 1fr; row-gap: 8px; }
}

.raw-editor {
  width: 100%;
  height: 360px;
  font-family: var(--mono);
  font-size: 0.78rem;
  resize: vertical;
  line-height: 1.5;
}

.entry-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.entry-table th, .entry-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.entry-table th { color: var(--text-dim); font-weight: 500; }
.entry-table button {
  background: none;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 0.82rem;
}
.entry-table td.mono { font-family: var(--mono); font-size: 0.78rem; color: var(--text-dim); }

.history-badge { font-size: 0.78rem; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.history-connect { background: rgba(76,175,109,0.18); color: var(--green); }
.history-disconnect { background: rgba(224,85,79,0.18); color: var(--red); }

.waypoint-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.waypoint-form #wpLabelInput { flex: 2 1 140px; }
.waypoint-form #wpXInput,
.waypoint-form #wpYInput,
.waypoint-form #wpZInput { flex: 1 1 60px; min-width: 0; }
.waypoint-form #wpDimensionInput { flex: 1 1 120px; }
.waypoint-form #wpNoteInput { flex: 2 1 140px; }
.waypoint-form #btnAddWaypoint { flex: 0 0 auto; }

@media (max-width: 480px) {
  .topbar h1 { font-size: 0.92rem; }
  .command-form { flex-direction: column; }
  .waypoint-form #wpLabelInput,
  .waypoint-form #wpNoteInput,
  .waypoint-form #btnAddWaypoint { flex-basis: 100%; }
  .player-coords { white-space: normal; flex-basis: 100%; margin-right: 0; }
}
