:root{
  --bg: #0b0d10;
  --bg-2: #121418;
  --panel: #161a20;
  --border: #2a2f36;
  --fg: #d6d6d6;
  --fg-dim: #9aa4b2;
  --link: #6aa9ff;
  --green: #8bc34a;
  --blue: #67d4ff;
  --yellow: #ffc857;
  --nick-self: #67d4ff;
  --nick-other: #8bc34a;
  --nick-system: #9aa4b2;
  --ts: #586273;
}

body{
  margin:0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.35;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 10px;
  box-sizing: border-box;
}

#chat{
  width: min(960px, 100%);
  margin: auto;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: min(820px, 95vh);
  max-height: 95vh;
  box-shadow: 0 10px 26px rgba(0,0,0,0.35);
}

#topicBar{
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  color: var(--fg-dim);
}
#topicBar .chan { color: var(--yellow); }
#topicBar .sep { color: #3b4654; padding: 0 6px; }
#topicBar .net { color: #7aa2f7; }

#messages{
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  padding: 6px 10px;
  min-height: 0;
}


#messages .row{
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  grid-template-areas:
    "ts nick"
    "text text";
  column-gap: 10px;
  row-gap: 2px;
  margin: 1px 0;
  align-items: baseline;
}

#messages .text{
  color: var(--fg);
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: normal; 
}

#messages .ts{ color: var(--ts); text-align: right; grid-area: ts; white-space: nowrap; padding-right: 2px; }
#messages .nick{ white-space: nowrap; grid-area: nick; padding-left: 2px; }
#messages .text{ grid-area: text; display: block; }


#messages .me .nick { color: var(--nick-self); }
#messages .them .nick { color: var(--nick-other); }
#messages .system .nick { color: var(--nick-system); }
#messages .system .text { color: var(--fg-dim); font-style: italic; }

#inputBar{
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  padding: 10px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
}
input, button{
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 15px;
}
input:focus{ border-color: #3a89ff66; outline:none; }
button{ cursor: pointer; background:#11161c; }
button:hover{ background:#16202a; }
button:active{ background:#0d141c; }
button.danger { background: #1e1418; border-color: #4a2c36; }
button.danger:hover { background: #261820; }
button.danger:active { background: #1a1117; }

#settingsBtn {
  touch-action: manipulation;
  position: relative;
}

#settingsBtn::after {
  position: absolute;
  top: -24px;
  right: 0;
  font-size: 10px;
  color: var(--fg-dim);
  opacity: 0;
  transition: opacity 0.2s ease;
}

#settingsBtn.longPressHint::after {
  opacity: 1;
}

#settingsPanel{
  border-top: 1px solid var(--border);
  padding: 12px 10px 16px;
  background: var(--bg);
  display: grid;
  gap: 10px;
  max-height: min(60vh, 520px);
  overflow-y: auto;
}
.settingsActions {
  border: 1px dashed var(--border);
  padding: 10px;
  border-radius: 8px;
  display: grid;
  gap: 6px;
  align-content: start;
}
.settingsActions .hint {
  color: var(--fg-dim);
  font-size: 12px;
}
.hidden{ display:none !important; }
#byteIndicator {
  font-size: 12px;
  color: #888;
  margin: 4px 8px;
}
#byteIndicator.over {
  color: red;
  font-weight: bold;
}

.toggleRow label, .sliderRow label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.sliderRow {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}

#outputVolume {
  width: 90%;
}

.dangerZone {
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 64, 129, 0.05);
}

.dangerToggle {
  font-weight: bold;
  color: var(--yellow);
}

@media (max-width: 720px) {
  #chat {
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }

  #messages .row{
    grid-template-columns: max-content minmax(0, 1fr);
    grid-template-areas:
      "ts nick"
      "text text";
    row-gap: 4px;
  }

  #messages .ts { text-align: left; }

  #inputBar{
    grid-template-columns: 1fr auto auto;
    gap: 6px;
  }

  input, button{
    font-size: 16px;
  }

  /* Let the content flex to the dynamic viewport so the input stays visible */
  body {
    padding: max(6px, env(safe-area-inset-top, 6px))
             max(6px, env(safe-area-inset-right, 6px))
             max(6px, env(safe-area-inset-bottom, 6px))
             max(6px, env(safe-area-inset-left, 6px));
  }

  #messages {
    min-height: 0;
  }
}
