:root {
  color-scheme: dark;
  --bg: #12140f;
  --panel: #1b2016;
  --ink: #f6f8f1;
  --muted: #b7c2a8;
  --line: #343b2b;
  --accent: #dff25a;
  --accent-ink: #1c2208;
  --danger: #ff8d8d;
  --good: #b6f27a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Malgun Gothic", sans-serif;
}

button, input, textarea, select { font: inherit; }

.shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}

aside {
  background: #171b12;
  border-right: 1px solid var(--line);
  padding: 22px 14px;
}

.brand {
  margin: 0 8px 18px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.05em;
}

.brand span { color: var(--accent); }

.brand small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
}

nav button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: inherit;
  border: 0;
  border-left: 3px solid transparent;
  padding: 10px 12px;
  margin: 2px 0;
  cursor: pointer;
}

nav button.on {
  border-left-color: var(--accent);
  background: #262c1c;
}

#logout {
  width: calc(100% - 16px);
  margin: 18px 8px 0;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login form {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 24px;
}

main { min-width: 0; padding: 28px 32px 72px; }

.panel { display: none; max-width: 980px; min-width: 0; }
.panel.on { display: block; }

h1 { margin: 0 0 8px; font-size: 24px; }
h2 { margin: 22px 0 8px; font-size: 16px; }
p { line-height: 1.55; }

.muted { color: var(--muted); }
.good { color: var(--good); }
.bad { color: var(--danger); }
.mono { font-family: Consolas, "Malgun Gothic", monospace; }

.status {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 16px 0;
}

label { display: block; margin: 14px 0 6px; color: #d7decc; font-size: 13px; }

input, textarea, select {
  width: 100%;
  background: #0e100c;
  color: var(--ink);
  border: 1px solid #3c4332;
  border-radius: 8px;
  padding: 10px 12px;
}

textarea { min-height: 84px; resize: vertical; }

.row, .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions { margin-top: 14px; }

button.primary, button.ghost, button.tiny {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 10px 16px; }
button.ghost { background: #2a3122; color: var(--ink); padding: 10px 16px; }
button.ghost.on { background: var(--accent); color: var(--accent-ink); }
button.tiny { background: transparent; color: var(--muted); padding: 4px 8px; }
button.linkish {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

dialog {
  width: min(720px, calc(100vw - 32px));
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog h2 { margin: 0 0 8px; }
dialog .card { margin-top: 8px; }
table.memos col.who { width: 7rem; }
table.memos col.when { width: 9.5rem; }
table.memos col.act { width: 4.5rem; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-top: 14px;
  min-width: 0;
}

table { width: 100%; border-collapse: collapse; }
.card table { table-layout: fixed; }
th, td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
table.commands col.name { width: 7.5rem; }
table.commands col.perm { width: 6.5rem; }
table.commands col.act { width: 7.6rem; }
table.commands.trash col.act { width: 12rem; }
table.commands th:nth-child(1),
table.commands td:nth-child(1),
table.commands th:nth-child(3),
table.commands td:nth-child(3),
table.commands th:nth-child(4),
table.commands td:nth-child(4) {
  white-space: nowrap;
  overflow-wrap: normal;
}
table.commands td:nth-child(4) button { white-space: nowrap; }
table.commands.songs th:nth-child(1),
table.commands.songs td:nth-child(1) { width: 4.2rem; }
table.commands.songs th:nth-child(2),
table.commands.songs td:nth-child(2) { width: 6.5rem; }
table.commands.songs th:nth-child(5),
table.commands.songs td:nth-child(5) { width: 4.2rem; white-space: nowrap; }
table.commands.songs th:nth-child(3),
table.commands.songs td:nth-child(3),
table.commands.songs th:nth-child(4),
table.commands.songs td:nth-child(4) {
  white-space: normal;
  overflow-wrap: anywhere;
}
table.playlist-log td:nth-child(1),
table.playlist-log td:nth-child(2) { white-space: normal; overflow-wrap: anywhere; }
table.playlist-log input.nick { width: 8rem; max-width: 100%; padding: 4px 6px; }
table.playlist-log td:nth-child(4) { white-space: nowrap; }
.days { display: flex; align-items: center; gap: 8px; margin: 8px 0 12px; }
.days select, .days button { height: 34px; }
table.builtins col.use { width: 3.2rem; }
table.builtins col.name { width: 9rem; }
table.builtins col.about { width: auto; }
table.builtins col.perm { width: 6rem; }
table.builtins col.cool { width: 6.5rem; }
table.builtins input.cool { width: 100%; min-width: 0; padding: 4px 6px; }
table.builtins th,
table.builtins td { white-space: nowrap; overflow-wrap: normal; }
table.builtins td:nth-child(4) { white-space: normal; }
table.aliases col.alias { width: 10rem; }
table.aliases col.target { width: 10rem; }
table.aliases col.act { width: 8rem; }
table.aliases th,
table.aliases td { white-space: nowrap; overflow-wrap: normal; }
table.aliases td:nth-child(3) button { white-space: nowrap; }

.current {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}

.current label { margin: 0; white-space: nowrap; }
.current select { max-width: 420px; }

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

.channel-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.channel-card.on { border-color: var(--accent); }
.channel-card h2 { margin: 0 0 4px; }

#flash { min-height: 1.4em; }

.chat-preview { margin-top: 12px; }
.chat-preview > .muted { margin: 8px 0; }
.chat-log {
  display: grid;
  gap: 8px;
  max-width: 440px;
}
.chat-line {
  background: #12160e;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
}
.chat-line.mine { margin-left: 48px; border-color: #4d5a32; }
.chat-line.bot { margin-right: 28px; }
.chat-head { display: flex; gap: 8px; align-items: baseline; }
.chat-line strong { font-size: 13px; }
.chat-line.bot strong { color: var(--accent); }
.chat-head span { color: var(--muted); font-size: 12px; }
.chat-line p { margin: 4px 0 0; overflow-wrap: anywhere; line-height: 1.45; }
pre.log {
  white-space: pre-wrap;
  background: #0e100c;
  border-radius: 12px;
  padding: 12px;
  max-height: 520px;
  overflow: auto;
}
pre.log .when {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 14px 0;
}
.stats div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}
.stats span { display: block; color: var(--muted); font-size: 13px; }
.stats strong { display: block; margin-top: 4px; font-size: 22px; }
.stats strong.words { font-size: 18px; line-height: 1.35; }
.stats strong.on { color: var(--good); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; min-height: 36px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: #12160e;
  border-radius: 999px;
  padding: 6px 8px 6px 12px;
}
.help { margin: 0 0 12px; padding-left: 18px; }
.help li { margin: 6px 0; }
.help code { color: var(--accent); }

.overlay-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}
.overlay-card h2 { margin: 0 0 4px; }
.overlay-card p { margin: 0 0 8px; }
.overlay-preview {
  height: 210px;
  border-radius: 12px;
  overflow: hidden;
  background: #141810;
  border: 1px solid var(--line);
}
.overlay-preview iframe { width: 100%; height: 100%; border: 0; background: transparent; color-scheme: normal; }
.overlay-preview.clear { background: transparent; }
.overlay-link { display: block; margin-top: 8px; overflow-wrap: anywhere; font-size: 13px; color: var(--accent); }
.overlay-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.overlay-fields label { margin: 0; font-size: 12px; }
.overlay-fields select, .overlay-fields input { padding: 6px 8px; }
#matchClock { font-size: 18px; font-weight: 800; }
#matchDialog { width: min(760px, calc(100vw - 32px)); }
#matchList { max-height: min(60vh, 520px); overflow: auto; margin-top: 8px; }
#matchList .actions { justify-content: space-between; align-items: center; gap: 12px; }
#matchList .actions span { min-width: 0; }

.check { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.check input, input.tick { width: auto; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  aside { border-right: 0; border-bottom: 1px solid var(--line); }
  nav { display: flex; gap: 6px; overflow: auto; }
  nav button { width: auto; border-left: 0; border-bottom: 3px solid transparent; }
  nav button.on { border-bottom-color: var(--accent); }
  .stats { grid-template-columns: repeat(2, 1fr); }
  main { padding: 18px 14px 48px; }
  .grid { grid-template-columns: 1fr; }
  .overlay-board { grid-template-columns: 1fr; }
}
