/* Backchannel: a classic early-2000s Windows voice-chat look. */
:root {
  --face: #d4d0c8;
  --light: #ffffff;
  --mid: #808080;
  --dark: #404040;
  --navy: #0a246a;
  --sky: #a6caf0;
  --text: #000000;
  --muted-text: #555555;
  --desk: #3a6ea5;
  --lamp-off: #2f3a2f;
  --lamp-on: #39ff14;
  font: 12px Tahoma, "Segoe UI", Verdana, Geneva, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--desk);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

/* ---- raised / sunken bevels ---- */
.window, button, .menu, dialog {
  background: var(--face);
  border: 2px solid;
  border-color: var(--light) var(--dark) var(--dark) var(--light);
  box-shadow: inset -1px -1px 0 var(--mid), inset 1px 1px 0 #dfdfdf;
}
.sunken, input:not([type=range]):not([type=radio]):not([type=checkbox]) {
  background: #fff;
  border: 2px solid;
  border-color: var(--mid) var(--light) var(--light) var(--mid);
  box-shadow: inset 1px 1px 0 var(--dark), inset -1px -1px 0 #dfdfdf;
}

.window {
  width: min(860px, 100%);
  height: min(620px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  padding: 3px;
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 6px;
  color: #fff;
  font-weight: bold;
  background: linear-gradient(90deg, var(--navy), var(--sky));
  user-select: none;
}
.app-icon {
  width: 14px; height: 14px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 6h3l4-4v12l-4-4H2z' fill='%23fff'/%3E%3Cpath d='M11 5a4 4 0 0 1 0 6M12.5 3a7 7 0 0 1 0 10' stroke='%237CFC00' fill='none' stroke-width='1.5'/%3E%3C/svg%3E") center/contain no-repeat;
}
.title-status { margin-left: auto; font-weight: normal; font-size: 11px; opacity: .9; }

.toolbar {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 8px 6px 6px;
  border-bottom: 1px solid var(--mid);
  box-shadow: 0 1px 0 var(--light);
}
.toolbar .field { flex: 0 1 200px; }
.toolbar-buttons { display: flex; flex-wrap: wrap; gap: 6px; }

.field { display: flex; flex-direction: column; gap: 3px; }
input { font: inherit; color: var(--text); padding: 3px 4px; min-width: 0; }
input:focus-visible { outline: 1px dotted #000; outline-offset: -4px; }

button {
  font: inherit;
  color: var(--text);
  min-height: 23px;
  padding: 2px 12px;
  cursor: pointer;
}
button:active:not(:disabled), button.pressed {
  border-color: var(--dark) var(--light) var(--light) var(--dark);
  box-shadow: inset 1px 1px 0 var(--mid);
  padding: 3px 11px 1px 13px;
}
button:disabled { color: var(--mid); text-shadow: 1px 1px 0 var(--light); cursor: default; }
button:focus-visible { outline: 1px dotted #000; outline-offset: -5px; }
button.default { outline: 1px solid #000; }

.main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 8px;
  padding: 8px 6px;
}
.pane { display: flex; flex-direction: column; min-height: 0; gap: 4px; }
.pane-label { font-weight: bold; }
.hint { color: var(--muted-text); font-size: 11px; }

/* ---- channel tree ---- */
.tree {
  flex: 1;
  overflow: auto;
  padding: 4px 2px;
  user-select: none;
}
.row {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 19px;
  padding: 0 4px;
  white-space: nowrap;
  position: relative;
}
.row .label { overflow: hidden; text-overflow: ellipsis; }
.row .count { color: var(--muted-text); font-size: 11px; }
.row.server { font-weight: bold; }
.row.channel { padding-left: 20px; cursor: pointer; }
.row.channel.here { cursor: default; }
.row.channel:hover:not(.here) .label { text-decoration: underline; }
.row.channel:focus-visible { outline: 1px dotted #000; outline-offset: -1px; }
.row.channel.here .label { background: var(--navy); color: #fff; padding: 0 3px; margin: 0 -3px; }
.row.user { padding-left: 40px; }
.row.user.clickable { cursor: pointer; }
.row.user.clickable:hover .label { text-decoration: underline; }
.row.user.me .label { font-weight: bold; }

/* dotted tree connectors */
.row.channel::before, .row.user::before {
  content: "";
  position: absolute;
  top: 50%;
  width: 9px;
  border-top: 1px dotted var(--mid);
}
.row.channel::before { left: 9px; }
.row.user::before { left: 28px; }
/* vertical trunks: .trunk-a is the server's line down past channels, .trunk-line a channel's line past its users */
.row.trunk-a::after, .row > .trunk-line {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  border-left: 1px dotted var(--mid);
}
.row.trunk-a::after { left: 9px; }
.row.trunk-a.end::after { bottom: 50%; }
.row > .trunk-line { left: 28px; }
.row > .trunk-line.end { bottom: 50%; }

.icon { width: 14px; height: 14px; flex: none; background: center/contain no-repeat; }
.icon.server { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect x='1' y='2' width='14' height='9' fill='%23c0c0c0' stroke='%23000'/%3E%3Crect x='3' y='4' width='10' height='5' fill='%23008080'/%3E%3Cpath d='M5 13h6v1.5H5z' fill='%23000'/%3E%3C/svg%3E"); }
.icon.channel { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M1 4h5l1.5 1.5H15V14H1z' fill='%23f6d365' stroke='%23806000'/%3E%3C/svg%3E"); }
.icon.private { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 7V5a3.5 3.5 0 0 1 7 0v2' stroke='%23000' fill='none' stroke-width='1.5'/%3E%3Crect x='2.5' y='7' width='11' height='8' fill='%23e8b923' stroke='%23705000'/%3E%3C/svg%3E"); }

.lamp {
  width: 10px; height: 10px;
  flex: none;
  border-radius: 50%;
  background: var(--lamp-off);
  border: 1px solid #000;
  box-shadow: inset 1px 1px 0 rgba(255,255,255,.25);
}
.lamp.on { background: var(--lamp-on); box-shadow: 0 0 5px var(--lamp-on), inset 1px 1px 0 rgba(255,255,255,.6); }
.lamp.connecting { background: #c9a227; }
.flag {
  font-size: 9px;
  font-weight: bold;
  line-height: 11px;
  padding: 0 2px;
  border: 1px solid;
}
.flag.muted { color: #b00000; border-color: #b00000; }
.flag.deaf { color: #fff; background: #b00000; border-color: #b00000; }
.flag.host { color: #806000; border-color: #806000; }
.flag.you { color: var(--muted-text); border: 0; font-weight: normal; }

/* ---- side pane ---- */
fieldset.group {
  margin: 0;
  padding: 6px 8px 8px;
  border: 1px solid var(--mid);
  box-shadow: 1px 1px 0 var(--light), inset 1px 1px 0 var(--light);
  display: flex;
  flex-direction: column;
  gap: 7px;
}
legend { padding: 0 3px; }
.mode-row, .check-row { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
.ptt-row, .va-row { display: flex; align-items: center; gap: 8px; }
.ptt-row[hidden], .va-row[hidden], .talk[hidden] { display: none; }
.small { color: var(--muted-text); font-size: 11px; }
.bind { min-width: 70px; font-weight: bold; }
.bind.listening { font-weight: normal; font-style: italic; }
.vol { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.vol input { width: 90px; }
input[type=range] { accent-color: var(--navy); }
label:has(input[type=radio]), label:has(input[type=checkbox]) { display: inline-flex; align-items: center; gap: 3px; cursor: pointer; }

.meter { position: relative; flex: 1; height: 14px; overflow: hidden; }
.meter-fill {
  position: absolute; inset: 0 auto 0 0; width: 0;
  background: repeating-linear-gradient(90deg, #108010 0 6px, transparent 6px 8px);
}
.meter.open .meter-fill { background: repeating-linear-gradient(90deg, #20c020 0 6px, transparent 6px 8px); }
.meter-mark { position: absolute; top: 0; bottom: 0; width: 2px; background: #c00000; }
.va-row input[type=range] { width: 90px; }

.talk { min-height: 34px; font-weight: bold; touch-action: none; }
.talk.pressed { background: #b8e0b8; }

.chat { flex: 1; min-height: 0; }
.chatlog {
  flex: 1;
  min-height: 60px;
  overflow-y: auto;
  padding: 3px 5px;
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.chatlog .sys { color: #666; font-style: italic; }
.chatlog .time { color: #888; }
.chatlog .who { font-weight: bold; color: var(--navy); }
.chatlog .who.me { color: #006000; }
.chat-form { display: flex; gap: 4px; }
.chat-form input { flex: 1; }

/* ---- status bar ---- */
.statusbar { display: flex; gap: 3px; padding-top: 3px; }
.sb-cell {
  padding: 2px 5px;
  min-height: 19px;
  border: 1px solid;
  border-color: var(--mid) var(--light) var(--light) var(--mid);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-cell.grow { flex: 1; }
button.mic-status {
  box-shadow: none;
  background: var(--face);
  color: #900;
  min-height: 19px;
}
button.mic-status:active { padding: 2px 5px; }

/* ---- dialogs, menu, toast ---- */
dialog { padding: 3px; min-width: 300px; max-width: calc(100vw - 32px); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .25); }
.dlg-title {
  color: #fff; font-weight: bold;
  padding: 3px 6px;
  background: linear-gradient(90deg, var(--navy), var(--sky));
}
.dlg-body { padding: 10px 10px 4px; display: flex; flex-direction: column; gap: 9px; }
.dlg-body p { margin: 0; }
.dlg-buttons { display: flex; justify-content: flex-end; gap: 6px; padding: 8px 10px 8px; }
.dlg-buttons button { min-width: 75px; }
.invite-note { padding: 5px 7px; background: #ffffe1; border: 1px solid #000; }
.error { color: #b00000; }

.menu {
  position: fixed;
  z-index: 10;
  min-width: 180px;
  padding: 3px;
  display: flex;
  flex-direction: column;
}
.menu[hidden] { display: none; }
.menu-title { font-weight: bold; padding: 4px 6px; border-bottom: 1px solid var(--mid); margin-bottom: 3px; }
.menu-row { display: flex; align-items: center; gap: 6px; padding: 4px 6px; }
.menu-row input { flex: 1; }
.menu-btn {
  border: 0; box-shadow: none; background: transparent;
  justify-content: flex-start; text-align: left;
}
.menu-btn:hover { background: var(--navy); color: #fff; }
.menu-btn[hidden] { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #ffffe1;
  border: 1px solid #000;
  padding: 6px 12px;
  box-shadow: 2px 2px 0 rgba(0,0,0,.4);
  z-index: 20;
  max-width: calc(100vw - 40px);
}

@media (max-width: 700px) {
  body { padding: 0; align-items: stretch; }
  .window { height: 100vh; height: 100dvh; width: 100%; }
  .main { grid-template-columns: 1fr; grid-template-rows: minmax(140px, 1fr) auto; overflow: auto; }
  .chat { min-height: 220px; }
  .toolbar .field { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .lamp.on { box-shadow: none; }
}
