:root {
  --bg: #f6f8fb;
  --bg-sky: #dfe9f5;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --border: #e1e6ee;
  --text: #16202c;
  --muted: #5b6878;
  --cloud: #ffffff;
  --cloud-edge: #c9d6e6;
  --accent: #0f8a8c;
  --on-accent: #fff;
  --danger: #c93a32;
  --ok: #1e9b61;
  --warn: #d7860b;
  --nick-l: 38%;
  --nick-s: 62%;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shadow: 0 1px 2px rgb(16 24 40 / .05), 0 8px 24px -12px rgb(16 24 40 / .18);
  --input-bar-h: 65px; /* 1px border + 10px + 44px input + 10px */
  color-scheme: light;
}

/* Dark follows the system unless theme.js set data-theme="light"; data-theme="dark"
   forces it. The two blocks hold the same values - keep them in step. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e131a;
    --bg-sky: #16202d;
    --surface: #151c25;
    --surface-2: #1b2430;
    --border: #243040;
    --text: #e7edf4;
    --muted: #93a1b2;
    --cloud: #26344a;
    --cloud-edge: #3a4b63;
    --accent: #45c4c6;
    --on-accent: #07201f;
    --danger: #ff7a73;
    --ok: #4fcb8e;
    --warn: #f2a93b;
    --nick-l: 70%;
    --nick-s: 60%;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 10px 28px -14px rgb(0 0 0 / .6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e131a;
  --bg-sky: #16202d;
  --surface: #151c25;
  --surface-2: #1b2430;
  --border: #243040;
  --text: #e7edf4;
  --muted: #93a1b2;
  --cloud: #26344a;
  --cloud-edge: #3a4b63;
  --accent: #45c4c6;
  --on-accent: #07201f;
  --danger: #ff7a73;
  --ok: #4fcb8e;
  --warn: #f2a93b;
  --nick-l: 70%;
  --nick-s: 60%;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 10px 28px -14px rgb(0 0 0 / .6);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: linear-gradient(180deg, var(--bg-sky) 0, var(--bg) 360px) no-repeat, var(--bg);
  color: var(--text);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

button, input { font: inherit; color: inherit; }

code { font-family: var(--mono); font-size: .9em; }

svg { flex: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --------------------------------------------------------------- connect */

.connect {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px;
}

.hero { padding: 64px 0 28px; text-align: center; }

.hero-cloud {
  width: 76px;
  height: auto;
  margin-bottom: 8px;
  fill: var(--cloud);
  stroke: var(--cloud-edge);
  stroke-width: 1.5;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3.2rem);
  font-weight: 750;
  letter-spacing: -.035em;
  line-height: 1.05;
}

h1 span { color: var(--muted); font-weight: 500; }

.tagline { margin: 14px 0 0; color: var(--muted); font-size: 1.05rem; }
.tagline em { color: var(--text); font-style: normal; font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.connect-card {
  width: 100%;
  max-width: 420px;
  margin-bottom: 32px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 600; font-size: .92rem; }
.field small { color: var(--muted); font-size: .8rem; }

.field input, .join-form input, .input-bar input {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
}

.field input:focus, .join-form input:focus, .input-bar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.check { display: flex; align-items: center; gap: 10px; font-size: .92rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.button {
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 650;
  cursor: pointer;
  transition: filter .15s ease;
}

.button:hover { filter: brightness(1.08); }
.button:disabled { opacity: .6; cursor: progress; }

.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  font-size: .9rem;
}

.server-note { margin: -4px 0 0; text-align: center; color: var(--muted); font-size: .8rem; }

/* Install: under the connect card, only where it can be done (install.js). */
.install { margin: 16px 0; text-align: center; }

.install-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
}

.install-button:hover { border-color: var(--accent); color: var(--accent); }

.install-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.install-hint { max-width: 22rem; margin: 0; text-wrap: balance; color: var(--muted); font-size: .85rem; }
.install-hint b { color: var(--text); font-weight: 600; }
.install-button:not([hidden]) + .install-hint { margin-top: 10px; }

/* The theme switch and the credit footer sit at the bottom of the page. */
.theme-switch {
  display: inline-flex;
  gap: 2px;
  margin: auto 0 16px; /* the card's bottom margin keeps it at least 32px below */
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

/* Same layout as the other normake.com sites: credit left, Ko-fi right,
   stacked and centred when there is no room for both on one line. */
footer.smallprint {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px 24px;
  width: 100%;
  max-width: 720px;
  padding: 16px 0 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .85rem;
}

footer.smallprint p { margin: 0; }

footer.smallprint p a {
  color: var(--text);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 3px;
}

footer.smallprint p a:hover { text-decoration-color: currentColor; }

/* Ko-fi's button, drawn here rather than by their widget script: their
   shape, the site's colours. */
footer.smallprint .ko-fi a.kofi-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: .85rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

footer.smallprint .ko-fi a.kofi-button:hover { border-color: var(--accent); }

.kofi-cup { width: 19px; height: 15px; object-fit: contain; animation: kofi-wiggle 3s infinite; }

@keyframes kofi-wiggle {
  0%, 60% { transform: rotate(0) scale(1); }
  75% { transform: rotate(0) scale(1.12); }
  80% { transform: rotate(0) scale(1.1); }
  84%, 92% { transform: rotate(-10deg) scale(1.1); }
  88%, 96% { transform: rotate(10deg) scale(1.1); }
  100% { transform: rotate(0) scale(1); }
}

@media (max-width: 560px) {
  footer.smallprint { flex-direction: column; text-align: center; }
}

.theme-switch button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
}

.theme-switch button:hover { color: var(--text); }

.theme-switch button[aria-pressed="true"] {
  background: var(--surface-2);
  color: var(--text);
}

.theme-switch svg, .theme-cycle svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------ chat shell */

.chat {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 220px;
  background: var(--bg);
}

.chat.users-hidden { grid-template-columns: 250px minmax(0, 1fr); }
.chat.users-hidden .userlist { display: none; }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 40px;
  height: 40px;
  padding: 0 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
}

.icon-button:hover { background: var(--surface-2); color: var(--text); }

.icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.text-button {
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
}

.text-button:hover { background: var(--surface-2); }

.mobile-only { display: none; }

/* --------------------------------------------------------------- sidebar */

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 60px;
  padding: 0 16px;
  font-weight: 750;
  letter-spacing: -.02em;
  border-bottom: 1px solid var(--border);
}

.brand > svg { width: 30px; fill: var(--cloud); stroke: var(--cloud-edge); stroke-width: 2; }
.brand span span { color: var(--muted); font-weight: 500; }

.brand .theme-cycle { margin-left: auto; margin-right: -8px; min-width: 34px; height: 34px; }
.theme-cycle svg { width: 18px; height: 18px; }
.theme-cycle svg:not(.t-system), .theme-cycle[data-current="light"] .t-system, .theme-cycle[data-current="dark"] .t-system { display: none; }
.theme-cycle[data-current="light"] .t-light, .theme-cycle[data-current="dark"] .t-dark { display: block; }

.sidebar nav { flex: 1; overflow-y: auto; padding: 10px 8px; }

.buffer-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }

.buffer-list .section {
  padding: 12px 10px 4px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.buffer {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: var(--muted);
  font-size: .95rem;
}

.buffer:hover { background: var(--surface-2); color: var(--text); }

.buffer.active {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--text);
  font-weight: 600;
}

.buffer.unread { color: var(--text); font-weight: 600; }
.buffer.parted .buffer-name { opacity: .55; font-style: italic; }

.buffer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}

.badge.highlight { background: var(--accent); color: var(--surface); }

.join-form { display: flex; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--border); }
.join-form input { padding: 7px 10px; }

.me {
  display: flex;
  align-items: center;
  gap: 8px;
  /* Same height as .input-bar so both top borders line up across the page */
  min-height: calc(var(--input-bar-h) + env(safe-area-inset-bottom));
  padding: 10px 12px 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

.me-nick { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 650; }

.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status-dot.connected { background: var(--ok); }
.status-dot.connecting, .status-dot.registering { background: var(--warn); }
.status-dot.closed { background: var(--danger); }

/* ------------------------------------------------------------------ main */

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 60px;
  padding: 8px 12px 8px 20px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.title { flex: 1; min-width: 0; }

.title h2 { margin: 0; font-size: 1.05rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.3; }

.topic {
  margin: 0;
  color: var(--muted);
  font-size: .85rem;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topic.expanded { white-space: normal; }
.topic a { color: var(--accent); text-underline-offset: 2px; }
.topic a.chan { text-decoration: none; font-weight: 600; }

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px;
  background: color-mix(in srgb, var(--warn) 14%, var(--surface));
  border-bottom: 1px solid var(--border);
  font-size: .88rem;
}

.banner span { flex: 1; }

.banner.error { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }

/* ------------------------------------------------------------------- log */

.log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 0 8px;
  font-size: .95rem;
  line-height: 1.5;
}

.log:focus { outline: none; }

.line {
  display: grid;
  grid-template-columns: 3.4rem minmax(0, 1fr);
  padding: 2px 20px 2px 12px;
  overflow-wrap: anywhere;
}

.line:hover { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }

.line time {
  padding-top: .12em;
  color: var(--muted);
  font: .75rem/1.9 var(--mono);
  text-align: right;
  padding-right: 10px;
  opacity: .8;
  user-select: none;
}

.line .nick { font-weight: 650; cursor: pointer; }
.line .nick::after { content: " "; }

.nick-color { color: hsl(var(--hue, 200) var(--nick-s) var(--nick-l)); }

.line.event { color: var(--muted); font-size: .85rem; }
.line.event .content::before { content: "→ "; opacity: .7; }
.line.event.leave .content::before { content: "← "; }
.line.event .nick { font-weight: 600; }

.line.action .content { font-style: italic; }
.line.action .nick::before { content: "* "; }

.line.notice .nick::before { content: "-"; }
.line.notice .nick::after { content: "- "; }
.line.notice .text { color: var(--muted); }

.line.info { color: var(--muted); font-size: .88rem; }
.line.info .text { white-space: pre-wrap; }
.line.motd .text { font-family: var(--mono); font-size: .8rem; white-space: pre-wrap; }

.line.error { color: var(--danger); font-size: .88rem; }

.line.highlight {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.day {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 20px 6px;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 650;
}

.day::before, .day::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

.log a { color: var(--accent); text-underline-offset: 2px; }
.log a.chan { text-decoration: none; font-weight: 600; }
.log a.chan:hover { text-decoration: underline; }

/* mIRC formatting */
.f-b { font-weight: 700; }
.f-i { font-style: italic; }
.f-u { text-decoration: underline; }
.f-s { text-decoration: line-through; }
.f-u.f-s { text-decoration: underline line-through; }
.f-m { font-family: var(--mono); font-size: .9em; }

.empty {
  margin: 40px 24px;
  color: var(--muted);
  text-align: center;
  font-size: .92rem;
}

/* ----------------------------------------------------------------- input */

.input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: calc(var(--input-bar-h) + env(safe-area-inset-bottom));
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.input-bar input { height: 44px; }
.input-bar .send { color: var(--accent); }

/* -------------------------------------------------------------- userlist */

.userlist {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.userlist h3 {
  display: flex;
  align-items: center;
  height: 60px;
  margin: 0;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.userlist ul { flex: 1; list-style: none; margin: 0; padding: 8px; overflow-y: auto; }

.userlist li button {
  display: flex;
  gap: 2px;
  width: 100%;
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-size: .9rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.userlist li button:hover { background: var(--surface-2); }
.userlist .prefix { width: 1ch; color: var(--muted); font-family: var(--mono); font-weight: 700; }
.userlist .away { opacity: .5; }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgb(0 0 0 / .35);
}

/* ---------------------------------------------------------------- narrow */

@media (max-width: 1180px) {
  .chat, .chat.users-hidden { grid-template-columns: 250px minmax(0, 1fr); }
  .chat .userlist {
    display: flex;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    width: min(280px, 85vw);
    box-shadow: var(--shadow);
    transform: translateX(100%);
    transition: transform .2s ease;
  }
  .chat.users-open .userlist { transform: none; }
}

@media (max-width: 820px) {
  .chat, .chat.users-hidden { grid-template-columns: minmax(0, 1fr); }
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 30;
    width: min(290px, 85vw);
    box-shadow: var(--shadow);
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .chat.sidebar-open .sidebar { transform: none; }
  .topbar { padding-left: 8px; }
  .line { padding-right: 12px; padding-left: 4px; grid-template-columns: 3rem minmax(0, 1fr); }
  .line time { padding-right: 8px; }
  .hero { padding-top: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .chat .userlist { transition: none; }
  .kofi-cup { animation: none; }
}
