:root {
  --bg: #0e0e10;
  --card: #18181b;
  --border: #2a2a31;
  --text: #ffffff;
  --muted: #b3b3b8;
  --accent: #9147ff;
  --gap: 10px;
  --label-bg: rgba(0, 0, 0, 0.72);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.content-layout {
  flex: 1;
  min-height: 0;
  display: flex;
}

.topbar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: #111114;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.title {
  font-size: 18px;
  font-weight: 700;
}

.hint {
  font-size: 13px;
  color: var(--muted);
}

.topbar-buttons {
  display: flex;
  gap: 8px;
}

.grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: var(--gap);
  padding: var(--gap);
  min-height: 0;
  min-width: 0;
}

.tile {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  min-height: 300px;
}

.player {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #000;
}

.label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 2;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--label-bg);
  border: 1px solid rgba(255,255,255,0.1);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.empty {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  padding: 20px;
  font-size: 14px;
}

@media (max-width: 1400px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(4, 1fr);
  }
}

@media (max-width: 900px) {
  .grid {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(8, 40vh);
  }
}

.config-btn,
.share-btn,
.chat-btn,
.tech-btn {
  padding: 8px 16px;
  background: var(--accent);
  color: var(--text);
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.config-btn:hover,
.share-btn:hover,
.chat-btn:hover,
.tech-btn:hover {
  background: #7c3aed;
}

.tech-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.chat-panel {
  width: 0;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
  background: #111114;
  border-left: 1px solid transparent;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.25s ease, opacity 0.2s ease, border-color 0.2s ease;
}

body.chat-open .chat-panel {
  width: 380px;
  opacity: 1;
  pointer-events: auto;
  border-left-color: var(--border);
}

.chat-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chat-header-main {
  min-width: 0;
  flex: 1;
}

.chat-title {
  font-size: 15px;
  font-weight: 700;
}

.chat-status {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.chat-filter {
  margin-top: 8px;
  width: 100%;
}

.chat-filter-summary {
  list-style: none;
  cursor: pointer;
  border: 1px solid #34343d;
  border-radius: 8px;
  background: #17171c;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  user-select: none;
}

.chat-filter-summary::-webkit-details-marker {
  display: none;
}

.chat-filter-summary::after {
  content: "▾";
  float: right;
  color: var(--muted);
}

.chat-filter[open] .chat-filter-summary::after {
  content: "▴";
}

.chat-filter-options {
  margin-top: 6px;
  max-height: 150px;
  overflow-y: auto;
  border: 1px solid #2d2d36;
  border-radius: 8px;
  background: #141419;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-filter-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
  padding: 4px 2px;
}

.chat-filter-option input {
  margin: 0;
}

.chat-filter-empty {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 2px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-line {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid #26262f;
  background: #17171c;
}

.chat-line[hidden] {
  display: none !important;
}

.chat-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  background: #2e2e36;
  flex-shrink: 0;
}

.chat-content {
  min-width: 0;
}

.chat-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
  font-size: 12px;
}

.chat-channel {
  color: #8aa3ff;
  font-weight: 700;
}

.chat-user {
  font-weight: 700;
}

.chat-text {
  font-size: 14px;
  line-height: 1.35;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 1200px) {
  .chat-panel {
    width: min(380px, calc(100vw - 24px));
    position: fixed;
    top: 72px;
    right: 12px;
    bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    transform: translateX(calc(100% + 20px));
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
    transition: transform 0.25s ease, opacity 0.2s ease;
    z-index: 900;
  }

  body.chat-open .chat-panel {
    width: min(380px, calc(100vw - 24px));
    transform: translateX(0);
  }
}

.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s, color 0.2s;
}

.close-btn:hover {
  background: var(--border);
  color: var(--text);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.input-group input {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
}

.input-group input:focus {
  outline: none;
  border-color: var(--accent);
}

.remove-btn {
  background: #53212b;
  border: 1px solid #9b3b4d;
  color: #ff6b81;
  border-radius: 6px;
  width: 36px;
  cursor: pointer;
  font-size: 18px;
  transition: background 0.2s;
}

.remove-btn:hover {
  background: #6b2737;
}

.add-btn {
  width: 100%;
  padding: 10px;
  background: var(--bg);
  border: 1px dashed var(--border);
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: border-color 0.2s, color 0.2s;
}

.add-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.modal-footer {
  padding: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.save-btn {
  padding: 10px 24px;
  background: var(--accent);
  color: var(--text);
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.save-btn:hover {
  background: #7c3aed;
}
