:root {
  color-scheme: dark;
  --bg-deep: #0d0f15;
  --bg-rail: #10121a;
  --bg-sidebar: #171a23;
  --bg-chat: #1e212c;
  --bg-elevated: #252936;
  --bg-hover: #2b3040;
  --line: rgba(255, 255, 255, 0.075);
  --text: #f4f6fb;
  --muted: #9da5b6;
  --faint: #6f7789;
  --accent: #29358f;
  --accent-bright: #3f4fb5;
  --cyan: #ffc62b;
  --brand-red: #ef003c;
  --green: #3bd6a0;
  --danger: #ff647c;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; min-height: 100%; margin: 0; }
body { overflow: hidden; background: var(--bg-deep); color: var(--text); -webkit-tap-highlight-color: transparent; }
button, input, textarea { font: inherit; }
button { color: inherit; touch-action: manipulation; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.hidden { display: none !important; }
.mobile-only { display: none !important; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

.auth-screen {
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  display: grid;
  overflow-y: auto;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 18%, rgba(41, 53, 143, 0.36), transparent 34%),
    radial-gradient(circle at 82% 75%, rgba(239, 0, 60, 0.18), transparent 31%),
    radial-gradient(circle at 72% 12%, rgba(255, 198, 43, 0.1), transparent 20%),
    linear-gradient(145deg, #111520 0%, #090b10 100%);
}

.auth-screen::before, .auth-screen::after {
  content: "";
  position: fixed;
  width: 320px;
  height: 320px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 50%;
}
.auth-screen::before { top: -130px; right: -80px; box-shadow: 0 0 0 48px rgba(255,255,255,.012), 0 0 0 96px rgba(255,255,255,.008); }
.auth-screen::after { bottom: -190px; left: -50px; box-shadow: 0 0 0 60px rgba(255,255,255,.01); }

.auth-card {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  padding: 38px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 26px;
  background: rgba(24, 27, 38, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.eyebrow { margin: 0 0 7px; color: var(--cyan); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
.auth-logo-frame { position: relative; width: min(235px, 88%); height: auto; aspect-ratio: 988 / 837; margin: -2px auto 16px; overflow: hidden; }
.auth-logo { position: absolute; top: -23.059%; left: -12.956%; display: block; width: 126.923%; max-width: none; height: auto; filter: drop-shadow(0 16px 32px rgba(0,0,0,.3)); }
.auth-subtitle { margin: 5px 0 28px; color: var(--muted); line-height: 1.55; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 22px; border-radius: 12px; background: #11141c; }
.auth-tab { padding: 10px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 750; }
.auth-tab.active { background: var(--bg-elevated); color: var(--text); box-shadow: 0 4px 18px rgba(0,0,0,.2); }
.auth-form { display: grid; gap: 16px; }
.field { display: grid; gap: 8px; }
.field span { color: #c5cad5; font-size: 12px; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; }
.field input { width: 100%; padding: 13px 14px; border: 1px solid var(--line); border-radius: 11px; background: #11141c; color: var(--text); }
.field input::placeholder { color: #626a7b; }
.primary-button { min-height: 48px; margin-top: 4px; border: 0; border-radius: 11px; background: linear-gradient(135deg, var(--accent), var(--brand-red)); color: white; cursor: pointer; font-weight: 800; box-shadow: 0 10px 26px rgba(41,53,143,.3); }
.primary-button:hover { filter: brightness(1.08); }
.primary-button:disabled { opacity: .6; cursor: wait; }
.form-message { min-height: 20px; margin: -4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.form-message.error { color: #ff9aaa; }
.form-message.success { color: var(--green); }

.app { display: grid; grid-template-columns: 76px 260px minmax(0, 1fr) 230px; width: 100%; height: 100vh; height: 100dvh; min-width: 0; min-height: 0; overflow: hidden; }
.server-rail { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 14px 10px; background: var(--bg-rail); border-right: 1px solid var(--line); }
.server-button { position: relative; width: 48px; height: 48px; overflow: hidden; border: 0; border-radius: 16px; background: #242837; color: #dfe3ec; cursor: pointer; font-weight: 850; transition: .18s ease; }
.server-button:hover, .server-button.active { border-radius: 13px; background: var(--accent); color: white; }
.server-button.home { background: #f8f9fd; box-shadow: 0 7px 20px rgba(0,0,0,.24); }
.server-button.home img { position: absolute; top: 0; left: -12px; width: 72px; height: 72px; max-width: none; clip-path: inset(0 0 40% 0); }
.rail-divider { width: 32px; height: 1px; background: var(--line); }
.server-list { display: grid; gap: 10px; }

.channel-sidebar { position: relative; display: flex; min-width: 0; flex-direction: column; background: var(--bg-sidebar); border-right: 1px solid var(--line); }
.server-header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); box-shadow: 0 7px 18px rgba(0,0,0,.08); }
.server-header h2 { max-width: 190px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.server-header .eyebrow { margin-bottom: 3px; font-size: 9px; }
.channels { flex: 1; min-height: 0; overflow-y: auto; padding: 18px 10px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.channels section + section { margin-top: 26px; }
.section-label { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 7px; color: var(--faint); font-size: 10px; font-weight: 850; letter-spacing: .1em; }
.channel-list { display: grid; gap: 2px; }
.channel-button { display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; padding: 9px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; text-align: left; }
.channel-button:hover { background: rgba(255,255,255,.045); color: #dce0e9; }
.channel-button.active { background: var(--bg-hover); color: white; }
.channel-glyph { width: 18px; color: var(--faint); font-size: 18px; font-weight: 650; text-align: center; }
.channel-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }

.voice-panel { padding: 13px; border-top: 1px solid var(--line); background: rgba(59,214,160,.035); }
.voice-state { display: flex; align-items: center; gap: 9px; }
.voice-state strong { display: block; color: var(--green); font-size: 12px; }
.voice-state small { color: var(--muted); }
.voice-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 12px rgba(59,214,160,.7); }
.voice-participants { display: grid; gap: 4px; max-height: 94px; overflow-y: auto; margin: 10px 0; }
.voice-person { display: flex; align-items: center; gap: 7px; color: #cfd4de; font-size: 12px; }
.mini-avatar { display: grid; width: 22px; height: 22px; place-items: center; border-radius: 50%; font-size: 9px; font-weight: 850; }
.voice-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.control-button { padding: 7px 5px; border: 1px solid var(--line); border-radius: 8px; background: #20242f; color: var(--muted); cursor: pointer; font-size: 11px; font-weight: 750; }
.control-button[aria-pressed="true"] { background: rgba(255,100,124,.12); color: #ff9aaa; border-color: rgba(255,100,124,.22); }
.control-button.danger:hover { background: var(--danger); color: white; }
.account-bar { min-height: 62px; display: flex; align-items: center; gap: 9px; padding: 10px; border-top: 1px solid var(--line); background: #12151d; }
.avatar { display: grid; width: 35px; height: 35px; flex: 0 0 auto; place-items: center; border-radius: 50%; background: var(--accent); color: white; font-weight: 850; }
.account-copy { min-width: 0; flex: 1; }
.account-copy strong, .account-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-copy strong { font-size: 12px; }
.account-copy small { margin-top: 2px; color: var(--green); font-size: 10px; }
.icon-button { display: grid; width: 34px; height: 34px; flex: 0 0 auto; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; }
.icon-button:hover { background: var(--bg-hover); color: white; }

.chat-panel { display: grid; min-width: 0; min-height: 0; grid-template-rows: 72px minmax(0, 1fr) auto; background: var(--bg-chat); }
.chat-header { display: flex; align-items: center; gap: 13px; min-width: 0; padding: 0 22px; border-bottom: 1px solid var(--line); background: rgba(30,33,44,.94); }
.channel-symbol { color: var(--faint); font-size: 26px; font-weight: 500; }
.chat-heading { min-width: 0; flex: 1; display: flex; align-items: baseline; gap: 14px; }
.chat-heading h2 { margin: 0; font-size: 15px; }
.chat-heading p { min-width: 0; margin: 0; padding-left: 14px; border-left: 1px solid var(--line); color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.connection-pill { display: flex; align-items: center; gap: 7px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 10px; font-weight: 750; }
.connection-pill span:first-child { width: 6px; height: 6px; border-radius: 50%; background: #f6b93b; }
.connection-pill.online span:first-child { background: var(--green); }
.connection-pill.error span:first-child { background: var(--danger); }

.message-scroller { min-height: 0; overflow-y: auto; padding: 24px 24px 8px; scrollbar-color: #101219 transparent; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.channel-welcome { padding: 38px 10px 24px; }
.welcome-icon { display: grid; width: 58px; height: 58px; place-items: center; border-radius: 18px; background: linear-gradient(145deg, var(--accent), var(--brand-red)); box-shadow: 0 14px 28px rgba(41,53,143,.24); font-size: 28px; font-weight: 750; }
.channel-welcome h2 { margin: 17px 0 5px; font-size: 28px; letter-spacing: -.025em; }
.channel-welcome h2 span { color: var(--accent-bright); }
.channel-welcome p { margin: 0; color: var(--muted); }
.message-list { display: grid; }
.message { display: grid; grid-template-columns: 42px minmax(0,1fr); gap: 12px; padding: 8px 10px; border-radius: 9px; }
.message:hover { background: rgba(0,0,0,.09); }
.message-avatar { display: grid; width: 40px; height: 40px; place-items: center; border-radius: 50%; color: white; font-size: 13px; font-weight: 850; }
.message-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.message-meta strong { font-size: 14px; }
.message-meta time { color: var(--faint); font-size: 10px; }
.message-content { margin: 0; color: #d9dde7; font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; white-space: pre-wrap; }
.empty-state { padding: 10px; color: var(--faint); font-size: 13px; }

.message-composer { display: flex; align-items: end; gap: 10px; padding: 10px 22px 20px; }
.composer-shell { display: flex; min-width: 0; flex: 1; align-items: center; gap: 10px; min-height: 48px; padding: 8px 12px; border: 1px solid transparent; border-radius: 13px; background: var(--bg-elevated); }
.composer-shell:focus-within { border-color: rgba(41,53,143,.58); box-shadow: 0 0 0 3px rgba(41,53,143,.12); }
.composer-plus { display: grid; width: 25px; height: 25px; flex: 0 0 auto; place-items: center; border-radius: 50%; background: #737b8c; color: #20232c; font-size: 18px; font-weight: 800; }
.composer-shell textarea { min-height: 24px; max-height: 130px; flex: 1; resize: none; border: 0; outline: none; background: transparent; color: var(--text); line-height: 1.45; }
.composer-shell textarea::placeholder { color: #7d8494; }
.character-count { align-self: flex-end; color: var(--faint); font-size: 9px; }
.send-button { height: 48px; padding: 0 18px; border: 0; border-radius: 12px; background: var(--accent); color: white; cursor: pointer; font-size: 12px; font-weight: 800; }
.send-button:hover { background: var(--accent-bright); }

.member-sidebar { display: flex; min-width: 0; flex-direction: column; padding: 24px 14px 14px; background: #191c25; border-left: 1px solid var(--line); }
.member-heading { display: flex; justify-content: space-between; padding: 0 8px 10px; color: var(--faint); font-size: 10px; font-weight: 850; letter-spacing: .1em; }
.member-list { flex: 1; min-height: 0; overflow-y: auto; }
.member { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 9px; color: #c7ccd7; font-size: 12px; font-weight: 650; }
.member:hover { background: rgba(255,255,255,.035); }
.member-avatar-wrap { position: relative; }
.member-avatar-wrap::after { content: ""; position: absolute; right: -1px; bottom: -1px; width: 7px; height: 7px; border: 2px solid #191c25; border-radius: 50%; background: var(--green); }
.member-note { display: flex; gap: 9px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: rgba(77,216,208,.035); }
.member-note p { margin: 0; color: var(--faint); font-size: 10px; line-height: 1.45; }
.member-note strong { color: var(--muted); }
.status-orb { width: 8px; height: 8px; flex: 0 0 auto; margin-top: 3px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 12px rgba(77,216,208,.5); }
.toast { position: fixed; z-index: 50; right: 22px; bottom: 22px; max-width: min(360px, calc(100vw - 44px)); padding: 12px 16px; border: 1px solid var(--line); border-radius: 11px; background: #0f121a; box-shadow: var(--shadow); color: #dfe3eb; font-size: 12px; opacity: 0; pointer-events: none; transform: translateY(12px); transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.sidebar-backdrop { display: none; }

@media (min-width: 1500px) {
  .app { grid-template-columns: 80px 280px minmax(0, 1fr) 260px; }
  .server-button { width: 50px; height: 50px; }
  .message-scroller { padding-inline: clamp(28px, 4vw, 64px); }
  .message-composer { padding-inline: clamp(28px, 4vw, 64px); }
}

@media (max-width: 1180px) {
  .app { grid-template-columns: 72px 250px minmax(0, 1fr); }
  .member-sidebar { display: none; }
}

@media (max-width: 820px) {
  .mobile-only { display: grid !important; }
  .app { grid-template-columns: 64px minmax(0, 1fr); }
  .server-rail { position: relative; z-index: 20; padding-inline: 7px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .server-button { width: 46px; height: 46px; }
  .channel-sidebar { position: fixed; z-index: 30; top: 0; bottom: 0; left: 64px; width: min(310px, calc(100vw - 64px)); padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); transform: translateX(-110%); box-shadow: 22px 0 52px rgba(0,0,0,.46); transition: transform .22s ease; }
  .channel-sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; z-index: 25; inset: 0; display: block; border: 0; background: rgba(4,6,12,.68); opacity: 0; pointer-events: none; transition: opacity .22s ease; }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
  .chat-panel { grid-column: 2; }
  .chat-heading p { display: none; }
  .chat-header { min-height: 64px; padding: env(safe-area-inset-top) 14px 0; }
  .icon-button { width: 44px; height: 44px; }
  .channel-button { min-height: 44px; }
  .control-button { min-height: 42px; }
  .message-scroller { padding-inline: 12px; }
  .message-composer { padding: 8px 10px max(12px, env(safe-area-inset-bottom)); }
  .character-count { display: none; }
  .send-button { width: 48px; min-width: 48px; overflow: hidden; padding: 0; font-size: 0; }
  .send-button::after { content: "↑"; font-size: 19px; }
  .toast { right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); max-width: calc(100vw - 24px); }
}

@media (max-width: 560px) {
  .auth-screen { place-items: start center; padding: max(14px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom)); }
  .auth-card { width: 100%; padding: 24px 20px; border-radius: 20px; }
  .auth-logo-frame { width: min(220px, 82%); margin-bottom: 12px; }
  .auth-subtitle { margin-bottom: 22px; font-size: 14px; }
  .auth-tabs { margin-bottom: 18px; }
  .field input { min-height: 48px; font-size: 16px; }
  .primary-button { min-height: 50px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .server-rail { display: none; }
  .channel-sidebar { left: 0; width: min(320px, 88vw); }
  .chat-panel { grid-column: 1; }
  .chat-header { padding-inline: 8px 12px; }
  .channel-symbol { display: none; }
  .connection-pill { padding-inline: 8px; }
  .connection-label { display: none; }
  .channel-welcome { padding: 24px 4px 18px; }
  .channel-welcome h2 { font-size: clamp(21px, 7vw, 25px); }
  .channel-welcome p { font-size: 13px; }
  .message { grid-template-columns: 34px minmax(0,1fr); gap: 9px; padding-inline: 3px; }
  .message-avatar { width: 34px; height: 34px; }
  .message-meta { flex-wrap: wrap; row-gap: 1px; }
  .message-content { font-size: 14px; }
  .composer-plus { display: none; }
  .composer-shell { padding-inline: 11px; }
}

@media (max-width: 360px) {
  .auth-card { padding-inline: 16px; }
  .auth-tab { padding-inline: 6px; font-size: 13px; }
  .chat-heading { gap: 6px; }
  .chat-header { gap: 6px; }
  .message-scroller { padding-inline: 8px; }
  .message-composer { gap: 6px; padding-inline: 7px; }
  .send-button { width: 44px; min-width: 44px; }
}

@media (max-height: 620px) and (orientation: landscape) and (min-width: 600px) {
  .auth-screen { place-items: start center; padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left)); }
  .auth-card { display: grid; width: min(760px, 100%); grid-template-columns: minmax(190px, .8fr) minmax(320px, 1.2fr); column-gap: 28px; padding: 20px 24px; }
  .auth-card > .eyebrow { grid-column: 1; grid-row: 1; }
  .auth-logo-frame { grid-column: 1; grid-row: 2; width: min(190px, 90%); margin: 0 auto 8px; }
  .auth-subtitle { grid-column: 1; grid-row: 3; margin: 0; font-size: 13px; }
  .auth-tabs { grid-column: 2; grid-row: 1; margin-bottom: 12px; }
  .auth-form { grid-column: 2; grid-row: 2 / span 2; gap: 10px; }
  .field { gap: 5px; }
  .field input { min-height: 44px; padding-block: 9px; }
  .form-message { min-height: 18px; }
  .chat-panel { grid-template-rows: 58px minmax(0, 1fr) auto; }
  .chat-header { min-height: 58px; }
  .channel-sidebar { padding-top: 0; }
  .server-header { min-height: 58px; }
  .channels { padding-block: 10px; }
  .channels section + section { margin-top: 14px; }
  .voice-participants { max-height: 48px; }
  .account-bar { min-height: 54px; }
  .message-scroller { padding-top: 12px; }
  .channel-welcome { padding-top: 12px; }
  .welcome-icon { width: 46px; height: 46px; }
}

@media (hover: none) {
  .channel-button:active, .icon-button:active, .server-button:active { background: var(--bg-hover); }
}

@media (pointer: coarse) {
  .channel-button { min-height: 44px; }
  .icon-button { min-width: 44px; min-height: 44px; }
  .control-button { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
